Compare commits

..

No commits in common. "0a701b55d2709f1093f052df5e6e0fa2f56a8e58" and "1ef1b4ae3056d311bc84dc9709f912b139c6c6b8" have entirely different histories.

10 changed files with 210 additions and 44 deletions

View file

@ -1,23 +1,33 @@
package client.renderer;
import java.util.List;
import java.util.Map;
import client.renderer.blockmodel.IBakedModel;
import client.renderer.blockmodel.ModelManager;
import client.renderer.texture.TextureAtlasSprite;
import common.collect.Lists;
import common.collect.Maps;
import common.init.ItemRegistry;
import common.item.Item;
import common.item.ItemStack;
import common.model.ItemMeshDefinition;
public class ItemModelMesher
{
// private final Map<Integer, ResourceLocation> simpleShapes = Maps.<Integer, ResourceLocation>newHashMap();
private final Map<Integer, IBakedModel> simpleShapesCache = Maps.<Integer, IBakedModel>newHashMap();
private final Map<Item, ItemMeshDefinition> shapers = Maps.<Item, ItemMeshDefinition>newHashMap();
private final ModelManager modelManager;
public ItemModelMesher(ModelManager modelManager)
{
this.modelManager = modelManager;
for(Item item : ItemRegistry.REGISTRY) {
ItemMeshDefinition mesher = item.getMesher();
if(mesher != null)
this.shapers.put(item, mesher);
}
}
public TextureAtlasSprite getParticleIcon(Item item)
@ -30,6 +40,16 @@ public class ItemModelMesher
Item item = stack.getItem();
IBakedModel ibakedmodel = this.simpleShapesCache.get(this.getIndex(item));
if (ibakedmodel == null)
{
ItemMeshDefinition itemmeshdefinition = this.shapers.get(item);
if (itemmeshdefinition != null)
{
ibakedmodel = this.modelManager.getModel(itemmeshdefinition.getModelLocation(stack));
}
}
if (ibakedmodel == null)
{
ibakedmodel = this.modelManager.getMissingModel();
@ -90,10 +110,22 @@ public class ItemModelMesher
public void rebuildCache()
{
this.simpleShapesCache.clear();
List<ItemStack> stacks = Lists.newArrayList();
for(Item item : ItemRegistry.REGISTRY) {
this.simpleShapesCache.put(this.getIndex(item),
this.modelManager.getModel("item/" +
ItemRegistry.getNameFromItem(item).toString()));
if(this.shapers.containsKey(item))
continue;
item.getRenderItems(item, stacks);
for(ItemStack stack : stacks) {
this.simpleShapesCache.put(this.getIndex(item),
this.modelManager.getModel("item/" +
ItemRegistry.getNameFromItem(item).toString() + '#' + "inventory"));
}
stacks.clear();
}
// for (Entry<Integer, ResourceLocation> entry : this.simpleShapes.entrySet())
// {
// this.simpleShapesCache.put(entry.getKey(), this.modelManager.getModel((ResourceLocation)entry.getValue()));
// }
}
}

View file

@ -36,7 +36,7 @@ public abstract class ModelBakery
"blocks/destroy_stage_8", "blocks/destroy_stage_9",
"items/empty_armor_slot_helmet", "items/empty_armor_slot_chestplate",
"items/empty_armor_slot_leggings", "items/empty_armor_slot_boots");
protected static final String MISSING = "builtin/missing";
protected static final String MISSING = "builtin/missing" + '#' + "missing";
public static final ModelBlock MODEL_GENERATED = (ModelBlock)new ModelBlock(null).add().d("");
public static final ModelBlock MODEL_ENTITY = (ModelBlock)new ModelBlock(null).add().d("");
@ -134,6 +134,7 @@ public abstract class ModelBakery
// variants.add(res);
// RenderRegistry.registerVariants(variantNames);
List<ItemStack> stacks = Lists.newArrayList();
for (Item item : ItemRegistry.REGISTRY)
{
// List<Integer> list = variantNames.get(item);
@ -141,17 +142,13 @@ public abstract class ModelBakery
// list = Collections.<Integer>singletonList(0);
// for(Integer s : list)
// {
String loc = "item/" + ItemRegistry.getNameFromItem(item);
models.put(loc, (ModelBlock)item.getModel(ModelBlock.PROVIDER, ItemRegistry.getNameFromItem(item)));
itemLocations.add(loc);
String[] extra = item.getSprites();
if(extra != null) {
for(String sprite : extra) {
loc = "item/" + sprite;
models.put(loc, (ModelBlock)ModelBlock.PROVIDER.getModel(item.getTransform(), sprite));
itemLocations.add(loc);
}
}
item.getRenderItems(item, stacks);
for(ItemStack stack : stacks) {
String resourcelocation = "item/" + ItemRegistry.getNameFromItem(item).toString() + '#' + "inventory";
models.put(resourcelocation, (ModelBlock)item.getModel(ModelBlock.PROVIDER, ItemRegistry.getNameFromItem(item).toString()));
itemLocations.add(resourcelocation);
}
stacks.clear();
}
final Set<String> set = Sets.<String>newHashSet();

