Files
CustomNPC-Plus/src/main/java/noppes/npcs/items/ItemCustomizable.java
T

141 lines
5.5 KiB
Java
Raw Normal View History

package noppes.npcs.items;
2025-02-13 18:20:01 -06:00
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2025-02-14 12:28:17 -06:00
import net.minecraft.block.Block;
2025-02-13 18:20:01 -06:00
import net.minecraft.client.renderer.texture.IIconRegister;
2025-02-14 12:28:17 -06:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
2025-02-13 18:20:01 -06:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
2025-02-13 18:20:01 -06:00
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
2025-02-14 12:28:17 -06:00
import noppes.npcs.EventHooks;
import noppes.npcs.api.item.IItemCustomizable;
2025-02-13 18:20:01 -06:00
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.scripted.NpcAPI;
2025-02-14 12:28:17 -06:00
import noppes.npcs.scripted.event.ItemEvent;
import org.lwjgl.opengl.GL11;
2025-03-12 20:12:01 -04:00
public abstract class ItemCustomizable extends Item implements ItemRenderInterface {
2025-02-13 18:20:01 -06:00
@SideOnly(Side.CLIENT)
2025-03-12 20:12:01 -04:00
public void registerIcons(IIconRegister par1IconRegister) {
2025-02-13 18:20:01 -06:00
this.itemIcon = Items.iron_pickaxe.getIconFromDamage(0);
}
@Override
2025-03-12 20:12:01 -04:00
public int getColorFromItemStack(ItemStack itemStack, int par2) {
2025-02-13 18:20:01 -06:00
return 0x8B4513;
}
2025-02-14 12:28:17 -06:00
@Override
2025-03-12 20:12:01 -04:00
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack) {
2025-02-14 12:28:17 -06:00
if (entityLivingBase.worldObj.isRemote) {
return false;
}
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent((IItemCustomizable) istack, NpcAPI.Instance().getIEntity(entityLivingBase), 2, null);
return EventHooks.onScriptItemAttack((IItemCustomizable) istack, eve);
}
2025-03-12 20:12:01 -04:00
public int getMaxItemUseDuration(ItemStack stack) {
2025-02-14 12:28:17 -06:00
IItemCustomizable customizable = (IItemCustomizable) NpcAPI.Instance().getIItemStack(stack);
return customizable.getMaxItemUseDuration();
}
public boolean showDurabilityBar(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable && ((IItemCustomizable) istack).getDurabilityShow();
}
public double getDurabilityForDisplay(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? 1.0D - ((IItemCustomizable) istack).getDurabilityValue() : 1.0D;
}
public int getItemStackLimit(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? istack.getMaxStackSize() : super.getItemStackLimit(stack);
}
2025-03-12 20:12:01 -04:00
public boolean isItemTool(ItemStack stack) {
2025-02-14 12:28:17 -06:00
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? ((IItemCustomizable) istack).isTool() : super.isItemTool(stack);
}
2025-03-12 20:12:01 -04:00
public float getDigSpeed(ItemStack stack, Block block, int metadata) {
2025-02-14 12:28:17 -06:00
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? ((IItemCustomizable) istack).getDigSpeed() : super.getDigSpeed(stack, block, metadata);
}
2025-03-12 20:12:01 -04:00
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity) {
2025-02-14 12:28:17 -06:00
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
if (istack instanceof IItemCustomizable) {
2025-03-12 20:12:01 -04:00
if (((IItemCustomizable) istack).getArmorType() == -1)
2025-02-14 12:28:17 -06:00
return true;
return armorType == ((IItemCustomizable) istack).getArmorType();
}
return super.isValidArmor(stack, armorType, entity);
}
2025-03-12 20:12:01 -04:00
public int getItemEnchantability(ItemStack stack) {
2025-02-14 12:28:17 -06:00
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? ((IItemCustomizable) istack).getEnchantability() : super.getItemEnchantability(stack);
}
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent((IItemCustomizable) istack, NpcAPI.Instance().getIEntity(attacker), 1, NpcAPI.Instance().getIEntity(target));
return EventHooks.onScriptItemAttack((IItemCustomizable) istack, eve);
}
2025-02-13 18:20:01 -06:00
@Override
2025-03-12 20:12:01 -04:00
public boolean requiresMultipleRenderPasses() {
2025-02-13 18:20:01 -06:00
return true;
}
@Override
2025-03-12 20:12:01 -04:00
public Item setUnlocalizedName(String name) {
2025-02-13 18:20:01 -06:00
GameRegistry.registerItem(this, name);
return super.setUnlocalizedName(name);
}
2025-03-12 20:12:01 -04:00
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
2025-02-13 18:20:01 -06:00
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
2025-03-12 20:12:01 -04:00
public EnumAction getItemUseAction(ItemStack stack) {
2025-02-13 18:20:01 -06:00
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
2025-02-14 12:28:17 -06:00
if (istack instanceof IItemCustomizable) {
switch (((IItemCustomizable) istack).getItemUseAction()) {
2025-02-13 18:20:01 -06:00
case 0:
return EnumAction.none;
case 1:
return EnumAction.block;
case 2:
return EnumAction.bow;
case 3:
return EnumAction.eat;
case 4:
return EnumAction.drink;
}
}
return super.getItemUseAction(stack);
}
@Override
2025-03-12 20:12:01 -04:00
public void renderSpecial() {
}
2025-02-14 12:28:17 -06:00
public void renderOffset(IItemCustomizable scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.getScaleX(), 0.2F * scriptCustomItem.getScaleY(), 0.07F * scriptCustomItem.getScaleZ());
}
}