mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 12:39:05 +00:00
Merge branch 'packet' into animation-events-2
This commit is contained in:
commit
25d917c338
19 files changed
+1029
-773
No files matched your search
@@ -28,7 +28,9 @@ public class CustomItems {
|
||||
public static Item mount;
|
||||
public static Item teleporter;
|
||||
public static Item tool;
|
||||
|
||||
public static Item scripted_item;
|
||||
public static Item linked_item;
|
||||
|
||||
public static Item soulstoneEmpty;
|
||||
public static Item soulstoneFull;
|
||||
@@ -245,6 +247,7 @@ public class CustomItems {
|
||||
mount = new ItemMounter().setUnlocalizedName("npcMounter").setFull3D();
|
||||
teleporter = new ItemTeleporter().setUnlocalizedName("npcTeleporter").setFull3D();
|
||||
scripted_item = new ItemScripted().setUnlocalizedName("scripted_item").setFull3D();
|
||||
linked_item = new ItemLinked().setUnlocalizedName("linked_item").setFull3D();
|
||||
tool = new ItemNpcTool().setUnlocalizedName("npcTool").setFull3D();
|
||||
|
||||
redstoneBlock = new BlockNpcRedstone().setHardness(50.0F).setResistance(2000).setBlockName("npcRedstoneBlock").setBlockTextureName("customnpcs:npcRedstoneBlock").setCreativeTab(tab);
|
||||
|
||||
@@ -22,6 +22,7 @@ import noppes.npcs.api.gui.IItemSlot;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IFrame;
|
||||
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;
|
||||
@@ -42,76 +43,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ import noppes.npcs.entity.*;
|
||||
import noppes.npcs.entity.data.ModelData;
|
||||
import noppes.npcs.entity.data.ModelPartData;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.items.ItemLinked;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import tconstruct.client.tabs.InventoryTabCustomNpc;
|
||||
@@ -528,7 +529,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 if (item instanceof ItemNpcTool) {
|
||||
MinecraftForgeClient.registerItemRenderer(item, new NpcItemToolRenderer());
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
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
|
||||
public class LinkedItemController {
|
||||
private static LinkedItemController Instance;
|
||||
private int lastUsedID = 0;
|
||||
|
||||
private final HashMap<Integer, LinkedItem> linkedItems = new HashMap<>();
|
||||
private final HashMap<Integer, EffectScript> linkedItemsScripts = new HashMap<>();
|
||||
|
||||
private LinkedItemController() {
|
||||
}
|
||||
|
||||
public static LinkedItemController Instance() {
|
||||
if (Instance == null) {
|
||||
Instance = new 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()) {
|
||||
int linkedItemId = linkedItem.getId();
|
||||
int id = this.linkedItems.containsKey(linkedItemId) ? linkedItemId : this.getUnusedId();
|
||||
this.linkedItems.put(id, linkedItem);
|
||||
linkedItem.setId(id);
|
||||
this.addScript(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemDisplayData {
|
||||
public String texture = "minecraft:textures/items/iron_pickaxe.png";
|
||||
public Float translateX = 0F, translateY = 0F, translateZ = 0F;
|
||||
public Integer itemColor = 0x8B4513;
|
||||
public Float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
|
||||
public Float rotationX = 0F, rotationY = 0F, rotationZ = 0F;
|
||||
public Float rotationXRate = 0F, rotationYRate = 0F, rotationZRate = 0F;
|
||||
public Boolean durabilityShow = false;
|
||||
public Integer durabilityColor = -1;
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
this.setBoolean(compound, "DurabilityShow", this.durabilityShow);
|
||||
this.setInteger(compound, "DurabilityColor", this.durabilityColor);
|
||||
this.setInteger(compound, "ItemColor", this.itemColor);
|
||||
if (this.texture != null) {
|
||||
compound.setString("ItemTexture", this.texture);
|
||||
}
|
||||
|
||||
this.setFloat(compound, "RotationX", this.rotationX);
|
||||
this.setFloat(compound, "RotationY", this.rotationY);
|
||||
this.setFloat(compound, "RotationZ", this.rotationZ);
|
||||
|
||||
this.setFloat(compound, "RotationXRate", this.rotationXRate);
|
||||
this.setFloat(compound, "RotationYRate", this.rotationYRate);
|
||||
this.setFloat(compound, "RotationZRate", this.rotationZRate);
|
||||
|
||||
this.setFloat(compound, "ScaleX", this.scaleX);
|
||||
this.setFloat(compound, "ScaleY", this.scaleY);
|
||||
this.setFloat(compound, "ScaleZ", this.scaleZ);
|
||||
|
||||
this.setFloat(compound, "TranslateX", this.translateX);
|
||||
this.setFloat(compound, "TranslateY", this.translateY);
|
||||
this.setFloat(compound, "TranslateZ", this.translateZ);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("DurabilityShow")) {
|
||||
this.durabilityShow = compound.getBoolean("DurabilityShow");
|
||||
}
|
||||
if (compound.hasKey("DurabilityColor")) {
|
||||
this.durabilityColor = compound.getInteger("DurabilityColor");
|
||||
}
|
||||
if (compound.hasKey("ItemColor")) {
|
||||
this.itemColor = compound.getInteger("ItemColor");
|
||||
}
|
||||
if (compound.hasKey("ItemTexture")) {
|
||||
this.texture = compound.getString("ItemTexture");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationX")) {
|
||||
this.rotationX = compound.getFloat("RotationX");
|
||||
}
|
||||
if (compound.hasKey("RotationY")) {
|
||||
this.rotationY = compound.getFloat("RotationY");
|
||||
}
|
||||
if (compound.hasKey("RotationZ")) {
|
||||
this.rotationZ = compound.getFloat("RotationZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationXRate")) {
|
||||
this.rotationXRate = compound.getFloat("RotationXRate");
|
||||
}
|
||||
if (compound.hasKey("RotationYRate")) {
|
||||
this.rotationYRate = compound.getFloat("RotationYRate");
|
||||
}
|
||||
if (compound.hasKey("RotationZRate")) {
|
||||
this.rotationZRate = compound.getFloat("RotationZRate");
|
||||
}
|
||||
|
||||
if (compound.hasKey("ScaleX")) {
|
||||
this.scaleX = compound.getFloat("ScaleX");
|
||||
}
|
||||
if (compound.hasKey("ScaleY")) {
|
||||
this.scaleY = compound.getFloat("ScaleY");
|
||||
}
|
||||
if (compound.hasKey("ScaleZ")) {
|
||||
this.scaleZ = compound.getFloat("ScaleZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("TranslateX")) {
|
||||
this.translateX = compound.getFloat("TranslateX");
|
||||
}
|
||||
if (compound.hasKey("TranslateY")) {
|
||||
this.translateY = compound.getFloat("TranslateY");
|
||||
}
|
||||
if (compound.hasKey("TranslateZ")) {
|
||||
this.translateZ = compound.getFloat("TranslateZ");
|
||||
}
|
||||
}
|
||||
|
||||
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
|
||||
if (value != null) {
|
||||
compound.setBoolean(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setInteger(NBTTagCompound compound, String key, Integer value) {
|
||||
if (value != null) {
|
||||
compound.setInteger(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFloat(NBTTagCompound compound, String key, Float value) {
|
||||
if (value != null) {
|
||||
compound.setFloat(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
|
||||
public class LinkedItem {
|
||||
public static final String LINKED_NBT_TAG = "LinkedId";
|
||||
|
||||
private int id = -1;
|
||||
private String name;
|
||||
public final ItemDisplayData display = new ItemDisplayData();
|
||||
|
||||
public double durabilityValue = 1.0D;
|
||||
public int stackSize = 64;
|
||||
|
||||
public int maxItemUseDuration = 20;
|
||||
public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink
|
||||
|
||||
public boolean isNormalItem = 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 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() {
|
||||
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);
|
||||
compound.setInteger("MaxStackSize",this.stackSize);
|
||||
|
||||
compound.setBoolean("IsTool", this.isTool);
|
||||
compound.setBoolean("IsNormalItem", this.isNormalItem);
|
||||
compound.setInteger("DigSpeed", this.digSpeed);
|
||||
compound.setInteger("ArmorType", this.armorType);
|
||||
compound.setInteger("Enchantability", this.enchantability);
|
||||
|
||||
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
|
||||
compound.setInteger("ItemUseAction", this.itemUseAction);
|
||||
return compound;
|
||||
}
|
||||
|
||||
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");
|
||||
this.stackSize = compound.getInteger("MaxStackSize");
|
||||
|
||||
this.isTool = compound.getBoolean("IsTool");
|
||||
this.isNormalItem = compound.getBoolean("IsNormalItem");
|
||||
this.digSpeed = compound.getInteger("DigSpeed");
|
||||
this.armorType = compound.getInteger("ArmorType");
|
||||
this.enchantability = compound.getInteger("Enchantability");
|
||||
|
||||
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
|
||||
this.itemUseAction = compound.getInteger("ItemUseAction");
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
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.event.ItemEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public abstract class ItemCustomizable extends Item implements ItemRenderInterface {
|
||||
|
||||
@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 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item setUnlocalizedName(String name){
|
||||
GameRegistry.registerItem(this, name);
|
||||
return super.setUnlocalizedName(name);
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
public EnumAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
|
||||
if (istack instanceof IItemCustomizable) {
|
||||
switch (((IItemCustomizable) 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSpecial() {}
|
||||
|
||||
public void renderOffset(IItemCustomizable scriptCustomItem) {
|
||||
GL11.glTranslatef(0.135F * scriptCustomItem.getScaleX(), 0.2F * scriptCustomItem.getScaleY(), 0.07F * scriptCustomItem.getScaleZ());
|
||||
}
|
||||
}
|
||||
@@ -1,158 +1,12 @@
|
||||
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.util.ChatComponentTranslation;
|
||||
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 ItemLinked extends Item implements ItemRenderInterface {
|
||||
public class ItemLinked extends ItemCustomizable {
|
||||
|
||||
public ItemLinked() {
|
||||
maxStackSize = 1;
|
||||
CustomNpcs.proxy.registerItem(this);
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@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 player)
|
||||
{
|
||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@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 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSpecial() {}
|
||||
|
||||
public void renderOffset(ScriptCustomItem scriptCustomItem) {
|
||||
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,17 @@
|
||||
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.util.ChatComponentTranslation;
|
||||
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 Item implements ItemRenderInterface {
|
||||
public class ItemScripted extends ItemCustomizable {
|
||||
|
||||
public ItemScripted() {
|
||||
maxStackSize = 1;
|
||||
setCreativeTab(CustomItems.tab);
|
||||
@@ -34,27 +19,6 @@ public class ItemScripted extends Item implements ItemRenderInterface {
|
||||
setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@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 player)
|
||||
{
|
||||
if(player.isSneaking() && player.capabilities.isCreativeMode) {
|
||||
@@ -64,102 +28,6 @@ public class ItemScripted extends Item implements ItemRenderInterface {
|
||||
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, player);
|
||||
}
|
||||
}
|
||||
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@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 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSpecial() {}
|
||||
|
||||
public void renderOffset(ScriptCustomItem scriptCustomItem) {
|
||||
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
|
||||
return super.onItemRightClick(stack, world, player);
|
||||
}
|
||||
}
|
||||
@@ -48,13 +48,11 @@ import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.containers.ContainerNpcInterface;
|
||||
import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.Frame;
|
||||
import noppes.npcs.controllers.data.FramePart;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.entity.EntityProjectile;
|
||||
import noppes.npcs.items.ItemLinked;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import noppes.npcs.scripted.entity.*;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
@@ -64,7 +62,6 @@ import noppes.npcs.util.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -473,7 +470,17 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
if (scriptItemCache.containsKey(itemstack)) {
|
||||
scriptStack = scriptItemCache.get(itemstack).getObject();
|
||||
} else {
|
||||
if (itemstack.getItem() instanceof ItemScripted) {
|
||||
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) {
|
||||
scriptStack = new ScriptCustomItem(itemstack);
|
||||
} else if (itemstack.getItem() instanceof ItemArmor) {
|
||||
scriptStack = new ScriptItemArmor(itemstack);
|
||||
|
||||
@@ -5,16 +5,17 @@ import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IItemEvent;
|
||||
import noppes.npcs.api.item.IItemCustom;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IItemCustom item;
|
||||
public final IItemCustomizable item;
|
||||
|
||||
public ItemEvent(IItemCustom item) {
|
||||
public ItemEvent(IItemCustomizable item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public IItemCustom getItem() {
|
||||
public IItemCustomizable getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -23,7 +24,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
}
|
||||
|
||||
public static class InitEvent extends ItemEvent implements IItemEvent.InitEvent {
|
||||
public InitEvent(IItemCustom item) {
|
||||
public InitEvent(IItemCustomizable item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public static class UpdateEvent extends ItemEvent implements IItemEvent.UpdateEvent {
|
||||
public final IEntity entity;
|
||||
|
||||
public UpdateEvent(IItemCustom item, IEntity entity) {
|
||||
public UpdateEvent(IItemCustomizable item, IEntity entity) {
|
||||
super(item);
|
||||
this.entity = entity;
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IEntity entity;
|
||||
public final IPlayer player;
|
||||
|
||||
public TossedEvent(IItemCustom item, IPlayer player, IEntity entity) {
|
||||
public TossedEvent(IItemCustomizable item, IPlayer player, IEntity entity) {
|
||||
super(item);
|
||||
this.entity = entity;
|
||||
this.player = player;
|
||||
@@ -76,7 +77,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public static class PickedUpEvent extends ItemEvent implements IItemEvent.PickedUpEvent {
|
||||
public final IPlayer player;
|
||||
|
||||
public PickedUpEvent(IItemCustom item, IPlayer player) {
|
||||
public PickedUpEvent(IItemCustomizable item, IPlayer player) {
|
||||
super(item);
|
||||
this.player = player;
|
||||
}
|
||||
@@ -94,7 +95,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public static class SpawnEvent extends ItemEvent implements IItemEvent.SpawnEvent {
|
||||
public final IEntity entity;
|
||||
|
||||
public SpawnEvent(IItemCustom item, IEntity entity){
|
||||
public SpawnEvent(IItemCustomizable item, IEntity entity){
|
||||
super(item);
|
||||
this.entity = entity;
|
||||
}
|
||||
@@ -114,7 +115,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IEntity target;
|
||||
public final IPlayer player;
|
||||
|
||||
public InteractEvent(IItemCustom item, IPlayer player, int type, IEntity target) {
|
||||
public InteractEvent(IItemCustomizable item, IPlayer player, int type, IEntity target) {
|
||||
super(item);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
@@ -148,7 +149,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final Object target;
|
||||
public final IPlayer player;
|
||||
|
||||
public RightClickEvent(IItemCustom item, IPlayer player, int type, Object target) {
|
||||
public RightClickEvent(IItemCustomizable item, IPlayer player, int type, Object target) {
|
||||
super(item);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
@@ -178,7 +179,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IEntity target;
|
||||
public final IEntity swingingEntity;
|
||||
|
||||
public AttackEvent(IItemCustom item, IEntity swingingEntity, int type, IEntity target) {
|
||||
public AttackEvent(IItemCustomizable item, IEntity swingingEntity, int type, IEntity target) {
|
||||
super(item);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
@@ -207,7 +208,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IPlayer player;
|
||||
public final int duration;
|
||||
|
||||
public StartUsingItem(IItemCustom item, IPlayer player, int duration){
|
||||
public StartUsingItem(IItemCustomizable item, IPlayer player, int duration){
|
||||
super(item);
|
||||
this.player = player;
|
||||
this.duration = duration;
|
||||
@@ -231,7 +232,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IPlayer player;
|
||||
public final int duration;
|
||||
|
||||
public UsingItem(IItemCustom item, IPlayer player, int duration){
|
||||
public UsingItem(IItemCustomizable item, IPlayer player, int duration){
|
||||
super(item);
|
||||
this.player = player;
|
||||
this.duration = duration;
|
||||
@@ -255,7 +256,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IPlayer player;
|
||||
public final int duration;
|
||||
|
||||
public StopUsingItem(IItemCustom item, IPlayer player, int duration){
|
||||
public StopUsingItem(IItemCustomizable item, IPlayer player, int duration){
|
||||
super(item);
|
||||
this.player = player;
|
||||
this.duration = duration;
|
||||
@@ -279,7 +280,7 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent {
|
||||
public final IPlayer player;
|
||||
public final int duration;
|
||||
|
||||
public FinishUsingItem(IItemCustom item, IPlayer player, int duration){
|
||||
public FinishUsingItem(IItemCustomizable item, IPlayer player, int duration){
|
||||
super(item);
|
||||
this.player = player;
|
||||
this.duration = duration;
|
||||
|
||||
@@ -14,7 +14,7 @@ import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, INpcScriptHandler {
|
||||
public class ScriptCustomItem extends ScriptCustomizableItem implements IItemCustom, INpcScriptHandler {
|
||||
public List<ScriptContainer> scripts = new ArrayList();
|
||||
public List<Integer> errored = new ArrayList();
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
@@ -33,8 +33,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
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 Display itemDisplay = new Display();
|
||||
|
||||
public long lastInited = -1;
|
||||
|
||||
public ScriptCustomItem(ItemStack item) {
|
||||
@@ -65,6 +63,11 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
return this.enabled && ScriptController.HasStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INpcScriptHandler getScriptHandler() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
this.callScript(type.function, event);
|
||||
}
|
||||
@@ -140,17 +143,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
public void clearConsole() {
|
||||
}
|
||||
|
||||
public String getTexture() {
|
||||
return this.itemDisplay.texture == null ? "" : this.itemDisplay.texture;
|
||||
}
|
||||
|
||||
public void setTexture(String texture){
|
||||
if(texture == null)
|
||||
texture = "";
|
||||
this.itemDisplay.texture = texture;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public int getMaxStackSize() {
|
||||
return this.stackSize;
|
||||
}
|
||||
@@ -210,33 +202,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public boolean getDurabilityShow() {
|
||||
return this.itemDisplay.durabilityShow;
|
||||
}
|
||||
|
||||
public void setDurabilityShow(boolean bo) {
|
||||
this.itemDisplay.durabilityShow = bo;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public int getDurabilityColor() {
|
||||
return this.itemDisplay.durabilityColor;
|
||||
}
|
||||
|
||||
public void setDurabilityColor(int color) {
|
||||
this.itemDisplay.durabilityColor = color;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.itemDisplay.itemColor;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.itemDisplay.itemColor = color;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public int getMaxItemUseDuration(){
|
||||
return this.maxItemUseDuration;
|
||||
}
|
||||
@@ -264,165 +229,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setRotation(float rotationX, float rotationY, float rotationZ){
|
||||
this.itemDisplay.rotationX = rotationX;
|
||||
this.itemDisplay.rotationY = rotationY;
|
||||
this.itemDisplay.rotationZ = rotationZ;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setRotationRate(float rotationXRate, float rotationYRate, float rotationZRate){
|
||||
this.itemDisplay.rotationXRate = rotationXRate;
|
||||
this.itemDisplay.rotationYRate = rotationYRate;
|
||||
this.itemDisplay.rotationZRate = rotationZRate;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setScale(float scaleX, float scaleY, float scaleZ){
|
||||
this.itemDisplay.scaleX = scaleX;
|
||||
this.itemDisplay.scaleY = scaleY;
|
||||
this.itemDisplay.scaleZ = scaleZ;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setTranslate(float translateX, float translateY, float translateZ){
|
||||
this.itemDisplay.translateX = translateX;
|
||||
this.itemDisplay.translateY = translateY;
|
||||
this.itemDisplay.translateZ = translateZ;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public float getRotationX() {
|
||||
return this.itemDisplay.rotationX;
|
||||
}
|
||||
|
||||
public float getRotationY() {
|
||||
return this.itemDisplay.rotationY;
|
||||
}
|
||||
|
||||
public float getRotationZ() {
|
||||
return this.itemDisplay.rotationZ;
|
||||
}
|
||||
|
||||
public float getRotationXRate() {
|
||||
return this.itemDisplay.rotationXRate;
|
||||
}
|
||||
|
||||
public float getRotationYRate() {
|
||||
return this.itemDisplay.rotationYRate;
|
||||
}
|
||||
|
||||
public float getRotationZRate() {
|
||||
return this.itemDisplay.rotationZRate;
|
||||
}
|
||||
|
||||
public float getScaleX() {
|
||||
return this.itemDisplay.scaleX;
|
||||
}
|
||||
|
||||
public float getScaleY() {
|
||||
return this.itemDisplay.scaleY;
|
||||
}
|
||||
|
||||
public float getScaleZ() {
|
||||
return this.itemDisplay.scaleZ;
|
||||
}
|
||||
|
||||
public float getTranslateX() {
|
||||
return this.itemDisplay.translateX;
|
||||
}
|
||||
|
||||
public float getTranslateY() {
|
||||
return this.itemDisplay.translateY;
|
||||
}
|
||||
|
||||
public float getTranslateZ() {
|
||||
return this.itemDisplay.translateZ;
|
||||
}
|
||||
|
||||
public NBTTagCompound getMCNbt() {
|
||||
NBTTagCompound compound = super.getMCNbt();
|
||||
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
||||
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void setMCNbt(NBTTagCompound compound) {
|
||||
setScriptNBT(compound.getCompoundTag("ScriptedData"));
|
||||
setItemNBT(compound.getCompoundTag("ItemData"));
|
||||
}
|
||||
|
||||
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
|
||||
compound.setBoolean("DurabilityShow",this.itemDisplay.durabilityShow);
|
||||
compound.setDouble("DurabilityValue",this.durabilityValue);
|
||||
compound.setInteger("DurabilityColor",this.itemDisplay.durabilityColor );
|
||||
compound.setInteger("ItemColor",this.itemDisplay.itemColor);
|
||||
compound.setInteger("MaxStackSize",this.stackSize);
|
||||
compound.setString("ItemTexture",this.itemDisplay.texture);
|
||||
|
||||
compound.setFloat("RotationX",this.itemDisplay.rotationX);
|
||||
compound.setFloat("RotationY",this.itemDisplay.rotationY);
|
||||
compound.setFloat("RotationZ",this.itemDisplay.rotationZ);
|
||||
|
||||
compound.setFloat("RotationXRate",this.itemDisplay.rotationXRate);
|
||||
compound.setFloat("RotationYRate",this.itemDisplay.rotationYRate);
|
||||
compound.setFloat("RotationZRate",this.itemDisplay.rotationZRate);
|
||||
|
||||
compound.setFloat("ScaleX",this.itemDisplay.scaleX);
|
||||
compound.setFloat("ScaleY",this.itemDisplay.scaleY);
|
||||
compound.setFloat("ScaleZ",this.itemDisplay.scaleZ);
|
||||
|
||||
compound.setFloat("TranslateX",this.itemDisplay.translateX);
|
||||
compound.setFloat("TranslateY",this.itemDisplay.translateY);
|
||||
compound.setFloat("TranslateZ",this.itemDisplay.translateZ);
|
||||
|
||||
compound.setBoolean("IsTool", this.isTool);
|
||||
compound.setBoolean("IsNormalItem", this.isNormalItem);
|
||||
compound.setInteger("DigSpeed", this.digSpeed);
|
||||
compound.setInteger("ArmorType", this.armorType);
|
||||
compound.setInteger("Enchantability", this.enchantability);
|
||||
|
||||
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
|
||||
compound.setInteger("ItemUseAction", this.itemUseAction);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void setItemNBT(NBTTagCompound compound) {
|
||||
this.itemDisplay.durabilityShow = compound.getBoolean("DurabilityShow");
|
||||
this.durabilityValue = compound.getDouble("DurabilityValue");
|
||||
if (compound.hasKey("DurabilityColor")) {
|
||||
this.itemDisplay.durabilityColor = compound.getInteger("DurabilityColor");
|
||||
}
|
||||
this.itemDisplay.itemColor = compound.getInteger("ItemColor");
|
||||
this.stackSize = compound.getInteger("MaxStackSize");
|
||||
this.itemDisplay.texture = compound.getString("ItemTexture");
|
||||
|
||||
this.itemDisplay.rotationX = compound.getFloat("RotationX");
|
||||
this.itemDisplay.rotationY = compound.getFloat("RotationY");
|
||||
this.itemDisplay.rotationZ = compound.getFloat("RotationZ");
|
||||
|
||||
this.itemDisplay.rotationXRate = compound.getFloat("RotationXRate");
|
||||
this.itemDisplay.rotationYRate = compound.getFloat("RotationYRate");
|
||||
this.itemDisplay.rotationZRate = compound.getFloat("RotationZRate");
|
||||
|
||||
this.itemDisplay.scaleX = compound.getFloat("ScaleX");
|
||||
this.itemDisplay.scaleY = compound.getFloat("ScaleY");
|
||||
this.itemDisplay.scaleZ = compound.getFloat("ScaleZ");
|
||||
|
||||
this.itemDisplay.translateX = compound.getFloat("TranslateX");
|
||||
this.itemDisplay.translateY = compound.getFloat("TranslateY");
|
||||
this.itemDisplay.translateZ = compound.getFloat("TranslateZ");
|
||||
|
||||
this.isTool = compound.getBoolean("IsTool");
|
||||
this.isNormalItem = compound.getBoolean("IsNormalItem");
|
||||
this.digSpeed = compound.getInteger("DigSpeed");
|
||||
this.armorType = compound.getInteger("ArmorType");
|
||||
this.enchantability = compound.getInteger("Enchantability");
|
||||
|
||||
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
|
||||
this.itemUseAction = compound.getInteger("ItemUseAction");
|
||||
}
|
||||
|
||||
public void saveScriptData() {
|
||||
NBTTagCompound c = this.item.getTagCompound();
|
||||
if (c == null) {
|
||||
@@ -439,31 +245,45 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
|
||||
}
|
||||
}
|
||||
|
||||
public void saveItemData() {
|
||||
NBTTagCompound c = this.item.getTagCompound();
|
||||
if (c == null) {
|
||||
this.item.setTagCompound(c = new NBTTagCompound());
|
||||
}
|
||||
|
||||
c.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
||||
public NBTTagCompound getMCNbt() {
|
||||
NBTTagCompound compound = super.getMCNbt();
|
||||
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void loadItemData() {
|
||||
NBTTagCompound c = this.item.getTagCompound();
|
||||
if (c != null && !c.getCompoundTag("ItemData").hasNoTags()){
|
||||
this.setItemNBT(c.getCompoundTag("ItemData"));
|
||||
}
|
||||
public void setMCNbt(NBTTagCompound compound) {
|
||||
super.setMCNbt(compound);
|
||||
setScriptNBT(compound.getCompoundTag("ScriptedData"));
|
||||
}
|
||||
|
||||
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
|
||||
super.getItemNBT(compound);
|
||||
compound.setDouble("DurabilityValue",this.durabilityValue);
|
||||
compound.setInteger("MaxStackSize",this.stackSize);
|
||||
|
||||
public static class Display {
|
||||
public String texture = "minecraft:textures/items/iron_pickaxe.png";
|
||||
public float translateX, translateY, translateZ;
|
||||
public int itemColor = 0x8B4513;
|
||||
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
|
||||
public float rotationX, rotationY, rotationZ;
|
||||
public float rotationXRate, rotationYRate, rotationZRate;
|
||||
public boolean durabilityShow = false;
|
||||
public int durabilityColor = -1;
|
||||
compound.setBoolean("IsTool", this.isTool);
|
||||
compound.setBoolean("IsNormalItem", this.isNormalItem);
|
||||
compound.setInteger("DigSpeed", this.digSpeed);
|
||||
compound.setInteger("ArmorType", this.armorType);
|
||||
compound.setInteger("Enchantability", this.enchantability);
|
||||
|
||||
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
|
||||
compound.setInteger("ItemUseAction", this.itemUseAction);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void setItemNBT(NBTTagCompound compound) {
|
||||
super.setItemNBT(compound);
|
||||
this.durabilityValue = compound.getDouble("DurabilityValue");
|
||||
this.stackSize = compound.getInteger("MaxStackSize");
|
||||
|
||||
this.isTool = compound.getBoolean("IsTool");
|
||||
this.isNormalItem = compound.getBoolean("IsNormalItem");
|
||||
this.digSpeed = compound.getInteger("DigSpeed");
|
||||
this.armorType = compound.getInteger("ArmorType");
|
||||
this.enchantability = compound.getInteger("Enchantability");
|
||||
|
||||
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
|
||||
this.itemUseAction = compound.getInteger("ItemUseAction");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.controllers.data.ItemDisplayData;
|
||||
|
||||
public abstract class ScriptCustomizableItem extends ScriptItemStack implements IItemCustomizable {
|
||||
public final ItemDisplayData itemDisplay = new ItemDisplayData();
|
||||
|
||||
public ScriptCustomizableItem(ItemStack item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
public abstract int getMaxStackSize();
|
||||
|
||||
// public abstract void setArmorType(int armorType);
|
||||
|
||||
public abstract int getArmorType();
|
||||
|
||||
// public abstract void setIsTool(boolean isTool);
|
||||
|
||||
public abstract boolean isTool();
|
||||
|
||||
// public abstract void setIsNormalItem(boolean normalItem);
|
||||
|
||||
public abstract boolean isNormalItem();
|
||||
|
||||
// public abstract void setDigSpeed(int digSpeed);
|
||||
|
||||
public abstract int getDigSpeed();
|
||||
|
||||
// public abstract void setMaxStackSize(int size);
|
||||
|
||||
public abstract double getDurabilityValue();
|
||||
|
||||
// public abstract void setDurabilityValue(float value);
|
||||
|
||||
public abstract int getMaxItemUseDuration();
|
||||
|
||||
// public abstract void setMaxItemUseDuration(int duration);
|
||||
|
||||
public abstract int getItemUseAction();
|
||||
|
||||
// public abstract void setItemUseAction(int action);
|
||||
|
||||
public abstract int getEnchantability();
|
||||
|
||||
// public abstract void setEnchantability(int enchantability);
|
||||
|
||||
public String getTexture() {
|
||||
return this.itemDisplay.texture == null ? "" : this.itemDisplay.texture;
|
||||
}
|
||||
|
||||
public void setTexture(String texture){
|
||||
if(texture == null)
|
||||
texture = "";
|
||||
this.itemDisplay.texture = texture;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public Boolean getDurabilityShow() {
|
||||
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : false;
|
||||
}
|
||||
|
||||
public void setDurabilityShow(Boolean bo) {
|
||||
this.itemDisplay.durabilityShow = bo;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public Integer getDurabilityColor() {
|
||||
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : -1;
|
||||
}
|
||||
|
||||
public void setDurabilityColor(Integer color) {
|
||||
this.itemDisplay.durabilityColor = color;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public Integer getColor() {
|
||||
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : 0x8B4513;
|
||||
}
|
||||
|
||||
public void setColor(Integer color) {
|
||||
this.itemDisplay.itemColor = color;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
|
||||
public void setRotation(Float rotationX, Float rotationY, Float rotationZ){
|
||||
this.itemDisplay.rotationX = rotationX;
|
||||
this.itemDisplay.rotationY = rotationY;
|
||||
this.itemDisplay.rotationZ = rotationZ;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setRotationRate(Float rotationXRate, Float rotationYRate, Float rotationZRate){
|
||||
this.itemDisplay.rotationXRate = rotationXRate;
|
||||
this.itemDisplay.rotationYRate = rotationYRate;
|
||||
this.itemDisplay.rotationZRate = rotationZRate;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setScale(Float scaleX, Float scaleY, Float scaleZ){
|
||||
this.itemDisplay.scaleX = scaleX;
|
||||
this.itemDisplay.scaleY = scaleY;
|
||||
this.itemDisplay.scaleZ = scaleZ;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public void setTranslate(Float translateX, Float translateY, Float translateZ){
|
||||
this.itemDisplay.translateX = translateX;
|
||||
this.itemDisplay.translateY = translateY;
|
||||
this.itemDisplay.translateZ = translateZ;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public Float getRotationX() {
|
||||
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : 0;
|
||||
}
|
||||
|
||||
public Float getRotationY() {
|
||||
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : 0;
|
||||
}
|
||||
|
||||
public Float getRotationZ() {
|
||||
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : 0;
|
||||
}
|
||||
|
||||
public Float getRotationXRate() {
|
||||
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : 0;
|
||||
}
|
||||
|
||||
public Float getRotationYRate() {
|
||||
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : 0;
|
||||
}
|
||||
|
||||
public Float getRotationZRate() {
|
||||
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : 0;
|
||||
}
|
||||
|
||||
public Float getScaleX() {
|
||||
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : 0;
|
||||
}
|
||||
|
||||
public Float getScaleY() {
|
||||
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : 0;
|
||||
}
|
||||
|
||||
public Float getScaleZ() {
|
||||
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : 0;
|
||||
}
|
||||
|
||||
public Float getTranslateX() {
|
||||
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : 0;
|
||||
}
|
||||
|
||||
public Float getTranslateY() {
|
||||
return this.itemDisplay.translateY != null ? this.itemDisplay.translateY : 0;
|
||||
}
|
||||
|
||||
public Float getTranslateZ() {
|
||||
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : 0;
|
||||
}
|
||||
|
||||
public NBTTagCompound getMCNbt() {
|
||||
NBTTagCompound compound = super.getMCNbt();
|
||||
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void setMCNbt(NBTTagCompound compound) {
|
||||
super.setMCNbt(compound);
|
||||
setItemNBT(compound.getCompoundTag("ItemData"));
|
||||
}
|
||||
|
||||
public void saveItemData() {
|
||||
NBTTagCompound c = this.item.getTagCompound();
|
||||
if (c == null) {
|
||||
this.item.setTagCompound(c = new NBTTagCompound());
|
||||
}
|
||||
c.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
public void loadItemData() {
|
||||
NBTTagCompound c = this.item.getTagCompound();
|
||||
if (c != null && !c.getCompoundTag("ItemData").hasNoTags()){
|
||||
this.setItemNBT(c.getCompoundTag("ItemData"));
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
|
||||
this.itemDisplay.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void setItemNBT(NBTTagCompound compound) {
|
||||
this.itemDisplay.readFromNBT(compound);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.api.item.IItemLinked;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.data.INpcScriptHandler;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLinked {
|
||||
private final LinkedItem linkedItem;
|
||||
|
||||
public ScriptLinkedItem(ItemStack item) {
|
||||
super(item);
|
||||
int linkedItemId = item.getTagCompound().getInteger(LinkedItem.LINKED_NBT_TAG);
|
||||
this.linkedItem = LinkedItemController.Instance().get(linkedItemId);
|
||||
|
||||
this.itemDisplay.texture = null;
|
||||
this.itemDisplay.translateX = null;
|
||||
this.itemDisplay.translateY = null;
|
||||
this.itemDisplay.translateZ = null;
|
||||
this.itemDisplay.itemColor = null;
|
||||
this.itemDisplay.scaleX = null;
|
||||
this.itemDisplay.scaleY = null;
|
||||
this.itemDisplay.scaleZ = null;
|
||||
this.itemDisplay.rotationX = null;
|
||||
this.itemDisplay.rotationY = null;
|
||||
this.itemDisplay.rotationZ = null;
|
||||
this.itemDisplay.rotationXRate = null;
|
||||
this.itemDisplay.rotationYRate = null;
|
||||
this.itemDisplay.rotationZRate = null;
|
||||
this.itemDisplay.durabilityShow = null;
|
||||
this.itemDisplay.durabilityColor = null;
|
||||
}
|
||||
|
||||
public LinkedItem getLinkedItem() {
|
||||
return this.linkedItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INpcScriptHandler getScriptHandler() {
|
||||
return this.getLinkedItem().getScriptHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return this.linkedItem.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArmorType() {
|
||||
return this.linkedItem.armorType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTool() {
|
||||
return this.linkedItem.isTool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNormalItem() {
|
||||
return this.linkedItem.isNormalItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDigSpeed() {
|
||||
return this.linkedItem.digSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityValue() {
|
||||
return this.linkedItem.durabilityValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration() {
|
||||
return this.linkedItem.maxItemUseDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemUseAction() {
|
||||
return this.linkedItem.itemUseAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantability() {
|
||||
return this.linkedItem.enchantability;
|
||||
}
|
||||
|
||||
public String getTexture() {
|
||||
return this.itemDisplay.texture == null ? this.linkedItem.display.texture : this.itemDisplay.texture;
|
||||
}
|
||||
|
||||
public Boolean getDurabilityShow() {
|
||||
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : this.linkedItem.display.durabilityShow;
|
||||
}
|
||||
|
||||
public Integer getDurabilityColor() {
|
||||
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : this.linkedItem.display.durabilityColor;
|
||||
}
|
||||
|
||||
public Integer getColor() {
|
||||
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : this.linkedItem.display.itemColor;
|
||||
}
|
||||
|
||||
public Float getRotationX() {
|
||||
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : this.linkedItem.display.rotationX;
|
||||
}
|
||||
|
||||
public Float getRotationY() {
|
||||
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : this.linkedItem.display.rotationY;
|
||||
}
|
||||
|
||||
public Float getRotationZ() {
|
||||
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : this.linkedItem.display.rotationZ;
|
||||
}
|
||||
|
||||
public Float getRotationXRate() {
|
||||
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : this.linkedItem.display.rotationXRate;
|
||||
}
|
||||
|
||||
public Float getRotationYRate() {
|
||||
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : this.linkedItem.display.rotationYRate;
|
||||
}
|
||||
|
||||
public Float getRotationZRate() {
|
||||
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : this.linkedItem.display.rotationZRate;
|
||||
}
|
||||
|
||||
public Float getScaleX() {
|
||||
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : this.linkedItem.display.scaleX;
|
||||
}
|
||||
|
||||
public Float getScaleY() {
|
||||
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : this.linkedItem.display.scaleY;
|
||||
}
|
||||
|
||||
public Float getScaleZ() {
|
||||
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : this.linkedItem.display.scaleZ;
|
||||
}
|
||||
|
||||
public Float getTranslateX() {
|
||||
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : this.linkedItem.display.translateX;
|
||||
}
|
||||
|
||||
public Float getTranslateY() {
|
||||
return this.itemDisplay.translateY != null ? this.itemDisplay.translateY : this.linkedItem.display.translateY;
|
||||
}
|
||||
|
||||
public Float getTranslateZ() {
|
||||
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : this.linkedItem.display.translateZ;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user