View file

@ -226,9 +226,34 @@ public class RenderItem
{
EntityNPC entityplayer = (EntityNPC)entityToRenderFor;
Item item = stack.getItem();
String sprite = item == null ? null : item.getSprite(entityplayer, stack);
if(sprite != null)
ibakedmodel = this.itemModelMesher.getModelManager().getModel("item/" + sprite);
String modelresourcelocation = null;
if (item == Items.fishing_rod && entityplayer.fishEntity != null)
{
modelresourcelocation = "item/fishing_rod_cast" + '#' + "inventory";
}
else if (item == Items.bow && entityplayer.getItemInUse() != null)
{
int i = stack.getMaxItemUseDuration() - entityplayer.getItemInUseCount();
if (i >= 18)
{
modelresourcelocation = "item/bow_pulling_3" + '#' + "inventory";
}
else if (i > 13)
{
modelresourcelocation = "item/bow_pulling_2" + '#' + "inventory";
}
else if (i > 0)
{
modelresourcelocation = "item/bow_pulling_1" + '#' + "inventory";
}
}
if (modelresourcelocation != null)
{
ibakedmodel = this.itemModelMesher.getModelManager().getModel(modelresourcelocation);
}
}
this.renderItemModelTransform(stack, ibakedmodel, cameraTransformType);

View file

@ -11,6 +11,7 @@ import common.collect.Sets;
import common.color.TextColor;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving;
import common.model.ItemMeshDefinition;
import common.model.Model;
import common.model.ModelProvider;
import common.model.Transforms;
@ -292,11 +293,11 @@ public class Item
return provider.getModel(this.getTransform(), name);
}
public String[] getSprites() {
public ItemMeshDefinition getMesher() {
return null;
}
public String getSprite(EntityNPC player, ItemStack stack) {
return null;
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
subItems.add(new ItemStack(itemIn));
}
}

View file

@ -8,6 +8,7 @@ import common.color.DyeColor;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.init.Items;
import common.model.ItemMeshDefinition;
import common.model.Model;
import common.model.ModelProvider;
import common.tags.TagObject;
@ -177,6 +178,44 @@ public class ItemBanner extends ItemBlock
return enumdyecolor;
}
// protected boolean validateNbt(NBTTagCompound tag) {
// if(tag.hasKey("BlockEntityTag")) {
// if(!tag.hasTag("BlockEntityTag")) {
// return false;
// }
// NBTTagCompound etag = tag.getCompoundTag("BlockEntityTag");
// if(etag.hasKey("Patterns")) {
// if(!etag.hasList("Patterns")) {
// return false;
// }
// NBTTagList patterns = etag.getTagList("Patterns", 10);
// if(patterns.tagCount() > 16) {
// NBTTagList npatterns = new NBTTagList();
// for(int z = 0; z < 16; z++) {
// npatterns.appendTag(patterns.get(z));
// }
// etag.setTag("Patterns", npatterns);
// }
// }
// if(etag.hasKey("Base")) {
// if(!etag.hasInt("Base")) {
// return false;
// }
// }
// }
// return true;
// }
public ItemMeshDefinition getMesher() {
return new ItemMeshDefinition()
{
public String getModelLocation(ItemStack stack)
{
return "item/banner" + '#' + "inventory";
}
};
}
public Model getModel(ModelProvider provider, String name) {
return provider.getModel(provider.getEntityModel(), this.getTransform());
}

View file

