diff --git a/client/src/main/java/client/renderer/ItemModelMesher.java b/client/src/main/java/client/renderer/ItemModelMesher.java index a9f58e4d..b8402af6 100755 --- a/client/src/main/java/client/renderer/ItemModelMesher.java +++ b/client/src/main/java/client/renderer/ItemModelMesher.java @@ -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 simpleShapes = Maps.newHashMap(); private final Map simpleShapesCache = Maps.newHashMap(); + private final Map shapers = Maps.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 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 entry : this.simpleShapes.entrySet()) +// { +// this.simpleShapesCache.put(entry.getKey(), this.modelManager.getModel((ResourceLocation)entry.getValue())); +// } } } diff --git a/client/src/main/java/client/renderer/blockmodel/ModelBakery.java b/client/src/main/java/client/renderer/blockmodel/ModelBakery.java index 9d39bd0a..2e581db0 100755 --- a/client/src/main/java/client/renderer/blockmodel/ModelBakery.java +++ b/client/src/main/java/client/renderer/blockmodel/ModelBakery.java @@ -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 stacks = Lists.newArrayList(); for (Item item : ItemRegistry.REGISTRY) { // List list = variantNames.get(item); @@ -141,17 +142,13 @@ public abstract class ModelBakery // list = Collections.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 set = Sets.newHashSet(); diff --git a/client/src/main/java/client/renderer/entity/RenderItem.java b/client/src/main/java/client/renderer/entity/RenderItem.java index e1d04bfa..5d10f719 100755 --- a/client/src/main/java/client/renderer/entity/RenderItem.java +++ b/client/src/main/java/client/renderer/entity/RenderItem.java @@ -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); diff --git a/common/src/main/java/common/item/Item.java b/common/src/main/java/common/item/Item.java index 2a04dc25..7b579e97 100755 --- a/common/src/main/java/common/item/Item.java +++ b/common/src/main/java/common/item/Item.java @@ -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 subItems) { + subItems.add(new ItemStack(itemIn)); } } diff --git a/common/src/main/java/common/item/ItemBanner.java b/common/src/main/java/common/item/ItemBanner.java index 08010f31..1020ecfb 100755 --- a/common/src/main/java/common/item/ItemBanner.java +++ b/common/src/main/java/common/item/ItemBanner.java @@ -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; @@ -176,6 +177,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()); diff --git a/common/src/main/java/common/item/ItemBow.java b/common/src/main/java/common/item/ItemBow.java index b33f610c..86181393 100755 --- a/common/src/main/java/common/item/ItemBow.java +++ b/common/src/main/java/common/item/ItemBow.java @@ -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 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() { diff --git a/common/src/main/java/common/item/ItemEnchantedBook.java b/common/src/main/java/common/item/ItemEnchantedBook.java index 762d62e8..b857cde1 100755 --- a/common/src/main/java/common/item/ItemEnchantedBook.java +++ b/common/src/main/java/common/item/ItemEnchantedBook.java @@ -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 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"; + } + }; + } } diff --git a/common/src/main/java/common/item/ItemFishingRod.java b/common/src/main/java/common/item/ItemFishingRod.java index ce607e47..601c30ba 100755 --- a/common/src/main/java/common/item/ItemFishingRod.java +++ b/common/src/main/java/common/item/ItemFishingRod.java @@ -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 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() { diff --git a/common/src/main/java/common/item/ItemPotion.java b/common/src/main/java/common/item/ItemPotion.java index 70faf0cf..8aba65f0 100755 --- a/common/src/main/java/common/item/ItemPotion.java +++ b/common/src/main/java/common/item/ItemPotion.java @@ -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; @@ -340,6 +341,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 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"); diff --git a/common/src/main/java/common/model/ItemMeshDefinition.java b/common/src/main/java/common/model/ItemMeshDefinition.java new file mode 100755 index 00000000..354f27fe --- /dev/null +++ b/common/src/main/java/common/model/ItemMeshDefinition.java @@ -0,0 +1,7 @@ +package common.model; + +import common.item.ItemStack; + +public interface ItemMeshDefinition { + String getModelLocation(ItemStack stack); +}