2022-05-11 01:10:31 -05:00
|
|
|
package noppes.npcs.items;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2022-05-11 02:07:06 -05:00
|
|
|
import net.minecraft.block.Block;
|
2022-05-11 14:24:12 -05:00
|
|
|
import net.minecraft.client.Minecraft;
|
2022-05-11 13:30:13 -05:00
|
|
|
import net.minecraft.client.entity.EntityClientPlayerMP;
|
2022-05-11 01:10:31 -05:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.init.Items;
|
2022-05-11 02:33:56 -05:00
|
|
|
import net.minecraft.item.EnumAction;
|
2022-05-11 01:10:31 -05:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import noppes.npcs.CustomItems;
|
|
|
|
|
import noppes.npcs.CustomNpcs;
|
2022-05-11 13:30:13 -05:00
|
|
|
import noppes.npcs.EventHooks;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.constants.EnumGuiType;
|
2022-05-11 13:30:13 -05:00
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2022-05-11 13:30:13 -05:00
|
|
|
import noppes.npcs.scripted.event.ItemEvent;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.IItemStack;
|
2022-05-11 13:30:13 -05:00
|
|
|
import noppes.npcs.scripted.interfaces.IPlayer;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.scripted.item.ScriptCustomItem;
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
|
|
public class ItemScripted extends Item implements ItemRenderInterface {
|
|
|
|
|
public ItemScripted() {
|
|
|
|
|
maxStackSize = 1;
|
|
|
|
|
setCreativeTab(CustomItems.tab);
|
|
|
|
|
CustomNpcs.proxy.registerItem(this);
|
|
|
|
|
setHasSubtypes(true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 13:30:13 -05:00
|
|
|
@Override
|
|
|
|
|
public void onUpdate(ItemStack stack, World world, Entity player, int p_77663_4_, boolean p_77663_5_) {
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
EventHooks.onScriptItemUpdate((ScriptCustomItem) istack, (EntityPlayer) player);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void registerIcons(IIconRegister par1IconRegister){
|
|
|
|
|
this.itemIcon = Items.iron_pickaxe.getIconFromDamage(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getColorFromItemStack(ItemStack itemStack, int par2){
|
|
|
|
|
return 0x8B4513;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean requiresMultipleRenderPasses(){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item setUnlocalizedName(String name){
|
|
|
|
|
GameRegistry.registerItem(this, name);
|
|
|
|
|
return super.setUnlocalizedName(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entityPlayer)
|
|
|
|
|
{
|
|
|
|
|
if(entityPlayer.isSneaking()) {
|
|
|
|
|
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, entityPlayer);
|
|
|
|
|
}
|
|
|
|
|
entityPlayer.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 13:30:13 -05:00
|
|
|
@Override
|
|
|
|
|
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack){
|
|
|
|
|
if(entityLivingBase instanceof EntityClientPlayerMP)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptCustomItem) istack, ScriptController.Instance.getScriptForEntity(entityLivingBase), 2, null);
|
|
|
|
|
return EventHooks.onScriptItemAttack((ScriptCustomItem) istack, eve);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public int getMaxItemUseDuration(ItemStack stack){
|
|
|
|
|
return (new ScriptCustomItem(stack)).getMaxItemUseDuration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ScriptCustomItem GetWrapper(ItemStack stack) {
|
|
|
|
|
return new ScriptCustomItem(stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean showDurabilityBar(ItemStack stack) {
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
return istack instanceof ScriptCustomItem && (new ScriptCustomItem(stack)).durabilityShow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getDurabilityForDisplay(ItemStack stack) {
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
return istack instanceof ScriptCustomItem ? 1.0D - (new ScriptCustomItem(stack)).durabilityValue : 1.0D;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getItemStackLimit(ItemStack stack) {
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
return istack instanceof ScriptCustomItem ? (new ScriptCustomItem(stack)).getMaxStackSize() : super.getItemStackLimit(stack);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 02:07:06 -05:00
|
|
|
public boolean isItemTool(ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
return istack instanceof ScriptCustomItem ? (new ScriptCustomItem(stack)).isTool() : super.isItemTool(stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getDigSpeed(ItemStack stack, Block block, int metadata)
|
|
|
|
|
{
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
return istack instanceof ScriptCustomItem ? (new ScriptCustomItem(stack)).getDigSpeed() : super.getDigSpeed(stack, block, metadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
|
|
|
|
|
{
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
|
|
|
|
|
if((new ScriptCustomItem(stack)).getArmorType() == -1)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return istack instanceof ScriptCustomItem ? armorType == (new ScriptCustomItem(stack)).getArmorType() : super.isValidArmor(stack, armorType, entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getItemEnchantability(ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
return istack instanceof ScriptCustomItem ? (new ScriptCustomItem(stack)).getEnchantability() : super.getItemEnchantability(stack);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
|
2022-05-11 13:30:13 -05:00
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptCustomItem) istack, ScriptController.Instance.getScriptForEntity(attacker), 1, ScriptController.Instance.getScriptForEntity(target));
|
|
|
|
|
return EventHooks.onScriptItemAttack((ScriptCustomItem) istack, eve);
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 02:33:56 -05:00
|
|
|
public EnumAction getItemUseAction(ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
|
|
|
|
if (istack instanceof ScriptCustomItem) {
|
|
|
|
|
switch (((ScriptCustomItem) istack).getItemUseAction()) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 01:10:31 -05:00
|
|
|
@Override
|
2022-05-11 13:30:13 -05:00
|
|
|
public void renderSpecial() {
|
|
|
|
|
GL11.glTranslatef(0.135F, 0.2F, 0.07F);
|
|
|
|
|
}
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|