More linked item changes

This commit is contained in:
luisc committed 2025-02-14 12:28:17 -06:00
1 parent d394174108
commit 4a1a092757
15 files changed
+338 -436

No files matched your search

+68 -36
View File
@@ -20,7 +20,7 @@ import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.entity.IProjectile;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.CustomGuiController;
@@ -41,76 +41,108 @@ public class EventHooks {
public EventHooks() {
}
public static void onScriptItemInit(IItemCustom handler) {
if (!((ScriptCustomItem) handler).isClient()) {
ItemEvent.InitEvent event = new ItemEvent.InitEvent(handler);
((ScriptCustomItem) handler).callScript(EnumScriptType.INIT, event);
public static void onScriptItemInit(IItemCustomizable item) {
INpcScriptHandler handler = item.getScriptHandler();
if (handler != null && !handler.isClient()) {
ItemEvent.InitEvent event = new ItemEvent.InitEvent(item);
handler.callScript(EnumScriptType.INIT, event);
NpcAPI.EVENT_BUS.post(event);
}
}
public static void onScriptItemUpdate(IItemCustom handler, EntityLivingBase player) {
if (!((ScriptCustomItem) handler).isClient()) {
ItemEvent.UpdateEvent event = new ItemEvent.UpdateEvent(handler, NpcAPI.Instance().getIEntity(player));
((ScriptCustomItem) handler).callScript(EnumScriptType.TICK, event);
public static void onScriptItemUpdate(IItemCustomizable item, EntityLivingBase player) {
INpcScriptHandler handler = item.getScriptHandler();
if (handler != null && !handler.isClient()) {
ItemEvent.UpdateEvent event = new ItemEvent.UpdateEvent(item, NpcAPI.Instance().getIEntity(player));
handler.callScript(EnumScriptType.TICK, event);
NpcAPI.EVENT_BUS.post(event);
}
}
public static boolean onScriptItemTossed(IItemCustom handler, EntityPlayer player, EntityItem entity) {
ItemEvent.TossedEvent event = new ItemEvent.TossedEvent(handler, (IPlayer)NpcAPI.Instance().getIEntity(player), NpcAPI.Instance().getIEntity(entity));
((ScriptCustomItem) handler).callScript(EnumScriptType.TOSSED, event);
public static boolean onScriptItemTossed(IItemCustomizable item, EntityPlayer player, EntityItem entity) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.TossedEvent event = new ItemEvent.TossedEvent(item, (IPlayer)NpcAPI.Instance().getIEntity(player), NpcAPI.Instance().getIEntity(entity));
if (handler != null) {
handler.callScript(EnumScriptType.TOSSED, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemPickedUp(IItemCustom handler, EntityPlayer player) {
ItemEvent.PickedUpEvent event = new ItemEvent.PickedUpEvent(handler, (IPlayer)NpcAPI.Instance().getIEntity(player));
((ScriptCustomItem) handler).callScript(EnumScriptType.PICKEDUP, event);
public static boolean onScriptItemPickedUp(IItemCustomizable item, EntityPlayer player) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.PickedUpEvent event = new ItemEvent.PickedUpEvent(item, (IPlayer)NpcAPI.Instance().getIEntity(player));
if (handler != null) {
handler.callScript(EnumScriptType.PICKEDUP, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemSpawn(IItemCustom handler, EntityItem entity) {
ItemEvent.SpawnEvent event = new ItemEvent.SpawnEvent(handler, NpcAPI.Instance().getIEntity(entity));
((ScriptCustomItem) handler).callScript(EnumScriptType.SPAWN, event);
public static boolean onScriptItemSpawn(IItemCustomizable item, EntityItem entity) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.SpawnEvent event = new ItemEvent.SpawnEvent(item, NpcAPI.Instance().getIEntity(entity));
if (handler != null) {
handler.callScript(EnumScriptType.SPAWN, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemInteract(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.InteractEvent event) {
((ScriptCustomItem) handler).callScript(EnumScriptType.INTERACT, event);
public static boolean onScriptItemInteract(IItemCustomizable item, noppes.npcs.scripted.event.ItemEvent.InteractEvent event) {
INpcScriptHandler handler = item.getScriptHandler();
if (handler != null) {
handler.callScript(EnumScriptType.INTERACT, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemRightClick(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.RightClickEvent event) {
((ScriptCustomItem) handler).callScript(EnumScriptType.RIGHT_CLICK, event);
public static boolean onScriptItemRightClick(IItemCustomizable item, noppes.npcs.scripted.event.ItemEvent.RightClickEvent event) {
INpcScriptHandler handler = item.getScriptHandler();
if (handler != null) {
handler.callScript(EnumScriptType.RIGHT_CLICK, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemAttack(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) {
((ScriptCustomItem) handler).callScript(EnumScriptType.ATTACK, event);
public static boolean onScriptItemAttack(IItemCustomizable item, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) {
INpcScriptHandler handler = item.getScriptHandler();
if (handler != null) {
handler.callScript(EnumScriptType.ATTACK, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onStartUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.StartUsingItem event = new ItemEvent.StartUsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.START_USING_ITEM, event);
public static boolean onStartUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.StartUsingItem event = new ItemEvent.StartUsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.START_USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.UsingItem event = new ItemEvent.UsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.USING_ITEM, event);
public static boolean onUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.UsingItem event = new ItemEvent.UsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onStopUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.StopUsingItem event = new ItemEvent.StopUsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.STOP_USING_ITEM, event);
public static boolean onStopUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.StopUsingItem event = new ItemEvent.StopUsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.STOP_USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onFinishUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.FinishUsingItem event = new ItemEvent.FinishUsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.FINISH_USING_ITEM, event);
public static boolean onFinishUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = item.getScriptHandler();
ItemEvent.FinishUsingItem event = new ItemEvent.FinishUsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.FINISH_USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
@@ -63,6 +63,7 @@ import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.*;
import noppes.npcs.entity.data.ModelData;
import noppes.npcs.entity.data.ModelPartData;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import org.lwjgl.input.Keyboard;
import tconstruct.client.tabs.InventoryTabCustomNpc;
@@ -507,7 +508,7 @@ public class ClientProxy extends CommonProxy {
@Override
public void registerItem(Item item) {
if (item instanceof ItemScripted) {
if (item instanceof ItemScripted || item instanceof ItemLinked) {
MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer());
} else {
MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer());
@@ -14,10 +14,12 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.NpcAPI;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -44,9 +46,13 @@ public class CustomItemRenderer implements IItemRenderer {
@Override
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack);
IItemStack iItemStack = NpcAPI.Instance().getIItemStack(itemStack);
if (!(iItemStack instanceof IItemCustomizable)) {
return;
}
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture);
IItemCustomizable scriptCustomItem = (IItemCustomizable) iItemStack;
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
if (!imageData.imageLoaded()) {
return;
}
@@ -64,34 +70,34 @@ public class CustomItemRenderer implements IItemRenderer {
if (!entityItem.ignoreFrustumCheck) {
entityItem.ignoreFrustumCheck = true;
float entityXZSize = (float) Math.sqrt(Math.pow(scriptCustomItem.itemDisplay.scaleX,2) + Math.pow(scriptCustomItem.itemDisplay.scaleZ,2));
this.setEntitySize(entityItem, entityXZSize * 0.25F, scriptCustomItem.itemDisplay.scaleY * 0.25F);
float entityXZSize = (float) Math.sqrt(Math.pow(scriptCustomItem.getScaleX(),2) + Math.pow(scriptCustomItem.getScaleZ(),2));
this.setEntitySize(entityItem, entityXZSize * 0.25F, scriptCustomItem.getScaleY() * 0.25F);
double XSize = entityItem.boundingBox.maxX - entityItem.boundingBox.minX;
double YSize = entityItem.boundingBox.maxY - entityItem.boundingBox.minY;
double ZSize = entityItem.boundingBox.maxZ - entityItem.boundingBox.minZ;
entityItem.boundingBox.maxX = entityItem.boundingBox.minX + XSize * scriptCustomItem.itemDisplay.scaleX;
entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * scriptCustomItem.itemDisplay.scaleY;
entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * scriptCustomItem.itemDisplay.scaleZ;
entityItem.boundingBox.maxX = entityItem.boundingBox.minX + XSize * scriptCustomItem.getScaleX();
entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * scriptCustomItem.getScaleY();
entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * scriptCustomItem.getScaleZ();
}
float entityRenderTicks = Minecraft.getMinecraft().timer.renderPartialTicks;
float bobbing = MathHelper.sin(((float)entityItem.age + entityRenderTicks) / 10.0F + entityItem.hoverStart) * 0.1F + 0.1F;
if(!scriptCustomItem.isNormalItem){
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZ, 0, 0, 1);
if(!scriptCustomItem.isNormalItem()){
GL11.glRotatef(scriptCustomItem.getRotationX(), 1, 0, 0);
GL11.glRotatef(scriptCustomItem.getRotationY(), 0, 1, 0);
GL11.glRotatef(scriptCustomItem.getRotationZ(), 0, 0, 1);
}
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationXRate * entityRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationYRate * entityRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZRate * entityRenderTicks %360, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.getRotationXRate() * entityRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.getRotationYRate() * entityRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.getRotationZRate() * entityRenderTicks %360, 0, 0, 1);
if (!renderInFrame) {
if(!scriptCustomItem.isNormalItem){
GL11.glScalef(scriptCustomItem.itemDisplay.scaleX, scriptCustomItem.itemDisplay.scaleY, scriptCustomItem.itemDisplay.scaleZ);
GL11.glTranslatef(0.0F, (Math.max(scriptCustomItem.itemDisplay.scaleY, 1) - 1) * (1.0F / 4), 0.0F);
if(!scriptCustomItem.isNormalItem()){
GL11.glScalef(scriptCustomItem.getScaleX(), scriptCustomItem.getScaleY(), scriptCustomItem.getScaleZ());
GL11.glTranslatef(0.0F, (Math.max(scriptCustomItem.getScaleY(), 1) - 1) * (1.0F / 4), 0.0F);
}
GL11.glTranslatef(0.0F, -bobbing, 0.0F);
}
@@ -108,8 +114,7 @@ public class CustomItemRenderer implements IItemRenderer {
return;
}
if (type == ItemRenderType.EQUIPPED_FIRST_PERSON && scriptCustomItem.isNormalItem) {
if (type == ItemRenderType.EQUIPPED_FIRST_PERSON && scriptCustomItem.isNormalItem()) {
GL11.glPushMatrix();
GL11.glTranslatef(0.9375F, 0.0625F, 0.0F);
GL11.glRotatef(-315.0F, 0.0F, 0.0F, 1.0F);
@@ -138,29 +143,29 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glRotatef(-315.0F, 0.0F, 0.0F, 1.0F);
((ItemScripted) itemStack.getItem()).renderOffset(scriptCustomItem);
if(scriptCustomItem.isNormalItem){
if(scriptCustomItem.isNormalItem()){
GL11.glTranslatef(-0.05F, 0.3F, 0.3F);
GL11.glRotatef(50, 1, 0, 0);
GL11.glRotatef(-80, 0, 1, 0);
GL11.glRotatef(80, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationXRate * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationYRate * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZRate * item3dRenderTicks %360, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.getRotationXRate() * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.getRotationYRate() * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.getRotationZRate() * item3dRenderTicks %360, 0, 0, 1);
GL11.glScalef(0.6F, 0.6F,0.6F);
}
else {
GL11.glTranslatef(scriptCustomItem.itemDisplay.translateX, scriptCustomItem.itemDisplay.translateY, scriptCustomItem.itemDisplay.translateZ);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZ, 0, 0, 1);
GL11.glTranslatef(scriptCustomItem.getTranslateX(), scriptCustomItem.getTranslateY(), scriptCustomItem.getTranslateZ());
GL11.glRotatef(scriptCustomItem.getRotationX(), 1, 0, 0);
GL11.glRotatef(scriptCustomItem.getRotationY(), 0, 1, 0);
GL11.glRotatef(scriptCustomItem.getRotationZ(), 0, 0, 1);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationXRate * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationYRate * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZRate * item3dRenderTicks %360, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.getRotationXRate() * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.getRotationYRate() * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.getRotationZRate() * item3dRenderTicks %360, 0, 0, 1);
GL11.glScalef(scriptCustomItem.itemDisplay.scaleX, scriptCustomItem.itemDisplay.scaleY, scriptCustomItem.itemDisplay.scaleZ);
GL11.glScalef(scriptCustomItem.getScaleX(), scriptCustomItem.getScaleY(), scriptCustomItem.getScaleZ());
}
int color = scriptCustomItem.getColor();
@@ -226,11 +231,11 @@ public class CustomItemRenderer implements IItemRenderer {
}
}
public void renderEntityCustomItem(ScriptCustomItem scriptCustomItem, ItemStack itemStack, EntityItem entityItem) {
public void renderEntityCustomItem(IItemCustomizable scriptCustomItem, ItemStack itemStack, EntityItem entityItem) {
int pass = 0;
GL11.glPushMatrix();
ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture).bindTexture();
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
if (renderInFrame)
{
@@ -276,8 +281,8 @@ public class CustomItemRenderer implements IItemRenderer {
b0 = 4;
}
if(!scriptCustomItem.isNormalItem)
GL11.glScalef(scriptCustomItem.itemDisplay.scaleX, scriptCustomItem.itemDisplay.scaleY, scriptCustomItem.itemDisplay.scaleZ);
if(!scriptCustomItem.isNormalItem())
GL11.glScalef(scriptCustomItem.getScaleX(), scriptCustomItem.getScaleY(), scriptCustomItem.getScaleZ());
GL11.glTranslatef(-f7, -f8, -((f9 + f10) * (float)b0 / 2.0F));
for (int k = 0; k < b0; ++k)
@@ -289,7 +294,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
}*/
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture);
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, imageData.getTotalWidth(), imageData.getTotalHeight(), f9);
if (itemStack.hasEffect(pass))
@@ -378,7 +383,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glPopMatrix();
}
public void renderInventoryCustomItem(ScriptCustomItem scriptCustomItem) {
public void renderInventoryCustomItem(IItemCustomizable scriptCustomItem) {
GL11.glPushMatrix();
int color = scriptCustomItem.getColor();
float itemRed = (color >> 16 & 255) / 255f;
@@ -389,13 +394,13 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture).bindTexture();
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
renderCustomItemSlot(0,0,16,16, itemRed, itemGreen, itemBlue);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
if (scriptCustomItem.item.hasEffect(0))
if (scriptCustomItem.getMCItemStack().hasEffect(0))
{
renderEffect(Minecraft.getMinecraft().getTextureManager(), 0, 0);
}
@@ -457,14 +462,14 @@ public class CustomItemRenderer implements IItemRenderer {
tessellator.draw();
}
public void renderItem3d(ScriptCustomItem scriptCustomItem, EntityLivingBase entityLivingBase, ItemStack itemStack) {
public void renderItem3d(IItemCustomizable scriptCustomItem, EntityLivingBase entityLivingBase, ItemStack itemStack) {
item3dRenderTicks++;
Minecraft mc = Minecraft.getMinecraft();
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture).bindTexture();
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
Tessellator tessellator = Tessellator.instance;
IIcon icon = entityLivingBase.getItemIcon(itemStack, par3);
@@ -482,7 +487,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
renderCustomItemIn2D(itemStack, tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 0.0625F);
renderCustomItemIn2D(scriptCustomItem, tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 0.0625F);
if (itemStack.hasEffect(par3)) {
GL11.glDepthFunc(GL11.GL_EQUAL);
@@ -517,9 +522,9 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
public static void renderCustomItemIn2D(ItemStack itemStack, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_)
public static void renderCustomItemIn2D(IItemCustomizable wrapper, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_)
{
ImageData imageData = ClientCacheHandler.getImageData(ItemScripted.GetWrapper(itemStack).itemDisplay.texture);
ImageData imageData = ClientCacheHandler.getImageData(wrapper.getTexture());
int width = imageData.getTotalWidth();
int height = imageData.getTotalHeight();
@@ -1,13 +1,22 @@
package noppes.npcs.controllers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import noppes.npcs.CustomNpcs;
import noppes.npcs.controllers.data.EffectScript;
import noppes.npcs.controllers.data.INpcScriptHandler;
import noppes.npcs.controllers.data.LinkedItem;
import java.io.File;
import java.util.HashMap;
//TODO: load this data from somewhere, use in GUIs, create script wrapper
//TODO: load this data from somewhere, use in GUIs
public class LinkedItemController {
private static LinkedItemController Instance;
private final HashMap<String, LinkedItem> linkedItems = new HashMap<>();
private int lastUsedID = 0;
private final HashMap<Integer, LinkedItem> linkedItems = new HashMap<>();
private final HashMap<Integer, EffectScript> linkedItemsScripts = new HashMap<>();
private LinkedItemController() {
}
@@ -19,16 +28,64 @@ public class LinkedItemController {
return Instance;
}
public int getUnusedId() {
for (int id : this.linkedItems.keySet()) {
if (id > this.lastUsedID)
this.lastUsedID = id;
}
this.lastUsedID++;
return this.lastUsedID;
}
private File getDir() {
return new File(CustomNpcs.getWorldSaveDirectory(), "linkeditems");
}
public LinkedItem createItem(String name) {
return new LinkedItem(name);
}
public void add(LinkedItem linkedItem) {
if (linkedItem != null) {
String name = linkedItem.getName();
if (name != null && !name.isEmpty()) {
this.linkedItems.put(name.toLowerCase(), linkedItem);
int linkedItemId = linkedItem.getId();
int id = this.linkedItems.containsKey(linkedItemId) ? linkedItemId : this.getUnusedId();
this.linkedItems.put(id, linkedItem);
linkedItem.setId(id);
this.addScript(id);
}
}
}
public LinkedItem get(String name) {
return name != null && !name.isEmpty() ? this.linkedItems.get(name.toLowerCase()) : null;
@SideOnly(Side.SERVER)
private void addScript(int id) {
this.linkedItemsScripts.put(id, new EffectScript());
}
public void remove(int id) {
this.linkedItems.remove(id);
this.removeScript(id);
}
@SideOnly(Side.SERVER)
private void removeScript(int id) {
this.linkedItemsScripts.remove(id);
}
public LinkedItem get(int id) {
return this.linkedItems.get(id);
}
public boolean contains(int id) {
return this.linkedItems.containsKey(id);
}
public boolean contains(LinkedItem linkedItem) {
return this.linkedItems.containsValue(linkedItem);
}
public INpcScriptHandler getScriptHandler(int id) {
return this.linkedItemsScripts.get(id);
}
}
@@ -7,6 +7,7 @@ import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.NpcAPI;
@@ -16,7 +17,7 @@ import javax.script.ScriptEngine;
import java.io.IOException;
import java.util.*;
public class EffectScript implements IScriptHandler {
public class EffectScript implements INpcScriptHandler {
public ScriptContainer container;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
@@ -50,7 +51,12 @@ public class EffectScript implements IScriptHandler {
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
}
@Override
@Override
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@Override
public void callScript(String s, Event event) {
if (!this.isEnabled()) {
return;
@@ -2,13 +2,15 @@ package noppes.npcs.controllers.data;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.nbt.NBTTagInt;
import noppes.npcs.CustomItems;
import noppes.npcs.controllers.LinkedItemController;
public class LinkedItem {
public static final String LINKED_NBT_TAG = "LinkedName";
public static final String LINKED_NBT_TAG = "LinkedId";
private final String name;
private int id = -1;
private String name;
public final ItemDisplayData display = new ItemDisplayData();
public double durabilityValue = 1.0D;
@@ -23,22 +25,44 @@ public class LinkedItem {
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 LinkedItem() {
this("New");
}
public LinkedItem(String name) {
this.name = name;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public ItemStack createStack() {
ItemStack linkedStack = new ItemStack(CustomItems.linked_item);
linkedStack.setTagInfo(LinkedItem.LINKED_NBT_TAG, new NBTTagString(this.getName()));
return linkedStack;
if (LinkedItemController.Instance().contains(this)) {
ItemStack linkedStack = new ItemStack(CustomItems.linked_item);
linkedStack.setTagInfo(LinkedItem.LINKED_NBT_TAG, new NBTTagInt(this.getId()));
return linkedStack;
}
return null;
}
public INpcScriptHandler getScriptHandler() {
return LinkedItemController.Instance().getScriptHandler(this.getId());
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Id", this.id);
compound.setString("Name", this.name);
compound.setTag("Display", this.display.writeToNBT());
compound.setDouble("DurabilityValue",this.durabilityValue);
@@ -56,6 +80,9 @@ public class LinkedItem {
}
public void readFromNBT(NBTTagCompound compound) {
this.id = compound.hasKey("Id") ? compound.getInteger("Id") : LinkedItemController.Instance().getUnusedId();
this.name = compound.getString("Name");
this.display.readFromNBT(compound.getCompoundTag("Display"));
this.durabilityValue = compound.getDouble("DurabilityValue");
@@ -1,165 +0,0 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.NpcAPI;
import javax.script.ScriptEngine;
import java.io.IOException;
import java.util.*;
public class LinkedItemScript implements IScriptHandler {
public ScriptContainer container;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setString("ScriptLanguage", scriptLanguage);
compound.setBoolean("ScriptEnabled", enabled);
if (container != null)
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
return compound;
}
public LinkedItemScript readFromNBT(NBTTagCompound compound) {
scriptLanguage = compound.getString("ScriptLanguage");
enabled = compound.getBoolean("ScriptEnabled");
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
container = new ScriptContainer(this);
container.readFromNBT(compound.getCompoundTag("ScriptContent"));
}
return this;
}
public boolean isEnabled() {
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
}
@Override
public void callScript(String s, Event event) {
if (!this.isEnabled()) {
return;
}
ScriptEngine engine = container.engine;
engine.put("API", NpcAPI.Instance());
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
engine.put(engineObjects.getKey(), engineObjects.getValue());
}
container.run(s, event);
}
@Override
public boolean isClient() {
return FMLCommonHandler.instance().getEffectiveSide().isClient();
}
@Override
public boolean getEnabled() {
return this.enabled;
}
@Override
public void setEnabled(boolean b) {
this.enabled = b;
}
@Override
public String getLanguage() {
return this.scriptLanguage;
}
@Override
public void setLanguage(String s) {
this.scriptLanguage = s;
}
@Override
public void setScripts(List<ScriptContainer> list) {
if (list == null || list.isEmpty()) {
container = null;
return;
}
container = list.get(0);
}
@Override
public List<ScriptContainer> getScripts() {
if (container == null)
return new ArrayList<>();
return Collections.singletonList(container);
}
@Override
public String noticeString() {
return "";
}
@Override
public Map<Long, String> getConsoleText() {
TreeMap<Long, String> map = new TreeMap();
int tab = 0;
Iterator var3 = this.getScripts().iterator();
while(var3.hasNext()) {
ScriptContainer script = (ScriptContainer)var3.next();
++tab;
Iterator var5 = script.console.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<Long, String> longStringEntry = (Map.Entry)var5.next();
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + (String)longStringEntry.getValue());
}
}
return map;
}
@Override
public void clearConsole() {
Iterator var1 = this.getScripts().iterator();
while(var1.hasNext()) {
ScriptContainer script = (ScriptContainer)var1.next();
script.console.clear();
}
}
public void saveScript(ByteBuf buffer) throws IOException {
int tab = buffer.readInt();
int totalScripts = buffer.readInt();
if (totalScripts == 0) {
this.container = null;
}
if (tab == 0) {
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
ScriptContainer script = new ScriptContainer(this);
script.readFromNBT(tabCompound);
this.container = script;
} else {
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
this.setLanguage(compound.getString("ScriptLanguage"));
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
if (!ScriptController.Instance.languages.isEmpty()) {
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
} else {
this.setLanguage("ECMAScript");
}
}
this.setEnabled(compound.getBoolean("ScriptEnabled"));
}
}
}
@@ -3,16 +3,22 @@ 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;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import noppes.npcs.EventHooks;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptCustomizableItem;
import noppes.npcs.scripted.event.ItemEvent;
import org.lwjgl.opengl.GL11;
public abstract class ItemCustomizable extends Item implements ItemRenderInterface {
@@ -26,6 +32,73 @@ public abstract class ItemCustomizable extends Item implements ItemRenderInterfa
return 0x8B4513;
}
@Override
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack){
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);
}
public int getMaxItemUseDuration(ItemStack stack){
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);
}
public boolean isItemTool(ItemStack stack)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? ((IItemCustomizable) istack).isTool() : super.isItemTool(stack);
}
public float getDigSpeed(ItemStack stack, Block block, int metadata)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof IItemCustomizable ? ((IItemCustomizable) istack).getDigSpeed() : super.getDigSpeed(stack, block, metadata);
}
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
if (istack instanceof IItemCustomizable) {
if(((IItemCustomizable) istack).getArmorType() == -1)
return true;
return armorType == ((IItemCustomizable) istack).getArmorType();
}
return super.isValidArmor(stack, armorType, entity);
}
public int getItemEnchantability(ItemStack stack)
{
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);
}
@Override
public boolean requiresMultipleRenderPasses(){
return true;
@@ -47,8 +120,8 @@ public abstract class ItemCustomizable extends Item implements ItemRenderInterfa
public EnumAction getItemUseAction(ItemStack stack)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
if (istack instanceof ScriptCustomizableItem) {
switch (((ScriptCustomizableItem) istack).getItemUseAction()) {
if (istack instanceof IItemCustomizable) {
switch (((IItemCustomizable) istack).getItemUseAction()) {
case 0:
return EnumAction.none;
case 1:
@@ -66,4 +139,8 @@ public abstract class ItemCustomizable extends Item implements ItemRenderInterfa
@Override
public void renderSpecial() {}
public void renderOffset(IItemCustomizable scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.getScaleX(), 0.2F * scriptCustomItem.getScaleY(), 0.07F * scriptCustomItem.getScaleZ());
}
}
@@ -1,15 +1,6 @@
package noppes.npcs.items;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import noppes.npcs.CustomNpcs;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptLinkedItem;
import org.lwjgl.opengl.GL11;
public class ItemLinked extends ItemCustomizable {
@@ -18,82 +9,4 @@ public class ItemLinked extends ItemCustomizable {
CustomNpcs.proxy.registerItem(this);
setHasSubtypes(true);
}
@Override
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack){
if (entityLivingBase.worldObj.isRemote) {
return false;
}
//TODO: re-implement item attack swing hook
// IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
// ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent((ScriptLinkedItem) istack, NpcAPI.Instance().getIEntity(entityLivingBase), 2, null);
// return EventHooks.onScriptItemAttack((ScriptLinkedItem) istack, eve);
return true;
}
public int getMaxItemUseDuration(ItemStack stack){
return (new ScriptLinkedItem(stack)).getMaxItemUseDuration();
}
//TODO: Use this in existing item scripted rendering. Refactor the renderer to use the new abstract ScriptCustomizableItem class
public static ScriptLinkedItem GetWrapper(ItemStack stack) {
return new ScriptLinkedItem(stack);
}
public boolean showDurabilityBar(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptLinkedItem && (new ScriptLinkedItem(stack)).itemDisplay.durabilityShow;
}
public double getDurabilityForDisplay(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptLinkedItem ? 1.0D - (new ScriptLinkedItem(stack)).getDurabilityValue() : 1.0D;
}
public int getItemStackLimit(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).getMaxStackSize() : super.getItemStackLimit(stack);
}
public boolean isItemTool(ItemStack stack)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).isTool() : super.isItemTool(stack);
}
public float getDigSpeed(ItemStack stack, Block block, int metadata)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).getDigSpeed() : super.getDigSpeed(stack, block, metadata);
}
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
if((new ScriptLinkedItem(stack)).getArmorType() == -1)
return true;
return istack instanceof ScriptLinkedItem ? armorType == (new ScriptLinkedItem(stack)).getArmorType() : super.isValidArmor(stack, armorType, entity);
}
public int getItemEnchantability(ItemStack stack)
{
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptLinkedItem ? (new ScriptLinkedItem(stack)).getEnchantability() : super.getItemEnchantability(stack);
}
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
//TODO: re-implement item attack hook
// ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptLinkedItem) istack, NpcAPI.Instance().getIEntity(attacker), 1, NpcAPI.Instance().getIEntity(target));
// return EventHooks.onScriptItemAttack((ScriptLinkedItem) istack, eve);
return true;
}
public void renderOffset(ScriptLinkedItem scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
}
}
@@ -1,8 +1,5 @@
package noppes.npcs.items;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
@@ -10,14 +7,8 @@ import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.EventHooks;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.ItemEvent;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
public class ItemScripted extends ItemCustomizable {
@@ -39,76 +30,4 @@ public class ItemScripted extends ItemCustomizable {
}
return super.onItemRightClick(stack, world, player);
}
@Override
public boolean onEntitySwing(EntityLivingBase entityLivingBase, ItemStack stack){
if (entityLivingBase.worldObj.isRemote) {
return false;
}
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptCustomItem) istack, NpcAPI.Instance().getIEntity(entityLivingBase), 2, null);
return EventHooks.onScriptItemAttack((ScriptCustomItem) istack, eve);
}
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)).itemDisplay.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);
}
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) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
ItemEvent.AttackEvent eve = new ItemEvent.AttackEvent( (ScriptCustomItem) istack, NpcAPI.Instance().getIEntity(attacker), 1, NpcAPI.Instance().getIEntity(target));
return EventHooks.onScriptItemAttack((ScriptCustomItem) istack, eve);
}
public void renderOffset(ScriptCustomItem scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
}
}
@@ -470,8 +470,14 @@ public class NpcAPI extends AbstractNpcAPI {
if (scriptItemCache.containsKey(itemstack)) {
scriptStack = scriptItemCache.get(itemstack).getObject();
} else {
String linkedItemName = itemstack.getTagCompound().getString(LinkedItem.LINKED_NBT_TAG);
LinkedItem linkedItem = LinkedItemController.Instance().get(linkedItemName);
LinkedItem linkedItem;
if (itemstack.hasTagCompound()) {
int linkedItemId = itemstack.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
linkedItem = LinkedItemController.Instance().get(linkedItemId);
} else {
linkedItem = null;
}
if (linkedItem != null && itemstack.getItem() instanceof ItemLinked) {
scriptStack = new ScriptLinkedItem(itemstack);
} else if (itemstack.getItem() instanceof ItemScripted) {
@@ -63,6 +63,11 @@ public class ScriptCustomItem extends ScriptCustomizableItem implements IItemCus
return this.enabled && ScriptController.HasStart;
}
@Override
public INpcScriptHandler getScriptHandler() {
return this;
}
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@@ -16,6 +16,9 @@ import net.minecraftforge.common.IPlantable;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.api.INbt;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.LinkedItem;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
@@ -313,6 +316,16 @@ public class ScriptItemStack implements IItemStack {
if(item == null)
return null;
if (item.getItem() instanceof ItemLinked) {
LinkedItem linkedItem;
if (item.hasTagCompound()) {
int linkedItemId = item.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
linkedItem = LinkedItemController.Instance().get(linkedItemId);
if (linkedItem != null) {
return new ScriptLinkedItem(item);
}
}
}
if(item.getItem() instanceof ItemScripted) {
return new ScriptCustomItem(item);
}
@@ -2,6 +2,7 @@ package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.INpcScriptHandler;
import noppes.npcs.controllers.data.LinkedItem;
public class ScriptLinkedItem extends ScriptCustomizableItem {
@@ -9,8 +10,8 @@ public class ScriptLinkedItem extends ScriptCustomizableItem {
public ScriptLinkedItem(ItemStack item) {
super(item);
String linkedItemName = item.getTagCompound().getString(LinkedItem.LINKED_NBT_TAG);
this.linkedItem = LinkedItemController.Instance().get(linkedItemName);
int linkedItemId = item.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
this.linkedItem = LinkedItemController.Instance().get(linkedItemId);
this.itemDisplay.texture = null;
this.itemDisplay.translateX = null;
@@ -34,6 +35,11 @@ public class ScriptLinkedItem extends ScriptCustomizableItem {
return this.linkedItem;
}
@Override
public INpcScriptHandler getScriptHandler() {
return this.getLinkedItem().getScriptHandler();
}
@Override
public int getMaxStackSize() {
return this.linkedItem.stackSize;