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 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;
|
2022-07-07 16:22:50 -05:00
|
|
|
import net.minecraft.util.ChatComponentTranslation;
|
2022-05-11 01:10:31 -05:00
|
|
|
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;
|
2023-01-07 00:21:08 -05:00
|
|
|
import noppes.npcs.config.ConfigScript;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.constants.EnumGuiType;
|
2022-06-28 04:39:50 -05:00
|
|
|
import noppes.npcs.entity.EntityItemScripted;
|
2022-05-11 13:30:13 -05:00
|
|
|
import noppes.npcs.scripted.event.ItemEvent;
|
2022-11-15 15:25:53 -05:00
|
|
|
import noppes.npcs.api.item.IItemStack;
|
2022-05-11 01:10:31 -05:00
|
|
|
import noppes.npcs.scripted.item.ScriptCustomItem;
|
2022-05-11 22:08:31 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2022-05-11 01:10:31 -05:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 16:22:50 -05:00
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
2022-05-11 01:10:31 -05:00
|
|
|
{
|
2022-07-07 16:22:50 -05:00
|
|
|
if(player.isSneaking() && player.capabilities.isCreativeMode) {
|
2023-01-07 00:21:08 -05:00
|
|
|
if(!ConfigScript.isScriptDev(player)){
|
2022-07-07 16:22:50 -05:00
|
|
|
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
|
|
|
|
|
} else {
|
|
|
|
|
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, player);
|
|
|
|
|
}
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|
2022-07-07 16:22:50 -05:00
|
|
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
2022-05-11 01:10:31 -05:00
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 13:30:13 -05:00
|
|
|
@Override
|
|
|
|
|
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack){
|
2022-07-03 08:50:10 -05:00
|
|
|
if (entityLivingBase.worldObj.isRemote) {
|
2022-05-11 13:30:13 -05:00
|
|
|
return false;
|
2022-07-03 08:50:10 -05:00
|
|
|
}
|
2022-05-11 13:30:13 -05:00
|
|
|
|
|
|
|
|
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
2022-05-11 22:08:31 -05:00
|
|
|
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptCustomItem) istack, NpcAPI.Instance().getIEntity(entityLivingBase), 2, null);
|
2022-05-11 13:30:13 -05:00
|
|
|
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);
|
2022-05-11 22:08:31 -05:00
|
|
|
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptCustomItem) istack, NpcAPI.Instance().getIEntity(attacker), 1, NpcAPI.Instance().getIEntity(target));
|
2022-05-11 13:30:13 -05:00
|
|
|
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 22:08:31 -05:00
|
|
|
public void renderSpecial() {}
|
|
|
|
|
|
2022-06-28 04:39:50 -05:00
|
|
|
public boolean hasCustomEntity(ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EntityItemScripted createEntity(World world, Entity location, ItemStack itemstack)
|
|
|
|
|
{
|
|
|
|
|
EntityItemScripted entityScriptedItem = new EntityItemScripted(world,location.posX,location.posY,location.posZ, itemstack);
|
|
|
|
|
entityScriptedItem.motionX = location.motionX;
|
|
|
|
|
entityScriptedItem.motionY = location.motionY;
|
|
|
|
|
entityScriptedItem.motionZ = location.motionZ;
|
|
|
|
|
|
|
|
|
|
return entityScriptedItem;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 22:08:31 -05:00
|
|
|
public void renderOffset(ScriptCustomItem scriptCustomItem) {
|
|
|
|
|
GL11.glTranslatef(0.135F * scriptCustomItem.scaleX, 0.2F * scriptCustomItem.scaleY, 0.07F * scriptCustomItem.scaleZ);
|
2022-05-11 13:30:13 -05:00
|
|
|
}
|
2022-05-11 01:10:31 -05:00
|
|
|
}
|