@ -1,7 +1,6 @@
package common.item;
import java.util.List;
import java.util.Map;
import common.enchantment.Enchantment;
import common.enchantment.EnchantmentHelper;
@ -138,21 +137,16 @@ public class ItemBow extends Item
return 1;
}
public String[] getSprites() {
return new String[] {"bow_pulling_0", "bow_pulling_1", "bow_pulling_2"};
}
public String getSprite(EntityNPC player, ItemStack stack) {
if(player.getItemInUse() != null) {
int pull = stack.getMaxItemUseDuration() - player.getItemInUseCount();
if(pull >= 18)
return "bow_pulling_2";
else if(pull > 13)
return "bow_pulling_1";
else if(pull > 0)
return "bow_pulling_0";
}
return null;
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
super.getRenderItems(itemIn, subItems);
for(int z = 0; z < 3; z++) {
final int data = z + 1;
subItems.add(new ItemStack(new ItemBow() {
public Model getModel(ModelProvider provider, String name) {
return provider.getModel(this.getTransform(), "bow_pulling_" + data);
}
}));
}
}
public Transforms getTransform() {

View file

@ -9,6 +9,7 @@ import common.enchantment.EnchantmentHelper;
import common.enchantment.RngEnchantment;
import common.entity.npc.EntityNPC;
import common.init.Items;
import common.model.ItemMeshDefinition;
import common.rng.Random;
import common.tags.TagObject;
@ -145,4 +146,58 @@ public class ItemEnchantedBook extends Item
EnchantmentHelper.addRandomEnchantment(rand, itemstack, 30);
return new RngLoot(itemstack, minChance, maxChance, weight);
}
// public Set<String> getValidTags() {
// return Sets.newHashSet("StoredEnchantments");
// }
//
// protected boolean validateNbt(NBTTagCompound tag) {
// if(tag.hasKey("StoredEnchantments")) {
// if(!tag.hasList("StoredEnchantments")) {
// return false;
// }
// NBTTagList ench = tag.getTagList("StoredEnchantments", 10);
// if(ench.hasNoTags()) {
// return false;
// }
// if(ench.tagCount() > Enchantment.getNames().size()) {
// return false;
// }
// Enchantment[] ecn = new Enchantment[ench.tagCount()];
// for(int e = 0; e < ench.tagCount(); e++) {
// NBTTagCompound ec = ench.getCompoundTagAt(e);
// if(ec.getKeySet().size() != 2 || !ec.hasShort("id") || !ec.hasShort("lvl")) {
// return false;
// }
// int id = ec.getShort("id");
// int lvl = ec.getShort("lvl");
// Enchantment en = Enchantment.getEnchantmentById(id);
// if(en == null) {
// return false;
// }
//// if(!adv && (lvl < en.getMinLevel() || lvl > en.getMaxLevel())) {
//// return false;
//// }
// ecn[e] = en;
// }
// for(int e = 0; e < ecn.length; e++) {
// for(int f = 0; f < ecn.length; f++) {
// if(f != e && ecn[e] == ecn[f]) {
// return false;
// }
// }
// }
// }
// return true;
// }
public ItemMeshDefinition getMesher() {
return new ItemMeshDefinition()
{
public String getModelLocation(ItemStack stack)
{
return "item/enchanted_book" + '#' + "inventory";
}
};
}
}

View file

@ -1,7 +1,6 @@
package common.item;
import java.util.List;
import java.util.Map;
import common.entity.npc.EntityNPC;
import common.entity.projectile.EntityHook;
@ -79,12 +78,13 @@ public class ItemFishingRod extends Item
return 1;
}
public String[] getSprites() {
return new String[] {"fishing_rod_cast"};
}
public String getSprite(EntityNPC player, ItemStack stack) {
return player.fishEntity != null ? "fishing_rod_cast" : null;
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
super.getRenderItems(itemIn, subItems);
subItems.add(new ItemStack(new ItemFishingRod() {
public Model getModel(ModelProvider provider, String name) {
return provider.getModel(this.getTransform(), "fishing_rod_cast");
}
}));
}
public Transforms getTransform() {

View file

@ -11,6 +11,7 @@ import common.entity.npc.EntityNPC;
import common.entity.projectile.EntityPotion;
import common.init.Items;
import common.init.SoundEvent;
import common.model.ItemMeshDefinition;
import common.model.Model;
import common.model.ModelProvider;
import common.potion.Potion;
@ -341,6 +342,21 @@ public class ItemPotion extends Item
return data;
}
public ItemMeshDefinition getMesher() {
return new ItemMeshDefinition()
{
public String getModelLocation(ItemStack stack)
{
return ItemPotion.this.isSplashPotion() ? ("item/splash_potion" + '#' + "inventory") : ("item/potion" + '#' + "inventory");
}
};
}
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
if(this.data == 0 || this.data == 16384)
super.getRenderItems(itemIn, subItems);
}
public Model getModel(ModelProvider provider, String name) {
return provider.getModel(this.getTransform(), "potion_overlay", this.isSplashPotion() ? "potion_bottle_splash" : "potion_bottle_drinkable");
}

View file

@ -0,0 +1,7 @@
package common.model;
import common.item.ItemStack;
public interface ItemMeshDefinition {
String getModelLocation(ItemStack stack);
}