Implemented the ItemMeshDefinition for the Sentient Sword, allowing for me to make the sword enchantable while still allowing the texture to change. This may be expanded to other items.
This commit is contained in:
parent
cb77b7821f
commit
1abae8e4ee
|
@ -0,0 +1,25 @@
|
|||
package WayofTime.bloodmagic.client.mesh;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import WayofTime.bloodmagic.item.soul.ItemSentientSword;
|
||||
|
||||
public class ItemSentientSwordMeshDefinition implements ItemMeshDefinition
|
||||
{
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack)
|
||||
{
|
||||
if (stack != null && stack.getItem() instanceof ItemSentientSword)
|
||||
{
|
||||
if (((ItemSentientSword) stack.getItem()).getActivated(stack))
|
||||
{
|
||||
return new ModelResourceLocation("bloodmagic:ItemSentientSword1", "inventory");
|
||||
} else
|
||||
{
|
||||
return new ModelResourceLocation("bloodmagic:ItemSentientSword0", "inventory");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -40,8 +40,7 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
|||
super(ModItems.soulToolMaterial);
|
||||
|
||||
setUnlocalizedName(Constants.Mod.MODID + ".sentientSword");
|
||||
setHasSubtypes(true);
|
||||
setNoRepair();
|
||||
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
}
|
||||
|
||||
|
@ -129,14 +128,19 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean getActivated(ItemStack stack)
|
||||
public boolean getActivated(ItemStack stack)
|
||||
{
|
||||
return stack.getItemDamage() > 0;
|
||||
NBTHelper.checkNBT(stack);
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
|
||||
return tag.getBoolean("activated");
|
||||
}
|
||||
|
||||
private ItemStack setActivated(ItemStack stack, boolean activated)
|
||||
public ItemStack setActivated(ItemStack stack, boolean activated)
|
||||
{
|
||||
stack.setItemDamage(activated ? 1 : 0);
|
||||
NBTHelper.checkNBT(stack);
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
tag.setBoolean("activated", activated);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package WayofTime.bloodmagic.proxy;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.client.mesh.ItemSentientSwordMeshDefinition;
|
||||
import WayofTime.bloodmagic.client.render.RenderAlchemyArray;
|
||||
import WayofTime.bloodmagic.client.render.RenderAltar;
|
||||
import WayofTime.bloodmagic.client.render.entity.SentientArrowRenderFactory;
|
||||
|
@ -43,6 +45,8 @@ public class ClientProxy extends CommonProxy
|
|||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileAlchemyArray.class, new RenderAlchemyArray());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileAltar.class, new RenderAltar());
|
||||
|
||||
ModelLoader.setCustomMeshDefinition(ModItems.sentientSword, new ItemSentientSwordMeshDefinition());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -132,7 +132,7 @@ public class ModItems
|
|||
public static Item sentientArmourGem;
|
||||
|
||||
public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 0, 10, 8, 50);
|
||||
public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 0, 7, 8, 50);
|
||||
public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 520, 7, 8, 50);
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
@ -327,8 +327,8 @@ public class ModItems
|
|||
renderHelper.itemRender(soulGem, 4);
|
||||
renderHelper.itemRender(soulSnare);
|
||||
|
||||
renderHelper.itemRender(sentientSword, 0);
|
||||
renderHelper.itemRender(sentientSword, 1);
|
||||
renderHelper.customItemRender(sentientSword, 0);
|
||||
renderHelper.customItemRender(sentientSword, 1);
|
||||
renderHelper.itemRender(sentientBow, 0, "ItemSentientBow");
|
||||
renderHelper.itemRender(sentientBow, 1, "ItemSentientBow_pulling_0");
|
||||
renderHelper.itemRender(sentientBow, 2, "ItemSentientBow_pulling_1");
|
||||
|
|
|
@ -56,6 +56,25 @@ public class InventoryRenderHelper
|
|||
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(resName, "inventory"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Model for the given Item and meta. This does not call
|
||||
* setCustomModelResourceLocation, to allow the implementation of
|
||||
* ItemMeshDefinition.
|
||||
*
|
||||
* @param item
|
||||
* - Item to register Model for
|
||||
* @param meta
|
||||
* - Meta of Item
|
||||
* @param name
|
||||
* - Name of the model JSON
|
||||
*/
|
||||
public void customItemRender(Item item, int meta, String name)
|
||||
{
|
||||
ResourceLocation resName = new ResourceLocation(domain + name);
|
||||
|
||||
ModelBakery.registerItemVariants(item, resName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand of {@code itemRender(Item, int, String)}
|
||||
*
|
||||
|
@ -69,6 +88,11 @@ public class InventoryRenderHelper
|
|||
itemRender(item, meta, getClassName(item) + meta);
|
||||
}
|
||||
|
||||
public void customItemRender(Item item, int meta)
|
||||
{
|
||||
customItemRender(item, meta, getClassName(item) + meta);
|
||||
}
|
||||
|
||||
public void itemRender(Item item, String name)
|
||||
{
|
||||
itemRender(item, 0, name);
|
||||
|
|
Loading…
Reference in a new issue