Added some more functions for scripted items

This commit is contained in:
Luis C.M committed 2022-05-11 02:07:06 -05:00
1 parent 26f5f86dca
commit a18cf5625b
2 files changed
+81 -5

No files matched your search

@@ -3,6 +3,7 @@ package noppes.npcs.items;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -10,8 +11,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
@@ -21,8 +20,6 @@ import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
public class ItemScripted extends Item implements ItemRenderInterface {
public ItemScripted() {
maxStackSize = 1;
@@ -87,6 +84,34 @@ public class ItemScripted extends Item implements ItemRenderInterface {
return istack instanceof ScriptCustomItem ? (new ScriptCustomItem(stack)).getMaxStackSize() : super.getItemStackLimit(stack);
}
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);
}
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
return true;
}
@@ -19,6 +19,7 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public long lastInited = -1L;
public boolean loaded = false;
public boolean durabilityShow = false;
public double durabilityValue = 1.0D;
@@ -26,7 +27,11 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS
public int itemColor = 0x8B4513;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public boolean loaded = false;
public boolean isTool = false;
public int digSpeed = 1;
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
public int enchantability;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public int width = -1, height = -1;
@@ -160,6 +165,33 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS
return this.stackSize;
}
public void setArmorType(int armorType){
this.armorType = armorType;
saveItemData();
}
public int getArmorType(){
return this.armorType;
}
public void setIsTool(boolean isTool){
this.isTool = isTool;
saveItemData();
}
public boolean isTool(){
return this.isTool;
}
public void setDigSpeed(int digSpeed){
this.digSpeed = digSpeed;
saveItemData();
}
public int getDigSpeed(){
return this.digSpeed;
}
public void setMaxStackSize(int size) {
if (size >= 1 && size <= 64) {
this.stackSize = size;
@@ -214,6 +246,15 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS
saveItemData();
}
public int getEnchantability(){
return this.enchantability;
}
public void setEnchantability(int enchantability){
this.enchantability = enchantability;
saveItemData();
}
public void setRotation(float rotationX, float rotationY, float rotationZ){
this.rotationX = rotationX;
this.rotationY = rotationY;
@@ -350,6 +391,11 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS
compound.setInteger("Width", this.width);
compound.setInteger("Height", this.height);
compound.setBoolean("IsTool", this.isTool);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
compound.setInteger("Enchantability", this.enchantability);
return compound;
}
@@ -377,6 +423,11 @@ public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IS
this.width = compound.getInteger("Width");
this.height = compound.getInteger("Height");
this.isTool = compound.getBoolean("IsTool");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");
this.enchantability = compound.getInteger("Enchantability");
}
public void saveScriptData() {