fix item sprites
This commit is contained in:
parent
1ef1b4ae30
commit
5c0e71f80c
10 changed files with 43 additions and 209 deletions
|
@ -1,33 +1,23 @@
|
|||
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)
|
||||
|
@ -40,16 +30,6 @@ 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();
|
||||
|
@ -110,22 +90,10 @@ public class ItemModelMesher
|
|||
public void rebuildCache()
|
||||
{
|
||||
this.simpleShapesCache.clear();
|
||||
List<ItemStack> stacks = Lists.newArrayList();
|
||||
for(Item item : ItemRegistry.REGISTRY) {
|
||||
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();
|
||||
this.simpleShapesCache.put(this.getIndex(item),
|
||||
this.modelManager.getModel("item/" +
|
||||
ItemRegistry.getNameFromItem(item).toString() + '#' + "inventory"));
|
||||
}
|
||||
|
||||
// for (Entry<Integer, ResourceLocation> entry : this.simpleShapes.entrySet())
|
||||
// {
|
||||
// this.simpleShapesCache.put(entry.getKey(), this.modelManager.getModel((ResourceLocation)entry.getValue()));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,6 @@ 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);
|
||||
|
@ -142,13 +141,17 @@ public abstract class ModelBakery
|
|||
// list = Collections.<Integer>singletonList(0);
|
||||
// for(Integer s : list)
|
||||
// {
|
||||
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();
|
||||
String loc = "item/" + ItemRegistry.getNameFromItem(item) + '#' + "inventory";
|
||||
models.put(loc, (ModelBlock)item.getModel(ModelBlock.PROVIDER, ItemRegistry.getNameFromItem(item)));
|
||||
itemLocations.add(loc);
|
||||
String[] extra = item.getRenderItems();
|
||||
if(extra != null) {
|
||||
for(String sprite : extra) {
|
||||
loc = "item/" + sprite + '#' + "inventory";
|
||||
models.put(loc, (ModelBlock)ModelBlock.PROVIDER.getModel(item.getTransform(), sprite));
|
||||
itemLocations.add(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Set<String> set = Sets.<String>newHashSet();
|
||||
|
|
|
@ -226,34 +226,9 @@ public class RenderItem
|
|||
{
|
||||
EntityNPC entityplayer = (EntityNPC)entityToRenderFor;
|
||||
Item item = stack.getItem();
|
||||
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);
|
||||
}
|
||||
String sprite = item == null ? null : item.getSprite(entityplayer, stack);
|
||||
if(sprite != null)
|
||||
ibakedmodel = this.itemModelMesher.getModelManager().getModel("item/" + sprite + '#' + "inventory");
|
||||
}
|
||||
|
||||
this.renderItemModelTransform(stack, ibakedmodel, cameraTransformType);
|
||||
|
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
@ -293,11 +292,11 @@ public class Item
|
|||
return provider.getModel(this.getTransform(), name);
|
||||
}
|
||||
|
||||
public ItemMeshDefinition getMesher() {
|
||||
public String[] getRenderItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
subItems.add(new ItemStack(itemIn));
|
||||
public String getSprite(EntityNPC player, ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ 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,44 +176,6 @@ 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());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package common.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import common.enchantment.Enchantment;
|
||||
import common.enchantment.EnchantmentHelper;
|
||||
|
@ -137,16 +138,21 @@ public class ItemBow extends Item
|
|||
return 1;
|
||||
}
|
||||
|
||||
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 String[] getRenderItems() {
|
||||
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 Transforms getTransform() {
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
||||
|
@ -146,58 +145,4 @@ 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";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package common.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.projectile.EntityHook;
|
||||
|
@ -78,13 +79,12 @@ public class ItemFishingRod extends Item
|
|||
return 1;
|
||||
}
|
||||
|
||||
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 String[] getRenderItems() {
|
||||
return new String[] {"fishing_rod_cast"};
|
||||
}
|
||||
|
||||
public String getSprite(EntityNPC player, ItemStack stack) {
|
||||
return player.fishEntity != null ? "fishing_rod_cast" : null;
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
|
|
|
@ -11,7 +11,6 @@ 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,21 +340,6 @@ 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");
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package common.model;
|
||||
|
||||
import common.item.ItemStack;
|
||||
|
||||
public interface ItemMeshDefinition {
|
||||
String getModelLocation(ItemStack stack);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue