From 459976c54d82a0f97f8a4fcaf27e24b23f14ebc0 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 5 Sep 2021 21:48:36 -0500 Subject: [PATCH 01/58] Modified giveItem() method to give the player item(s) with all attributes of the ScriptItemStack parameter. --- src/main/java/noppes/npcs/scripted/ScriptPlayer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java index 19eb36dc6..2b98f0c7d 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java @@ -245,8 +245,12 @@ public class ScriptPlayer extends ScriptLivingBase{ * @return Returns whether or not it gave the item succesfully */ public boolean giveItem(ScriptItemStack item, int amount){ - String itemname = Item.itemRegistry.getNameForObject(item.getMCItemStack().getItem()); - return giveItem(itemname, item.getItemDamage(), amount); + if(item != null && item.getMCItemStack() != null) { + item.setStackSize(amount); + return this.player.inventory.addItemStackToInventory(item.getMCItemStack()); + } else { + return false; + } } /** From 2a378190aeb85b134af26e7d74c3e5433a1dfa0a Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 5 Sep 2021 21:53:58 -0500 Subject: [PATCH 02/58] Added EntityCustomFX class, used for spawning custom particles on entities. --- .../noppes/npcs/client/fx/EntityCustomFX.java | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/main/java/noppes/npcs/client/fx/EntityCustomFX.java diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java new file mode 100644 index 000000000..bd6ee8456 --- /dev/null +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -0,0 +1,126 @@ +package noppes.npcs.client.fx; + +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.ModelPartData; +import noppes.npcs.client.ClientProxy; +import org.lwjgl.opengl.GL11; + +public class EntityCustomFX extends EntityFX { + private Entity entity; + private final ResourceLocation location; + private boolean move = true; + private float startX = 0, startY = 0, startZ = 0; + + public float scale1 = 1.0F; + public float scale2 = 1.0F; + public float scaleRate = 1.0F; + public int scaleRateStart = 0; + + public float alpha1 = 1.0F; + public float alpha2 = 0; + public float alphaRate = 0.0F; + public int alphaRateStart = 0; + + public EntityCustomFX(Entity entity, double x, double y, double z, + double motionX, double motionY, double motionZ, float gravity, + float scale1, float scale2, float scaleRate, int scaleRateStart, + float alpha1, float alpha2, float alphaRate, int alphaRateStart, + int age, + ModelPartData data) { + super(entity.worldObj, x, y, z, motionX, motionY, motionZ); + + this.scale1 = scale1; + this.scale2 = scale2; + this.scaleRate = Math.abs(scaleRate); + this.scaleRateStart = scaleRateStart; + particleScale = scale1; + if(scale1 > scale2) + this.scaleRate *= -1; + + this.alpha1 = alpha1; + this.alpha2 = alpha2; + this.alphaRate = Math.abs(alphaRate); + this.alphaRateStart = alphaRateStart; + particleAlpha = alpha1; + if(alpha1 > alpha2) + this.alphaRate *= -1; + + particleGravity = gravity/0.04F; + particleMaxAge = age; + + this.motionX = motionX; + this.motionY = motionY; + this.motionZ = motionZ; + + this.entity = entity; + noClip = true; + + particleRed = (data.color >> 16 & 255) / 255f; + particleGreen = (data.color >> 8 & 255) / 255f; + particleBlue = (data.color & 255) / 255f; + + if(Math.floor(Math.random()*3) == 1){ + move = false; + this.startX = (float) entity.posX; + this.startY = (float) entity.posY; + this.startZ = (float) entity.posZ; + } + + location = new ResourceLocation(data.texture); + } + + @Override + public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) + { + if(move){ + startX = (float)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)par2); + startY = (float)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)par2); + startZ = (float)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)par2); + } + Tessellator tessellator = Tessellator.instance; + tessellator.draw(); + + float scale = this.scaleRate / (float)particleMaxAge; + if((this.scaleRate < 0 && particleScale+scale < this.scale2) || (this.scaleRate > 0 && particleScale+scale > this.scale2)) + particleScale = this.scale2; + else if(particleAge >= this.scaleRateStart) + particleScale += scale; + + float alpha = this.alphaRate / (float)particleMaxAge; + if((this.alphaRate < 0 && particleAlpha+alpha < this.alpha2) || (this.alphaRate > 0 && particleAlpha+alpha > this.alpha2)) + particleAlpha = this.alpha2; + else if(particleAge >= this.alphaRateStart) + particleAlpha += alpha; + + ClientProxy.bindTexture(location); + + float f = 0.0f; + float f1 = 1.0f; + float f2 = 0.0f; + float f3 = 1.0f; + float f4 = 0.1F * particleScale; + float f5 = (float)(((prevPosX + (posX - prevPosX) * (double)par2) - interpPosX) + startX); + float f6 = (float)(((prevPosY + (posY - prevPosY) * (double)par2) - interpPosY) + startY); + float f7 = (float)(((prevPosZ + (posZ - prevPosZ) * (double)par2) - interpPosZ) + startZ); + + GL11.glColor4f(1, 1, 1, 1.0F); + tessellator.startDrawingQuads(); + tessellator.setBrightness(240); + par1Tessellator.setColorOpaque_F(1, 1, 1); + par1Tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha); + par1Tessellator.addVertexWithUV(f5 - par3 * f4 - par6 * f4, f6 - par4 * f4, f7 - par5 * f4 - par7 * f4, f1, f3); + par1Tessellator.addVertexWithUV((f5 - par3 * f4) + par6 * f4, f6 + par4 * f4, (f7 - par5 * f4) + par7 * f4, f1, f2); + par1Tessellator.addVertexWithUV(f5 + par3 * f4 + par6 * f4, f6 + par4 * f4, f7 + par5 * f4 + par7 * f4, f, f2); + par1Tessellator.addVertexWithUV((f5 + par3 * f4) - par6 * f4, f6 - par4 * f4, (f7 + par5 * f4) - par7 * f4, f, f3); + + tessellator.draw(); + tessellator.startDrawingQuads(); + } + + public int getFXLayer(){ + return 0; + } +} From 9f4ab7f01efdc151e413355daa3e9be2d76f0a98 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 5 Sep 2021 23:01:25 -0500 Subject: [PATCH 03/58] Added getWidth() getHeight() and getYOffset() functions to ScriptEntity --- src/main/java/noppes/npcs/scripted/ScriptEntity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index b7391b251..7f16bfc01 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -30,6 +30,17 @@ public class ScriptEntity { this.entity = entity; } + public double getYOffset() { return entity.getYOffset(); } + + /** + * @return The entities width + */ + public double getWidth(){ return entity.width; } + + /** + * @return The entities height + */ + public double getHeight(){ return entity.height; } /** * @return The entities x position From fbc22fdef244864fdac276c1f8ebd14596994a93 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 01:24:38 -0500 Subject: [PATCH 04/58] Added Custom Particles for scripted entities that work on server and client sides. --- src/main/java/noppes/npcs/ModelPartData.java | 158 ++++++++++++++++-- .../java/noppes/npcs/NoppesUtilServer.java | 28 ++++ .../java/noppes/npcs/client/NoppesUtil.java | 69 ++++++++ .../npcs/client/PacketHandlerClient.java | 3 + .../npcs/constants/EnumPacketClient.java | 2 +- .../noppes/npcs/scripted/ScriptEntity.java | 46 +++++ 6 files changed, 295 insertions(+), 11 deletions(-) diff --git a/src/main/java/noppes/npcs/ModelPartData.java b/src/main/java/noppes/npcs/ModelPartData.java index 5e41cf672..a75b6f376 100644 --- a/src/main/java/noppes/npcs/ModelPartData.java +++ b/src/main/java/noppes/npcs/ModelPartData.java @@ -1,5 +1,6 @@ package noppes.npcs; +import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; @@ -8,9 +9,13 @@ public class ModelPartData { public String texture; public byte type = 0; public boolean playerTexture; - + + public int amount, maxAge, scaleRateStart, alphaRateStart; + public float scale1, scale2, scaleRate, gravity, alpha1, alpha2, alphaRate; + public double x, y, z, motionX, motionY, motionZ; + private ResourceLocation location; - + public ModelPartData(){ playerTexture = true; } @@ -24,26 +29,108 @@ public class ModelPartData { NBTTagCompound compound = new NBTTagCompound(); compound.setByte("Type", type); compound.setInteger("Color", color); + + compound.setInteger("Amount", amount); + compound.setInteger("MaxAge", maxAge); + + compound.setFloat("Scale1", scale1); + compound.setFloat("Scale2", scale2); + compound.setFloat("ScaleRate", scaleRate); + compound.setInteger("ScaleRateStart",scaleRateStart); + + compound.setFloat("Alpha1", alpha1); + compound.setFloat("Alpha2", alpha2); + compound.setFloat("AlphaRate", alphaRate); + compound.setInteger("AlphaRateStart",alphaRateStart); + + compound.setDouble("X",x); + compound.setDouble("Y",y); + compound.setDouble("Z",z); + compound.setDouble("MotionX",motionX); + compound.setDouble("MotionY",motionY); + compound.setDouble("MotionZ",motionZ); + compound.setFloat("Gravity",gravity); + if(texture != null && !texture.isEmpty()) compound.setString("Texture", texture); compound.setBoolean("PlayerTexture", playerTexture); return compound; } - + public void readFromNBT(NBTTagCompound compound){ type = compound.getByte("Type"); color = compound.getInteger("Color"); texture = compound.getString("Texture"); + + amount = compound.getInteger("Amount"); + maxAge = compound.getInteger("MaxAge"); + + scale1 = compound.getFloat("Scale1"); + scale2 = compound.getFloat("Scale2"); + scaleRate = compound.getFloat("ScaleRate"); + scaleRateStart = compound.getInteger("ScaleRateStart"); + + alpha1 = compound.getFloat("Alpha1"); + alpha2 = compound.getFloat("Alpha2"); + alphaRate = compound.getFloat("AlphaRate"); + alphaRateStart = compound.getInteger("AlphaRateStart"); + + x = compound.getDouble("X"); + y = compound.getDouble("Y"); + z = compound.getDouble("Z"); + motionX = compound.getDouble("MotionX"); + motionY = compound.getDouble("MotionY"); + motionZ = compound.getDouble("MotionZ"); + gravity = compound.getFloat("Gravity"); + playerTexture = compound.getBoolean("PlayerTexture"); location = null; } - + + public void setAttributes(String texture, int HEXcolor, int amount, int maxAge, + double x, double y, double z, + double motionX, double motionY, double motionZ, float gravity, + float scale1, float scale2, float scaleRate, int scaleRateStart, + float alpha1, float alpha2, float alphaRate, int alphaRateStart) { + this.location = null; + if(texture.isEmpty()){ + playerTexture = true; + this.texture = texture; + } + else{ + this.texture = texture; + this.color = HEXcolor; + this.amount = amount; + + this.scale1 = scale1; + this.scale2 = scale2; + this.scaleRate = scaleRate; + this.scaleRateStart = scaleRateStart; + + this.alpha1 = alpha1; + this.alpha2 = alpha2; + this.alphaRate = alphaRate; + this.alphaRateStart = alphaRateStart; + + this.maxAge = maxAge; + this.x = x; + this.y = y; + this.z = z; + this.motionX = motionX; + this.motionY = motionY; + this.motionZ = motionZ; + this.gravity = gravity; + + playerTexture = false; + } + } + public ResourceLocation getResource(){ if(texture.isEmpty()) return null; if(location != null) return location; - location = new ResourceLocation(texture); + location = new ResourceLocation(texture); return location; } @@ -59,7 +146,7 @@ public class ModelPartData { playerTexture = false; } } - + public String toString(){ return "Color: " + color + " Type: " + type; } @@ -67,9 +154,60 @@ public class ModelPartData { public String getColor() { String str = Integer.toHexString(color); - while(str.length() < 6) - str = "0" + str; - - return str; + while(str.length() < 6) + str = "0" + str; + + return str; + } + + public int getAmount() { + return amount; + } + + public double getX() { + return x; + } + public double getY() { + return y; + } + public double getZ() { + return z; + } + public double getMotionX() { + return motionX; + } + public double getMotionY() { + return motionY; + } + public double getMotionZ() { + return motionZ; + } + + public float getScale1() { + return scale1; + } + public float getScale2() {return scale2;} + public float getScaleRate() { + return scaleRate; + } + public int getScaleRateStart() {return scaleRateStart;} + + public float getAlpha1() {return alpha1;} + public float getAlpha2() {return alpha2;} + public float getAlphaRate() { + return alphaRate; + } + public int getAlphaRateStart() {return alphaRateStart;} + + public int getMaxAge() { + return maxAge; + } + + public float getGravity() { + return gravity; + } + + public void setAmount(int amount) { + this.amount = amount; } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 237f62357..073e386a4 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -291,6 +291,34 @@ public class NoppesUtilServer { Server.sendAssociatedData(entity, EnumPacketClient.PARTICLE, entity.posX, entity.posY, entity.posZ, entity.height, entity.width, entity.yOffset, particle); } + public static void spawnScriptedParticle(Entity entity, String directory, int HEXcolor, int amount, int maxAge, + double x, double y, double z, + double motionX, double motionY, double motionZ, float gravity, + float scale1, float scale2, float scaleRate, int scaleRateStart, + float alpha1, float alpha2, float alphaRate, int alphaRateStart, + String playerName, EntityPlayer playerObj + ){ + List playerEntities = playerObj.worldObj.getEntitiesWithinAABB(Entity.class, playerObj.boundingBox.expand(300, 300, 300)); + + String UUID = ""; + int entityID = -1; + for(Entity e : playerEntities){ + if(e.equals(entity)){ + UUID = e.getUniqueID().toString(); + entityID = e.getEntityId(); + break; + } + } + + Server.sendAssociatedData(entity, EnumPacketClient.SCRIPTED_PARTICLE, + directory, HEXcolor, amount, maxAge, + x, y, z, + motionX, motionY, motionZ, gravity, + scale1, scale2, scaleRate, scaleRateStart, + alpha1, alpha2, alphaRate, alphaRateStart, + playerName, UUID, entityID + ); + } public static void deleteNpc(EntityNPCInterface npc,EntityPlayer player) { Server.sendAssociatedData(npc, EnumPacketClient.DELETE_NPC, npc.getEntityId()); diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index 945911008..60d503068 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -6,12 +6,14 @@ import java.io.File; import java.io.IOException; import java.net.URI; import java.util.HashMap; +import java.util.List; import java.util.Random; import java.util.Vector; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -19,8 +21,10 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.Util; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; +import noppes.npcs.ModelPartData; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.Server; +import noppes.npcs.client.fx.EntityCustomFX; import noppes.npcs.client.gui.player.GuiDialogInteract; import noppes.npcs.client.gui.player.GuiQuestCompletion; import noppes.npcs.client.gui.util.GuiContainerNPCInterface; @@ -67,6 +71,71 @@ public class NoppesUtil { } } + public static void spawnScriptedParticle(ByteBuf buffer){ + Minecraft minecraft = Minecraft.getMinecraft(); + + String directory = Server.readString(buffer); + + int HEXcolor = buffer.readInt(); + int amount = buffer.readInt(); + int maxAge = buffer.readInt(); + + double x = buffer.readDouble(); + double y = buffer.readDouble(); + double z = buffer.readDouble(); + + double motionX = buffer.readDouble(); + double motionY = buffer.readDouble(); + double motionZ = buffer.readDouble(); + float gravity = buffer.readFloat(); + + float scale1 = buffer.readFloat(); + float scale2 = buffer.readFloat(); + float scaleRate = buffer.readFloat(); + int scaleRateStart = buffer.readInt(); + + float alpha1 = buffer.readFloat(); + float alpha2 = buffer.readFloat(); + float alphaRate = buffer.readFloat(); + int alphaRateStart = buffer.readInt(); + + String playerName = Server.readString(buffer); + String UUID = Server.readString(buffer); + + int entityID = buffer.readInt(); + + ModelPartData particle = new ModelPartData(); + particle.setAttributes( + directory, HEXcolor, amount, maxAge, + x, y, z, + motionX, motionY, motionZ, gravity, + scale1, scale2, scaleRate, scaleRateStart, + alpha1, alpha2, alphaRate, alphaRateStart + ); + + World worldObj = Minecraft.getMinecraft().theWorld; + EntityPlayer player = worldObj.getPlayerEntityByName(playerName); + List entities = player.worldObj.getEntitiesWithinAABB(Entity.class, player.boundingBox.expand(300, 300, 300)); + for(Entity entity : entities){ + if(UUID.equals(entity.getPersistentID().toString()) || (entity.getEntityId() == entityID)){ + EntityCustomFX fx = new EntityCustomFX( + entity, + x, y, z, + motionX, motionY, motionZ, gravity, + scale1, scale2, scaleRate, scaleRateStart, + alpha1, alpha2, alphaRate, alphaRateStart, + particle.getMaxAge(), + particle + ); + + for(int i = 0; i < particle.getAmount(); i++){ + minecraft.effectRenderer.addEffect(fx); + } + break; + } + } + } + public static void clickSound() { Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 4331b1d43..2689b498b 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -151,6 +151,9 @@ public class PacketHandlerClient extends PacketHandlerServer{ EnumGuiType gui = EnumGuiType.values()[buffer.readInt()]; CustomNpcs.proxy.openGui(NoppesUtil.getLastNpc(), gui, buffer.readInt(), buffer.readInt(), buffer.readInt()); } + else if(type == EnumPacketClient.SCRIPTED_PARTICLE){ + NoppesUtil.spawnScriptedParticle(buffer); + } else if(type == EnumPacketClient.PARTICLE){ NoppesUtil.spawnParticle(buffer); } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index c392e5e51..8c53c6b57 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -1,6 +1,6 @@ package noppes.npcs.constants; public enum EnumPacketClient { - CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG + CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG } diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 7f16bfc01..febba5261 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; @@ -18,6 +19,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.Server; +import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.EntityType; @@ -30,6 +35,47 @@ public class ScriptEntity { this.entity = entity; } + /** + * @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" + * @param HEXcolor The particle's color as a HEX integer + * @param amount The amount of particles to spawn + + * @param scale1 The particle's starting scale1 + * @param scale2 The particle's ending scale1 + * @param scaleRate Multiplier for the particle's growth rate. Using a negative number shrinks the particle, positive expands it, and value of 0 keeps it from growing or shrinking altogether. + * @param maxAge The particle's maximum age in MC ticks + + * @param x The particle's x position + * @param y The particle's y position + * @param z The particle's z position + + * @param motionX The particle's speed in the x axis + * @param motionY The particle's speed in the y axis + * @param motionZ The particle's speed in the z axis + * + * @param gravity The particle's gravity + */ + public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge, + double x, double y, double z, + double motionX, double motionY, double motionZ, float gravity, + float scale1, float scale2, float scaleRate, int scaleRateStart, + float alpha1, float alpha2, float alphaRate, int alphaRateStart + ) { + List entities = entity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, entity.boundingBox.expand(300, 300, 300)); + if(entities.size() < 1) + return; + EntityPlayer playerObj = entities.get(0); + String playerName = playerObj.getDisplayName(); + + NoppesUtilServer.spawnScriptedParticle(entity, directory, HEXcolor, amount, maxAge, + x, y, z, + motionX, motionY, motionZ, gravity, + scale1, scale2, scaleRate, scaleRateStart, + alpha1, alpha2, alphaRate, alphaRateStart, + playerName, playerObj + ); + } + public double getYOffset() { return entity.getYOffset(); } /** From 6e9c693d49cd798189e09cf87bec289bdf786c02 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 12:28:14 -0500 Subject: [PATCH 05/58] Changed entity search method for custom particles to solely use entity IDs instead of entities near the closest player. --- .../java/noppes/npcs/NoppesUtilServer.java | 16 ++------- .../java/noppes/npcs/client/NoppesUtil.java | 34 +++++++------------ .../noppes/npcs/scripted/ScriptEntity.java | 9 ++--- 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 073e386a4..7d426d6f9 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -296,27 +296,15 @@ public class NoppesUtilServer { double motionX, double motionY, double motionZ, float gravity, float scale1, float scale2, float scaleRate, int scaleRateStart, float alpha1, float alpha2, float alphaRate, int alphaRateStart, - String playerName, EntityPlayer playerObj + int entityID ){ - List playerEntities = playerObj.worldObj.getEntitiesWithinAABB(Entity.class, playerObj.boundingBox.expand(300, 300, 300)); - - String UUID = ""; - int entityID = -1; - for(Entity e : playerEntities){ - if(e.equals(entity)){ - UUID = e.getUniqueID().toString(); - entityID = e.getEntityId(); - break; - } - } - Server.sendAssociatedData(entity, EnumPacketClient.SCRIPTED_PARTICLE, directory, HEXcolor, amount, maxAge, x, y, z, motionX, motionY, motionZ, gravity, scale1, scale2, scaleRate, scaleRateStart, alpha1, alpha2, alphaRate, alphaRateStart, - playerName, UUID, entityID + entityID ); } diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index 60d503068..a40f8f586 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -99,9 +99,6 @@ public class NoppesUtil { float alphaRate = buffer.readFloat(); int alphaRateStart = buffer.readInt(); - String playerName = Server.readString(buffer); - String UUID = Server.readString(buffer); - int entityID = buffer.readInt(); ModelPartData particle = new ModelPartData(); @@ -114,25 +111,20 @@ public class NoppesUtil { ); World worldObj = Minecraft.getMinecraft().theWorld; - EntityPlayer player = worldObj.getPlayerEntityByName(playerName); - List entities = player.worldObj.getEntitiesWithinAABB(Entity.class, player.boundingBox.expand(300, 300, 300)); - for(Entity entity : entities){ - if(UUID.equals(entity.getPersistentID().toString()) || (entity.getEntityId() == entityID)){ - EntityCustomFX fx = new EntityCustomFX( - entity, - x, y, z, - motionX, motionY, motionZ, gravity, - scale1, scale2, scaleRate, scaleRateStart, - alpha1, alpha2, alphaRate, alphaRateStart, - particle.getMaxAge(), - particle - ); + Entity entity = worldObj.getEntityByID(entityID); - for(int i = 0; i < particle.getAmount(); i++){ - minecraft.effectRenderer.addEffect(fx); - } - break; - } + EntityCustomFX fx = new EntityCustomFX( + entity, + x, y, z, + motionX, motionY, motionZ, gravity, + scale1, scale2, scaleRate, scaleRateStart, + alpha1, alpha2, alphaRate, alphaRateStart, + particle.getMaxAge(), + particle + ); + + for(int i = 0; i < particle.getAmount(); i++){ + minecraft.effectRenderer.addEffect(fx); } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index febba5261..40893bbfb 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -61,18 +61,13 @@ public class ScriptEntity { float scale1, float scale2, float scaleRate, int scaleRateStart, float alpha1, float alpha2, float alphaRate, int alphaRateStart ) { - List entities = entity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, entity.boundingBox.expand(300, 300, 300)); - if(entities.size() < 1) - return; - EntityPlayer playerObj = entities.get(0); - String playerName = playerObj.getDisplayName(); - + int entityID = entity.getEntityId(); NoppesUtilServer.spawnScriptedParticle(entity, directory, HEXcolor, amount, maxAge, x, y, z, motionX, motionY, motionZ, gravity, scale1, scale2, scaleRate, scaleRateStart, alpha1, alpha2, alphaRate, alphaRateStart, - playerName, playerObj + entityID ); } From 61ad3dc849557a2798a718ee307afd8b989a2f56 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 12:47:51 -0500 Subject: [PATCH 06/58] Removed ModelPartData parameter from EntityCustomFX. Reverted ModelPartData to its original version, no longer storing particle attributes. --- src/main/java/noppes/npcs/ModelPartData.java | 140 +----------------- .../java/noppes/npcs/client/NoppesUtil.java | 15 +- .../noppes/npcs/client/fx/EntityCustomFX.java | 13 +- 3 files changed, 10 insertions(+), 158 deletions(-) diff --git a/src/main/java/noppes/npcs/ModelPartData.java b/src/main/java/noppes/npcs/ModelPartData.java index a75b6f376..963bd3d30 100644 --- a/src/main/java/noppes/npcs/ModelPartData.java +++ b/src/main/java/noppes/npcs/ModelPartData.java @@ -1,6 +1,5 @@ package noppes.npcs; -import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; @@ -10,10 +9,6 @@ public class ModelPartData { public byte type = 0; public boolean playerTexture; - public int amount, maxAge, scaleRateStart, alphaRateStart; - public float scale1, scale2, scaleRate, gravity, alpha1, alpha2, alphaRate; - public double x, y, z, motionX, motionY, motionZ; - private ResourceLocation location; public ModelPartData(){ @@ -29,28 +24,6 @@ public class ModelPartData { NBTTagCompound compound = new NBTTagCompound(); compound.setByte("Type", type); compound.setInteger("Color", color); - - compound.setInteger("Amount", amount); - compound.setInteger("MaxAge", maxAge); - - compound.setFloat("Scale1", scale1); - compound.setFloat("Scale2", scale2); - compound.setFloat("ScaleRate", scaleRate); - compound.setInteger("ScaleRateStart",scaleRateStart); - - compound.setFloat("Alpha1", alpha1); - compound.setFloat("Alpha2", alpha2); - compound.setFloat("AlphaRate", alphaRate); - compound.setInteger("AlphaRateStart",alphaRateStart); - - compound.setDouble("X",x); - compound.setDouble("Y",y); - compound.setDouble("Z",z); - compound.setDouble("MotionX",motionX); - compound.setDouble("MotionY",motionY); - compound.setDouble("MotionZ",motionZ); - compound.setFloat("Gravity",gravity); - if(texture != null && !texture.isEmpty()) compound.setString("Texture", texture); compound.setBoolean("PlayerTexture", playerTexture); @@ -61,70 +34,10 @@ public class ModelPartData { type = compound.getByte("Type"); color = compound.getInteger("Color"); texture = compound.getString("Texture"); - - amount = compound.getInteger("Amount"); - maxAge = compound.getInteger("MaxAge"); - - scale1 = compound.getFloat("Scale1"); - scale2 = compound.getFloat("Scale2"); - scaleRate = compound.getFloat("ScaleRate"); - scaleRateStart = compound.getInteger("ScaleRateStart"); - - alpha1 = compound.getFloat("Alpha1"); - alpha2 = compound.getFloat("Alpha2"); - alphaRate = compound.getFloat("AlphaRate"); - alphaRateStart = compound.getInteger("AlphaRateStart"); - - x = compound.getDouble("X"); - y = compound.getDouble("Y"); - z = compound.getDouble("Z"); - motionX = compound.getDouble("MotionX"); - motionY = compound.getDouble("MotionY"); - motionZ = compound.getDouble("MotionZ"); - gravity = compound.getFloat("Gravity"); - playerTexture = compound.getBoolean("PlayerTexture"); location = null; } - public void setAttributes(String texture, int HEXcolor, int amount, int maxAge, - double x, double y, double z, - double motionX, double motionY, double motionZ, float gravity, - float scale1, float scale2, float scaleRate, int scaleRateStart, - float alpha1, float alpha2, float alphaRate, int alphaRateStart) { - this.location = null; - if(texture.isEmpty()){ - playerTexture = true; - this.texture = texture; - } - else{ - this.texture = texture; - this.color = HEXcolor; - this.amount = amount; - - this.scale1 = scale1; - this.scale2 = scale2; - this.scaleRate = scaleRate; - this.scaleRateStart = scaleRateStart; - - this.alpha1 = alpha1; - this.alpha2 = alpha2; - this.alphaRate = alphaRate; - this.alphaRateStart = alphaRateStart; - - this.maxAge = maxAge; - this.x = x; - this.y = y; - this.z = z; - this.motionX = motionX; - this.motionY = motionY; - this.motionZ = motionZ; - this.gravity = gravity; - - playerTexture = false; - } - } - public ResourceLocation getResource(){ if(texture.isEmpty()) return null; @@ -159,55 +72,4 @@ public class ModelPartData { return str; } - - public int getAmount() { - return amount; - } - - public double getX() { - return x; - } - public double getY() { - return y; - } - public double getZ() { - return z; - } - public double getMotionX() { - return motionX; - } - public double getMotionY() { - return motionY; - } - public double getMotionZ() { - return motionZ; - } - - public float getScale1() { - return scale1; - } - public float getScale2() {return scale2;} - public float getScaleRate() { - return scaleRate; - } - public int getScaleRateStart() {return scaleRateStart;} - - public float getAlpha1() {return alpha1;} - public float getAlpha2() {return alpha2;} - public float getAlphaRate() { - return alphaRate; - } - public int getAlphaRateStart() {return alphaRateStart;} - - public int getMaxAge() { - return maxAge; - } - - public float getGravity() { - return gravity; - } - - public void setAmount(int amount) { - this.amount = amount; - } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index a40f8f586..7c1ae2c9b 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -101,29 +101,20 @@ public class NoppesUtil { int entityID = buffer.readInt(); - ModelPartData particle = new ModelPartData(); - particle.setAttributes( - directory, HEXcolor, amount, maxAge, - x, y, z, - motionX, motionY, motionZ, gravity, - scale1, scale2, scaleRate, scaleRateStart, - alpha1, alpha2, alphaRate, alphaRateStart - ); - World worldObj = Minecraft.getMinecraft().theWorld; Entity entity = worldObj.getEntityByID(entityID); EntityCustomFX fx = new EntityCustomFX( entity, + directory, HEXcolor, x, y, z, motionX, motionY, motionZ, gravity, scale1, scale2, scaleRate, scaleRateStart, alpha1, alpha2, alphaRate, alphaRateStart, - particle.getMaxAge(), - particle + maxAge ); - for(int i = 0; i < particle.getAmount(); i++){ + for(int i = 0; i < amount; i++){ minecraft.effectRenderer.addEffect(fx); } } diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java index bd6ee8456..9bfe60963 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -24,12 +24,11 @@ public class EntityCustomFX extends EntityFX { public float alphaRate = 0.0F; public int alphaRateStart = 0; - public EntityCustomFX(Entity entity, double x, double y, double z, + public EntityCustomFX(Entity entity, String directory, int HEXColor, double x, double y, double z, double motionX, double motionY, double motionZ, float gravity, float scale1, float scale2, float scaleRate, int scaleRateStart, float alpha1, float alpha2, float alphaRate, int alphaRateStart, - int age, - ModelPartData data) { + int age) { super(entity.worldObj, x, y, z, motionX, motionY, motionZ); this.scale1 = scale1; @@ -58,9 +57,9 @@ public class EntityCustomFX extends EntityFX { this.entity = entity; noClip = true; - particleRed = (data.color >> 16 & 255) / 255f; - particleGreen = (data.color >> 8 & 255) / 255f; - particleBlue = (data.color & 255) / 255f; + particleRed = (HEXColor >> 16 & 255) / 255f; + particleGreen = (HEXColor >> 8 & 255) / 255f; + particleBlue = (HEXColor & 255) / 255f; if(Math.floor(Math.random()*3) == 1){ move = false; @@ -69,7 +68,7 @@ public class EntityCustomFX extends EntityFX { this.startZ = (float) entity.posZ; } - location = new ResourceLocation(data.texture); + location = new ResourceLocation(directory); } @Override From 1c2534bfc46fb8b0cfdda1b2521bc50eb1c24f47 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 13:33:09 -0500 Subject: [PATCH 07/58] Removed ModelPartData parameter from EntityCustomFX. Reverted ModelPartData to its original version, no longer storing particle attributes. --- src/main/java/noppes/npcs/client/fx/EntityCustomFX.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java index 9bfe60963..40480c6d0 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -4,9 +4,10 @@ import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; -import noppes.npcs.ModelPartData; import noppes.npcs.client.ClientProxy; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import org.lwjgl.opengl.GL44; public class EntityCustomFX extends EntityFX { private Entity entity; From b43d89f91e790da37e58db884720ae142febc462 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 13:36:28 -0500 Subject: [PATCH 08/58] Removed redundant/unused imports from EntityCustomFX --- src/main/java/noppes/npcs/client/fx/EntityCustomFX.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java index 40480c6d0..e3c968232 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -6,8 +6,6 @@ import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ClientProxy; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import org.lwjgl.opengl.GL44; public class EntityCustomFX extends EntityFX { private Entity entity; From 50e3ae7f833d4b41719d2d39f27284cd94c2ff7b Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 13:37:36 -0500 Subject: [PATCH 09/58] Removed screen darken from NPC dialogues. --- .../java/noppes/npcs/client/gui/player/GuiDialogInteract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index b6864bb1d..40e088d96 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -128,7 +128,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glDisable(GL11.GL_TEXTURE_2D); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); } - super.drawScreen(i, j, f); + //super.drawScreen(i, j, f); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); From f6d914903852b308c49d66556a8b0f44e161c917 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 6 Sep 2021 13:40:25 -0500 Subject: [PATCH 10/58] Undid removing screen darken from NPC dialogues. --- .../java/noppes/npcs/client/gui/player/GuiDialogInteract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 40e088d96..b6864bb1d 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -128,7 +128,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glDisable(GL11.GL_TEXTURE_2D); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); } - //super.drawScreen(i, j, f); + super.drawScreen(i, j, f); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); From c39ebc4909340db287954e7410c3b76ac7e93c02 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 8 Sep 2021 13:41:57 -0500 Subject: [PATCH 11/58] Added ScriptEntityParticle class to store and modify scripted particle objects in code. Added support for this calss to ScriptWorld and ScriptEntity. --- .../noppes/npcs/scripted/ScriptEntity.java | 18 +- .../npcs/scripted/ScriptEntityParticle.java | 224 ++++++++++++++++++ .../noppes/npcs/scripted/ScriptWorld.java | 8 + 3 files changed, 244 insertions(+), 6 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 40893bbfb..0d24236d9 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -30,7 +30,7 @@ import noppes.npcs.scripted.constants.EntityType; public class ScriptEntity { protected Entity entity; private Map tempData = new HashMap(); - + public ScriptEntity(Entity entity){ this.entity = entity; } @@ -39,10 +39,6 @@ public class ScriptEntity { * @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" * @param HEXcolor The particle's color as a HEX integer * @param amount The amount of particles to spawn - - * @param scale1 The particle's starting scale1 - * @param scale2 The particle's ending scale1 - * @param scaleRate Multiplier for the particle's growth rate. Using a negative number shrinks the particle, positive expands it, and value of 0 keeps it from growing or shrinking altogether. * @param maxAge The particle's maximum age in MC ticks * @param x The particle's x position @@ -52,8 +48,17 @@ public class ScriptEntity { * @param motionX The particle's speed in the x axis * @param motionY The particle's speed in the y axis * @param motionZ The particle's speed in the z axis - * * @param gravity The particle's gravity + + * @param scale1 The particle's starting scale + * @param scale2 The particle's ending scale + * @param scaleRate Multiplier for the particle's scale growth rate + * @param scaleRateStart The time at which the particle begins growing/shrinking + + * @param alpha1 The particle's starting transparency + * @param alpha2 The particle's ending transparency + * @param scaleRate Multiplier for the particle's transparency growth rate + * @param alphaRateStart The time at which the particle begins appearing/fading */ public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge, double x, double y, double z, @@ -70,6 +75,7 @@ public class ScriptEntity { entityID ); } + public void spawnParticle(ScriptEntityParticle entityParticle) { entityParticle.spawnOnEntity(this); } public double getYOffset() { return entity.getYOffset(); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java new file mode 100644 index 000000000..9dd76a2df --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java @@ -0,0 +1,224 @@ +package noppes.npcs.scripted; + +import net.minecraft.entity.Entity; +import noppes.npcs.NoppesUtilServer; + +/** + * Created by luisc on 9/8/2021. + */ +public class ScriptEntityParticle { + private ScriptEntity entity; + + private String directory; + private int HEXcolor = 0xFFFFFF; + private int amount = 1; + private int maxAge = 20; + private double x = 0,y = 0,z = 0; + private double motionX = 0,motionY = 0,motionZ = 0; + private float gravity = 0; + private float scale1 = 1.0f,scale2 = 1.0f,scaleRate = 0.0f; + private float alpha1 = 1.0f,alpha2 = 1.0f,alphaRate = 0.0f; + private int scaleRateStart = 0, alphaRateStart = 0; + + public ScriptEntityParticle(String directory){ + this.directory = directory; + } + + public void spawnOnEntity(ScriptEntity entity){ + int entityID = entity.getMCEntity().getEntityId(); + NoppesUtilServer.spawnScriptedParticle(entity.getMCEntity(), directory, HEXcolor, amount, maxAge, + x, y, z, + motionX, motionY, motionZ, gravity, + scale1, scale2, scaleRate, scaleRateStart, + alpha1, alpha2, alphaRate, alphaRateStart, + entityID + ); + } + + public ScriptEntity getEntity() { + return entity; + } + + public String getDirectory() { + return directory; + } + + public int getHEXcolor() { + return HEXcolor; + } + + public int getAmount() { + return amount; + } + + public int getMaxAge() { + return maxAge; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public double getMotionX() { + return motionX; + } + + public double getMotionY() { + return motionY; + } + + public double getMotionZ() { + return motionZ; + } + + public float getGravity() { + return gravity; + } + + public float getScale1() { + return scale1; + } + + public float getScale2() { + return scale2; + } + + public float getScaleRate() { + return scaleRate; + } + + public float getAlpha1() { + return alpha1; + } + + public float getAlpha2() { + return alpha2; + } + + public float getAlphaRate() { + return alphaRate; + } + + public int getScaleRateStart() { + return scaleRateStart; + } + + public int getAlphaRateStart() { + return alphaRateStart; + } + + public void setEntity(ScriptEntity entity) { + this.entity = entity; + } + + public void setDirectory(String directory) { + this.directory = directory; + } + + public void setHEXcolor(int HEXcolor) { + this.HEXcolor = HEXcolor; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public void setMaxAge(int maxAge) { + this.maxAge = maxAge; + } + + public void setPosition(double x, double y, double z){ + this.x = x; + this.y = y; + this.z = z; + } + + public void setX(double x) { + this.x = x; + } + + public void setY(double y) { + this.y = y; + } + + public void setZ(double z) { + this.z = z; + } + + public void setMotion(double motionX, double motionY, double motionZ, float gravity){ + this.motionX = motionX; + this.motionY = motionY; + this.motionZ = motionZ; + this.gravity = gravity; + } + + public void setMotionX(double motionX) { + this.motionX = motionX; + } + + public void setMotionY(double motionY) { + this.motionY = motionY; + } + + public void setMotionZ(double motionZ) { + this.motionZ = motionZ; + } + + public void setGravity(float gravity) { + this.gravity = gravity; + } + + public void setScale(float scale1, float scale2, float scaleRate, int scaleRateStart){ + this.scale1 = scale1; + this.scale2 = scale2; + this.scaleRate = scaleRate; + this.scaleRateStart = scaleRateStart; + } + + public void setScale1(float scale1) { + this.scale1 = scale1; + } + + public void setScale2(float scale2) { + this.scale2 = scale2; + } + + public void setScaleRate(float scaleRate) { + this.scaleRate = scaleRate; + } + + public void setScaleRateStart(int scaleRateStart) { + this.scaleRateStart = scaleRateStart; + } + + public void setAlpha(float alpha1, float alpha2, float alphaRate, int alphaRateStart){ + this.alpha1 = alpha1; + this.alpha2 = alpha2; + this.alphaRate = alphaRate; + this.alphaRateStart = alphaRateStart; + } + + public void setAlpha1(float alpha1) { + this.alpha1 = alpha1; + } + + public void setAlpha2(float alpha2) { + this.alpha2 = alpha2; + } + + public void setAlphaRate(float alphaRate) { + this.alphaRate = alphaRate; + } + + public void setAlphaRateStart(int alphaRateStart) { + this.alphaRateStart = alphaRateStart; + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index b22b335db..db047e28b 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -187,6 +187,14 @@ public class ScriptWorld{ return null; return new ScriptItemStack(new ItemStack(item, size, damage)); } + + /** + * @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" + * @return Returns ScriptEntityParticle object + */ + public ScriptEntityParticle createEntityParticle(String directory){ + return new ScriptEntityParticle(directory); + } /** * @param key Get temp data for this key From 71e13a177fdaba1ceb3e8c8b39bf42d8e97d444f Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 8 Sep 2021 13:45:50 -0500 Subject: [PATCH 12/58] Removed Entity field from ScriptEntityParticle --- .../noppes/npcs/scripted/ScriptEntityParticle.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java index 9dd76a2df..849faafce 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java @@ -7,8 +7,6 @@ import noppes.npcs.NoppesUtilServer; * Created by luisc on 9/8/2021. */ public class ScriptEntityParticle { - private ScriptEntity entity; - private String directory; private int HEXcolor = 0xFFFFFF; private int amount = 1; @@ -35,10 +33,6 @@ public class ScriptEntityParticle { ); } - public ScriptEntity getEntity() { - return entity; - } - public String getDirectory() { return directory; } @@ -115,10 +109,6 @@ public class ScriptEntityParticle { return alphaRateStart; } - public void setEntity(ScriptEntity entity) { - this.entity = entity; - } - public void setDirectory(String directory) { this.directory = directory; } From 4ba0460a161b61ac76eed893cf8f94b8e078c320 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 15 Sep 2021 13:24:46 -0500 Subject: [PATCH 13/58] Added NBT tag support to ScriptEntity, ScriptItemStack, and ScriptWorld --- .../npcs/scripted/CustomNPCsException.java | 11 + .../noppes/npcs/scripted/ScriptEntity.java | 10 + .../noppes/npcs/scripted/ScriptItemStack.java | 20 ++ .../java/noppes/npcs/scripted/ScriptNBT.java | 200 ++++++++++++++++++ .../noppes/npcs/scripted/ScriptWorld.java | 18 ++ 5 files changed, 259 insertions(+) create mode 100644 src/main/java/noppes/npcs/scripted/CustomNPCsException.java create mode 100644 src/main/java/noppes/npcs/scripted/ScriptNBT.java diff --git a/src/main/java/noppes/npcs/scripted/CustomNPCsException.java b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java new file mode 100644 index 000000000..deeb5994e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java @@ -0,0 +1,11 @@ +package noppes.npcs.scripted; + +public class CustomNPCsException extends RuntimeException { + public CustomNPCsException(String message, Object... obs) { + super(String.format(message, obs)); + } + + public CustomNPCsException(Exception ex, String message, Object... obs) { + super(String.format(message, obs), ex); + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 0d24236d9..2deeb9d8e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -486,4 +486,14 @@ public class ScriptEntity { public Entity getMCEntity(){ return entity; } + + public ScriptNBT getNBT(){ + NBTTagCompound compound = new NBTTagCompound(); + entity.writeToNBT(compound); + return new ScriptNBT(compound); + } + + public ScriptNBT getEntityNBT(){return new ScriptNBT(this.entity.getEntityData());} + + public void setEntityNBT(ScriptNBT nbt) {this.entity.readFromNBT(nbt.getMCNBT());} } diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 5be275499..69762aba9 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -206,4 +206,24 @@ public class ScriptItemStack { public ItemStack getMCItemStack() { return item; } + + public ScriptNBT getNBT() { + NBTTagCompound compound = this.item.getTagCompound(); + if(compound == null) { + this.item.readFromNBT(compound = new NBTTagCompound()); + } + + return new ScriptNBT(compound); + } + + public boolean hasNBT() { + NBTTagCompound compound = this.item.getTagCompound(); + return compound != null && !compound.hasNoTags(); + } + + public ScriptNBT getItemNBT() { + NBTTagCompound compound = new NBTTagCompound(); + this.item.writeToNBT(compound); + return new ScriptNBT(compound); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptNBT.java b/src/main/java/noppes/npcs/scripted/ScriptNBT.java new file mode 100644 index 000000000..b2abe4d2b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptNBT.java @@ -0,0 +1,200 @@ +package noppes.npcs.scripted; + +import net.minecraft.nbt.*; +import noppes.npcs.util.NBTJsonUtil; + +import java.util.Iterator; + +public class ScriptNBT { + private NBTTagCompound compound; + + public ScriptNBT(NBTTagCompound compound) { + this.compound = compound; + } + + public void remove(String key) { + this.compound.removeTag(key); + } + + public boolean has(String key) { + return this.compound.hasKey(key); + } + + public boolean getBoolean(String key) { + return this.compound.getBoolean(key); + } + + public void setBoolean(String key, boolean value) { + this.compound.setBoolean(key, value); + } + + public short getShort(String key) { + return this.compound.getShort(key); + } + + public void setShort(String key, short value) { + this.compound.setShort(key, value); + } + + public int getInteger(String key) { + return this.compound.getInteger(key); + } + + public void setInteger(String key, int value) { + this.compound.setInteger(key, value); + } + + public byte getByte(String key) { + return this.compound.getByte(key); + } + + public void setByte(String key, byte value) { + this.compound.setByte(key, value); + } + + public long getLong(String key) { + return this.compound.getLong(key); + } + + public void setLong(String key, long value) { + this.compound.setLong(key, value); + } + + public double getDouble(String key) { + return this.compound.getDouble(key); + } + + public void setDouble(String key, double value) { + this.compound.setDouble(key, value); + } + + public float getFloat(String key) { + return this.compound.getFloat(key); + } + + public void setFloat(String key, float value) { + this.compound.setFloat(key, value); + } + + public String getString(String key) { + return this.compound.getString(key); + } + + public void setString(String key, String value) { + this.compound.setString(key, value); + } + + public byte[] getByteArray(String key) { + return this.compound.getByteArray(key); + } + + public void setByteArray(String key, byte[] value) { + this.compound.setByteArray(key, value); + } + + public int[] getIntegerArray(String key) { + return this.compound.getIntArray(key); + } + + public void setIntegerArray(String key, int[] value) { + this.compound.setIntArray(key, value); + } + + public Object[] getList(String key, int type) { + NBTTagList list = this.compound.getTagList(key, type); + Object[] nbts = new Object[list.func_150303_d()]; + + for(int i = 0; i < list.func_150303_d(); ++i) { + if(list.func_150303_d() == 10) { + nbts[i] = new ScriptNBT(list.getCompoundTagAt(i)); + } else if(list.func_150303_d() == 8) { + nbts[i] = list.getStringTagAt(i); + } else if(list.func_150303_d() == 6) { + nbts[i] = Double.valueOf(list.func_150309_d(i)); + } else if(list.func_150303_d() == 5) { + nbts[i] = Float.valueOf(list.func_150308_e(i)); + } else if(list.func_150303_d() == 3) { + nbts[i] = Integer.valueOf(list.getStringTagAt(i)); + } else if(list.func_150303_d() == 11) { + nbts[i] = list.func_150306_c(i); + } + } + + return nbts; + } + + public int getListType(String key) { + NBTBase b = this.compound.getTag(key); + if(b == null) { + return 0; + } else if(b.getId() != 9) { + throw new CustomNPCsException("NBT tag " + key + " isn\'t a list", new Object[0]); + } else { + return ((NBTTagList)b).func_150303_d(); + } + } + + public void setList(String key, Object[] value) { + NBTTagList list = new NBTTagList(); + Object[] var4 = value; + int var5 = value.length; + + for(int var6 = 0; var6 < var5; ++var6) { + Object nbt = var4[var6]; + if(nbt instanceof ScriptNBT) { + list.appendTag(((ScriptNBT)nbt).getMCNBT()); + } else if(nbt instanceof String) { + list.appendTag(new NBTTagString((String) nbt)); + } else if(nbt instanceof Double) { + list.appendTag(new NBTTagDouble(((Double) nbt).doubleValue())); + } else if(nbt instanceof Float) { + list.appendTag(new NBTTagFloat(((Float) nbt).floatValue())); + } else if(nbt instanceof Integer) { + list.appendTag(new NBTTagInt(((Integer) nbt).intValue())); + } else if(nbt instanceof int[]) { + list.appendTag(new NBTTagIntArray((int[]) ((int[]) nbt))); + } + } + + this.compound.setTag(key, list); + } + + public ScriptNBT getCompound(String key) { + return new ScriptNBT(this.compound.getCompoundTag(key)); + } + + public void setCompound(String key, ScriptNBT value) { + if(value == null) + throw new CustomNPCsException("Value cant be null", new Object[0]); + else this.compound.setTag(key, value.getMCNBT()); + } + + public String[] getKeys() { + return (String[])this.compound.func_150296_c().toArray(new String[this.compound.func_150296_c().size()]); + } + + public int getType(String key) { + return this.compound.func_150299_b(key); + } + + public NBTTagCompound getMCNBT() { + return this.compound; + } + + public String toJsonString() { + return NBTJsonUtil.Convert(this.compound); + } + + public boolean isEqual(ScriptNBT nbt) { + return nbt == null?false:this.compound.equals(nbt.getMCNBT()); + } + + public void clear() { + Iterator var1 = this.compound.func_150296_c().iterator(); + + while(var1.hasNext()) { + String name = (String)var1.next(); + this.compound.removeTag(name); + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index db047e28b..17df0f740 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -6,6 +6,7 @@ import java.util.Map; import net.minecraft.block.Block; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -350,4 +351,21 @@ public class ScriptWorld{ public World getMCWorld(){ return world; } + + public ScriptEntity createEntityFromNBT(ScriptNBT nbt) { + Entity entity = EntityList.createEntityFromNBT(nbt.getMCNBT(), this.world); + if(entity == null) { + throw new CustomNPCsException("Failed to create an entity from given NBT", new Object[0]); + } + return new ScriptEntity(entity); + } + + public ScriptItemStack createItemFromNBT(ScriptNBT nbt) { + ItemStack item = ItemStack.loadItemStackFromNBT(nbt.getMCNBT()); + if(item.stackSize < 1) { + throw new CustomNPCsException("Failed to create an item from given NBT", new Object[0]); + } else { + return new ScriptItemStack(item); + } + } } From a5f9ec103f7d9d0add74535cda15c4cd4a655862 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 15 Sep 2021 14:06:20 -0500 Subject: [PATCH 14/58] GiveItem and RemoveItem methods now update the player's server-side inventory to client changes --- .../noppes/npcs/scripted/ScriptPlayer.java | 84 +++++++++++++------ 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java index 2b98f0c7d..62e0fd70a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java @@ -1,5 +1,6 @@ package noppes.npcs.scripted; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -8,6 +9,7 @@ import net.minecraft.stats.StatBase; import net.minecraft.stats.StatList; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.WorldSettings; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesStringUtils; @@ -180,6 +182,15 @@ public class ScriptPlayer extends ScriptLivingBase{ } return i; } + + public int inventoryItemCount(String id, int damage) { + Item item = (Item)Item.itemRegistry.getObject(id); + if(item == null) { + throw new CustomNPCsException("Unknown item id: " + id, new Object[0]); + } else { + return this.inventoryItemCount(new ScriptItemStack(new ItemStack(item, 1, damage))); + } + } /** * @since 1.7.10d @@ -202,26 +213,32 @@ public class ScriptPlayer extends ScriptLivingBase{ */ public boolean removeItem(ScriptItemStack item, int amount){ int count = inventoryItemCount(item); - if(amount > count) + if(amount > count) { return false; - else if(count == amount) - removeAllItems(item); - else{ - for(int i = 0; i < player.inventory.mainInventory.length; i++){ - ItemStack is = player.inventory.mainInventory[i]; - if (is != null && is.isItemEqual(item.item)){ - if(amount > is.stackSize){ - player.inventory.mainInventory[i] = null; - amount -= is.stackSize; - } - else{ - is.splitStack(amount); - break; - } - } + } else { + if (count == amount) { + this.removeAllItems(item); + } else { + for(int i = 0; i < ((EntityPlayerMP)this.entity).inventory.getSizeInventory(); ++i) { + ItemStack is = ((EntityPlayerMP)this.entity).inventory.getStackInSlot(i); + if(is != null && this.isItemEqual(item.getMCItemStack(), is)) { + if(amount < is.stackSize) { + is.splitStack(amount); + break; + } + + player.inventory.setInventorySlotContents(i, null); + amount -= is.stackSize; + } + } } + this.updatePlayerInventory(); + return true; } - return true; + } + + private boolean isItemEqual(ItemStack stack, ItemStack other) { + return other.stackSize<1?false:(stack.getItem() != other.getItem()?false:(stack.getItemDamageForDisplay() < 0?true:stack.getItemDamageForDisplay() == other.getItemDamageForDisplay())); } /** @@ -233,8 +250,9 @@ public class ScriptPlayer extends ScriptLivingBase{ */ public boolean removeItem(String id, int damage, int amount){ Item item = (Item)Item.itemRegistry.getObject(id); - if(item == null) - return false; + if(item == null) { + throw new CustomNPCsException("Unknown item id: " + id, new Object[0]); + } return removeItem(new ScriptItemStack(new ItemStack(item, 1, damage)), amount); } @@ -245,9 +263,14 @@ public class ScriptPlayer extends ScriptLivingBase{ * @return Returns whether or not it gave the item succesfully */ public boolean giveItem(ScriptItemStack item, int amount){ - if(item != null && item.getMCItemStack() != null) { + if(item != null && item.getMCItemStack() != null && amount > 0) { item.setStackSize(amount); - return this.player.inventory.addItemStackToInventory(item.getMCItemStack()); + ItemStack mcItemStack = item.getMCItemStack(); + boolean bool = player.inventory.addItemStackToInventory(mcItemStack); + if(bool) { + updatePlayerInventory(); + } + return bool; } else { return false; } @@ -262,9 +285,17 @@ public class ScriptPlayer extends ScriptLivingBase{ */ public boolean giveItem(String id, int damage, int amount){ Item item = (Item)Item.itemRegistry.getObject(id); - if(item == null) - return false; - return player.inventory.addItemStackToInventory(new ItemStack(item, amount, damage)); + if(item == null) { + throw new CustomNPCsException("Unknown item id: " + id, new Object[0]); + } + + ItemStack itemStack = new ItemStack(item, amount, damage); + boolean bool = player.inventory.addItemStackToInventory(itemStack); + if(bool) { + updatePlayerInventory(); + } + + return bool; } /** @@ -293,6 +324,7 @@ public class ScriptPlayer extends ScriptLivingBase{ if (is != null && is.isItemEqual(item.item)) player.inventory.mainInventory[i] = null; } + updatePlayerInventory(); } @@ -342,4 +374,8 @@ public class ScriptPlayer extends ScriptLivingBase{ return null; return new ScriptPixelmonPlayerData(player); } + + public void updatePlayerInventory() { + ((EntityPlayerMP)this.entity).inventoryContainer.detectAndSendChanges(); + } } From 58a1ccc3e79901eb989cf176c2aaeb66fd45dc9b Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 23 Sep 2021 03:02:58 -0500 Subject: [PATCH 15/58] Added new knockback function with x y and z knockback power parameters. --- .../java/noppes/npcs/scripted/ScriptEntity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 2deeb9d8e..ccb7203cc 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -461,6 +461,20 @@ public class ScriptEntity { entity.motionZ *= 0.6D; entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); } + + /** + * @param xpower How strong the knockback is on the x axis + * @param ypower How strong the knockback is on the y axis + * @param zpower How strong the knockback is on the z axis + * @param direction The direction in which he flies back (0-360). Usually based on getRotation() + */ + public void knockback(int xpower, int ypower, int zpower, float direction){ + float v = direction * (float)Math.PI / 180.0F; + entity.addVelocity(-MathHelper.sin(v) * (float)xpower, ypower, MathHelper.cos(v) * (float)zpower); + entity.motionX *= 0.6D; + entity.motionZ *= 0.6D; + entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); + } /** * @since 1.7.10c From 5a1c4757cf6113cd786f9e5af51c9961ad5e133d Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 30 Sep 2021 00:56:49 -0500 Subject: [PATCH 16/58] Went down huge rabbit hole to attempt adding scripted events for players. Chock full of errors, trying to backport classes from the 1.12 version. --- .../java/noppes/npcs/EventDataScript.java | 143 +++++++++ src/main/java/noppes/npcs/EventHooks.java | 160 ++++++++++ .../noppes/npcs/EventScriptContainer.java | 233 ++++++++++++++ src/main/java/noppes/npcs/IScriptHandler.java | 34 +++ src/main/java/noppes/npcs/NBTTags.java | 64 +++- .../java/noppes/npcs/client/ClientProxy.java | 14 +- .../npcs/client/gui/GuiScriptEvent.java | 154 ++++++++++ .../noppes/npcs/constants/EnumGuiType.java | 2 +- .../noppes/npcs/constants/EnumScriptType.java | 59 +++- .../npcs/controllers/IScriptHandler.java | 34 +++ .../npcs/controllers/data/PlayerData.java | 289 ++++++++++++++++++ .../controllers/data/PlayerScriptData.java | 165 ++++++++++ .../noppes/npcs/items/ItemNpcScripter.java | 16 +- .../npcs/scripted/CommandNoppesBase.java | 127 ++++++++ .../npcs/scripted/CustomNPCsException.java | 16 + .../java/noppes/npcs/scripted/IContainer.java | 26 ++ .../noppes/npcs/scripted/IDamageSource.java | 23 ++ .../java/noppes/npcs/scripted/IDimension.java | 14 + src/main/java/noppes/npcs/scripted/INbt.java | 78 +++++ .../noppes/npcs/scripted/IScoreboard.java | 45 +++ .../npcs/scripted/IScoreboardObjective.java | 30 ++ .../npcs/scripted/IScoreboardScore.java | 14 + .../noppes/npcs/scripted/IScoreboardTeam.java | 36 +++ .../java/noppes/npcs/scripted/ITimers.java | 20 ++ .../java/noppes/npcs/scripted/IWorld.java | 94 ++++++ .../java/noppes/npcs/scripted/NpcAPI.java | 119 ++++++++ .../npcs/scripted/entity/ICustomNpc.java | 75 +++++ .../noppes/npcs/scripted/entity/IEntity.java | 150 +++++++++ .../npcs/scripted/entity/IEntityItem.java | 32 ++ .../npcs/scripted/entity/IEntityLiving.java | 21 ++ .../scripted/entity/IEntityLivingBase.java | 70 +++++ .../noppes/npcs/scripted/entity/IPlayer.java | 119 ++++++++ .../npcs/scripted/entity/IProjectile.java | 33 ++ .../npcs/scripted/entity/IThrowable.java | 12 + .../npcs/scripted/entity/data/IData.java | 20 ++ .../scripted/entity/data/INPCAdvanced.java | 18 ++ .../npcs/scripted/entity/data/INPCAi.java | 92 ++++++ .../scripted/entity/data/INPCDisplay.java | 76 +++++ .../scripted/entity/data/INPCInventory.java | 40 +++ .../npcs/scripted/entity/data/INPCJob.java | 10 + .../npcs/scripted/entity/data/INPCMelee.java | 32 ++ .../npcs/scripted/entity/data/INPCRanged.java | 108 +++++++ .../npcs/scripted/entity/data/INPCRole.java | 10 + .../npcs/scripted/entity/data/INPCStats.java | 55 ++++ .../scripted/entity/data/IPlayerMail.java | 29 ++ .../noppes/npcs/scripted/gui/IButton.java | 32 ++ .../noppes/npcs/scripted/gui/ICustomGui.java | 69 +++++ .../scripted/gui/ICustomGuiComponent.java | 26 ++ .../noppes/npcs/scripted/gui/IItemSlot.java | 20 ++ .../java/noppes/npcs/scripted/gui/ILabel.java | 28 ++ .../noppes/npcs/scripted/gui/IScroll.java | 28 ++ .../noppes/npcs/scripted/gui/ITextField.java | 20 ++ .../npcs/scripted/gui/ITexturedRect.java | 30 ++ .../npcs/scripted/handler/ICloneHandler.java | 19 ++ .../scripted/handler/IFactionHandler.java | 19 ++ .../npcs/scripted/handler/IQuestHandler.java | 16 + .../npcs/scripted/handler/IRecipeHandler.java | 22 ++ .../scripted/handler/data/IAvailability.java | 38 +++ .../npcs/scripted/handler/data/IDialog.java | 42 +++ .../handler/data/IDialogCategory.java | 17 ++ .../scripted/handler/data/IDialogHandler.java | 16 + .../scripted/handler/data/IDialogOption.java | 14 + .../npcs/scripted/handler/data/IFaction.java | 45 +++ .../npcs/scripted/handler/data/IQuest.java | 47 +++ .../scripted/handler/data/IQuestCategory.java | 17 ++ .../scripted/handler/data/IQuestHandler.java | 14 + .../handler/data/IQuestObjective.java | 18 ++ .../npcs/scripted/handler/data/IRecipe.java | 42 +++ .../noppes/npcs/scripted/item/IItemStack.java | 92 ++++++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 247 +++++++++++++++ .../java/noppes/npcs/util/LRUHashMap.java | 22 ++ .../assets/customnpcs/lang/en_US.lang | 23 ++ 72 files changed, 4014 insertions(+), 20 deletions(-) create mode 100644 src/main/java/noppes/npcs/EventDataScript.java create mode 100644 src/main/java/noppes/npcs/EventHooks.java create mode 100644 src/main/java/noppes/npcs/EventScriptContainer.java create mode 100644 src/main/java/noppes/npcs/IScriptHandler.java create mode 100644 src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java create mode 100644 src/main/java/noppes/npcs/controllers/IScriptHandler.java create mode 100644 src/main/java/noppes/npcs/controllers/data/PlayerData.java create mode 100644 src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java create mode 100644 src/main/java/noppes/npcs/scripted/CommandNoppesBase.java create mode 100644 src/main/java/noppes/npcs/scripted/CustomNPCsException.java create mode 100644 src/main/java/noppes/npcs/scripted/IContainer.java create mode 100644 src/main/java/noppes/npcs/scripted/IDamageSource.java create mode 100644 src/main/java/noppes/npcs/scripted/IDimension.java create mode 100644 src/main/java/noppes/npcs/scripted/INbt.java create mode 100644 src/main/java/noppes/npcs/scripted/IScoreboard.java create mode 100644 src/main/java/noppes/npcs/scripted/IScoreboardObjective.java create mode 100644 src/main/java/noppes/npcs/scripted/IScoreboardScore.java create mode 100644 src/main/java/noppes/npcs/scripted/IScoreboardTeam.java create mode 100644 src/main/java/noppes/npcs/scripted/ITimers.java create mode 100644 src/main/java/noppes/npcs/scripted/IWorld.java create mode 100644 src/main/java/noppes/npcs/scripted/NpcAPI.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntity.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntityItem.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IPlayer.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IProjectile.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/IThrowable.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/IData.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java create mode 100644 src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/IButton.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ICustomGui.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/IItemSlot.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ILabel.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/IScroll.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ITextField.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialog.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IFaction.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuest.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java create mode 100644 src/main/java/noppes/npcs/scripted/item/IItemStack.java create mode 100644 src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java create mode 100644 src/main/java/noppes/npcs/util/LRUHashMap.java diff --git a/src/main/java/noppes/npcs/EventDataScript.java b/src/main/java/noppes/npcs/EventDataScript.java new file mode 100644 index 000000000..e39c11d15 --- /dev/null +++ b/src/main/java/noppes/npcs/EventDataScript.java @@ -0,0 +1,143 @@ +package noppes.npcs; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListenableFutureTask; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.ScriptEvent; +import noppes.npcs.scripted.ScriptNpc; +import noppes.npcs.scripted.ScriptWorld; +import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.constants.RoleType; +import org.apache.commons.lang3.Validate; + +import javax.script.ScriptEngine; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; + +public class EventDataScript implements IScriptHandler { + private List scripts = new ArrayList(); + private String scriptLanguage = "ECMAScript"; + public long lastInited = -1L; + public boolean hadInteract = true; + private boolean enabled = false; + + public EventDataScript() { + } + + public void clear() { + this.scripts = new ArrayList(); + } + + public void readFromNBT(NBTTagCompound compound) { + this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); + this.scriptLanguage = compound.getString("ScriptLanguage"); + this.enabled = compound.getBoolean("ScriptEnabled"); + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setTag("Scripts", NBTTags.NBTScript(this.scripts)); + compound.setString("ScriptLanguage", this.scriptLanguage); + compound.setBoolean("ScriptEnabled", this.enabled); + return compound; + } + + public void runScript(EnumScriptType type, Event event) { + } + + public void runScript(String type, Event event) { + if(this.isEnabled()) { + Minecraft.getMinecraft().func_152344_a(() -> { + if (ScriptController.Instance.lastLoaded > this.lastInited) { + this.lastInited = ScriptController.Instance.lastLoaded; + if (!type.equals("init")) { + EventHooks.onForgeInit(this); + } + } + + Iterator var3 = this.scripts.iterator(); + + while (var3.hasNext()) { + EventScriptContainer script = (EventScriptContainer) var3.next(); + script.run(type, event); + } + + }); + } + } + + public boolean isEnabled() { + return this.enabled && ScriptController.HasStart && this.scripts.size() > 0; + } + + public boolean isClient() { + return false; + } + + public boolean getEnabled() { + return this.enabled; + } + + public void setEnabled(boolean bo) { + this.enabled = bo; + } + + public String getLanguage() { + return this.scriptLanguage; + } + + public void setLanguage(String lang) { + this.scriptLanguage = lang; + } + + public List getScripts() { + return this.scripts; + } + + public String noticeString() { + return "ForgeScript"; + } + + public Map getConsoleText() { + TreeMap map = new TreeMap(); + int tab = 0; + Iterator var3 = this.getScripts().iterator(); + + while(var3.hasNext()) { + EventScriptContainer script = (EventScriptContainer)var3.next(); + ++tab; + Iterator var5 = script.console.entrySet().iterator(); + + while(var5.hasNext()) { + Map.Entry entry = (Map.Entry)var5.next(); + map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue()); + } + } + + return map; + } + + public void clearConsole() { + Iterator var1 = this.getScripts().iterator(); + + while(var1.hasNext()) { + EventScriptContainer script = (EventScriptContainer)var1.next(); + script.console.clear(); + } + + } +} diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java new file mode 100644 index 000000000..0829601d2 --- /dev/null +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -0,0 +1,160 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.util.DamageSource; +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.entity.IEntityItem; +import noppes.npcs.scripted.entity.IProjectile; +import noppes.npcs.scripted.event.PlayerEvent.AttackEvent; +import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; +import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed; +import noppes.npcs.scripted.event.PlayerEvent.ContainerOpen; +import noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent; +import noppes.npcs.scripted.event.PlayerEvent.FactionUpdateEvent; +import noppes.npcs.scripted.event.PlayerEvent.KeyPressedEvent; +import noppes.npcs.scripted.event.PlayerEvent.LevelUpEvent; +import noppes.npcs.scripted.event.PlayerEvent.LoginEvent; +import noppes.npcs.scripted.event.PlayerEvent.LogoutEvent; +import noppes.npcs.scripted.event.PlayerEvent.PickUpEvent; +import noppes.npcs.scripted.event.PlayerEvent.TossEvent; +import noppes.npcs.scripted.wrapper.PlayerWrapper; +import noppes.npcs.scripted.wrapper.WrapperNpcAPI; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.data.PlayerData; + +public class EventHooks { + public EventHooks() { + } + + public static void onForgeInit(EventDataScript handler) { + noppes.npcs.scripted.event.ForgeEvent.InitEvent event = new noppes.npcs.scripted.event.ForgeEvent.InitEvent(); + handler.runScript(EnumScriptType.INIT, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerInit(PlayerScriptData handler) { + noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(handler.getPlayer()); + handler.runScript(EnumScriptType.INIT, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerTick(PlayerScriptData handler) { + noppes.npcs.scripted.event.PlayerEvent.UpdateEvent event = new noppes.npcs.scripted.event.PlayerEvent.UpdateEvent(handler.getPlayer()); + handler.runScript(EnumScriptType.TICK, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerInteract(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) { + handler.runScript(EnumScriptType.INTERACT, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerAttack(PlayerScriptData handler, AttackEvent event) { + handler.runScript(EnumScriptType.ATTACK, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerBreak(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.BreakEvent event) { + handler.runScript(EnumScriptType.BROKEN, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerToss(PlayerScriptData handler, EntityItem entityItem) { + TossEvent event = new TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.func_92059_d())); + handler.runScript(EnumScriptType.TOSS, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerLevelUp(PlayerScriptData handler, int change) { + LevelUpEvent event = new LevelUpEvent(handler.getPlayer(), change); + handler.runScript(EnumScriptType.LEVEL_UP, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerPickUp(PlayerScriptData handler, EntityItem entityItem) { + PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.func_92059_d())); + handler.runScript(EnumScriptType.PICKUP, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerContainerOpen(PlayerScriptData handler, Container container) { + ContainerOpen event = new ContainerOpen(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); + handler.runScript(EnumScriptType.CONTAINER_OPEN, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerContainerClose(PlayerScriptData handler, Container container) { + ContainerClosed event = new ContainerClosed(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); + handler.runScript(EnumScriptType.CONTAINER_CLOSED, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerDeath(PlayerScriptData handler, DamageSource source, Entity entity) { + noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(handler.getPlayer(), source, entity); + handler.runScript(EnumScriptType.KILLED, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerKills(PlayerScriptData handler, EntityLivingBase entityLiving) { + noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent event = new noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent(handler.getPlayer(), entityLiving); + handler.runScript(EnumScriptType.KILLS, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerDamaged(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) { + handler.runScript(EnumScriptType.DAMAGED, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerLogin(PlayerScriptData handler) { + LoginEvent event = new LoginEvent(handler.getPlayer()); + handler.runScript(EnumScriptType.LOGIN, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerLogout(PlayerScriptData handler) { + LogoutEvent event = new LogoutEvent(handler.getPlayer()); + handler.runScript(EnumScriptType.LOGOUT, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerChat(PlayerScriptData handler, ChatEvent event) { + handler.runScript(EnumScriptType.CHAT, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerRanged(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) { + handler.runScript(EnumScriptType.RANGED_LAUNCHED, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerDamagedEntity(PlayerScriptData handler, DamagedEntityEvent event) { + handler.runScript(EnumScriptType.DAMAGED_ENTITY, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void OnPlayerFactionChange(PlayerScriptData handler, FactionUpdateEvent event) { + if(!handler.isClient()) { + handler.runScript(EnumScriptType.FACTION_UPDATE, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + } + + public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { + PlayerScriptData handler = PlayerData.get(player).scriptData; + KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); + handler.runScript(EnumScriptType.KEY_PRESSED, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } +} diff --git a/src/main/java/noppes/npcs/EventScriptContainer.java b/src/main/java/noppes/npcs/EventScriptContainer.java new file mode 100644 index 000000000..d60e04ddd --- /dev/null +++ b/src/main/java/noppes/npcs/EventScriptContainer.java @@ -0,0 +1,233 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.TreeMap; +import java.util.Map.Entry; +import javax.script.Invocable; +import javax.script.ScriptEngine; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import noppes.npcs.CustomNpcs; +import noppes.npcs.NBTTags; +import noppes.npcs.NoppesUtilServer; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.constants.*; + +public class EventScriptContainer { + private static final String lock = "lock"; + public static EventScriptContainer Current; + private static String CurrentType; + private static final HashMap Data = new HashMap(); + public String fullscript = ""; + public String script = ""; + public TreeMap console = new TreeMap(); + public boolean errored = false; + public List scripts = new ArrayList(); + private HashSet unknownFunctions = new HashSet(); + public long lastCreated = 0L; + private String currentScriptLanguage = null; + private ScriptEngine engine = null; + private IScriptHandler handler = null; + private boolean init = false; + private static Method luaCoerce; + private static Method luaCall; + + private static void FillMap(Class c) { + try { + Data.put(c.getSimpleName(), c.newInstance()); + } catch (Exception var8) { + ; + } + + Field[] declaredFields = c.getDeclaredFields(); + Field[] var2 = declaredFields; + int var3 = declaredFields.length; + + for(int var4 = 0; var4 < var3; ++var4) { + Field field = var2[var4]; + + try { + if(Modifier.isStatic(field.getModifiers()) && field.getType() == Integer.TYPE) { + Data.put(c.getSimpleName() + "_" + field.getName(), Integer.valueOf(field.getInt((Object)null))); + } + } catch (Exception var7) { + ; + } + } + + } + + public EventScriptContainer(IScriptHandler handler) { + this.handler = handler; + } + + public void readFromNBT(NBTTagCompound compound) { + this.script = compound.getString("Script"); + this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10)); + this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10)); + this.lastCreated = 0L; + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setString("Script", this.script); + compound.setTag("Console", NBTTags.NBTLongStringMap(this.console)); + compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts)); + return compound; + } + + private String getFullCode() { + if(!this.init) { + this.fullscript = this.script; + if(!this.fullscript.isEmpty()) { + this.fullscript = this.fullscript + "\n"; + } + + Iterator var1 = this.scripts.iterator(); + + while(var1.hasNext()) { + String loc = (String)var1.next(); + String code = (String)ScriptController.Instance.scripts.get(loc); + if(code != null && !code.isEmpty()) { + this.fullscript = this.fullscript + code + "\n"; + } + } + + this.unknownFunctions = new HashSet(); + } + + return this.fullscript; + } + + public void run(EnumScriptType type, Event event) { + this.run((String)type.function, (Object)event); + } + + public void run(String type, Object event) { + if(!this.errored && this.hasCode() && !this.unknownFunctions.contains(type) /*&& CustomNpcs.EnableScripting*/) { + this.setEngine(currentScriptLanguage.toLowerCase()); + if(this.engine != null) { + if(ScriptController.Instance.lastLoaded > this.lastCreated) { + this.lastCreated = ScriptController.Instance.lastLoaded; + this.init = false; + } + + String var3 = "lock"; + synchronized("lock") { + Current = this; + CurrentType = type; + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + this.engine.getContext().setWriter(pw); + this.engine.getContext().setErrorWriter(pw); + + try { + if(!this.init) { + this.engine.eval(this.getFullCode()); + this.init = true; + } + + if(this.engine.getFactory().getLanguageName().equals("lua")) { + Object e = this.engine.get(type); + if(e != null) { + if(luaCoerce == null) { + luaCoerce = Class.forName("org.luaj.vm2.lib.jse.CoerceJavaToLua").getMethod("coerce", new Class[]{Object.class}); + luaCall = e.getClass().getMethod("call", new Class[]{Class.forName("org.luaj.vm2.LuaValue")}); + } + + luaCall.invoke(e, new Object[]{luaCoerce.invoke((Object)null, new Object[]{event})}); + } else { + this.unknownFunctions.add(type); + } + } else { + ((Invocable)this.engine).invokeFunction(type, new Object[]{event}); + } + } catch (NoSuchMethodException var13) { + this.unknownFunctions.add(type); + } catch (Throwable var14) { + this.errored = true; + var14.printStackTrace(pw); + //NoppesUtilServer.NotifyOPs(this.handler.noticeString() + " script errored", new Object[0]); + } finally { + this.appandConsole(sw.getBuffer().toString().trim()); + pw.close(); + Current = null; + } + + } + } + } + } + + public void appandConsole(String message) { + if(message != null && !message.isEmpty()) { + long time = System.currentTimeMillis(); + if(this.console.containsKey(Long.valueOf(time))) { + message = (String)this.console.get(Long.valueOf(time)) + "\n" + message; + } + + this.console.put(Long.valueOf(time), message); + + while(this.console.size() > 40) { + this.console.remove(this.console.firstKey()); + } + + } + } + + public boolean hasCode() { + return !this.getFullCode().isEmpty(); + } + + public void setEngine(String scriptLanguage) { + if(this.currentScriptLanguage == null || !this.currentScriptLanguage.equals(scriptLanguage)) { + this.engine = ScriptController.Instance.getEngineByName(scriptLanguage); + if(this.engine == null) { + this.errored = true; + } else { + Iterator var2 = Data.entrySet().iterator(); + + while(var2.hasNext()) { + Entry entry = (Entry)var2.next(); + this.engine.put((String)entry.getKey(), entry.getValue()); + } + + //this.engine.put("dump", new Dump(this, (1)null)); + //this.engine.put("log", new Log(this, (1)null)); + this.currentScriptLanguage = scriptLanguage; + this.init = false; + } + } + } + + public boolean isValid() { + return this.init && !this.errored; + } + + static { + FillMap(AnimationType.class); + FillMap(EntityType.class); + FillMap(RoleType.class); + FillMap(JobType.class); + //FillMap(SideType.class); + //FillMap(TacticalType.class); + //FillMap(PotionType.class); + //FillMap(ParticleType.class); + Data.put("PosZero", new BlockPos(BlockPos.ORIGIN)); + } +} diff --git a/src/main/java/noppes/npcs/IScriptHandler.java b/src/main/java/noppes/npcs/IScriptHandler.java new file mode 100644 index 000000000..4ebedd19a --- /dev/null +++ b/src/main/java/noppes/npcs/IScriptHandler.java @@ -0,0 +1,34 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs; + +import java.util.List; +import java.util.Map; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.ScriptContainer; + +public interface IScriptHandler { + void runScript(EnumScriptType var1, Event var2); + + boolean isClient(); + + boolean getEnabled(); + + void setEnabled(boolean var1); + + String getLanguage(); + + void setLanguage(String var1); + + List getScripts(); + + String noticeString(); + + Map getConsoleText(); + + void clearConsole(); +} diff --git a/src/main/java/noppes/npcs/NBTTags.java b/src/main/java/noppes/npcs/NBTTags.java index 87fc9826a..f2f77b10f 100644 --- a/src/main/java/noppes/npcs/NBTTags.java +++ b/src/main/java/noppes/npcs/NBTTags.java @@ -1,11 +1,6 @@ package noppes.npcs; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Vector; +import java.util.*; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; @@ -13,6 +8,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.ScriptContainer; public class NBTTags { @@ -383,4 +379,60 @@ public class NBTTags { return compound; } + public static TreeMap GetLongStringMap(NBTTagList tagList) { + TreeMap list = new TreeMap(); + + for(int i = 0; i < tagList.tagCount(); ++i) { + NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i); + list.put(Long.valueOf(nbttagcompound.getLong("Long")), nbttagcompound.getString("String")); + } + + return list; + } + + public static NBTTagList NBTLongStringMap(Map map) { + NBTTagList nbttaglist = new NBTTagList(); + if(map == null) { + return nbttaglist; + } else { + Iterator var2 = map.keySet().iterator(); + + while(var2.hasNext()) { + long slot = ((Long)var2.next()).longValue(); + NBTTagCompound nbttagcompound = new NBTTagCompound(); + nbttagcompound.setLong("Long", slot); + nbttagcompound.setString("String", (String) map.get(Long.valueOf(slot))); + nbttaglist.appendTag(nbttagcompound); + } + + return nbttaglist; + } + } + + public static List GetScript(NBTTagList list, IScriptHandler handler) { + ArrayList scripts = new ArrayList(); + + for(int i = 0; i < list.tagCount(); ++i) { + NBTTagCompound compoundd = list.getCompoundTagAt(i); + EventScriptContainer script = new EventScriptContainer(handler); + script.readFromNBT(compoundd); + scripts.add(script); + } + + return scripts; + } + + public static NBTTagList NBTScript(List scripts) { + NBTTagList list = new NBTTagList(); + Iterator var2 = scripts.iterator(); + + while(var2.hasNext()) { + EventScriptContainer script = (EventScriptContainer)var2.next(); + NBTTagCompound compound = new NBTTagCompound(); + script.writeToNBT(compound); + list.appendTag(compound); + } + + return list; + } } diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 13f9c1c74..515a5cd34 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -62,16 +62,7 @@ import noppes.npcs.client.controllers.PresetController; import noppes.npcs.client.fx.EntityElementalStaffFX; import noppes.npcs.client.fx.EntityEnderFX; import noppes.npcs.client.fx.EntityRainbowFX; -import noppes.npcs.client.gui.GuiBorderBlock; -import noppes.npcs.client.gui.GuiMerchantAdd; -import noppes.npcs.client.gui.GuiNpcDimension; -import noppes.npcs.client.gui.GuiNpcMobSpawner; -import noppes.npcs.client.gui.GuiNpcMobSpawnerMounter; -import noppes.npcs.client.gui.GuiNpcPather; -import noppes.npcs.client.gui.GuiNpcRedstoneBlock; -import noppes.npcs.client.gui.GuiNpcRemoteEditor; -import noppes.npcs.client.gui.GuiNpcWaypoint; -import noppes.npcs.client.gui.GuiScript; +import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.global.GuiNPCManageBanks; import noppes.npcs.client.gui.global.GuiNPCManageDialogs; import noppes.npcs.client.gui.global.GuiNPCManageFactions; @@ -377,6 +368,9 @@ public class ClientProxy extends CommonProxy { else if(gui == EnumGuiType.NpcRemote && Minecraft.getMinecraft().currentScreen == null) return new GuiNpcRemoteEditor(); + else if(gui == EnumGuiType.ScriptEvent && Minecraft.getMinecraft().currentScreen == null) + return new GuiScriptEvent(); + else if(gui == EnumGuiType.PlayerMailman) return new GuiMailmanWrite((ContainerMail) container, x == 1, y == 1); diff --git a/src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java b/src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java new file mode 100644 index 000000000..9278fcec4 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java @@ -0,0 +1,154 @@ +package noppes.npcs.client.gui; + +import net.minecraft.server.MinecraftServer; +import noppes.npcs.EventDataScript; +import noppes.npcs.EventScriptContainer; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.ScriptContainer; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GuiScriptEvent extends GuiNPCInterface { + public boolean showScript = false; + private int activeTab = 0; + private String activeScriptTab = "init"; + public EventDataScript script; + public Map> languages = new HashMap>(); + + private static int activeConsole = 0; + + public GuiScriptEvent(){ + super(); + drawDefaultBackground = true; + closeOnEsc = true; + xSize = 420; + setBackground("menubg.png"); + + //Client.sendData(EnumPacketServer.RemoteNpcsGet); TODO: Get Player & Forge event scripts + } + + public void initGui() { + super.initGui(); + guiTop += 10; + GuiMenuTopButton top; + addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); + top.active = showScript; + addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); + top.active = !showScript; + addTopButton(new GuiMenuTopButton(15, top, "gui.website")); + + List list = new ArrayList(); + list.add("playerscript.attack"); + list.add("playerscript.break"); + list.add("playerscript.chat"); + list.add("playerscript.containerclosed"); + list.add("playerscript.containeropen"); + list.add("playerscript.damagedentity"); + list.add("playerscript.damaged"); + list.add("playerscript.killed"); + list.add("playerscript.factionupdate"); + list.add("playerscript.init"); + list.add("playerscript.interact"); + list.add("playerscript.keypressed"); + list.add("playerscript.kills"); + list.add("playerscript.levelup"); + list.add("playerscript.login"); + list.add("playerscript.logout"); + list.add("playerscript.pickup"); + list.add("playerscript.rangedlaunched"); + list.add("playerscript.toss"); + list.add("playerscript.update"); + + if(showScript) { + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.setSize(68, 198); + hooks.guiLeft = guiLeft + 4; + hooks.guiTop = guiTop + 14; + hooks.setUnsortedList(list); + hooks.selected = script.getScripts().indexOf(activeScriptTab); + addScroll(hooks); + + EventScriptContainer container = script.getScripts().get(script.getScripts().indexOf(activeScriptTab)); + + addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); + + addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); + addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); + addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); + + addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); + + addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); + + GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); + scroll.setSize(100, 120); + scroll.guiLeft = guiLeft + 315; + scroll.guiTop = guiTop + 92; + if(container != null) + scroll.setList(container.scripts); + addScroll(scroll); + } + else{ + addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); + getTopButton(14).active = true; + addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); + getTextField(2).canEdit = false; + addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); + addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); + + List l = new ArrayList(); + l.add("All"); + l.addAll(list); + addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); + + addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); + addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); + getButton(103).enabled = languages.size() > 0; + + addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); + //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, script.enabled?1:0)); + + if(MinecraftServer.getServer() != null) + addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); + } + } + + private int getScriptIndex() { + /* + int i = 0; + for(String language : languages.keySet()){ + if(language.equalsIgnoreCase(script.scriptLanguage)) + return i; + i++; + } + */ + return 0; + } + + private String getConsoleText() { + String console = ""; + /* + if(activeConsole == 0){ + for(ScriptContainer container : script.scripts.values()){ + if(!container.console.isEmpty()) + console += container.console + '\n'; + } + } + else{ + ScriptContainer container = script.scripts.get(activeConsole - 1); + if(container != null) + console = container.console; + } + */ + return console; + } + + @Override + public void save() { + + } +} diff --git a/src/main/java/noppes/npcs/constants/EnumGuiType.java b/src/main/java/noppes/npcs/constants/EnumGuiType.java index 4f1e0b7fa..39e728518 100644 --- a/src/main/java/noppes/npcs/constants/EnumGuiType.java +++ b/src/main/java/noppes/npcs/constants/EnumGuiType.java @@ -1,5 +1,5 @@ package noppes.npcs.constants; public enum EnumGuiType { - MainMenuDisplay, MainMenuInv, MainMenuStats, ManageFactions, MainMenuAdvanced, MainMenuGlobal, PlayerBankSmall, PlayerFollowerHire, PlayerFollower, SetupItemGiver, SetupTrader, SetupFollower, PlayerTrader, PlayerTransporter, RedstoneBlock, SetupTransporter, ManageTransport, ManageBanks, MobSpawner, SetupBank, ManageDialogs, ManageQuests, PlayerAnvil, QuestReward, ManageRecipes, QuestItem, NpcRemote, MoneyBag, MainMenuAI, MovingPath, PlayerBankUnlock, PlayerBankUprade, PlayerBankLarge, MobSpawnerAdd, PlayerMailbox, PlayerMailman, Waypoint, MerchantAdd, MobSpawnerMounter, Crate, NpcDimensions, Border, BigSign, Script, Companion, CompanionInv, CompanionTalent, CompanionTrader, ManageLinked + MainMenuDisplay, MainMenuInv, MainMenuStats, ManageFactions, MainMenuAdvanced, MainMenuGlobal, PlayerBankSmall, PlayerFollowerHire, PlayerFollower, SetupItemGiver, SetupTrader, SetupFollower, PlayerTrader, PlayerTransporter, RedstoneBlock, SetupTransporter, ManageTransport, ManageBanks, MobSpawner, SetupBank, ManageDialogs, ManageQuests, PlayerAnvil, QuestReward, ManageRecipes, QuestItem, NpcRemote, ScriptEvent, MoneyBag, MainMenuAI, MovingPath, PlayerBankUnlock, PlayerBankUprade, PlayerBankLarge, MobSpawnerAdd, PlayerMailbox, PlayerMailman, Waypoint, MerchantAdd, MobSpawnerMounter, Crate, NpcDimensions, Border, BigSign, Script, Companion, CompanionInv, CompanionTalent, CompanionTrader, ManageLinked } diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index 424a4e62d..e66f9709b 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -1,5 +1,62 @@ package noppes.npcs.constants; public enum EnumScriptType { - INIT, TICK, INTERACT, DIALOG, DAMAGED, KILLED, ATTACK, TARGET, COLLIDE, KILLS, DIALOG_OPTION + INIT("init"), + TICK("tick"), + INTERACT("interact"), + DIALOG("dialog"), + DAMAGED("damaged"), + KILLED("killed"), + ATTACK_MELEE("meleeAttack"), + TARGET("target"), + COLLIDE("collide"), + KILLS("kills"), + DIALOG_OPTION("dialogOption"), + TARGET_LOST("targetLost"), + ROLE("role"), + RANGED_LAUNCHED("rangedLaunched"), + CLICKED("clicked"), + FALLEN_UPON("fallenUpon"), + RAIN_FILLED("rainFilled"), + BROKEN("broken"), + HARVESTED("harvested"), + EXPLODED("exploded"), + NEIGHBOR_CHANGED("neighborChanged"), + REDSTONE("redstone"), + DOOR_TOGGLE("doorToggle"), + TIMER("timer"), + TOSS("toss"), + CONTAINER_OPEN("containerOpen"), + CONTAINER_CLOSED("containerClosed"), + LOGIN("login"), + LOGOUT("logout"), + CHAT("chat"), + DAMAGED_ENTITY("damagedEntity"), + DIALOG_CLOSE("dialogClose"), + SPAWN("spawn"), + TOSSED("tossed"), + PICKEDUP("pickedUp"), + PICKUP("pickUp"), + ATTACK("attack"), + PROJECTILE_TICK("projectileTick"), + PROJECTILE_IMPACT("projectileImpact"), + FACTION_UPDATE("factionUpdate"), + LEVEL_UP("levelUp"), + QUEST_START("questStart"), + QUEST_COMPLETED("questCompleted"), + QUEST_TURNIN("questTurnIn"), + KEY_PRESSED("keyPressed"), + CUSTOM_CHEST_CLOSED("customChestClosed"), + CUSTOM_CHEST_CLICKED("customChestClicked"), + SCRIPT_COMMAND("scriptCommand"), + CUSTOM_GUI_CLOSED("customGuiClosed"), + CUSTOM_GUI_BUTTON("customGuiButton"), + CUSTOM_GUI_SLOT("customGuiSlot"), + CUSTOM_GUI_SCROLL("customGuiScroll"); + + public String function; + + private EnumScriptType(String function) { + this.function = function; + } } diff --git a/src/main/java/noppes/npcs/controllers/IScriptHandler.java b/src/main/java/noppes/npcs/controllers/IScriptHandler.java new file mode 100644 index 000000000..a0e783fbc --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/IScriptHandler.java @@ -0,0 +1,34 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.controllers; + +import java.util.List; +import java.util.Map; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.ScriptContainer; + +public interface IScriptHandler { + void runScript(EnumScriptType var1, Event var2); + + boolean isClient(); + + boolean getEnabled(); + + void setEnabled(boolean var1); + + String getLanguage(); + + void setLanguage(String var1); + + List getScripts(); + + String noticeString(); + + Map getConsoleText(); + + void clearConsole(); +} diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java new file mode 100644 index 000000000..8e799073e --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -0,0 +1,289 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.controllers.data; + +import java.io.File; +import java.io.FileInputStream; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityInject; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.event.AttachCapabilitiesEvent; +import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; +import noppes.npcs.controllers.data.PlayerBankData; +import noppes.npcs.controllers.data.PlayerDialogData; +import noppes.npcs.controllers.data.PlayerFactionData; +import noppes.npcs.controllers.data.PlayerItemGiverData; +import noppes.npcs.controllers.data.PlayerMailData; +import noppes.npcs.controllers.data.PlayerQuestData; +import noppes.npcs.controllers.data.PlayerScriptData; +import noppes.npcs.controllers.data.PlayerTransportData; +import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.entity.data.DataTimers; +import noppes.npcs.roles.RoleCompanion; +import noppes.npcs.util.CustomNPCsScheduler; +import noppes.npcs.util.NBTJsonUtil; + +public class PlayerData implements ICapabilityProvider { + @CapabilityInject(PlayerData.class) + public static Capability PLAYERDATA_CAPABILITY = null; + public PlayerDialogData dialogData = new PlayerDialogData(); + public PlayerBankData bankData = new PlayerBankData(); + public PlayerQuestData questData = new PlayerQuestData(); + public PlayerTransportData transportData = new PlayerTransportData(); + public PlayerFactionData factionData = new PlayerFactionData(); + public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); + public PlayerMailData mailData = new PlayerMailData(); + public PlayerScriptData scriptData; + public DataTimers timers = new DataTimers(this); + public EntityNPCInterface editingNpc; + public NBTTagCompound cloned; + public NBTTagCompound scriptStoreddata = new NBTTagCompound(); + public EntityPlayer player; + public String playername = ""; + public String uuid = ""; + private EntityNPCInterface activeCompanion = null; + public int companionID = 0; + public int playerLevel = 0; + public boolean updateClient = false; + public int dialogId = -1; + private static final ResourceLocation key = new ResourceLocation("customnpcs", "playerdata"); + + public PlayerData() { + } + + public void setNBT(NBTTagCompound data) { + this.dialogData.loadNBTData(data); + this.bankData.loadNBTData(data); + this.questData.loadNBTData(data); + this.transportData.loadNBTData(data); + this.factionData.loadNBTData(data); + this.itemgiverData.loadNBTData(data); + this.mailData.loadNBTData(data); + this.timers.readFromNBT(data); + if(this.player != null) { + this.playername = this.player.func_70005_c_(); + this.uuid = this.player.getPersistentID().toString(); + } else { + this.playername = data.func_74779_i("PlayerName"); + this.uuid = data.func_74779_i("UUID"); + } + + this.companionID = data.func_74762_e("PlayerCompanionId"); + if(data.func_74764_b("PlayerCompanion") && !this.hasCompanion()) { + EntityCustomNpc npc = new EntityCustomNpc(this.player.field_70170_p); + npc.func_70037_a(data.func_74775_l("PlayerCompanion")); + npc.func_70107_b(this.player.field_70165_t, this.player.field_70163_u, this.player.field_70161_v); + if(npc.advanced.role == 6) { + this.setCompanion(npc); + ((RoleCompanion)npc.roleInterface).setSitting(false); + this.player.field_70170_p.func_72838_d(npc); + } + } + + this.scriptStoreddata = data.func_74775_l("ScriptStoreddata"); + } + + public NBTTagCompound getSyncNBT() { + NBTTagCompound compound = new NBTTagCompound(); + this.dialogData.saveNBTData(compound); + this.questData.saveNBTData(compound); + this.factionData.saveNBTData(compound); + return compound; + } + + public NBTTagCompound getNBT() { + if(this.player != null) { + this.playername = this.player.func_70005_c_(); + this.uuid = this.player.getPersistentID().toString(); + } + + NBTTagCompound compound = new NBTTagCompound(); + this.dialogData.saveNBTData(compound); + this.bankData.saveNBTData(compound); + this.questData.saveNBTData(compound); + this.transportData.saveNBTData(compound); + this.factionData.saveNBTData(compound); + this.itemgiverData.saveNBTData(compound); + this.mailData.saveNBTData(compound); + this.timers.writeToNBT(compound); + compound.func_74778_a("PlayerName", this.playername); + compound.func_74778_a("UUID", this.uuid); + compound.func_74768_a("PlayerCompanionId", this.companionID); + compound.func_74782_a("ScriptStoreddata", this.scriptStoreddata); + if(this.hasCompanion()) { + NBTTagCompound nbt = new NBTTagCompound(); + if(this.activeCompanion.func_184198_c(nbt)) { + compound.func_74782_a("PlayerCompanion", nbt); + } + } + + return compound; + } + + public boolean hasCompanion() { + return this.activeCompanion != null && !this.activeCompanion.field_70128_L; + } + + public void setCompanion(EntityNPCInterface npc) { + if(npc == null || npc.advanced.role == 6) { + ++this.companionID; + this.activeCompanion = npc; + if(npc != null) { + ((RoleCompanion)npc.roleInterface).companionID = this.companionID; + } + + this.save(false); + } + } + + public void updateCompanion(World world) { + if(this.hasCompanion() && world != this.activeCompanion.field_70170_p) { + RoleCompanion role = (RoleCompanion)this.activeCompanion.roleInterface; + role.owner = this.player; + if(role.isFollowing()) { + NBTTagCompound nbt = new NBTTagCompound(); + this.activeCompanion.func_184198_c(nbt); + this.activeCompanion.field_70128_L = true; + EntityCustomNpc npc = new EntityCustomNpc(world); + npc.func_70037_a(nbt); + npc.func_70107_b(this.player.field_70165_t, this.player.field_70163_u, this.player.field_70161_v); + this.setCompanion(npc); + ((RoleCompanion)npc.roleInterface).setSitting(false); + world.func_72838_d(npc); + } + } + } + + public boolean hasCapability(Capability capability, EnumFacing facing) { + return capability == PLAYERDATA_CAPABILITY; + } + + public T getCapability(Capability capability, EnumFacing facing) { + return this.hasCapability(capability, facing)?this:null; + } + + public static void register(AttachCapabilitiesEvent event) { + if(event.getObject() instanceof EntityPlayer) { + event.addCapability(key, new PlayerData()); + } + + } + + public synchronized void save(boolean update) { + NBTTagCompound compound = this.getNBT(); + String filename = this.uuid + ".json"; + CustomNPCsScheduler.runTack(() -> { + try { + File e = CustomNpcs.getWorldSaveDirectory("playerdata"); + File file = new File(e, filename + "_new"); + File file1 = new File(e, filename); + NBTJsonUtil.SaveFile(file, compound); + if(file1.exists()) { + file1.delete(); + } + + file.renameTo(file1); + } catch (Exception var5) { + LogWriter.except(var5); + } + + }); + if(update) { + this.updateClient = true; + } + + } + + public static NBTTagCompound loadPlayerDataOld(String player) { + File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata"); + String filename = player; + if(player.isEmpty()) { + filename = "noplayername"; + } + + filename = filename + ".dat"; + + File e; + try { + e = new File(saveDir, filename); + if(e.exists()) { + NBTTagCompound comp = CompressedStreamTools.func_74796_a(new FileInputStream(e)); + e.delete(); + e = new File(saveDir, filename + "_old"); + if(e.exists()) { + e.delete(); + } + + return comp; + } + } catch (Exception var6) { + LogWriter.except(var6); + } + + try { + e = new File(saveDir, filename + "_old"); + if(e.exists()) { + return CompressedStreamTools.func_74796_a(new FileInputStream(e)); + } + } catch (Exception var5) { + LogWriter.except(var5); + } + + return new NBTTagCompound(); + } + + public static NBTTagCompound loadPlayerData(String player) { + File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata"); + String filename = player; + if(player.isEmpty()) { + filename = "noplayername"; + } + + filename = filename + ".json"; + File file = null; + + try { + file = new File(saveDir, filename); + if(file.exists()) { + return NBTJsonUtil.LoadFile(file); + } + } catch (Exception var5) { + LogWriter.error("Error loading: " + file.getAbsolutePath(), var5); + } + + return new NBTTagCompound(); + } + + public static PlayerData get(EntityPlayer player) { + if(player.field_70170_p.field_72995_K) { + return CustomNpcs.proxy.getPlayerData(player); + } else { + PlayerData data = (PlayerData)player.getCapability(PLAYERDATA_CAPABILITY, (EnumFacing)null); + if(data.player == null) { + data.player = player; + data.playerLevel = player.field_71068_ca; + data.scriptData = new PlayerScriptData(player); + NBTTagCompound compound = loadPlayerData(player.getPersistentID().toString()); + if(compound.func_82582_d()) { + compound = loadPlayerDataOld(player.func_70005_c_()); + } + + data.setNBT(compound); + } + + return data; + } + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java b/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java new file mode 100644 index 000000000..86506a6d9 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java @@ -0,0 +1,165 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.controllers.data; + +import com.google.common.base.MoreObjects; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.Map.Entry; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.EventHooks; +import noppes.npcs.NBTTags; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.entity.IPlayer; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.IScriptHandler; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.controllers.ScriptController; + +public class PlayerScriptData implements IScriptHandler { + private List scripts = new ArrayList(); + private String scriptLanguage = "ECMAScript"; + private EntityPlayer player; + private IPlayer playerAPI; + private long lastPlayerUpdate = 0L; + public long lastInited = -1L; + public boolean hadInteract = true; + private boolean enabled = false; + private static Map console = new TreeMap(); + private static List errored = new ArrayList(); + + public PlayerScriptData(EntityPlayer player) { + this.player = player; + } + + public void clear() { + console = new TreeMap(); + errored = new ArrayList(); + this.scripts = new ArrayList(); + } + + public void readFromNBT(NBTTagCompound compound) { + this.scripts = NBTTags.GetScript(compound.func_150295_c("Scripts", 10), this); + this.scriptLanguage = compound.func_74779_i("ScriptLanguage"); + this.enabled = compound.func_74767_n("ScriptEnabled"); + console = NBTTags.GetLongStringMap(compound.func_150295_c("ScriptConsole", 10)); + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.func_74782_a("Scripts", NBTTags.NBTScript(this.scripts)); + compound.func_74778_a("ScriptLanguage", this.scriptLanguage); + compound.func_74757_a("ScriptEnabled", this.enabled); + compound.func_74782_a("ScriptConsole", NBTTags.NBTLongStringMap(console)); + return compound; + } + + public void runScript(EnumScriptType type, Event event) { + if(this.isEnabled()) { + ScriptContainer script; + if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) { + this.lastInited = ScriptController.Instance.lastLoaded; + errored.clear(); + if(this.player != null) { + this.scripts.clear(); + Iterator i = ScriptController.Instance.playerScripts.scripts.iterator(); + + while(i.hasNext()) { + script = (ScriptContainer)i.next(); + ScriptContainer s = new ScriptContainer(this); + s.readFromNBT(script.writeToNBT(new NBTTagCompound())); + this.scripts.add(s); + } + } + + this.lastPlayerUpdate = ScriptController.Instance.lastPlayerUpdate; + if(type != EnumScriptType.INIT) { + EventHooks.onPlayerInit(this); + } + } + + for(int var7 = 0; var7 < this.scripts.size(); ++var7) { + script = (ScriptContainer)this.scripts.get(var7); + if(!errored.contains(Integer.valueOf(var7))) { + script.run(type, event); + if(script.errored) { + errored.add(Integer.valueOf(var7)); + } + + Iterator var8 = script.console.entrySet().iterator(); + + while(var8.hasNext()) { + Entry entry = (Entry)var8.next(); + if(!console.containsKey(entry.getKey())) { + console.put(entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue()); + } + } + + script.console.clear(); + } + } + + } + } + + public boolean isEnabled() { + return ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.field_70170_p.field_72995_K); + } + + public boolean isClient() { + return !this.player.func_70613_aW(); + } + + public boolean getEnabled() { + return ScriptController.Instance.playerScripts.enabled; + } + + public void setEnabled(boolean bo) { + this.enabled = bo; + } + + public String getLanguage() { + return ScriptController.Instance.playerScripts.scriptLanguage; + } + + public void setLanguage(String lang) { + this.scriptLanguage = lang; + } + + public List getScripts() { + return this.scripts; + } + + public String noticeString() { + if(this.player == null) { + return "Global script"; + } else { + BlockPos pos = this.player.func_180425_c(); + return MoreObjects.toStringHelper(this.player).add("x", pos.func_177958_n()).add("y", pos.func_177956_o()).add("z", pos.func_177952_p()).toString(); + } + } + + public IPlayer getPlayer() { + if(this.playerAPI == null) { + this.playerAPI = (IPlayer)NpcAPI.Instance().getIEntity(this.player); + } + + return this.playerAPI; + } + + public Map getConsoleText() { + return console; + } + + public void clearConsole() { + console.clear(); + } +} diff --git a/src/main/java/noppes/npcs/items/ItemNpcScripter.java b/src/main/java/noppes/npcs/items/ItemNpcScripter.java index 3207b7cf7..c4e7b9750 100644 --- a/src/main/java/noppes/npcs/items/ItemNpcScripter.java +++ b/src/main/java/noppes/npcs/items/ItemNpcScripter.java @@ -1,16 +1,20 @@ package noppes.npcs.items; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; import noppes.npcs.CustomItems; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import noppes.npcs.CustomNpcs; +import noppes.npcs.constants.EnumGuiType; public class ItemNpcScripter extends Item{ - + public ItemNpcScripter(){ maxStackSize = 1; setCreativeTab(CustomItems.tab); @@ -25,7 +29,15 @@ public class ItemNpcScripter extends Item{ public boolean requiresMultipleRenderPasses(){ return true; } - + + @Override + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){ + if(!par2World.isRemote) + return par1ItemStack; + CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, par3EntityPlayer); + return par1ItemStack; + } + @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister par1IconRegister){ diff --git a/src/main/java/noppes/npcs/scripted/CommandNoppesBase.java b/src/main/java/noppes/npcs/scripted/CommandNoppesBase.java new file mode 100644 index 000000000..3bdd56cac --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/CommandNoppesBase.java @@ -0,0 +1,127 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.server.MinecraftServer; +//import net.minecraft.util.text.TextComponentTranslation; + +public abstract class CommandNoppesBase extends CommandBase { + public Map subcommands = new HashMap(); + + public CommandNoppesBase() { + Method[] var1 = this.getClass().getDeclaredMethods(); + int var2 = var1.length; + + for(int var3 = 0; var3 < var2; ++var3) { + Method m = var1[var3]; + CommandNoppesBase.SubCommand sc = (CommandNoppesBase.SubCommand)m.getAnnotation(CommandNoppesBase.SubCommand.class); + if(sc != null) { + String name = sc.name(); + if(name.equals("")) { + name = m.getName(); + } + + this.subcommands.put(name.toLowerCase(), m); + } + } + + } + + public void func_184881_a(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + } + + public String func_71518_a(ICommandSender sender) { + return this.getDescription(); + } + + public abstract String getDescription(); + + public String getUsage() { + return ""; + } + + public boolean runSubCommands() { + return !this.subcommands.isEmpty(); + } + + /* + protected void sendMessage(ICommandSender sender, String message, Object... obs) { + sender.func_145747_a(new TextComponentTranslation(message, obs)); + } + */ + + public void executeSub(MinecraftServer server, ICommandSender sender, String command, String[] args) throws CommandException { + Method m = (Method)this.subcommands.get(command.toLowerCase()); + if(m == null) { + throw new CommandException("Unknown subcommand " + command, new Object[0]); + } else { + CommandNoppesBase.SubCommand sc = (CommandNoppesBase.SubCommand)m.getAnnotation(CommandNoppesBase.SubCommand.class); + if(!sender.canCommandSenderUseCommand(sc.permission(), "commands.noppes." + this.getCommandName().toLowerCase() + "." + command.toLowerCase())) { + throw new CommandException("You are not allowed to use this command", new Object[0]); + } else { + this.canRun(server, sender, sc.usage(), args); + + try { + m.invoke(this, new Object[]{server, sender, args}); + } catch (Exception var8) { + if(var8.getCause() instanceof CommandException) { + throw (CommandException)var8.getCause(); + } + + var8.printStackTrace(); + } + + } + } + } + + public void canRun(MinecraftServer server, ICommandSender sender, String usage, String[] args) throws CommandException { + String[] np = usage.split(" "); + ArrayList required = new ArrayList(); + + for(int i = 0; i < np.length; ++i) { + String command = np[i]; + if(command.startsWith("<")) { + required.add(command); + } + + if(command.equals("") && args.length > i) { + CommandBase.getPlayer(sender, args[i]); + } + } + + if(args.length < required.size()) { + throw new CommandException("Missing parameter: " + (String)required.get(args.length), new Object[0]); + } + } + + public int func_82362_a() { + return 2; + } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD}) + public @interface SubCommand { + String name() default ""; + + String usage() default ""; + + String desc(); + + int permission() default 4; + } +} diff --git a/src/main/java/noppes/npcs/scripted/CustomNPCsException.java b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java new file mode 100644 index 000000000..f562b2dcf --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +public class CustomNPCsException extends RuntimeException { + public CustomNPCsException(String message, Object... obs) { + super(String.format(message, obs)); + } + + public CustomNPCsException(Exception ex, String message, Object... obs) { + super(String.format(message, obs), ex); + } +} diff --git a/src/main/java/noppes/npcs/scripted/IContainer.java b/src/main/java/noppes/npcs/scripted/IContainer.java new file mode 100644 index 000000000..83fd8a824 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IContainer.java @@ -0,0 +1,26 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import noppes.npcs.scripted.item.IItemStack; + +public interface IContainer { + int getSize(); + + IItemStack getSlot(int var1); + + void setSlot(int var1, IItemStack var2); + + IInventory getMCInventory(); + + Container getMCContainer(); + + int count(IItemStack var1, boolean var2, boolean var3); + + IItemStack[] getItems(); +} diff --git a/src/main/java/noppes/npcs/scripted/IDamageSource.java b/src/main/java/noppes/npcs/scripted/IDamageSource.java new file mode 100644 index 000000000..50563269c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IDamageSource.java @@ -0,0 +1,23 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.util.DamageSource; +import noppes.npcs.scripted.entity.IEntity; + +public interface IDamageSource { + String getType(); + + boolean isUnblockable(); + + boolean isProjectile(); + + IEntity getTrueSource(); + + IEntity getImmediateSource(); + + DamageSource getMCDamageSource(); +} diff --git a/src/main/java/noppes/npcs/scripted/IDimension.java b/src/main/java/noppes/npcs/scripted/IDimension.java new file mode 100644 index 000000000..3f5b26f9b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IDimension.java @@ -0,0 +1,14 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +public interface IDimension { + int getId(); + + String getName(); + + String getSuffix(); +} diff --git a/src/main/java/noppes/npcs/scripted/INbt.java b/src/main/java/noppes/npcs/scripted/INbt.java new file mode 100644 index 000000000..df1517d6f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/INbt.java @@ -0,0 +1,78 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.nbt.NBTTagCompound; + +public interface INbt { + void remove(String var1); + + boolean has(String var1); + + boolean getBoolean(String var1); + + void setBoolean(String var1, boolean var2); + + short getShort(String var1); + + void setShort(String var1, short var2); + + int getInteger(String var1); + + void setInteger(String var1, int var2); + + byte getByte(String var1); + + void setByte(String var1, byte var2); + + long getLong(String var1); + + void setLong(String var1, long var2); + + double getDouble(String var1); + + void setDouble(String var1, double var2); + + float getFloat(String var1); + + void setFloat(String var1, float var2); + + String getString(String var1); + + void setString(String var1, String var2); + + byte[] getByteArray(String var1); + + void setByteArray(String var1, byte[] var2); + + int[] getIntegerArray(String var1); + + void setIntegerArray(String var1, int[] var2); + + Object[] getList(String var1, int var2); + + int getListType(String var1); + + void setList(String var1, Object[] var2); + + INbt getCompound(String var1); + + void setCompound(String var1, INbt var2); + + String[] getKeys(); + + int getType(String var1); + + NBTTagCompound getMCNBT(); + + String toJsonString(); + + boolean isEqual(INbt var1); + + void clear(); + + void merge(INbt var1); +} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboard.java b/src/main/java/noppes/npcs/scripted/IScoreboard.java new file mode 100644 index 000000000..0a1b09275 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IScoreboard.java @@ -0,0 +1,45 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import noppes.npcs.scripted.IScoreboardObjective; +import noppes.npcs.scripted.IScoreboardTeam; + +public interface IScoreboard { + IScoreboardObjective[] getObjectives(); + + IScoreboardObjective getObjective(String var1); + + boolean hasObjective(String var1); + + void removeObjective(String var1); + + IScoreboardObjective addObjective(String var1, String var2); + + void setPlayerScore(String var1, String var2, int var3, String var4); + + int getPlayerScore(String var1, String var2, String var3); + + boolean hasPlayerObjective(String var1, String var2, String var3); + + void deletePlayerScore(String var1, String var2, String var3); + + IScoreboardTeam[] getTeams(); + + boolean hasTeam(String var1); + + IScoreboardTeam addTeam(String var1); + + IScoreboardTeam getTeam(String var1); + + void removeTeam(String var1); + + IScoreboardTeam getPlayerTeam(String var1); + + void removePlayerTeam(String var1); + + String[] getPlayerList(); +} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboardObjective.java b/src/main/java/noppes/npcs/scripted/IScoreboardObjective.java new file mode 100644 index 000000000..6679a3597 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IScoreboardObjective.java @@ -0,0 +1,30 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import noppes.npcs.scripted.IScoreboardScore; + +public interface IScoreboardObjective { + String getName(); + + String getDisplayName(); + + void setDisplayName(String var1); + + String getCriteria(); + + boolean isReadyOnly(); + + IScoreboardScore[] getScores(); + + IScoreboardScore getScore(String var1); + + boolean hasScore(String var1); + + IScoreboardScore createScore(String var1); + + void removeScore(String var1); +} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboardScore.java b/src/main/java/noppes/npcs/scripted/IScoreboardScore.java new file mode 100644 index 000000000..2b706d89a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IScoreboardScore.java @@ -0,0 +1,14 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +public interface IScoreboardScore { + int getValue(); + + void setValue(int var1); + + String getPlayerName(); +} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboardTeam.java b/src/main/java/noppes/npcs/scripted/IScoreboardTeam.java new file mode 100644 index 000000000..c4f4acb74 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IScoreboardTeam.java @@ -0,0 +1,36 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +public interface IScoreboardTeam { + String getName(); + + String getDisplayName(); + + void setDisplayName(String var1); + + void addPlayer(String var1); + + boolean hasPlayer(String var1); + + void removePlayer(String var1); + + String[] getPlayers(); + + void clearPlayers(); + + boolean getFriendlyFire(); + + void setFriendlyFire(boolean var1); + + void setColor(String var1); + + String getColor(); + + void setSeeInvisibleTeamPlayers(boolean var1); + + boolean getSeeInvisibleTeamPlayers(); +} diff --git a/src/main/java/noppes/npcs/scripted/ITimers.java b/src/main/java/noppes/npcs/scripted/ITimers.java new file mode 100644 index 000000000..24d1de2fe --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ITimers.java @@ -0,0 +1,20 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +public interface ITimers { + void start(int var1, int var2, boolean var3); + + void forceStart(int var1, int var2, boolean var3); + + boolean has(int var1); + + boolean stop(int var1); + + void reset(int var1); + + void clear(); +} diff --git a/src/main/java/noppes/npcs/scripted/IWorld.java b/src/main/java/noppes/npcs/scripted/IWorld.java new file mode 100644 index 000000000..2c941600c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IWorld.java @@ -0,0 +1,94 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldServer; +import noppes.npcs.scripted.IDimension; +import noppes.npcs.scripted.INbt; +import noppes.npcs.scripted.IScoreboard; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.entity.IPlayer; +import noppes.npcs.scripted.entity.data.IData; +import noppes.npcs.scripted.item.IItemStack; + +public interface IWorld { + /** @deprecated */ + IEntity[] getNearbyEntities(int var1, int var2, int var3, int var4, int var5); + + /** @deprecated */ + IEntity getClosestEntity(int var1, int var2, int var3, int var4, int var5); + + IEntity[] getAllEntities(int var1); + + long getTime(); + + void setTime(long var1); + + long getTotalTime(); + + void setBlock(int var1, int var2, int var3, String var4, int var5); + + void removeBlock(int var1, int var2, int var3); + + float getLightValue(int var1, int var2, int var3); + + IPlayer getPlayer(String var1); + + boolean isDay(); + + boolean isRaining(); + + IDimension getDimension(); + + void setRaining(boolean var1); + + void thunderStrike(double var1, double var3, double var5); + + void spawnParticle(String var1, double var2, double var4, double var6, double var8, double var10, double var12, double var14, int var16); + + void broadcast(String var1); + + IScoreboard getScoreboard(); + + IData getTempdata(); + + IData getStoreddata(); + + IItemStack createItem(String var1, int var2, int var3); + + IItemStack createItemFromNbt(INbt var1); + + void explode(double var1, double var3, double var5, float var7, boolean var8, boolean var9); + + IPlayer[] getAllPlayers(); + + String getBiomeName(int var1, int var2); + + void spawnEntity(IEntity var1); + + /** @deprecated */ + @Deprecated + IEntity spawnClone(double var1, double var3, double var5, int var7, String var8); + + /** @deprecated */ + @Deprecated + IEntity getClone(int var1, String var2); + + int getRedstonePower(int var1, int var2, int var3); + + WorldServer getMCWorld(); + + BlockPos getMCBlockPos(int var1, int var2, int var3); + + IEntity getEntity(String var1); + + IEntity createEntityFromNBT(INbt var1); + + IEntity createEntity(String var1); + + String getName(); +} diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java new file mode 100644 index 000000000..e385c6de3 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -0,0 +1,119 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import java.io.File; + +import net.minecraft.entity.Entity; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.eventhandler.EventBus; +import noppes.npcs.scripted.CommandNoppesBase; +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.IDamageSource; +import noppes.npcs.scripted.INbt; +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.entity.ICustomNpc; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.entity.data.IPlayerMail; +import noppes.npcs.scripted.gui.ICustomGui; +import noppes.npcs.scripted.handler.ICloneHandler; +import noppes.npcs.scripted.handler.IDialogHandler; +import noppes.npcs.scripted.handler.IFactionHandler; +import noppes.npcs.scripted.handler.IQuestHandler; +import noppes.npcs.scripted.handler.IRecipeHandler; +import noppes.npcs.scripted.item.IItemStack; + +public abstract class NpcAPI { + private static NpcAPI instance = null; + + public NpcAPI() { + } + + public abstract ICustomNpc createNPC(World var1); + + public abstract ICustomNpc spawnNPC(World var1, int var2, int var3, int var4); + + public abstract IEntity getIEntity(Entity var1); + + public abstract IContainer getIContainer(IInventory var1); + + public abstract IContainer getIContainer(Container var1); + + public abstract IItemStack getIItemStack(ItemStack var1); + + public abstract IWorld getIWorld(WorldServer var1); + + public abstract IWorld getIWorld(int var1); + + public abstract IWorld[] getIWorlds(); + + public abstract INbt getINbt(NBTTagCompound var1); + + public abstract IFactionHandler getFactions(); + + public abstract IRecipeHandler getRecipes(); + + public abstract IQuestHandler getQuests(); + + public abstract IDialogHandler getDialogs(); + + public abstract ICloneHandler getClones(); + + public abstract IDamageSource getIDamageSource(DamageSource var1); + + public abstract INbt stringToNbt(String var1); + + public abstract IPlayerMail createMail(String var1, String var2); + + public abstract ICustomGui createCustomGui(int var1, int var2, int var3, boolean var4); + + public abstract INbt getRawPlayerData(String var1); + + public abstract EventBus events(); + + public abstract void registerCommand(CommandNoppesBase var1); + + public abstract File getGlobalDir(); + + public abstract File getWorldDir(); + + public static boolean IsAvailable() { + return Loader.isModLoaded("customnpcs"); + } + + public static NpcAPI Instance() { + if(instance != null) { + return instance; + } else if(!IsAvailable()) { + return null; + } else { + try { + Class e = Class.forName("noppes.npcs.api.wrapper.WrapperNpcAPI"); + instance = (NpcAPI)e.getMethod("Instance", new Class[0]).invoke((Object)null, new Object[0]); + } catch (Exception var1) { + var1.printStackTrace(); + } + + return instance; + } + } + + public abstract void registerPermissionNode(String var1, int var2); + + public abstract boolean hasPermissionNode(String var1); + + public abstract String executeCommand(IWorld var1, String var2); + + public abstract String getRandomName(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java new file mode 100644 index 000000000..73cf3812f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java @@ -0,0 +1,75 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.EntityCreature; +import noppes.npcs.scripted.ITimers; +import noppes.npcs.scripted.entity.IEntityLiving; +import noppes.npcs.scripted.entity.IEntityLivingBase; +import noppes.npcs.scripted.entity.IPlayer; +import noppes.npcs.scripted.entity.IProjectile; +import noppes.npcs.scripted.entity.data.INPCAdvanced; +import noppes.npcs.scripted.entity.data.INPCAi; +import noppes.npcs.scripted.entity.data.INPCDisplay; +import noppes.npcs.scripted.entity.data.INPCInventory; +import noppes.npcs.scripted.entity.data.INPCJob; +import noppes.npcs.scripted.entity.data.INPCRole; +import noppes.npcs.scripted.entity.data.INPCStats; +import noppes.npcs.scripted.handler.data.IDialog; +import noppes.npcs.scripted.handler.data.IFaction; +import noppes.npcs.scripted.item.IItemStack; + +public interface ICustomNpc extends IEntityLiving { + INPCDisplay getDisplay(); + + INPCInventory getInventory(); + + INPCStats getStats(); + + INPCAi getAi(); + + INPCAdvanced getAdvanced(); + + IFaction getFaction(); + + void setFaction(int var1); + + INPCRole getRole(); + + INPCJob getJob(); + + ITimers getTimers(); + + int getHomeX(); + + int getHomeY(); + + int getHomeZ(); + + IEntityLivingBase getOwner(); + + void setHome(int var1, int var2, int var3); + + void reset(); + + void say(String var1); + + void sayTo(IPlayer var1, String var2); + + IProjectile shootItem(IEntityLivingBase var1, IItemStack var2, int var3); + + IProjectile shootItem(double var1, double var3, double var5, IItemStack var7, int var8); + + void giveItem(IPlayer var1, IItemStack var2); + + void setDialog(int var1, IDialog var2); + + IDialog getDialog(int var1); + + void updateClient(); + + String executeCommand(String var1); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntity.java b/src/main/java/noppes/npcs/scripted/entity/IEntity.java new file mode 100644 index 000000000..589c80fde --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IEntity.java @@ -0,0 +1,150 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.Entity; +import noppes.npcs.scripted.INbt; +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.entity.data.IData; +import noppes.npcs.scripted.item.IItemStack; + +public interface IEntity { + double getX(); + + void setX(double var1); + + double getY(); + + void setY(double var1); + + double getZ(); + + void setZ(double var1); + + int getBlockX(); + + int getBlockY(); + + int getBlockZ(); + + void setPosition(double var1, double var3, double var5); + + void setRotation(float var1); + + float getRotation(); + + float getHeight(); + + float getEyeHeight(); + + float getWidth(); + + void setPitch(float var1); + + float getPitch(); + + IEntity getMount(); + + void setMount(IEntity var1); + + IEntity[] getRiders(); + + IEntity[] getAllRiders(); + + void addRider(IEntity var1); + + void clearRiders(); + + void knockback(int var1, float var2); + + boolean isSneaking(); + + boolean isSprinting(); + + IEntityItem dropItem(IItemStack var1); + + boolean inWater(); + + boolean inFire(); + + boolean inLava(); + + IData getTempdata(); + + IData getStoreddata(); + + INbt getNbt(); + + boolean isAlive(); + + long getAge(); + + void despawn(); + + void spawn(); + + void kill(); + + boolean isBurning(); + + void setBurning(int var1); + + void extinguish(); + + IWorld getWorld(); + + String getTypeName(); + + int getType(); + + boolean typeOf(int var1); + + T getMCEntity(); + + String getUUID(); + + String generateNewUUID(); + + void storeAsClone(int var1, String var2); + + INbt getEntityNbt(); + + void setEntityNbt(INbt var1); + + IEntity[] rayTraceEntities(double var1, boolean var3, boolean var4); + + String[] getTags(); + + void addTag(String var1); + + boolean hasTag(String var1); + + void removeTag(String var1); + + void playAnimation(int var1); + + void damage(float var1); + + double getMotionX(); + + double getMotionY(); + + double getMotionZ(); + + void setMotionX(double var1); + + void setMotionY(double var1); + + void setMotionZ(double var1); + + String getName(); + + void setName(String var1); + + boolean hasCustomName(); + + String getEntityName(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntityItem.java b/src/main/java/noppes/npcs/scripted/entity/IEntityItem.java new file mode 100644 index 000000000..df5f9a933 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IEntityItem.java @@ -0,0 +1,32 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.item.EntityItem; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.item.IItemStack; + +public interface IEntityItem extends IEntity { + String getOwner(); + + void setOwner(String var1); + + int getPickupDelay(); + + void setPickupDelay(int var1); + + long getAge(); + + void setAge(long var1); + + int getLifeSpawn(); + + void setLifeSpawn(int var1); + + IItemStack getItem(); + + void setItem(IItemStack var1); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java b/src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java new file mode 100644 index 000000000..506d6faa1 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java @@ -0,0 +1,21 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.EntityLiving; +import noppes.npcs.scripted.entity.IEntityLivingBase; + +public interface IEntityLiving extends IEntityLivingBase { + boolean isNavigating(); + + void clearNavigation(); + + void navigateTo(double var1, double var3, double var5, double var7); + + void jump(); + + T getMCEntity(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java new file mode 100644 index 000000000..56f384664 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java @@ -0,0 +1,70 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.EntityLivingBase; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.item.IItemStack; + +public interface IEntityLivingBase extends IEntity { + float getHealth(); + + void setHealth(float var1); + + float getMaxHealth(); + + void setMaxHealth(float var1); + + boolean isAttacking(); + + void setAttackTarget(IEntityLivingBase var1); + + IEntityLivingBase getAttackTarget(); + + IEntityLivingBase getLastAttacked(); + + int getLastAttackedTime(); + + boolean canSeeEntity(IEntity var1); + + void swingMainhand(); + + void swingOffhand(); + + IItemStack getMainhandItem(); + + void setMainhandItem(IItemStack var1); + + IItemStack getOffhandItem(); + + void setOffhandItem(IItemStack var1); + + IItemStack getArmor(int var1); + + void setArmor(int var1, IItemStack var2); + + void addPotionEffect(int var1, int var2, int var3, boolean var4); + + void clearPotionEffects(); + + int getPotionEffect(int var1); + + boolean isChild(); + + T getMCEntity(); + + float getMoveForward(); + + void setMoveForward(float var1); + + float getMoveStrafing(); + + void setMoveStrafing(float var1); + + float getMoveVertical(); + + void setMoveVertical(float var1); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IPlayer.java b/src/main/java/noppes/npcs/scripted/entity/IPlayer.java new file mode 100644 index 000000000..ed8bdf016 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IPlayer.java @@ -0,0 +1,119 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.ITimers; +import noppes.npcs.scripted.entity.data.IPlayerMail; +import noppes.npcs.scripted.gui.ICustomGui; +import noppes.npcs.scripted.handler.data.IQuest; +import noppes.npcs.scripted.item.IItemStack; + +public interface IPlayer extends IEntityLivingBase { + String getDisplayName(); + + boolean hasFinishedQuest(int var1); + + boolean hasActiveQuest(int var1); + + void startQuest(int var1); + + int factionStatus(int var1); + + void finishQuest(int var1); + + void stopQuest(int var1); + + void removeQuest(int var1); + + boolean hasReadDialog(int var1); + + void showDialog(int var1, String var2); + + void removeDialog(int var1); + + void addDialog(int var1); + + void addFactionPoints(int var1, int var2); + + int getFactionPoints(int var1); + + void message(String var1); + + int getGamemode(); + + void setGamemode(int var1); + + /** @deprecated */ + int inventoryItemCount(IItemStack var1); + + /** @deprecated */ + int inventoryItemCount(String var1, int var2); + + IContainer getInventory(); + + boolean removeItem(IItemStack var1, int var2); + + boolean removeItem(String var1, int var2, int var3); + + void removeAllItems(IItemStack var1); + + boolean giveItem(IItemStack var1); + + boolean giveItem(String var1, int var2, int var3); + + void setSpawnpoint(int var1, int var2, int var3); + + void resetSpawnpoint(); + + boolean hasAchievement(String var1); + + int getExpLevel(); + + void setExpLevel(int var1); + + boolean hasPermission(String var1); + + Object getPixelmonData(); + + ITimers getTimers(); + + void closeGui(); + + T getMCEntity(); + + int getHunger(); + + void setHunger(int var1); + + void kick(String var1); + + void sendNotification(String var1, String var2, int var3); + + void sendMail(IPlayerMail var1); + + void clearData(); + + IQuest[] getActiveQuests(); + + IQuest[] getFinishedQuests(); + + void updatePlayerInventory(); + + void playSound(String var1, float var2, float var3); + + /** @deprecated */ + IContainer showChestGui(int var1); + + IContainer getOpenContainer(); + + boolean canQuestBeAccepted(int var1); + + void showCustomGui(ICustomGui var1); + + ICustomGui getCustomGui(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IProjectile.java b/src/main/java/noppes/npcs/scripted/entity/IProjectile.java new file mode 100644 index 000000000..fdcd8e8f4 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IProjectile.java @@ -0,0 +1,33 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.projectile.EntityThrowable; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.entity.IThrowable; +import noppes.npcs.scripted.item.IItemStack; + +public interface IProjectile extends IThrowable { + IItemStack getItem(); + + void setItem(IItemStack var1); + + boolean getHasGravity(); + + void setHasGravity(boolean var1); + + int getAccuracy(); + + void setAccuracy(int var1); + + void setHeading(IEntity var1); + + void setHeading(double var1, double var3, double var5); + + void setHeading(float var1, float var2); + + void enableEvents(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/IThrowable.java b/src/main/java/noppes/npcs/scripted/entity/IThrowable.java new file mode 100644 index 000000000..4e77c5468 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/IThrowable.java @@ -0,0 +1,12 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.projectile.EntityThrowable; +import noppes.npcs.scripted.entity.IEntity; + +public interface IThrowable extends IEntity { +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/IData.java b/src/main/java/noppes/npcs/scripted/entity/data/IData.java new file mode 100644 index 000000000..5df4d2e4b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/IData.java @@ -0,0 +1,20 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface IData { + void put(String var1, Object var2); + + Object get(String var1); + + void remove(String var1); + + boolean has(String var1); + + String[] getKeys(); + + void clear(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java new file mode 100644 index 000000000..d727e8565 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java @@ -0,0 +1,18 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCAdvanced { + void setLine(int var1, int var2, String var3, String var4); + + String getLine(int var1, int var2); + + int getLineCount(int var1); + + String getSound(int var1); + + void setSound(int var1, String var2); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java new file mode 100644 index 000000000..6b4a20db6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java @@ -0,0 +1,92 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCAi { + int getAnimation(); + + void setAnimation(int var1); + + int getCurrentAnimation(); + + void setReturnsHome(boolean var1); + + boolean getReturnsHome(); + + int getRetaliateType(); + + void setRetaliateType(int var1); + + int getMovingType(); + + void setMovingType(int var1); + + int getNavigationType(); + + void setNavigationType(int var1); + + int getStandingType(); + + void setStandingType(int var1); + + boolean getAttackInvisible(); + + void setAttackInvisible(boolean var1); + + int getWanderingRange(); + + void setWanderingRange(int var1); + + boolean getInteractWithNPCs(); + + void setInteractWithNPCs(boolean var1); + + boolean getStopOnInteract(); + + void setStopOnInteract(boolean var1); + + int getWalkingSpeed(); + + void setWalkingSpeed(int var1); + + int getMovingPathType(); + + boolean getMovingPathPauses(); + + void setMovingPathType(int var1, boolean var2); + + int getDoorInteract(); + + void setDoorInteract(int var1); + + boolean getCanSwim(); + + void setCanSwim(boolean var1); + + int getSheltersFrom(); + + void setSheltersFrom(int var1); + + boolean getAttackLOS(); + + void setAttackLOS(boolean var1); + + boolean getAvoidsWater(); + + void setAvoidsWater(boolean var1); + + boolean getLeapAtTarget(); + + void setLeapAtTarget(boolean var1); + + int getTacticalType(); + + void setTacticalType(int var1); + + int getTacticalRange(); + + void setTacticalRange(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java new file mode 100644 index 000000000..00881970b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java @@ -0,0 +1,76 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCDisplay { + String getName(); + + void setName(String var1); + + String getTitle(); + + void setTitle(String var1); + + String getSkinUrl(); + + void setSkinUrl(String var1); + + String getSkinPlayer(); + + void setSkinPlayer(String var1); + + String getSkinTexture(); + + void setSkinTexture(String var1); + + boolean getHasLivingAnimation(); + + void setHasLivingAnimation(boolean var1); + + int getVisible(); + + void setVisible(int var1); + + int getBossbar(); + + void setBossbar(int var1); + + int getSize(); + + void setSize(int var1); + + int getTint(); + + void setTint(int var1); + + int getShowName(); + + void setShowName(int var1); + + void setCapeTexture(String var1); + + String getCapeTexture(); + + void setOverlayTexture(String var1); + + String getOverlayTexture(); + + void setModelScale(int var1, float var2, float var3, float var4); + + float[] getModelScale(int var1); + + int getBossColor(); + + void setBossColor(int var1); + + void setModel(String var1); + + String getModel(); + + void setHasHitbox(boolean var1); + + boolean getHasHitbox(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java new file mode 100644 index 000000000..570f8222f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java @@ -0,0 +1,40 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +import noppes.npcs.scripted.item.IItemStack; + +public interface INPCInventory { + IItemStack getRightHand(); + + void setRightHand(IItemStack var1); + + IItemStack getLeftHand(); + + void setLeftHand(IItemStack var1); + + IItemStack getProjectile(); + + void setProjectile(IItemStack var1); + + IItemStack getArmor(int var1); + + void setArmor(int var1, IItemStack var2); + + void setDropItem(int var1, IItemStack var2, int var3); + + IItemStack getDropItem(int var1); + + int getExpMin(); + + int getExpMax(); + + int getExpRNG(); + + void setExp(int var1, int var2); + + IItemStack[] getItemsRNG(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java new file mode 100644 index 000000000..b5c75a336 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCJob { + int getType(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java new file mode 100644 index 000000000..13deb1538 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java @@ -0,0 +1,32 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCMelee { + int getStrength(); + + void setStrength(int var1); + + int getDelay(); + + void setDelay(int var1); + + int getRange(); + + void setRange(int var1); + + int getKnockback(); + + void setKnockback(int var1); + + int getEffectType(); + + int getEffectTime(); + + int getEffectStrength(); + + void setEffect(int var1, int var2, int var3); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java new file mode 100644 index 000000000..f63ea6891 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java @@ -0,0 +1,108 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCRanged { + int getStrength(); + + void setStrength(int var1); + + int getSpeed(); + + void setSpeed(int var1); + + int getBurst(); + + void setBurst(int var1); + + int getBurstDelay(); + + void setBurstDelay(int var1); + + int getKnockback(); + + void setKnockback(int var1); + + int getSize(); + + void setSize(int var1); + + boolean getRender3D(); + + void setRender3D(boolean var1); + + boolean getSpins(); + + void setSpins(boolean var1); + + boolean getSticks(); + + void setSticks(boolean var1); + + boolean getHasGravity(); + + void setHasGravity(boolean var1); + + boolean getAccelerate(); + + void setAccelerate(boolean var1); + + int getExplodeSize(); + + void setExplodeSize(int var1); + + int getEffectType(); + + int getEffectTime(); + + int getEffectStrength(); + + void setEffect(int var1, int var2, int var3); + + boolean getGlows(); + + void setGlows(boolean var1); + + int getParticle(); + + void setParticle(int var1); + + String getSound(int var1); + + void setSound(int var1, String var2); + + int getShotCount(); + + void setShotCount(int var1); + + boolean getHasAimAnimation(); + + void setHasAimAnimation(boolean var1); + + int getAccuracy(); + + void setAccuracy(int var1); + + int getRange(); + + void setRange(int var1); + + int getDelayMin(); + + int getDelayMax(); + + int getDelayRNG(); + + void setDelay(int var1, int var2); + + int getFireType(); + + void setFireType(int var1); + + int getMeleeRange(); + + void setMeleeRange(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java new file mode 100644 index 000000000..4de2a540d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +public interface INPCRole { + int getType(); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java new file mode 100644 index 000000000..c247e7ec3 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java @@ -0,0 +1,55 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +import noppes.npcs.scripted.entity.data.INPCMelee; +import noppes.npcs.scripted.entity.data.INPCRanged; + +public interface INPCStats { + int getMaxHealth(); + + void setMaxHealth(int var1); + + float getResistance(int var1); + + void setResistance(int var1, float var2); + + int getCombatRegen(); + + void setCombatRegen(int var1); + + int getHealthRegen(); + + void setHealthRegen(int var1); + + INPCMelee getMelee(); + + INPCRanged getRanged(); + + boolean getImmune(int var1); + + void setImmune(int var1, boolean var2); + + void setCreatureType(int var1); + + int getCreatureType(); + + int getRespawnType(); + + void setRespawnType(int var1); + + int getRespawnTime(); + + void setRespawnTime(int var1); + + boolean getHideDeadBody(); + + void setHideDeadBody(boolean var1); + + int getAggroRange(); + + void setAggroRange(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java b/src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java new file mode 100644 index 000000000..a53133ae9 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java @@ -0,0 +1,29 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.entity.data; + +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.handler.data.IQuest; + +public interface IPlayerMail { + String getSender(); + + void setSender(String var1); + + String getSubject(); + + void setSubject(String var1); + + String[] getText(); + + void setText(String[] var1); + + IQuest getQuest(); + + void setQuest(int var1); + + IContainer getContainer(); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/IButton.java b/src/main/java/noppes/npcs/scripted/gui/IButton.java new file mode 100644 index 000000000..b4fe804c3 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/IButton.java @@ -0,0 +1,32 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import noppes.npcs.scripted.gui.ICustomGuiComponent; + +public interface IButton extends ICustomGuiComponent { + int getWidth(); + + int getHeight(); + + IButton setSize(int var1, int var2); + + String getLabel(); + + IButton setLabel(String var1); + + String getTexture(); + + boolean hasTexture(); + + IButton setTexture(String var1); + + int getTextureX(); + + int getTextureY(); + + IButton setTextureOffset(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ICustomGui.java b/src/main/java/noppes/npcs/scripted/gui/ICustomGui.java new file mode 100644 index 000000000..a0ecc27a8 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ICustomGui.java @@ -0,0 +1,69 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import java.util.List; +import noppes.npcs.scripted.entity.IPlayer; +import noppes.npcs.scripted.gui.IButton; +import noppes.npcs.scripted.gui.ICustomGuiComponent; +import noppes.npcs.scripted.gui.IItemSlot; +import noppes.npcs.scripted.gui.ILabel; +import noppes.npcs.scripted.gui.IScroll; +import noppes.npcs.scripted.gui.ITextField; +import noppes.npcs.scripted.gui.ITexturedRect; +import noppes.npcs.scripted.item.IItemStack; + +public interface ICustomGui { + int getID(); + + int getWidth(); + + int getHeight(); + + List getComponents(); + + List getSlots(); + + void setSize(int var1, int var2); + + void setDoesPauseGame(boolean var1); + + void setBackgroundTexture(String var1); + + IButton addButton(int var1, String var2, int var3, int var4); + + IButton addButton(int var1, String var2, int var3, int var4, int var5, int var6); + + IButton addTexturedButton(int var1, String var2, int var3, int var4, int var5, int var6, String var7); + + IButton addTexturedButton(int var1, String var2, int var3, int var4, int var5, int var6, String var7, int var8, int var9); + + ILabel addLabel(int var1, String var2, int var3, int var4, int var5, int var6); + + ILabel addLabel(int var1, String var2, int var3, int var4, int var5, int var6, int var7); + + ITextField addTextField(int var1, int var2, int var3, int var4, int var5); + + ITexturedRect addTexturedRect(int var1, String var2, int var3, int var4, int var5, int var6); + + ITexturedRect addTexturedRect(int var1, String var2, int var3, int var4, int var5, int var6, int var7, int var8); + + IScroll addScroll(int var1, int var2, int var3, int var4, int var5, String[] var6); + + IItemSlot addItemSlot(int var1, int var2); + + IItemSlot addItemSlot(int var1, int var2, IItemStack var3); + + void showPlayerInventory(int var1, int var2); + + ICustomGuiComponent getComponent(int var1); + + void removeComponent(int var1); + + void updateComponent(ICustomGuiComponent var1); + + void update(IPlayer var1); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java b/src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java new file mode 100644 index 000000000..0e9d3882d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java @@ -0,0 +1,26 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +public interface ICustomGuiComponent { + int getID(); + + ICustomGuiComponent setID(int var1); + + int getPosX(); + + int getPosY(); + + ICustomGuiComponent setPos(int var1, int var2); + + boolean hasHoverText(); + + String[] getHoverText(); + + ICustomGuiComponent setHoverText(String var1); + + ICustomGuiComponent setHoverText(String[] var1); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/IItemSlot.java b/src/main/java/noppes/npcs/scripted/gui/IItemSlot.java new file mode 100644 index 000000000..7ac899cbb --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/IItemSlot.java @@ -0,0 +1,20 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import net.minecraft.inventory.Slot; +import noppes.npcs.scripted.gui.ICustomGuiComponent; +import noppes.npcs.scripted.item.IItemStack; + +public interface IItemSlot extends ICustomGuiComponent { + boolean hasStack(); + + IItemStack getStack(); + + IItemSlot setStack(IItemStack var1); + + Slot getMCSlot(); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ILabel.java b/src/main/java/noppes/npcs/scripted/gui/ILabel.java new file mode 100644 index 000000000..9851752dc --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ILabel.java @@ -0,0 +1,28 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import noppes.npcs.scripted.gui.ICustomGuiComponent; + +public interface ILabel extends ICustomGuiComponent { + String getText(); + + ILabel setText(String var1); + + int getWidth(); + + int getHeight(); + + ILabel setSize(int var1, int var2); + + int getColor(); + + ILabel setColor(int var1); + + float getScale(); + + ILabel setScale(float var1); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/IScroll.java b/src/main/java/noppes/npcs/scripted/gui/IScroll.java new file mode 100644 index 000000000..cbe388bef --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/IScroll.java @@ -0,0 +1,28 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import noppes.npcs.scripted.gui.ICustomGuiComponent; + +public interface IScroll extends ICustomGuiComponent { + int getWidth(); + + int getHeight(); + + IScroll setSize(int var1, int var2); + + String[] getList(); + + IScroll setList(String[] var1); + + int getDefaultSelection(); + + IScroll setDefaultSelection(int var1); + + boolean isMultiSelect(); + + IScroll setMultiSelect(boolean var1); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ITextField.java b/src/main/java/noppes/npcs/scripted/gui/ITextField.java new file mode 100644 index 000000000..449a090f5 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ITextField.java @@ -0,0 +1,20 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import noppes.npcs.scripted.gui.ICustomGuiComponent; + +public interface ITextField extends ICustomGuiComponent { + int getWidth(); + + int getHeight(); + + ITextField setSize(int var1, int var2); + + String getText(); + + ITextField setText(String var1); +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java b/src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java new file mode 100644 index 000000000..1bf160c5c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java @@ -0,0 +1,30 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.gui; + +import noppes.npcs.scripted.gui.ICustomGuiComponent; + +public interface ITexturedRect extends ICustomGuiComponent { + String getTexture(); + + ITexturedRect setTexture(String var1); + + int getWidth(); + + int getHeight(); + + ITexturedRect setSize(int var1, int var2); + + float getScale(); + + ITexturedRect setScale(float var1); + + int getTextureX(); + + int getTextureY(); + + ITexturedRect setTextureOffset(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java b/src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java new file mode 100644 index 000000000..0797f0597 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java @@ -0,0 +1,19 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler; + +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.entity.IEntity; + +public interface ICloneHandler { + IEntity spawn(double var1, double var3, double var5, int var7, String var8, IWorld var9); + + IEntity get(int var1, String var2, IWorld var3); + + void set(int var1, String var2, IEntity var3); + + void remove(int var1, String var2); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java b/src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java new file mode 100644 index 000000000..31744cb81 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java @@ -0,0 +1,19 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler; + +import java.util.List; +import noppes.npcs.scripted.handler.data.IFaction; + +public interface IFactionHandler { + List list(); + + IFaction delete(int var1); + + IFaction create(String var1, int var2); + + IFaction get(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java b/src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java new file mode 100644 index 000000000..4eb6d23b7 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler; + +import java.util.List; +import noppes.npcs.scripted.handler.data.IQuest; +import noppes.npcs.scripted.handler.data.IQuestCategory; + +public interface IQuestHandler { + List categories(); + + IQuest get(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java b/src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java new file mode 100644 index 000000000..500734f5f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java @@ -0,0 +1,22 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler; + +import java.util.List; +import net.minecraft.item.ItemStack; +import noppes.npcs.scripted.handler.data.IRecipe; + +public interface IRecipeHandler { + List getGlobalList(); + + List getCarpentryList(); + + IRecipe addRecipe(String var1, boolean var2, ItemStack var3, Object... var4); + + IRecipe addRecipe(String var1, boolean var2, ItemStack var3, int var4, int var5, ItemStack... var6); + + IRecipe delete(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java b/src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java new file mode 100644 index 000000000..d5ab810f1 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java @@ -0,0 +1,38 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import noppes.npcs.scripted.entity.IPlayer; + +public interface IAvailability { + boolean isAvailable(IPlayer var1); + + int getDaytime(); + + void setDaytime(int var1); + + int getMinPlayerLevel(); + + void setMinPlayerLevel(int var1); + + int getDialog(int var1); + + void setDialog(int var1, int var2, int var3); + + void removeDialog(int var1); + + int getQuest(int var1); + + void setQuest(int var1, int var2, int var3); + + void removeQuest(int var1); + + void setFaction(int var1, int var2, int var3, int var4); + + void removeFaction(int var1); + + void setScoreboard(int var1, String var2, int var3, int var4); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java new file mode 100644 index 000000000..c6e35bfc5 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java @@ -0,0 +1,42 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import java.util.List; +import noppes.npcs.scripted.handler.data.IAvailability; +import noppes.npcs.scripted.handler.data.IDialogCategory; +import noppes.npcs.scripted.handler.data.IDialogOption; +import noppes.npcs.scripted.handler.data.IQuest; + +public interface IDialog { + int getId(); + + String getName(); + + void setName(String var1); + + String getText(); + + void setText(String var1); + + IQuest getQuest(); + + void setQuest(IQuest var1); + + String getCommand(); + + void setCommand(String var1); + + List getOptions(); + + IDialogOption getOption(int var1); + + IAvailability getAvailability(); + + IDialogCategory getCategory(); + + void save(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java new file mode 100644 index 000000000..b0d889a5b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java @@ -0,0 +1,17 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import java.util.List; +import noppes.npcs.scripted.handler.data.IDialog; + +public interface IDialogCategory { + List dialogs(); + + String getName(); + + IDialog create(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java new file mode 100644 index 000000000..9c2adc114 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler; + +import java.util.List; +import noppes.npcs.scripted.handler.data.IDialog; +import noppes.npcs.scripted.handler.data.IDialogCategory; + +public interface IDialogHandler { + List categories(); + + IDialog get(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java new file mode 100644 index 000000000..d2631966b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java @@ -0,0 +1,14 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +public interface IDialogOption { + int getSlot(); + + String getName(); + + int getType(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IFaction.java b/src/main/java/noppes/npcs/scripted/handler/data/IFaction.java new file mode 100644 index 000000000..a72f945a2 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IFaction.java @@ -0,0 +1,45 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import noppes.npcs.scripted.entity.ICustomNpc; +import noppes.npcs.scripted.entity.IPlayer; + +public interface IFaction { + int getId(); + + String getName(); + + int getDefaultPoints(); + + void setDefaultPoints(int var1); + + int getColor(); + + int playerStatus(IPlayer var1); + + boolean hostileToNpc(ICustomNpc var1); + + boolean hostileToFaction(int var1); + + int[] getHostileList(); + + void addHostile(int var1); + + void removeHostile(int var1); + + boolean hasHostile(int var1); + + boolean getIsHidden(); + + void setIsHidden(boolean var1); + + boolean getAttackedByMobs(); + + void setAttackedByMobs(boolean var1); + + void save(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java new file mode 100644 index 000000000..b53972149 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java @@ -0,0 +1,47 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.entity.IPlayer; + +public interface IQuest { + int getId(); + + String getName(); + + void setName(String var1); + + int getType(); + + void setType(int var1); + + String getLogText(); + + void setLogText(String var1); + + String getCompleteText(); + + void setCompleteText(String var1); + + IQuest getNextQuest(); + + void setNextQuest(IQuest var1); + + IQuestObjective[] getObjectives(IPlayer var1); + + IQuestCategory getCategory(); + + IContainer getRewards(); + + String getNpcName(); + + void setNpcName(String var1); + + void save(); + + boolean getIsRepeatable(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java new file mode 100644 index 000000000..0bbe539a7 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java @@ -0,0 +1,17 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import java.util.List; +import noppes.npcs.scripted.handler.data.IQuest; + +public interface IQuestCategory { + List quests(); + + String getName(); + + IQuest create(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java new file mode 100644 index 000000000..69a0374cf --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java @@ -0,0 +1,14 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import java.util.List; + +public interface IQuestHandler { + List categories(); + + IQuest get(int var1); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java new file mode 100644 index 000000000..9e31c41ab --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java @@ -0,0 +1,18 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +public interface IQuestObjective { + int getProgress(); + + void setProgress(int var1); + + int getMaxProgress(); + + boolean isCompleted(); + + String getText(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java b/src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java new file mode 100644 index 000000000..a6ed19826 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java @@ -0,0 +1,42 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.handler.data; + +import net.minecraft.item.ItemStack; + +public interface IRecipe { + String getName(); + + boolean isGlobal(); + + void setIsGlobal(boolean var1); + + boolean getIgnoreNBT(); + + void setIgnoreNBT(boolean var1); + + boolean getIgnoreDamage(); + + void setIgnoreDamage(boolean var1); + + int getWidth(); + + int getHeight(); + + ItemStack getResult(); + + ItemStack[] getRecipe(); + + void saves(boolean var1); + + boolean saves(); + + void save(); + + void delete(); + + int getId(); +} diff --git a/src/main/java/noppes/npcs/scripted/item/IItemStack.java b/src/main/java/noppes/npcs/scripted/item/IItemStack.java new file mode 100644 index 000000000..9ee617f1d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/item/IItemStack.java @@ -0,0 +1,92 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.item; + +import net.minecraft.item.ItemStack; +import noppes.npcs.scripted.INbt; +import noppes.npcs.scripted.entity.IEntityLiving; +import noppes.npcs.scripted.entity.data.IData; + +public interface IItemStack { + int getStackSize(); + + void setStackSize(int var1); + + int getMaxStackSize(); + + int getItemDamage(); + + void setItemDamage(int var1); + + int getMaxItemDamage(); + + double getAttackDamage(); + + void damageItem(int var1, IEntityLiving var2); + + void addEnchantment(String var1, int var2); + + boolean isEnchanted(); + + boolean hasEnchant(String var1); + + boolean removeEnchant(String var1); + + /** @deprecated */ + boolean isBlock(); + + boolean isWearable(); + + boolean hasCustomName(); + + void setCustomName(String var1); + + String getDisplayName(); + + String getItemName(); + + String getName(); + + /** @deprecated */ + boolean isBook(); + + IItemStack copy(); + + ItemStack getMCItemStack(); + + INbt getNbt(); + + boolean hasNbt(); + + void removeNbt(); + + INbt getItemNbt(); + + boolean isEmpty(); + + int getType(); + + String[] getLore(); + + void setLore(String[] var1); + + /** @deprecated */ + void setAttribute(String var1, double var2); + + void setAttribute(String var1, double var2, int var4); + + double getAttribute(String var1); + + boolean hasAttribute(String var1); + + IData getTempdata(); + + IData getStoreddata(); + + int getFoodLevel(); + + boolean compare(IItemStack var1, boolean var2); +} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java new file mode 100644 index 000000000..233b2229d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -0,0 +1,247 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.wrapper; + +import java.io.File; +import java.util.Map; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.FakePlayer; +import cpw.mods.fml.common.eventhandler.EventBus; +import noppes.npcs.CustomNpcs; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.scripted.CommandNoppesBase; +import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.IDamageSource; +import noppes.npcs.scripted.INbt; +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.entity.ICustomNpc; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.entity.data.IPlayerMail; +import noppes.npcs.scripted.gui.ICustomGui; +import noppes.npcs.scripted.handler.ICloneHandler; +import noppes.npcs.scripted.handler.IDialogHandler; +import noppes.npcs.scripted.handler.IFactionHandler; +import noppes.npcs.scripted.handler.IQuestHandler; +import noppes.npcs.scripted.handler.IRecipeHandler; +import noppes.npcs.scripted.item.IItemStack; +import noppes.npcs.scripted.wrapper.ContainerWrapper; +import noppes.npcs.scripted.wrapper.DamageSourceWrapper; +import noppes.npcs.scripted.wrapper.ItemStackWrapper; +import noppes.npcs.scripted.wrapper.NBTWrapper; +import noppes.npcs.scripted.wrapper.WorldWrapper; +import noppes.npcs.scripted.wrapper.WrapperEntityData; +import noppes.npcs.scripted.wrapper.gui.CustomGuiWrapper; +import noppes.npcs.containers.ContainerNpcInterface; +import noppes.npcs.controllers.DialogController; +import noppes.npcs.controllers.FactionController; +import noppes.npcs.controllers.QuestController; +import noppes.npcs.controllers.RecipeController; +import noppes.npcs.controllers.ServerCloneController; +import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerMail; +import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.util.LRUHashMap; +import noppes.npcs.util.NBTJsonUtil; +import noppes.npcs.util.JsonException; + +public class WrapperNpcAPI extends NpcAPI { + private static final Map worldCache = new LRUHashMap(10); + public static final EventBus EVENT_BUS = new EventBus(); + private static NpcAPI instance = null; + + public WrapperNpcAPI() { + } + + public static void clearCache() { + worldCache.clear(); + } + + public IEntity getIEntity(Entity entity) { + return (IEntity)(entity != null && !entity.field_70170_p.field_72995_K?(entity instanceof EntityNPCInterface?((EntityNPCInterface)entity).wrappedNPC:WrapperEntityData.get(entity)):null); + } + + public ICustomNpc createNPC(World world) { + if(world.field_72995_K) { + return null; + } else { + EntityCustomNpc npc = new EntityCustomNpc(world); + return npc.wrappedNPC; + } + } + + public ICustomNpc spawnNPC(World world, int x, int y, int z) { + if(world.field_72995_K) { + return null; + } else { + EntityCustomNpc npc = new EntityCustomNpc(world); + npc.func_70080_a((double)x + 0.5D, (double)y, (double)z + 0.5D, 0.0F, 0.0F); + npc.ais.setStartPos((double)x, (double)y, (double)z); + npc.func_70606_j(npc.func_110138_aP()); + world.func_72838_d(npc); + return npc.wrappedNPC; + } + } + + public static NpcAPI Instance() { + if(instance == null) { + instance = new WrapperNpcAPI(); + } + + return instance; + } + + public EventBus events() { + return EVENT_BUS; + } + + public IItemStack getIItemStack(ItemStack itemstack) { + return (IItemStack)(itemstack != null && !itemstack.func_190926_b()?(IItemStack)itemstack.getCapability(ItemStackWrapper.ITEMSCRIPTEDDATA_CAPABILITY, (EnumFacing)null):ItemStackWrapper.AIR); + } + + public IWorld getIWorld(WorldServer world) { + WorldWrapper w = (WorldWrapper)worldCache.get(Integer.valueOf(world.field_73011_w.getDimension())); + if(w != null) { + w.world = world; + return w; + } else { + worldCache.put(Integer.valueOf(world.field_73011_w.getDimension()), w = WorldWrapper.createNew(world)); + return w; + } + } + + public IWorld getIWorld(int dimensionId) { + WorldServer[] var2 = CustomNpcs.Server.field_71305_c; + int var3 = var2.length; + + for(int var4 = 0; var4 < var3; ++var4) { + WorldServer world = var2[var4]; + if(world.field_73011_w.getDimension() == dimensionId) { + return this.getIWorld(world); + } + } + + throw new CustomNPCsException("Unknown dimension id: " + dimensionId, new Object[0]); + } + + public IContainer getIContainer(IInventory inventory) { + return new ContainerWrapper(inventory); + } + + public IContainer getIContainer(Container container) { + return (IContainer)(container instanceof ContainerNpcInterface?ContainerNpcInterface.getOrCreateIContainer((ContainerNpcInterface)container):new ContainerWrapper(container)); + } + + public IFactionHandler getFactions() { + this.checkWorld(); + return FactionController.instance; + } + + private void checkWorld() { + if(CustomNpcs.Server == null || CustomNpcs.Server.func_71241_aa()) { + throw new CustomNPCsException("No world is loaded right now", new Object[0]); + } + } + + public IRecipeHandler getRecipes() { + this.checkWorld(); + return RecipeController.instance; + } + + public IQuestHandler getQuests() { + this.checkWorld(); + return QuestController.instance; + } + + public IWorld[] getIWorlds() { + this.checkWorld(); + IWorld[] worlds = new IWorld[CustomNpcs.Server.field_71305_c.length]; + + for(int i = 0; i < CustomNpcs.Server.field_71305_c.length; ++i) { + worlds[i] = this.getIWorld(CustomNpcs.Server.field_71305_c[i]); + } + + return worlds; + } + + public File getGlobalDir() { + return CustomNpcs.Dir; + } + + public File getWorldDir() { + return CustomNpcs.getWorldSaveDirectory(); + } + + public void registerCommand(CommandNoppesBase command) { + CustomNpcs.NoppesCommand.registerCommand(command); + } + + public INbt getINbt(NBTTagCompound compound) { + return compound == null?new NBTWrapper(new NBTTagCompound()):new NBTWrapper(compound); + } + + public INbt stringToNbt(String str) { + if(str != null && !str.isEmpty()) { + try { + return this.getINbt(NBTJsonUtil.Convert(str)); + } catch (JsonException var3) { + throw new CustomNPCsException(var3, "Failed converting " + str, new Object[0]); + } + } else { + throw new CustomNPCsException("Cant cast empty string to nbt", new Object[0]); + } + } + + public IDamageSource getIDamageSource(DamageSource damagesource) { + return new DamageSourceWrapper(damagesource); + } + + public IDialogHandler getDialogs() { + return DialogController.instance; + } + + public ICloneHandler getClones() { + return ServerCloneController.Instance; + } + + public String executeCommand(IWorld world, String command) { + FakePlayer player = EntityNPCInterface.CommandPlayer; + player.func_70029_a(world.getMCWorld()); + player.func_70107_b(0.0D, 0.0D, 0.0D); + return NoppesUtilServer.runCommand(world.getMCWorld(), BlockPos.field_177992_a, "API", command, (EntityPlayer)null, player); + } + + public INbt getRawPlayerData(String uuid) { + return this.getINbt(PlayerData.loadPlayerData(uuid)); + } + + public IPlayerMail createMail(String sender, String subject) { + PlayerMail mail = new PlayerMail(); + mail.sender = sender; + mail.subject = subject; + return mail; + } + + public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) { + return new CustomGuiWrapper(id, width, height, pauseGame); + } + + public String getRandomName(int dictionary, int gender) { + return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender); + } +} diff --git a/src/main/java/noppes/npcs/util/LRUHashMap.java b/src/main/java/noppes/npcs/util/LRUHashMap.java new file mode 100644 index 000000000..a843369d8 --- /dev/null +++ b/src/main/java/noppes/npcs/util/LRUHashMap.java @@ -0,0 +1,22 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.util; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +public class LRUHashMap extends LinkedHashMap { + private final int maxSize; + + public LRUHashMap(int size) { + super(size, 0.75F, true); + this.maxSize = size; + } + + protected boolean removeEldestEntry(Entry eldest) { + return this.size() > this.maxSize; + } +} diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 85193e066..7c458469d 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -461,6 +461,29 @@ script.collide=Collide script.kills=Kills script.dialog_closed=Dialog Closed +eventscript.playerevent=Player Events + +playerscript.attack=Attack +playerscript.break=Break +playerscript.chat=Chat +playerscript.containerclosed=Closed Container +playerscript.containeropen=Open Container +playerscript.damagedentity=Damaged Entity +playerscript.damaged=Hurt +playerscript.killed=Killed +playerscript.factionupdate=Faction Updated +playerscript.init=Init +playerscript.interact=Interact +playerscript.keypressed=Key Pressed +playerscript.kills=Kills +playerscript.levelup=Level Up +playerscript.login=Login +playerscript.logout=Logout +playerscript.pickup=Pickup +playerscript.rangedlaunched=Range Launched +playerscript.toss=Toss +playerscript.update=Update + item.npcWand.name=Npc Wand item.npcMobCloner.name=Mob Cloner item.npcMovingPath.name=Npc Pather From 8b6e84a8d4ed9085a17e496c91fcc0a649378032 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 30 Sep 2021 01:48:54 -0500 Subject: [PATCH 17/58] Removed many unnecessary/redundant backported files. Focused only on classes that make events work. --- src/main/java/noppes/npcs/EventHooks.java | 6 +- .../noppes/npcs/EventScriptContainer.java | 1 + src/main/java/noppes/npcs/IScriptHandler.java | 34 --- src/main/java/noppes/npcs/NBTTags.java | 2 +- .../npcs/controllers/IScriptHandler.java | 4 +- .../npcs/controllers/ScriptController.java | 46 +++- .../controllers/data/PlayerScriptData.java | 50 ++-- .../npcs/scripted/CommandNoppesBase.java | 127 --------- .../npcs/scripted/CustomNPCsException.java | 16 -- .../java/noppes/npcs/scripted/IContainer.java | 26 -- .../noppes/npcs/scripted/IDamageSource.java | 23 -- .../java/noppes/npcs/scripted/IDimension.java | 14 - src/main/java/noppes/npcs/scripted/INbt.java | 78 ------ .../noppes/npcs/scripted/IScoreboard.java | 45 ---- .../npcs/scripted/IScoreboardObjective.java | 30 --- .../npcs/scripted/IScoreboardScore.java | 14 - .../noppes/npcs/scripted/IScoreboardTeam.java | 36 --- .../java/noppes/npcs/scripted/ITimers.java | 20 -- .../java/noppes/npcs/scripted/IWorld.java | 94 ------- .../java/noppes/npcs/scripted/NpcAPI.java | 119 --------- .../npcs/scripted/entity/ICustomNpc.java | 75 ------ .../noppes/npcs/scripted/entity/IEntity.java | 150 ----------- .../npcs/scripted/entity/IEntityItem.java | 32 --- .../npcs/scripted/entity/IEntityLiving.java | 21 -- .../scripted/entity/IEntityLivingBase.java | 70 ----- .../noppes/npcs/scripted/entity/IPlayer.java | 119 --------- .../npcs/scripted/entity/IProjectile.java | 33 --- .../npcs/scripted/entity/IThrowable.java | 12 - .../npcs/scripted/entity/data/IData.java | 20 -- .../scripted/entity/data/INPCAdvanced.java | 18 -- .../npcs/scripted/entity/data/INPCAi.java | 92 ------- .../scripted/entity/data/INPCDisplay.java | 76 ------ .../scripted/entity/data/INPCInventory.java | 40 --- .../npcs/scripted/entity/data/INPCJob.java | 10 - .../npcs/scripted/entity/data/INPCMelee.java | 32 --- .../npcs/scripted/entity/data/INPCRanged.java | 108 -------- .../npcs/scripted/entity/data/INPCRole.java | 10 - .../npcs/scripted/entity/data/INPCStats.java | 55 ---- .../scripted/entity/data/IPlayerMail.java | 29 -- .../npcs/scripted/event/PlayerEvent.java | 244 +++++++++++++++++ .../noppes/npcs/scripted/gui/IButton.java | 32 --- .../noppes/npcs/scripted/gui/ICustomGui.java | 69 ----- .../scripted/gui/ICustomGuiComponent.java | 26 -- .../noppes/npcs/scripted/gui/IItemSlot.java | 20 -- .../java/noppes/npcs/scripted/gui/ILabel.java | 28 -- .../noppes/npcs/scripted/gui/IScroll.java | 28 -- .../noppes/npcs/scripted/gui/ITextField.java | 20 -- .../npcs/scripted/gui/ITexturedRect.java | 30 --- .../npcs/scripted/handler/ICloneHandler.java | 19 -- .../scripted/handler/IFactionHandler.java | 19 -- .../npcs/scripted/handler/IQuestHandler.java | 16 -- .../npcs/scripted/handler/IRecipeHandler.java | 22 -- .../scripted/handler/data/IAvailability.java | 38 --- .../npcs/scripted/handler/data/IDialog.java | 42 --- .../handler/data/IDialogCategory.java | 17 -- .../scripted/handler/data/IDialogHandler.java | 16 -- .../scripted/handler/data/IDialogOption.java | 14 - .../npcs/scripted/handler/data/IFaction.java | 45 ---- .../npcs/scripted/handler/data/IQuest.java | 47 ---- .../scripted/handler/data/IQuestCategory.java | 17 -- .../scripted/handler/data/IQuestHandler.java | 14 - .../handler/data/IQuestObjective.java | 18 -- .../npcs/scripted/handler/data/IRecipe.java | 42 --- .../noppes/npcs/scripted/item/IItemStack.java | 92 ------- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 247 ------------------ .../java/noppes/npcs/util/LRUHashMap.java | 22 -- 66 files changed, 317 insertions(+), 2714 deletions(-) delete mode 100644 src/main/java/noppes/npcs/IScriptHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/CommandNoppesBase.java delete mode 100644 src/main/java/noppes/npcs/scripted/CustomNPCsException.java delete mode 100644 src/main/java/noppes/npcs/scripted/IContainer.java delete mode 100644 src/main/java/noppes/npcs/scripted/IDamageSource.java delete mode 100644 src/main/java/noppes/npcs/scripted/IDimension.java delete mode 100644 src/main/java/noppes/npcs/scripted/INbt.java delete mode 100644 src/main/java/noppes/npcs/scripted/IScoreboard.java delete mode 100644 src/main/java/noppes/npcs/scripted/IScoreboardObjective.java delete mode 100644 src/main/java/noppes/npcs/scripted/IScoreboardScore.java delete mode 100644 src/main/java/noppes/npcs/scripted/IScoreboardTeam.java delete mode 100644 src/main/java/noppes/npcs/scripted/ITimers.java delete mode 100644 src/main/java/noppes/npcs/scripted/IWorld.java delete mode 100644 src/main/java/noppes/npcs/scripted/NpcAPI.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntity.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntityItem.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IPlayer.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IProjectile.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/IThrowable.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/IData.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java delete mode 100644 src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java create mode 100644 src/main/java/noppes/npcs/scripted/event/PlayerEvent.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/IButton.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/ICustomGui.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/IItemSlot.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/ILabel.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/IScroll.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/ITextField.java delete mode 100644 src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialog.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IFaction.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuest.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java delete mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java delete mode 100644 src/main/java/noppes/npcs/scripted/item/IItemStack.java delete mode 100644 src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java delete mode 100644 src/main/java/noppes/npcs/util/LRUHashMap.java diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 0829601d2..145834048 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -11,11 +11,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.entity.IEntityItem; -import noppes.npcs.scripted.entity.IProjectile; +import noppes.npcs.controllers.data.PlayerScriptData; import noppes.npcs.scripted.event.PlayerEvent.AttackEvent; import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed; diff --git a/src/main/java/noppes/npcs/EventScriptContainer.java b/src/main/java/noppes/npcs/EventScriptContainer.java index d60e04ddd..b88844e57 100644 --- a/src/main/java/noppes/npcs/EventScriptContainer.java +++ b/src/main/java/noppes/npcs/EventScriptContainer.java @@ -26,6 +26,7 @@ import noppes.npcs.NBTTags; import noppes.npcs.NoppesUtilServer; import cpw.mods.fml.common.eventhandler.Event; import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.constants.*; diff --git a/src/main/java/noppes/npcs/IScriptHandler.java b/src/main/java/noppes/npcs/IScriptHandler.java deleted file mode 100644 index 4ebedd19a..000000000 --- a/src/main/java/noppes/npcs/IScriptHandler.java +++ /dev/null @@ -1,34 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs; - -import java.util.List; -import java.util.Map; -import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.constants.EnumScriptType; -import noppes.npcs.controllers.ScriptContainer; - -public interface IScriptHandler { - void runScript(EnumScriptType var1, Event var2); - - boolean isClient(); - - boolean getEnabled(); - - void setEnabled(boolean var1); - - String getLanguage(); - - void setLanguage(String var1); - - List getScripts(); - - String noticeString(); - - Map getConsoleText(); - - void clearConsole(); -} diff --git a/src/main/java/noppes/npcs/NBTTags.java b/src/main/java/noppes/npcs/NBTTags.java index f2f77b10f..60fa0df7d 100644 --- a/src/main/java/noppes/npcs/NBTTags.java +++ b/src/main/java/noppes/npcs/NBTTags.java @@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.controllers.IScriptHandler; public class NBTTags { diff --git a/src/main/java/noppes/npcs/controllers/IScriptHandler.java b/src/main/java/noppes/npcs/controllers/IScriptHandler.java index a0e783fbc..0932afb3d 100644 --- a/src/main/java/noppes/npcs/controllers/IScriptHandler.java +++ b/src/main/java/noppes/npcs/controllers/IScriptHandler.java @@ -8,8 +8,8 @@ package noppes.npcs.controllers; import java.util.List; import java.util.Map; import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.EventScriptContainer; import noppes.npcs.constants.EnumScriptType; -import noppes.npcs.controllers.ScriptContainer; public interface IScriptHandler { void runScript(EnumScriptType var1, Event var2); @@ -24,7 +24,7 @@ public interface IScriptHandler { void setLanguage(String var1); - List getScripts(); + List getScripts(); String noticeString(); diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 37f6df1e4..ae61d1043 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -19,6 +19,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -27,6 +28,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; +import noppes.npcs.controllers.data.PlayerScriptData; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.ScriptAnimal; import noppes.npcs.scripted.ScriptEntity; @@ -36,6 +38,7 @@ import noppes.npcs.scripted.ScriptMonster; import noppes.npcs.scripted.ScriptPixelmon; import noppes.npcs.scripted.ScriptPlayer; import noppes.npcs.scripted.ScriptWorld; +import noppes.npcs.util.JsonException; import noppes.npcs.util.NBTJsonUtil; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -49,10 +52,13 @@ public class ScriptController { public long lastLoaded = 0; public File dir; public NBTTagCompound compound = new NBTTagCompound(); - + private boolean loaded = false; public boolean shouldSave = false; - + + public PlayerScriptData playerScripts = new PlayerScriptData((EntityPlayer)null); + public long lastPlayerUpdate = 0L; + public ScriptController(){ loaded = false; Instance = this; @@ -68,6 +74,42 @@ public class ScriptController { } } + private File playerScriptsFile() { + return new File(this.dir, "player_scripts.json"); + } + + public boolean loadPlayerScripts() { + this.playerScripts.clear(); + File file = this.playerScriptsFile(); + + try { + if(!file.exists()) { + return false; + } else { + this.playerScripts.readFromNBT(NBTJsonUtil.LoadFile(file)); + return true; + } + } catch (Exception var3) { + LogWriter.error("Error loading: " + file.getAbsolutePath(), var3); + return false; + } + } + + public void setPlayerScripts(NBTTagCompound compound) { + this.playerScripts.readFromNBT(compound); + File file = this.playerScriptsFile(); + + try { + NBTJsonUtil.SaveFile(file, compound); + this.lastPlayerUpdate = System.currentTimeMillis(); + } catch (IOException var4) { + var4.printStackTrace(); + } catch (JsonException var5) { + var5.printStackTrace(); + } + + } + private void loadCategories(){ dir = new File(CustomNpcs.getWorldSaveDirectory(), "scripts"); if(!dir.exists()) diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java b/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java index 86506a6d9..3935bb78e 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java @@ -17,19 +17,18 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import cpw.mods.fml.common.eventhandler.Event; import noppes.npcs.EventHooks; +import noppes.npcs.EventScriptContainer; import noppes.npcs.NBTTags; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.entity.IPlayer; +import noppes.npcs.scripted.ScriptPlayer; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; -import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; public class PlayerScriptData implements IScriptHandler { - private List scripts = new ArrayList(); + private List scripts = new ArrayList(); private String scriptLanguage = "ECMAScript"; private EntityPlayer player; - private IPlayer playerAPI; + private ScriptPlayer playerAPI; private long lastPlayerUpdate = 0L; public long lastInited = -1L; public boolean hadInteract = true; @@ -48,23 +47,23 @@ public class PlayerScriptData implements IScriptHandler { } public void readFromNBT(NBTTagCompound compound) { - this.scripts = NBTTags.GetScript(compound.func_150295_c("Scripts", 10), this); - this.scriptLanguage = compound.func_74779_i("ScriptLanguage"); - this.enabled = compound.func_74767_n("ScriptEnabled"); - console = NBTTags.GetLongStringMap(compound.func_150295_c("ScriptConsole", 10)); + this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); + this.scriptLanguage = compound.getString("ScriptLanguage"); + this.enabled = compound.getBoolean("ScriptEnabled"); + console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } public NBTTagCompound writeToNBT(NBTTagCompound compound) { - compound.func_74782_a("Scripts", NBTTags.NBTScript(this.scripts)); - compound.func_74778_a("ScriptLanguage", this.scriptLanguage); - compound.func_74757_a("ScriptEnabled", this.enabled); - compound.func_74782_a("ScriptConsole", NBTTags.NBTLongStringMap(console)); + compound.setTag("Scripts", NBTTags.NBTScript(this.scripts)); + compound.setString("ScriptLanguage", this.scriptLanguage); + compound.setBoolean("ScriptEnabled", this.enabled); + compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(console)); return compound; } public void runScript(EnumScriptType type, Event event) { if(this.isEnabled()) { - ScriptContainer script; + EventScriptContainer script; if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) { this.lastInited = ScriptController.Instance.lastLoaded; errored.clear(); @@ -73,8 +72,8 @@ public class PlayerScriptData implements IScriptHandler { Iterator i = ScriptController.Instance.playerScripts.scripts.iterator(); while(i.hasNext()) { - script = (ScriptContainer)i.next(); - ScriptContainer s = new ScriptContainer(this); + script = ( EventScriptContainer)i.next(); + EventScriptContainer s = new EventScriptContainer(this); s.readFromNBT(script.writeToNBT(new NBTTagCompound())); this.scripts.add(s); } @@ -87,7 +86,7 @@ public class PlayerScriptData implements IScriptHandler { } for(int var7 = 0; var7 < this.scripts.size(); ++var7) { - script = (ScriptContainer)this.scripts.get(var7); + script = (EventScriptContainer)this.scripts.get(var7); if(!errored.contains(Integer.valueOf(var7))) { script.run(type, event); if(script.errored) { @@ -99,7 +98,7 @@ public class PlayerScriptData implements IScriptHandler { while(var8.hasNext()) { Entry entry = (Entry)var8.next(); if(!console.containsKey(entry.getKey())) { - console.put(entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue()); + console.put((Long)entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue()); } } @@ -111,11 +110,11 @@ public class PlayerScriptData implements IScriptHandler { } public boolean isEnabled() { - return ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.field_70170_p.field_72995_K); + return ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.worldObj.isRemote); } public boolean isClient() { - return !this.player.func_70613_aW(); + return this.player.isClientWorld(); } public boolean getEnabled() { @@ -134,7 +133,7 @@ public class PlayerScriptData implements IScriptHandler { this.scriptLanguage = lang; } - public List getScripts() { + public List getScripts() { return this.scripts; } @@ -142,16 +141,15 @@ public class PlayerScriptData implements IScriptHandler { if(this.player == null) { return "Global script"; } else { - BlockPos pos = this.player.func_180425_c(); - return MoreObjects.toStringHelper(this.player).add("x", pos.func_177958_n()).add("y", pos.func_177956_o()).add("z", pos.func_177952_p()).toString(); + BlockPos pos = new BlockPos(this.player); + return MoreObjects.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); } } - public IPlayer getPlayer() { + public ScriptPlayer getPlayer() { if(this.playerAPI == null) { - this.playerAPI = (IPlayer)NpcAPI.Instance().getIEntity(this.player); + this.playerAPI = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(this.player); } - return this.playerAPI; } diff --git a/src/main/java/noppes/npcs/scripted/CommandNoppesBase.java b/src/main/java/noppes/npcs/scripted/CommandNoppesBase.java deleted file mode 100644 index 3bdd56cac..000000000 --- a/src/main/java/noppes/npcs/scripted/CommandNoppesBase.java +++ /dev/null @@ -1,127 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.server.MinecraftServer; -//import net.minecraft.util.text.TextComponentTranslation; - -public abstract class CommandNoppesBase extends CommandBase { - public Map subcommands = new HashMap(); - - public CommandNoppesBase() { - Method[] var1 = this.getClass().getDeclaredMethods(); - int var2 = var1.length; - - for(int var3 = 0; var3 < var2; ++var3) { - Method m = var1[var3]; - CommandNoppesBase.SubCommand sc = (CommandNoppesBase.SubCommand)m.getAnnotation(CommandNoppesBase.SubCommand.class); - if(sc != null) { - String name = sc.name(); - if(name.equals("")) { - name = m.getName(); - } - - this.subcommands.put(name.toLowerCase(), m); - } - } - - } - - public void func_184881_a(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - } - - public String func_71518_a(ICommandSender sender) { - return this.getDescription(); - } - - public abstract String getDescription(); - - public String getUsage() { - return ""; - } - - public boolean runSubCommands() { - return !this.subcommands.isEmpty(); - } - - /* - protected void sendMessage(ICommandSender sender, String message, Object... obs) { - sender.func_145747_a(new TextComponentTranslation(message, obs)); - } - */ - - public void executeSub(MinecraftServer server, ICommandSender sender, String command, String[] args) throws CommandException { - Method m = (Method)this.subcommands.get(command.toLowerCase()); - if(m == null) { - throw new CommandException("Unknown subcommand " + command, new Object[0]); - } else { - CommandNoppesBase.SubCommand sc = (CommandNoppesBase.SubCommand)m.getAnnotation(CommandNoppesBase.SubCommand.class); - if(!sender.canCommandSenderUseCommand(sc.permission(), "commands.noppes." + this.getCommandName().toLowerCase() + "." + command.toLowerCase())) { - throw new CommandException("You are not allowed to use this command", new Object[0]); - } else { - this.canRun(server, sender, sc.usage(), args); - - try { - m.invoke(this, new Object[]{server, sender, args}); - } catch (Exception var8) { - if(var8.getCause() instanceof CommandException) { - throw (CommandException)var8.getCause(); - } - - var8.printStackTrace(); - } - - } - } - } - - public void canRun(MinecraftServer server, ICommandSender sender, String usage, String[] args) throws CommandException { - String[] np = usage.split(" "); - ArrayList required = new ArrayList(); - - for(int i = 0; i < np.length; ++i) { - String command = np[i]; - if(command.startsWith("<")) { - required.add(command); - } - - if(command.equals("") && args.length > i) { - CommandBase.getPlayer(sender, args[i]); - } - } - - if(args.length < required.size()) { - throw new CommandException("Missing parameter: " + (String)required.get(args.length), new Object[0]); - } - } - - public int func_82362_a() { - return 2; - } - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) - public @interface SubCommand { - String name() default ""; - - String usage() default ""; - - String desc(); - - int permission() default 4; - } -} diff --git a/src/main/java/noppes/npcs/scripted/CustomNPCsException.java b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java deleted file mode 100644 index f562b2dcf..000000000 --- a/src/main/java/noppes/npcs/scripted/CustomNPCsException.java +++ /dev/null @@ -1,16 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -public class CustomNPCsException extends RuntimeException { - public CustomNPCsException(String message, Object... obs) { - super(String.format(message, obs)); - } - - public CustomNPCsException(Exception ex, String message, Object... obs) { - super(String.format(message, obs), ex); - } -} diff --git a/src/main/java/noppes/npcs/scripted/IContainer.java b/src/main/java/noppes/npcs/scripted/IContainer.java deleted file mode 100644 index 83fd8a824..000000000 --- a/src/main/java/noppes/npcs/scripted/IContainer.java +++ /dev/null @@ -1,26 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import noppes.npcs.scripted.item.IItemStack; - -public interface IContainer { - int getSize(); - - IItemStack getSlot(int var1); - - void setSlot(int var1, IItemStack var2); - - IInventory getMCInventory(); - - Container getMCContainer(); - - int count(IItemStack var1, boolean var2, boolean var3); - - IItemStack[] getItems(); -} diff --git a/src/main/java/noppes/npcs/scripted/IDamageSource.java b/src/main/java/noppes/npcs/scripted/IDamageSource.java deleted file mode 100644 index 50563269c..000000000 --- a/src/main/java/noppes/npcs/scripted/IDamageSource.java +++ /dev/null @@ -1,23 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.entity.IEntity; - -public interface IDamageSource { - String getType(); - - boolean isUnblockable(); - - boolean isProjectile(); - - IEntity getTrueSource(); - - IEntity getImmediateSource(); - - DamageSource getMCDamageSource(); -} diff --git a/src/main/java/noppes/npcs/scripted/IDimension.java b/src/main/java/noppes/npcs/scripted/IDimension.java deleted file mode 100644 index 3f5b26f9b..000000000 --- a/src/main/java/noppes/npcs/scripted/IDimension.java +++ /dev/null @@ -1,14 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -public interface IDimension { - int getId(); - - String getName(); - - String getSuffix(); -} diff --git a/src/main/java/noppes/npcs/scripted/INbt.java b/src/main/java/noppes/npcs/scripted/INbt.java deleted file mode 100644 index df1517d6f..000000000 --- a/src/main/java/noppes/npcs/scripted/INbt.java +++ /dev/null @@ -1,78 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import net.minecraft.nbt.NBTTagCompound; - -public interface INbt { - void remove(String var1); - - boolean has(String var1); - - boolean getBoolean(String var1); - - void setBoolean(String var1, boolean var2); - - short getShort(String var1); - - void setShort(String var1, short var2); - - int getInteger(String var1); - - void setInteger(String var1, int var2); - - byte getByte(String var1); - - void setByte(String var1, byte var2); - - long getLong(String var1); - - void setLong(String var1, long var2); - - double getDouble(String var1); - - void setDouble(String var1, double var2); - - float getFloat(String var1); - - void setFloat(String var1, float var2); - - String getString(String var1); - - void setString(String var1, String var2); - - byte[] getByteArray(String var1); - - void setByteArray(String var1, byte[] var2); - - int[] getIntegerArray(String var1); - - void setIntegerArray(String var1, int[] var2); - - Object[] getList(String var1, int var2); - - int getListType(String var1); - - void setList(String var1, Object[] var2); - - INbt getCompound(String var1); - - void setCompound(String var1, INbt var2); - - String[] getKeys(); - - int getType(String var1); - - NBTTagCompound getMCNBT(); - - String toJsonString(); - - boolean isEqual(INbt var1); - - void clear(); - - void merge(INbt var1); -} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboard.java b/src/main/java/noppes/npcs/scripted/IScoreboard.java deleted file mode 100644 index 0a1b09275..000000000 --- a/src/main/java/noppes/npcs/scripted/IScoreboard.java +++ /dev/null @@ -1,45 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import noppes.npcs.scripted.IScoreboardObjective; -import noppes.npcs.scripted.IScoreboardTeam; - -public interface IScoreboard { - IScoreboardObjective[] getObjectives(); - - IScoreboardObjective getObjective(String var1); - - boolean hasObjective(String var1); - - void removeObjective(String var1); - - IScoreboardObjective addObjective(String var1, String var2); - - void setPlayerScore(String var1, String var2, int var3, String var4); - - int getPlayerScore(String var1, String var2, String var3); - - boolean hasPlayerObjective(String var1, String var2, String var3); - - void deletePlayerScore(String var1, String var2, String var3); - - IScoreboardTeam[] getTeams(); - - boolean hasTeam(String var1); - - IScoreboardTeam addTeam(String var1); - - IScoreboardTeam getTeam(String var1); - - void removeTeam(String var1); - - IScoreboardTeam getPlayerTeam(String var1); - - void removePlayerTeam(String var1); - - String[] getPlayerList(); -} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboardObjective.java b/src/main/java/noppes/npcs/scripted/IScoreboardObjective.java deleted file mode 100644 index 6679a3597..000000000 --- a/src/main/java/noppes/npcs/scripted/IScoreboardObjective.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import noppes.npcs.scripted.IScoreboardScore; - -public interface IScoreboardObjective { - String getName(); - - String getDisplayName(); - - void setDisplayName(String var1); - - String getCriteria(); - - boolean isReadyOnly(); - - IScoreboardScore[] getScores(); - - IScoreboardScore getScore(String var1); - - boolean hasScore(String var1); - - IScoreboardScore createScore(String var1); - - void removeScore(String var1); -} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboardScore.java b/src/main/java/noppes/npcs/scripted/IScoreboardScore.java deleted file mode 100644 index 2b706d89a..000000000 --- a/src/main/java/noppes/npcs/scripted/IScoreboardScore.java +++ /dev/null @@ -1,14 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -public interface IScoreboardScore { - int getValue(); - - void setValue(int var1); - - String getPlayerName(); -} diff --git a/src/main/java/noppes/npcs/scripted/IScoreboardTeam.java b/src/main/java/noppes/npcs/scripted/IScoreboardTeam.java deleted file mode 100644 index c4f4acb74..000000000 --- a/src/main/java/noppes/npcs/scripted/IScoreboardTeam.java +++ /dev/null @@ -1,36 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -public interface IScoreboardTeam { - String getName(); - - String getDisplayName(); - - void setDisplayName(String var1); - - void addPlayer(String var1); - - boolean hasPlayer(String var1); - - void removePlayer(String var1); - - String[] getPlayers(); - - void clearPlayers(); - - boolean getFriendlyFire(); - - void setFriendlyFire(boolean var1); - - void setColor(String var1); - - String getColor(); - - void setSeeInvisibleTeamPlayers(boolean var1); - - boolean getSeeInvisibleTeamPlayers(); -} diff --git a/src/main/java/noppes/npcs/scripted/ITimers.java b/src/main/java/noppes/npcs/scripted/ITimers.java deleted file mode 100644 index 24d1de2fe..000000000 --- a/src/main/java/noppes/npcs/scripted/ITimers.java +++ /dev/null @@ -1,20 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -public interface ITimers { - void start(int var1, int var2, boolean var3); - - void forceStart(int var1, int var2, boolean var3); - - boolean has(int var1); - - boolean stop(int var1); - - void reset(int var1); - - void clear(); -} diff --git a/src/main/java/noppes/npcs/scripted/IWorld.java b/src/main/java/noppes/npcs/scripted/IWorld.java deleted file mode 100644 index 2c941600c..000000000 --- a/src/main/java/noppes/npcs/scripted/IWorld.java +++ /dev/null @@ -1,94 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldServer; -import noppes.npcs.scripted.IDimension; -import noppes.npcs.scripted.INbt; -import noppes.npcs.scripted.IScoreboard; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.entity.IPlayer; -import noppes.npcs.scripted.entity.data.IData; -import noppes.npcs.scripted.item.IItemStack; - -public interface IWorld { - /** @deprecated */ - IEntity[] getNearbyEntities(int var1, int var2, int var3, int var4, int var5); - - /** @deprecated */ - IEntity getClosestEntity(int var1, int var2, int var3, int var4, int var5); - - IEntity[] getAllEntities(int var1); - - long getTime(); - - void setTime(long var1); - - long getTotalTime(); - - void setBlock(int var1, int var2, int var3, String var4, int var5); - - void removeBlock(int var1, int var2, int var3); - - float getLightValue(int var1, int var2, int var3); - - IPlayer getPlayer(String var1); - - boolean isDay(); - - boolean isRaining(); - - IDimension getDimension(); - - void setRaining(boolean var1); - - void thunderStrike(double var1, double var3, double var5); - - void spawnParticle(String var1, double var2, double var4, double var6, double var8, double var10, double var12, double var14, int var16); - - void broadcast(String var1); - - IScoreboard getScoreboard(); - - IData getTempdata(); - - IData getStoreddata(); - - IItemStack createItem(String var1, int var2, int var3); - - IItemStack createItemFromNbt(INbt var1); - - void explode(double var1, double var3, double var5, float var7, boolean var8, boolean var9); - - IPlayer[] getAllPlayers(); - - String getBiomeName(int var1, int var2); - - void spawnEntity(IEntity var1); - - /** @deprecated */ - @Deprecated - IEntity spawnClone(double var1, double var3, double var5, int var7, String var8); - - /** @deprecated */ - @Deprecated - IEntity getClone(int var1, String var2); - - int getRedstonePower(int var1, int var2, int var3); - - WorldServer getMCWorld(); - - BlockPos getMCBlockPos(int var1, int var2, int var3); - - IEntity getEntity(String var1); - - IEntity createEntityFromNBT(INbt var1); - - IEntity createEntity(String var1); - - String getName(); -} diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java deleted file mode 100644 index e385c6de3..000000000 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ /dev/null @@ -1,119 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted; - -import java.io.File; - -import net.minecraft.entity.Entity; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.DamageSource; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.eventhandler.EventBus; -import noppes.npcs.scripted.CommandNoppesBase; -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.IDamageSource; -import noppes.npcs.scripted.INbt; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.entity.ICustomNpc; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.entity.data.IPlayerMail; -import noppes.npcs.scripted.gui.ICustomGui; -import noppes.npcs.scripted.handler.ICloneHandler; -import noppes.npcs.scripted.handler.IDialogHandler; -import noppes.npcs.scripted.handler.IFactionHandler; -import noppes.npcs.scripted.handler.IQuestHandler; -import noppes.npcs.scripted.handler.IRecipeHandler; -import noppes.npcs.scripted.item.IItemStack; - -public abstract class NpcAPI { - private static NpcAPI instance = null; - - public NpcAPI() { - } - - public abstract ICustomNpc createNPC(World var1); - - public abstract ICustomNpc spawnNPC(World var1, int var2, int var3, int var4); - - public abstract IEntity getIEntity(Entity var1); - - public abstract IContainer getIContainer(IInventory var1); - - public abstract IContainer getIContainer(Container var1); - - public abstract IItemStack getIItemStack(ItemStack var1); - - public abstract IWorld getIWorld(WorldServer var1); - - public abstract IWorld getIWorld(int var1); - - public abstract IWorld[] getIWorlds(); - - public abstract INbt getINbt(NBTTagCompound var1); - - public abstract IFactionHandler getFactions(); - - public abstract IRecipeHandler getRecipes(); - - public abstract IQuestHandler getQuests(); - - public abstract IDialogHandler getDialogs(); - - public abstract ICloneHandler getClones(); - - public abstract IDamageSource getIDamageSource(DamageSource var1); - - public abstract INbt stringToNbt(String var1); - - public abstract IPlayerMail createMail(String var1, String var2); - - public abstract ICustomGui createCustomGui(int var1, int var2, int var3, boolean var4); - - public abstract INbt getRawPlayerData(String var1); - - public abstract EventBus events(); - - public abstract void registerCommand(CommandNoppesBase var1); - - public abstract File getGlobalDir(); - - public abstract File getWorldDir(); - - public static boolean IsAvailable() { - return Loader.isModLoaded("customnpcs"); - } - - public static NpcAPI Instance() { - if(instance != null) { - return instance; - } else if(!IsAvailable()) { - return null; - } else { - try { - Class e = Class.forName("noppes.npcs.api.wrapper.WrapperNpcAPI"); - instance = (NpcAPI)e.getMethod("Instance", new Class[0]).invoke((Object)null, new Object[0]); - } catch (Exception var1) { - var1.printStackTrace(); - } - - return instance; - } - } - - public abstract void registerPermissionNode(String var1, int var2); - - public abstract boolean hasPermissionNode(String var1); - - public abstract String executeCommand(IWorld var1, String var2); - - public abstract String getRandomName(int var1, int var2); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java deleted file mode 100644 index 73cf3812f..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/ICustomNpc.java +++ /dev/null @@ -1,75 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.EntityCreature; -import noppes.npcs.scripted.ITimers; -import noppes.npcs.scripted.entity.IEntityLiving; -import noppes.npcs.scripted.entity.IEntityLivingBase; -import noppes.npcs.scripted.entity.IPlayer; -import noppes.npcs.scripted.entity.IProjectile; -import noppes.npcs.scripted.entity.data.INPCAdvanced; -import noppes.npcs.scripted.entity.data.INPCAi; -import noppes.npcs.scripted.entity.data.INPCDisplay; -import noppes.npcs.scripted.entity.data.INPCInventory; -import noppes.npcs.scripted.entity.data.INPCJob; -import noppes.npcs.scripted.entity.data.INPCRole; -import noppes.npcs.scripted.entity.data.INPCStats; -import noppes.npcs.scripted.handler.data.IDialog; -import noppes.npcs.scripted.handler.data.IFaction; -import noppes.npcs.scripted.item.IItemStack; - -public interface ICustomNpc extends IEntityLiving { - INPCDisplay getDisplay(); - - INPCInventory getInventory(); - - INPCStats getStats(); - - INPCAi getAi(); - - INPCAdvanced getAdvanced(); - - IFaction getFaction(); - - void setFaction(int var1); - - INPCRole getRole(); - - INPCJob getJob(); - - ITimers getTimers(); - - int getHomeX(); - - int getHomeY(); - - int getHomeZ(); - - IEntityLivingBase getOwner(); - - void setHome(int var1, int var2, int var3); - - void reset(); - - void say(String var1); - - void sayTo(IPlayer var1, String var2); - - IProjectile shootItem(IEntityLivingBase var1, IItemStack var2, int var3); - - IProjectile shootItem(double var1, double var3, double var5, IItemStack var7, int var8); - - void giveItem(IPlayer var1, IItemStack var2); - - void setDialog(int var1, IDialog var2); - - IDialog getDialog(int var1); - - void updateClient(); - - String executeCommand(String var1); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntity.java b/src/main/java/noppes/npcs/scripted/entity/IEntity.java deleted file mode 100644 index 589c80fde..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IEntity.java +++ /dev/null @@ -1,150 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.Entity; -import noppes.npcs.scripted.INbt; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.entity.data.IData; -import noppes.npcs.scripted.item.IItemStack; - -public interface IEntity { - double getX(); - - void setX(double var1); - - double getY(); - - void setY(double var1); - - double getZ(); - - void setZ(double var1); - - int getBlockX(); - - int getBlockY(); - - int getBlockZ(); - - void setPosition(double var1, double var3, double var5); - - void setRotation(float var1); - - float getRotation(); - - float getHeight(); - - float getEyeHeight(); - - float getWidth(); - - void setPitch(float var1); - - float getPitch(); - - IEntity getMount(); - - void setMount(IEntity var1); - - IEntity[] getRiders(); - - IEntity[] getAllRiders(); - - void addRider(IEntity var1); - - void clearRiders(); - - void knockback(int var1, float var2); - - boolean isSneaking(); - - boolean isSprinting(); - - IEntityItem dropItem(IItemStack var1); - - boolean inWater(); - - boolean inFire(); - - boolean inLava(); - - IData getTempdata(); - - IData getStoreddata(); - - INbt getNbt(); - - boolean isAlive(); - - long getAge(); - - void despawn(); - - void spawn(); - - void kill(); - - boolean isBurning(); - - void setBurning(int var1); - - void extinguish(); - - IWorld getWorld(); - - String getTypeName(); - - int getType(); - - boolean typeOf(int var1); - - T getMCEntity(); - - String getUUID(); - - String generateNewUUID(); - - void storeAsClone(int var1, String var2); - - INbt getEntityNbt(); - - void setEntityNbt(INbt var1); - - IEntity[] rayTraceEntities(double var1, boolean var3, boolean var4); - - String[] getTags(); - - void addTag(String var1); - - boolean hasTag(String var1); - - void removeTag(String var1); - - void playAnimation(int var1); - - void damage(float var1); - - double getMotionX(); - - double getMotionY(); - - double getMotionZ(); - - void setMotionX(double var1); - - void setMotionY(double var1); - - void setMotionZ(double var1); - - String getName(); - - void setName(String var1); - - boolean hasCustomName(); - - String getEntityName(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntityItem.java b/src/main/java/noppes/npcs/scripted/entity/IEntityItem.java deleted file mode 100644 index df5f9a933..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IEntityItem.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.item.EntityItem; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.item.IItemStack; - -public interface IEntityItem extends IEntity { - String getOwner(); - - void setOwner(String var1); - - int getPickupDelay(); - - void setPickupDelay(int var1); - - long getAge(); - - void setAge(long var1); - - int getLifeSpawn(); - - void setLifeSpawn(int var1); - - IItemStack getItem(); - - void setItem(IItemStack var1); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java b/src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java deleted file mode 100644 index 506d6faa1..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IEntityLiving.java +++ /dev/null @@ -1,21 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.EntityLiving; -import noppes.npcs.scripted.entity.IEntityLivingBase; - -public interface IEntityLiving extends IEntityLivingBase { - boolean isNavigating(); - - void clearNavigation(); - - void navigateTo(double var1, double var3, double var5, double var7); - - void jump(); - - T getMCEntity(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java deleted file mode 100644 index 56f384664..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IEntityLivingBase.java +++ /dev/null @@ -1,70 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.item.IItemStack; - -public interface IEntityLivingBase extends IEntity { - float getHealth(); - - void setHealth(float var1); - - float getMaxHealth(); - - void setMaxHealth(float var1); - - boolean isAttacking(); - - void setAttackTarget(IEntityLivingBase var1); - - IEntityLivingBase getAttackTarget(); - - IEntityLivingBase getLastAttacked(); - - int getLastAttackedTime(); - - boolean canSeeEntity(IEntity var1); - - void swingMainhand(); - - void swingOffhand(); - - IItemStack getMainhandItem(); - - void setMainhandItem(IItemStack var1); - - IItemStack getOffhandItem(); - - void setOffhandItem(IItemStack var1); - - IItemStack getArmor(int var1); - - void setArmor(int var1, IItemStack var2); - - void addPotionEffect(int var1, int var2, int var3, boolean var4); - - void clearPotionEffects(); - - int getPotionEffect(int var1); - - boolean isChild(); - - T getMCEntity(); - - float getMoveForward(); - - void setMoveForward(float var1); - - float getMoveStrafing(); - - void setMoveStrafing(float var1); - - float getMoveVertical(); - - void setMoveVertical(float var1); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IPlayer.java b/src/main/java/noppes/npcs/scripted/entity/IPlayer.java deleted file mode 100644 index ed8bdf016..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IPlayer.java +++ /dev/null @@ -1,119 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.player.EntityPlayerMP; -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.ITimers; -import noppes.npcs.scripted.entity.data.IPlayerMail; -import noppes.npcs.scripted.gui.ICustomGui; -import noppes.npcs.scripted.handler.data.IQuest; -import noppes.npcs.scripted.item.IItemStack; - -public interface IPlayer extends IEntityLivingBase { - String getDisplayName(); - - boolean hasFinishedQuest(int var1); - - boolean hasActiveQuest(int var1); - - void startQuest(int var1); - - int factionStatus(int var1); - - void finishQuest(int var1); - - void stopQuest(int var1); - - void removeQuest(int var1); - - boolean hasReadDialog(int var1); - - void showDialog(int var1, String var2); - - void removeDialog(int var1); - - void addDialog(int var1); - - void addFactionPoints(int var1, int var2); - - int getFactionPoints(int var1); - - void message(String var1); - - int getGamemode(); - - void setGamemode(int var1); - - /** @deprecated */ - int inventoryItemCount(IItemStack var1); - - /** @deprecated */ - int inventoryItemCount(String var1, int var2); - - IContainer getInventory(); - - boolean removeItem(IItemStack var1, int var2); - - boolean removeItem(String var1, int var2, int var3); - - void removeAllItems(IItemStack var1); - - boolean giveItem(IItemStack var1); - - boolean giveItem(String var1, int var2, int var3); - - void setSpawnpoint(int var1, int var2, int var3); - - void resetSpawnpoint(); - - boolean hasAchievement(String var1); - - int getExpLevel(); - - void setExpLevel(int var1); - - boolean hasPermission(String var1); - - Object getPixelmonData(); - - ITimers getTimers(); - - void closeGui(); - - T getMCEntity(); - - int getHunger(); - - void setHunger(int var1); - - void kick(String var1); - - void sendNotification(String var1, String var2, int var3); - - void sendMail(IPlayerMail var1); - - void clearData(); - - IQuest[] getActiveQuests(); - - IQuest[] getFinishedQuests(); - - void updatePlayerInventory(); - - void playSound(String var1, float var2, float var3); - - /** @deprecated */ - IContainer showChestGui(int var1); - - IContainer getOpenContainer(); - - boolean canQuestBeAccepted(int var1); - - void showCustomGui(ICustomGui var1); - - ICustomGui getCustomGui(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IProjectile.java b/src/main/java/noppes/npcs/scripted/entity/IProjectile.java deleted file mode 100644 index fdcd8e8f4..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IProjectile.java +++ /dev/null @@ -1,33 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.projectile.EntityThrowable; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.entity.IThrowable; -import noppes.npcs.scripted.item.IItemStack; - -public interface IProjectile extends IThrowable { - IItemStack getItem(); - - void setItem(IItemStack var1); - - boolean getHasGravity(); - - void setHasGravity(boolean var1); - - int getAccuracy(); - - void setAccuracy(int var1); - - void setHeading(IEntity var1); - - void setHeading(double var1, double var3, double var5); - - void setHeading(float var1, float var2); - - void enableEvents(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/IThrowable.java b/src/main/java/noppes/npcs/scripted/entity/IThrowable.java deleted file mode 100644 index 4e77c5468..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/IThrowable.java +++ /dev/null @@ -1,12 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity; - -import net.minecraft.entity.projectile.EntityThrowable; -import noppes.npcs.scripted.entity.IEntity; - -public interface IThrowable extends IEntity { -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/IData.java b/src/main/java/noppes/npcs/scripted/entity/data/IData.java deleted file mode 100644 index 5df4d2e4b..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/IData.java +++ /dev/null @@ -1,20 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface IData { - void put(String var1, Object var2); - - Object get(String var1); - - void remove(String var1); - - boolean has(String var1); - - String[] getKeys(); - - void clear(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java deleted file mode 100644 index d727e8565..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCAdvanced.java +++ /dev/null @@ -1,18 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCAdvanced { - void setLine(int var1, int var2, String var3, String var4); - - String getLine(int var1, int var2); - - int getLineCount(int var1); - - String getSound(int var1); - - void setSound(int var1, String var2); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java deleted file mode 100644 index 6b4a20db6..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCAi.java +++ /dev/null @@ -1,92 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCAi { - int getAnimation(); - - void setAnimation(int var1); - - int getCurrentAnimation(); - - void setReturnsHome(boolean var1); - - boolean getReturnsHome(); - - int getRetaliateType(); - - void setRetaliateType(int var1); - - int getMovingType(); - - void setMovingType(int var1); - - int getNavigationType(); - - void setNavigationType(int var1); - - int getStandingType(); - - void setStandingType(int var1); - - boolean getAttackInvisible(); - - void setAttackInvisible(boolean var1); - - int getWanderingRange(); - - void setWanderingRange(int var1); - - boolean getInteractWithNPCs(); - - void setInteractWithNPCs(boolean var1); - - boolean getStopOnInteract(); - - void setStopOnInteract(boolean var1); - - int getWalkingSpeed(); - - void setWalkingSpeed(int var1); - - int getMovingPathType(); - - boolean getMovingPathPauses(); - - void setMovingPathType(int var1, boolean var2); - - int getDoorInteract(); - - void setDoorInteract(int var1); - - boolean getCanSwim(); - - void setCanSwim(boolean var1); - - int getSheltersFrom(); - - void setSheltersFrom(int var1); - - boolean getAttackLOS(); - - void setAttackLOS(boolean var1); - - boolean getAvoidsWater(); - - void setAvoidsWater(boolean var1); - - boolean getLeapAtTarget(); - - void setLeapAtTarget(boolean var1); - - int getTacticalType(); - - void setTacticalType(int var1); - - int getTacticalRange(); - - void setTacticalRange(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java deleted file mode 100644 index 00881970b..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCDisplay.java +++ /dev/null @@ -1,76 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCDisplay { - String getName(); - - void setName(String var1); - - String getTitle(); - - void setTitle(String var1); - - String getSkinUrl(); - - void setSkinUrl(String var1); - - String getSkinPlayer(); - - void setSkinPlayer(String var1); - - String getSkinTexture(); - - void setSkinTexture(String var1); - - boolean getHasLivingAnimation(); - - void setHasLivingAnimation(boolean var1); - - int getVisible(); - - void setVisible(int var1); - - int getBossbar(); - - void setBossbar(int var1); - - int getSize(); - - void setSize(int var1); - - int getTint(); - - void setTint(int var1); - - int getShowName(); - - void setShowName(int var1); - - void setCapeTexture(String var1); - - String getCapeTexture(); - - void setOverlayTexture(String var1); - - String getOverlayTexture(); - - void setModelScale(int var1, float var2, float var3, float var4); - - float[] getModelScale(int var1); - - int getBossColor(); - - void setBossColor(int var1); - - void setModel(String var1); - - String getModel(); - - void setHasHitbox(boolean var1); - - boolean getHasHitbox(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java deleted file mode 100644 index 570f8222f..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCInventory.java +++ /dev/null @@ -1,40 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -import noppes.npcs.scripted.item.IItemStack; - -public interface INPCInventory { - IItemStack getRightHand(); - - void setRightHand(IItemStack var1); - - IItemStack getLeftHand(); - - void setLeftHand(IItemStack var1); - - IItemStack getProjectile(); - - void setProjectile(IItemStack var1); - - IItemStack getArmor(int var1); - - void setArmor(int var1, IItemStack var2); - - void setDropItem(int var1, IItemStack var2, int var3); - - IItemStack getDropItem(int var1); - - int getExpMin(); - - int getExpMax(); - - int getExpRNG(); - - void setExp(int var1, int var2); - - IItemStack[] getItemsRNG(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java deleted file mode 100644 index b5c75a336..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCJob.java +++ /dev/null @@ -1,10 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCJob { - int getType(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java deleted file mode 100644 index 13deb1538..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCMelee.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCMelee { - int getStrength(); - - void setStrength(int var1); - - int getDelay(); - - void setDelay(int var1); - - int getRange(); - - void setRange(int var1); - - int getKnockback(); - - void setKnockback(int var1); - - int getEffectType(); - - int getEffectTime(); - - int getEffectStrength(); - - void setEffect(int var1, int var2, int var3); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java deleted file mode 100644 index f63ea6891..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCRanged.java +++ /dev/null @@ -1,108 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCRanged { - int getStrength(); - - void setStrength(int var1); - - int getSpeed(); - - void setSpeed(int var1); - - int getBurst(); - - void setBurst(int var1); - - int getBurstDelay(); - - void setBurstDelay(int var1); - - int getKnockback(); - - void setKnockback(int var1); - - int getSize(); - - void setSize(int var1); - - boolean getRender3D(); - - void setRender3D(boolean var1); - - boolean getSpins(); - - void setSpins(boolean var1); - - boolean getSticks(); - - void setSticks(boolean var1); - - boolean getHasGravity(); - - void setHasGravity(boolean var1); - - boolean getAccelerate(); - - void setAccelerate(boolean var1); - - int getExplodeSize(); - - void setExplodeSize(int var1); - - int getEffectType(); - - int getEffectTime(); - - int getEffectStrength(); - - void setEffect(int var1, int var2, int var3); - - boolean getGlows(); - - void setGlows(boolean var1); - - int getParticle(); - - void setParticle(int var1); - - String getSound(int var1); - - void setSound(int var1, String var2); - - int getShotCount(); - - void setShotCount(int var1); - - boolean getHasAimAnimation(); - - void setHasAimAnimation(boolean var1); - - int getAccuracy(); - - void setAccuracy(int var1); - - int getRange(); - - void setRange(int var1); - - int getDelayMin(); - - int getDelayMax(); - - int getDelayRNG(); - - void setDelay(int var1, int var2); - - int getFireType(); - - void setFireType(int var1); - - int getMeleeRange(); - - void setMeleeRange(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java deleted file mode 100644 index 4de2a540d..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCRole.java +++ /dev/null @@ -1,10 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -public interface INPCRole { - int getType(); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java b/src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java deleted file mode 100644 index c247e7ec3..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/INPCStats.java +++ /dev/null @@ -1,55 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -import noppes.npcs.scripted.entity.data.INPCMelee; -import noppes.npcs.scripted.entity.data.INPCRanged; - -public interface INPCStats { - int getMaxHealth(); - - void setMaxHealth(int var1); - - float getResistance(int var1); - - void setResistance(int var1, float var2); - - int getCombatRegen(); - - void setCombatRegen(int var1); - - int getHealthRegen(); - - void setHealthRegen(int var1); - - INPCMelee getMelee(); - - INPCRanged getRanged(); - - boolean getImmune(int var1); - - void setImmune(int var1, boolean var2); - - void setCreatureType(int var1); - - int getCreatureType(); - - int getRespawnType(); - - void setRespawnType(int var1); - - int getRespawnTime(); - - void setRespawnTime(int var1); - - boolean getHideDeadBody(); - - void setHideDeadBody(boolean var1); - - int getAggroRange(); - - void setAggroRange(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java b/src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java deleted file mode 100644 index a53133ae9..000000000 --- a/src/main/java/noppes/npcs/scripted/entity/data/IPlayerMail.java +++ /dev/null @@ -1,29 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.entity.data; - -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.handler.data.IQuest; - -public interface IPlayerMail { - String getSender(); - - void setSender(String var1); - - String getSubject(); - - void setSubject(String var1); - - String[] getText(); - - void setText(String[] var1); - - IQuest getQuest(); - - void setQuest(int var1); - - IContainer getContainer(); -} diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java new file mode 100644 index 000000000..9b6d3d337 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -0,0 +1,244 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.event; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.DamageSource; +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.IDamageSource; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.block.IBlock; +import noppes.npcs.scripted.entity.IEntity; +import noppes.npcs.scripted.entity.IEntityLivingBase; +import noppes.npcs.scripted.entity.IPlayer; +import noppes.npcs.scripted.event.CustomNPCsEvent; +import noppes.npcs.scripted.handler.data.IFaction; +import noppes.npcs.scripted.item.IItemStack; + +public class PlayerEvent extends CustomNPCsEvent { + public final IPlayer player; + + public PlayerEvent(IPlayer player) { + this.player = player; + } + + public static class FactionUpdateEvent extends PlayerEvent { + public final IFaction faction; + public int points; + public boolean init; + + public FactionUpdateEvent(IPlayer player, IFaction faction, int points, boolean init) { + super(player); + this.faction = faction; + this.points = points; + this.init = init; + } + } + + @Cancelable + public static class ChatEvent extends PlayerEvent { + public String message; + + public ChatEvent(IPlayer player, String message) { + super(player); + this.message = message; + } + } + + public static class KeyPressedEvent extends PlayerEvent { + public final int key; + public final boolean isCtrlPressed; + public final boolean isAltPressed; + public final boolean isShiftPressed; + public final boolean isMetaPressed; + + public KeyPressedEvent(IPlayer player, int key, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed) { + super(player); + this.key = key; + this.isCtrlPressed = isCtrlPressed; + this.isAltPressed = isAltPressed; + this.isShiftPressed = isShiftPressed; + this.isMetaPressed = isMetaPressed; + } + } + + public static class LevelUpEvent extends PlayerEvent { + public final int change; + + public LevelUpEvent(IPlayer player, int change) { + super(player); + this.change = change; + } + } + + public static class LogoutEvent extends PlayerEvent { + public LogoutEvent(IPlayer player) { + super(player); + } + } + + public static class LoginEvent extends PlayerEvent { + public LoginEvent(IPlayer player) { + super(player); + } + } + + public static class TimerEvent extends PlayerEvent { + public final int id; + + public TimerEvent(IPlayer player, int id) { + super(player); + this.id = id; + } + } + + @Cancelable + public static class DamagedEvent extends PlayerEvent { + public final IDamageSource damageSource; + public final IEntity source; + public float damage; + public boolean clearTarget = false; + + public DamagedEvent(IPlayer player, Entity source, float damage, DamageSource damagesource) { + super(player); + this.source = NpcAPI.Instance().getIEntity(source); + this.damage = damage; + this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + } + } + + public static class KilledEntityEvent extends PlayerEvent { + public final IEntityLivingBase entity; + + public KilledEntityEvent(IPlayer player, EntityLivingBase entity) { + super(player); + this.entity = (IEntityLivingBase)NpcAPI.Instance().getIEntity(entity); + } + } + + @Cancelable + public static class DiedEvent extends PlayerEvent { + public final IDamageSource damageSource; + public final String type; + public final IEntity source; + + public DiedEvent(IPlayer player, DamageSource damagesource, Entity entity) { + super(player); + this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + this.type = damagesource.field_76373_n; + this.source = NpcAPI.Instance().getIEntity(entity); + } + } + + @Cancelable + public static class RangedLaunchedEvent extends PlayerEvent { + public RangedLaunchedEvent(IPlayer player) { + super(player); + } + } + + @Cancelable + public static class DamagedEntityEvent extends PlayerEvent { + public final IDamageSource damageSource; + public final IEntity target; + public float damage; + + public DamagedEntityEvent(IPlayer player, Entity target, float damage, DamageSource damagesource) { + super(player); + this.target = NpcAPI.Instance().getIEntity(target); + this.damage = damage; + this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + } + } + + public static class ContainerClosed extends PlayerEvent { + public final IContainer container; + + public ContainerClosed(IPlayer player, IContainer container) { + super(player); + this.container = container; + } + } + + public static class ContainerOpen extends PlayerEvent { + public final IContainer container; + + public ContainerOpen(IPlayer player, IContainer container) { + super(player); + this.container = container; + } + } + + @Cancelable + public static class PickUpEvent extends PlayerEvent { + public final IItemStack item; + + public PickUpEvent(IPlayer player, IItemStack item) { + super(player); + this.item = item; + } + } + + @Cancelable + public static class TossEvent extends PlayerEvent { + public final IItemStack item; + + public TossEvent(IPlayer player, IItemStack item) { + super(player); + this.item = item; + } + } + + @Cancelable + public static class BreakEvent extends PlayerEvent { + public final IBlock block; + public int exp; + + public BreakEvent(IPlayer player, IBlock block, int exp) { + super(player); + this.block = block; + this.exp = exp; + } + } + + @Cancelable + public static class AttackEvent extends PlayerEvent { + public final int type; + public final Object target; + + public AttackEvent(IPlayer player, int type, Object target) { + super(player); + this.type = type; + this.target = target; + } + } + + @Cancelable + public static class InteractEvent extends PlayerEvent { + public final int type; + public final Object target; + + public InteractEvent(IPlayer player, int type, Object target) { + super(player); + this.type = type; + this.target = target; + } + } + + public static class UpdateEvent extends PlayerEvent { + public UpdateEvent(IPlayer player) { + super(player); + } + } + + public static class InitEvent extends PlayerEvent { + public InitEvent(IPlayer player) { + super(player); + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/IButton.java b/src/main/java/noppes/npcs/scripted/gui/IButton.java deleted file mode 100644 index b4fe804c3..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/IButton.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import noppes.npcs.scripted.gui.ICustomGuiComponent; - -public interface IButton extends ICustomGuiComponent { - int getWidth(); - - int getHeight(); - - IButton setSize(int var1, int var2); - - String getLabel(); - - IButton setLabel(String var1); - - String getTexture(); - - boolean hasTexture(); - - IButton setTexture(String var1); - - int getTextureX(); - - int getTextureY(); - - IButton setTextureOffset(int var1, int var2); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/ICustomGui.java b/src/main/java/noppes/npcs/scripted/gui/ICustomGui.java deleted file mode 100644 index a0ecc27a8..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/ICustomGui.java +++ /dev/null @@ -1,69 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import java.util.List; -import noppes.npcs.scripted.entity.IPlayer; -import noppes.npcs.scripted.gui.IButton; -import noppes.npcs.scripted.gui.ICustomGuiComponent; -import noppes.npcs.scripted.gui.IItemSlot; -import noppes.npcs.scripted.gui.ILabel; -import noppes.npcs.scripted.gui.IScroll; -import noppes.npcs.scripted.gui.ITextField; -import noppes.npcs.scripted.gui.ITexturedRect; -import noppes.npcs.scripted.item.IItemStack; - -public interface ICustomGui { - int getID(); - - int getWidth(); - - int getHeight(); - - List getComponents(); - - List getSlots(); - - void setSize(int var1, int var2); - - void setDoesPauseGame(boolean var1); - - void setBackgroundTexture(String var1); - - IButton addButton(int var1, String var2, int var3, int var4); - - IButton addButton(int var1, String var2, int var3, int var4, int var5, int var6); - - IButton addTexturedButton(int var1, String var2, int var3, int var4, int var5, int var6, String var7); - - IButton addTexturedButton(int var1, String var2, int var3, int var4, int var5, int var6, String var7, int var8, int var9); - - ILabel addLabel(int var1, String var2, int var3, int var4, int var5, int var6); - - ILabel addLabel(int var1, String var2, int var3, int var4, int var5, int var6, int var7); - - ITextField addTextField(int var1, int var2, int var3, int var4, int var5); - - ITexturedRect addTexturedRect(int var1, String var2, int var3, int var4, int var5, int var6); - - ITexturedRect addTexturedRect(int var1, String var2, int var3, int var4, int var5, int var6, int var7, int var8); - - IScroll addScroll(int var1, int var2, int var3, int var4, int var5, String[] var6); - - IItemSlot addItemSlot(int var1, int var2); - - IItemSlot addItemSlot(int var1, int var2, IItemStack var3); - - void showPlayerInventory(int var1, int var2); - - ICustomGuiComponent getComponent(int var1); - - void removeComponent(int var1); - - void updateComponent(ICustomGuiComponent var1); - - void update(IPlayer var1); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java b/src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java deleted file mode 100644 index 0e9d3882d..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/ICustomGuiComponent.java +++ /dev/null @@ -1,26 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -public interface ICustomGuiComponent { - int getID(); - - ICustomGuiComponent setID(int var1); - - int getPosX(); - - int getPosY(); - - ICustomGuiComponent setPos(int var1, int var2); - - boolean hasHoverText(); - - String[] getHoverText(); - - ICustomGuiComponent setHoverText(String var1); - - ICustomGuiComponent setHoverText(String[] var1); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/IItemSlot.java b/src/main/java/noppes/npcs/scripted/gui/IItemSlot.java deleted file mode 100644 index 7ac899cbb..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/IItemSlot.java +++ /dev/null @@ -1,20 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import net.minecraft.inventory.Slot; -import noppes.npcs.scripted.gui.ICustomGuiComponent; -import noppes.npcs.scripted.item.IItemStack; - -public interface IItemSlot extends ICustomGuiComponent { - boolean hasStack(); - - IItemStack getStack(); - - IItemSlot setStack(IItemStack var1); - - Slot getMCSlot(); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/ILabel.java b/src/main/java/noppes/npcs/scripted/gui/ILabel.java deleted file mode 100644 index 9851752dc..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/ILabel.java +++ /dev/null @@ -1,28 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import noppes.npcs.scripted.gui.ICustomGuiComponent; - -public interface ILabel extends ICustomGuiComponent { - String getText(); - - ILabel setText(String var1); - - int getWidth(); - - int getHeight(); - - ILabel setSize(int var1, int var2); - - int getColor(); - - ILabel setColor(int var1); - - float getScale(); - - ILabel setScale(float var1); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/IScroll.java b/src/main/java/noppes/npcs/scripted/gui/IScroll.java deleted file mode 100644 index cbe388bef..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/IScroll.java +++ /dev/null @@ -1,28 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import noppes.npcs.scripted.gui.ICustomGuiComponent; - -public interface IScroll extends ICustomGuiComponent { - int getWidth(); - - int getHeight(); - - IScroll setSize(int var1, int var2); - - String[] getList(); - - IScroll setList(String[] var1); - - int getDefaultSelection(); - - IScroll setDefaultSelection(int var1); - - boolean isMultiSelect(); - - IScroll setMultiSelect(boolean var1); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/ITextField.java b/src/main/java/noppes/npcs/scripted/gui/ITextField.java deleted file mode 100644 index 449a090f5..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/ITextField.java +++ /dev/null @@ -1,20 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import noppes.npcs.scripted.gui.ICustomGuiComponent; - -public interface ITextField extends ICustomGuiComponent { - int getWidth(); - - int getHeight(); - - ITextField setSize(int var1, int var2); - - String getText(); - - ITextField setText(String var1); -} diff --git a/src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java b/src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java deleted file mode 100644 index 1bf160c5c..000000000 --- a/src/main/java/noppes/npcs/scripted/gui/ITexturedRect.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.gui; - -import noppes.npcs.scripted.gui.ICustomGuiComponent; - -public interface ITexturedRect extends ICustomGuiComponent { - String getTexture(); - - ITexturedRect setTexture(String var1); - - int getWidth(); - - int getHeight(); - - ITexturedRect setSize(int var1, int var2); - - float getScale(); - - ITexturedRect setScale(float var1); - - int getTextureX(); - - int getTextureY(); - - ITexturedRect setTextureOffset(int var1, int var2); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java b/src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java deleted file mode 100644 index 0797f0597..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/ICloneHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler; - -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.entity.IEntity; - -public interface ICloneHandler { - IEntity spawn(double var1, double var3, double var5, int var7, String var8, IWorld var9); - - IEntity get(int var1, String var2, IWorld var3); - - void set(int var1, String var2, IEntity var3); - - void remove(int var1, String var2); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java b/src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java deleted file mode 100644 index 31744cb81..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/IFactionHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler; - -import java.util.List; -import noppes.npcs.scripted.handler.data.IFaction; - -public interface IFactionHandler { - List list(); - - IFaction delete(int var1); - - IFaction create(String var1, int var2); - - IFaction get(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java b/src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java deleted file mode 100644 index 4eb6d23b7..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/IQuestHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler; - -import java.util.List; -import noppes.npcs.scripted.handler.data.IQuest; -import noppes.npcs.scripted.handler.data.IQuestCategory; - -public interface IQuestHandler { - List categories(); - - IQuest get(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java b/src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java deleted file mode 100644 index 500734f5f..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/IRecipeHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler; - -import java.util.List; -import net.minecraft.item.ItemStack; -import noppes.npcs.scripted.handler.data.IRecipe; - -public interface IRecipeHandler { - List getGlobalList(); - - List getCarpentryList(); - - IRecipe addRecipe(String var1, boolean var2, ItemStack var3, Object... var4); - - IRecipe addRecipe(String var1, boolean var2, ItemStack var3, int var4, int var5, ItemStack... var6); - - IRecipe delete(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java b/src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java deleted file mode 100644 index d5ab810f1..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IAvailability.java +++ /dev/null @@ -1,38 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import noppes.npcs.scripted.entity.IPlayer; - -public interface IAvailability { - boolean isAvailable(IPlayer var1); - - int getDaytime(); - - void setDaytime(int var1); - - int getMinPlayerLevel(); - - void setMinPlayerLevel(int var1); - - int getDialog(int var1); - - void setDialog(int var1, int var2, int var3); - - void removeDialog(int var1); - - int getQuest(int var1); - - void setQuest(int var1, int var2, int var3); - - void removeQuest(int var1); - - void setFaction(int var1, int var2, int var3, int var4); - - void removeFaction(int var1); - - void setScoreboard(int var1, String var2, int var3, int var4); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java deleted file mode 100644 index c6e35bfc5..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java +++ /dev/null @@ -1,42 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import java.util.List; -import noppes.npcs.scripted.handler.data.IAvailability; -import noppes.npcs.scripted.handler.data.IDialogCategory; -import noppes.npcs.scripted.handler.data.IDialogOption; -import noppes.npcs.scripted.handler.data.IQuest; - -public interface IDialog { - int getId(); - - String getName(); - - void setName(String var1); - - String getText(); - - void setText(String var1); - - IQuest getQuest(); - - void setQuest(IQuest var1); - - String getCommand(); - - void setCommand(String var1); - - List getOptions(); - - IDialogOption getOption(int var1); - - IAvailability getAvailability(); - - IDialogCategory getCategory(); - - void save(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java deleted file mode 100644 index b0d889a5b..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IDialogCategory.java +++ /dev/null @@ -1,17 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import java.util.List; -import noppes.npcs.scripted.handler.data.IDialog; - -public interface IDialogCategory { - List dialogs(); - - String getName(); - - IDialog create(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java deleted file mode 100644 index 9c2adc114..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IDialogHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler; - -import java.util.List; -import noppes.npcs.scripted.handler.data.IDialog; -import noppes.npcs.scripted.handler.data.IDialogCategory; - -public interface IDialogHandler { - List categories(); - - IDialog get(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java deleted file mode 100644 index d2631966b..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IDialogOption.java +++ /dev/null @@ -1,14 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -public interface IDialogOption { - int getSlot(); - - String getName(); - - int getType(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IFaction.java b/src/main/java/noppes/npcs/scripted/handler/data/IFaction.java deleted file mode 100644 index a72f945a2..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IFaction.java +++ /dev/null @@ -1,45 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import noppes.npcs.scripted.entity.ICustomNpc; -import noppes.npcs.scripted.entity.IPlayer; - -public interface IFaction { - int getId(); - - String getName(); - - int getDefaultPoints(); - - void setDefaultPoints(int var1); - - int getColor(); - - int playerStatus(IPlayer var1); - - boolean hostileToNpc(ICustomNpc var1); - - boolean hostileToFaction(int var1); - - int[] getHostileList(); - - void addHostile(int var1); - - void removeHostile(int var1); - - boolean hasHostile(int var1); - - boolean getIsHidden(); - - void setIsHidden(boolean var1); - - boolean getAttackedByMobs(); - - void setAttackedByMobs(boolean var1); - - void save(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java deleted file mode 100644 index b53972149..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java +++ /dev/null @@ -1,47 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.entity.IPlayer; - -public interface IQuest { - int getId(); - - String getName(); - - void setName(String var1); - - int getType(); - - void setType(int var1); - - String getLogText(); - - void setLogText(String var1); - - String getCompleteText(); - - void setCompleteText(String var1); - - IQuest getNextQuest(); - - void setNextQuest(IQuest var1); - - IQuestObjective[] getObjectives(IPlayer var1); - - IQuestCategory getCategory(); - - IContainer getRewards(); - - String getNpcName(); - - void setNpcName(String var1); - - void save(); - - boolean getIsRepeatable(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java deleted file mode 100644 index 0bbe539a7..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IQuestCategory.java +++ /dev/null @@ -1,17 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import java.util.List; -import noppes.npcs.scripted.handler.data.IQuest; - -public interface IQuestCategory { - List quests(); - - String getName(); - - IQuest create(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java deleted file mode 100644 index 69a0374cf..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IQuestHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import java.util.List; - -public interface IQuestHandler { - List categories(); - - IQuest get(int var1); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java deleted file mode 100644 index 9e31c41ab..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IQuestObjective.java +++ /dev/null @@ -1,18 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -public interface IQuestObjective { - int getProgress(); - - void setProgress(int var1); - - int getMaxProgress(); - - boolean isCompleted(); - - String getText(); -} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java b/src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java deleted file mode 100644 index a6ed19826..000000000 --- a/src/main/java/noppes/npcs/scripted/handler/data/IRecipe.java +++ /dev/null @@ -1,42 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.handler.data; - -import net.minecraft.item.ItemStack; - -public interface IRecipe { - String getName(); - - boolean isGlobal(); - - void setIsGlobal(boolean var1); - - boolean getIgnoreNBT(); - - void setIgnoreNBT(boolean var1); - - boolean getIgnoreDamage(); - - void setIgnoreDamage(boolean var1); - - int getWidth(); - - int getHeight(); - - ItemStack getResult(); - - ItemStack[] getRecipe(); - - void saves(boolean var1); - - boolean saves(); - - void save(); - - void delete(); - - int getId(); -} diff --git a/src/main/java/noppes/npcs/scripted/item/IItemStack.java b/src/main/java/noppes/npcs/scripted/item/IItemStack.java deleted file mode 100644 index 9ee617f1d..000000000 --- a/src/main/java/noppes/npcs/scripted/item/IItemStack.java +++ /dev/null @@ -1,92 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.item; - -import net.minecraft.item.ItemStack; -import noppes.npcs.scripted.INbt; -import noppes.npcs.scripted.entity.IEntityLiving; -import noppes.npcs.scripted.entity.data.IData; - -public interface IItemStack { - int getStackSize(); - - void setStackSize(int var1); - - int getMaxStackSize(); - - int getItemDamage(); - - void setItemDamage(int var1); - - int getMaxItemDamage(); - - double getAttackDamage(); - - void damageItem(int var1, IEntityLiving var2); - - void addEnchantment(String var1, int var2); - - boolean isEnchanted(); - - boolean hasEnchant(String var1); - - boolean removeEnchant(String var1); - - /** @deprecated */ - boolean isBlock(); - - boolean isWearable(); - - boolean hasCustomName(); - - void setCustomName(String var1); - - String getDisplayName(); - - String getItemName(); - - String getName(); - - /** @deprecated */ - boolean isBook(); - - IItemStack copy(); - - ItemStack getMCItemStack(); - - INbt getNbt(); - - boolean hasNbt(); - - void removeNbt(); - - INbt getItemNbt(); - - boolean isEmpty(); - - int getType(); - - String[] getLore(); - - void setLore(String[] var1); - - /** @deprecated */ - void setAttribute(String var1, double var2); - - void setAttribute(String var1, double var2, int var4); - - double getAttribute(String var1); - - boolean hasAttribute(String var1); - - IData getTempdata(); - - IData getStoreddata(); - - int getFoodLevel(); - - boolean compare(IItemStack var1, boolean var2); -} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java deleted file mode 100644 index 233b2229d..000000000 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ /dev/null @@ -1,247 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.scripted.wrapper; - -import java.io.File; -import java.util.Map; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraftforge.common.util.FakePlayer; -import cpw.mods.fml.common.eventhandler.EventBus; -import noppes.npcs.CustomNpcs; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.scripted.CommandNoppesBase; -import noppes.npcs.scripted.CustomNPCsException; -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.IDamageSource; -import noppes.npcs.scripted.INbt; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.entity.ICustomNpc; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.entity.data.IPlayerMail; -import noppes.npcs.scripted.gui.ICustomGui; -import noppes.npcs.scripted.handler.ICloneHandler; -import noppes.npcs.scripted.handler.IDialogHandler; -import noppes.npcs.scripted.handler.IFactionHandler; -import noppes.npcs.scripted.handler.IQuestHandler; -import noppes.npcs.scripted.handler.IRecipeHandler; -import noppes.npcs.scripted.item.IItemStack; -import noppes.npcs.scripted.wrapper.ContainerWrapper; -import noppes.npcs.scripted.wrapper.DamageSourceWrapper; -import noppes.npcs.scripted.wrapper.ItemStackWrapper; -import noppes.npcs.scripted.wrapper.NBTWrapper; -import noppes.npcs.scripted.wrapper.WorldWrapper; -import noppes.npcs.scripted.wrapper.WrapperEntityData; -import noppes.npcs.scripted.wrapper.gui.CustomGuiWrapper; -import noppes.npcs.containers.ContainerNpcInterface; -import noppes.npcs.controllers.DialogController; -import noppes.npcs.controllers.FactionController; -import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.RecipeController; -import noppes.npcs.controllers.ServerCloneController; -import noppes.npcs.controllers.data.PlayerData; -import noppes.npcs.controllers.data.PlayerMail; -import noppes.npcs.entity.EntityCustomNpc; -import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.util.LRUHashMap; -import noppes.npcs.util.NBTJsonUtil; -import noppes.npcs.util.JsonException; - -public class WrapperNpcAPI extends NpcAPI { - private static final Map worldCache = new LRUHashMap(10); - public static final EventBus EVENT_BUS = new EventBus(); - private static NpcAPI instance = null; - - public WrapperNpcAPI() { - } - - public static void clearCache() { - worldCache.clear(); - } - - public IEntity getIEntity(Entity entity) { - return (IEntity)(entity != null && !entity.field_70170_p.field_72995_K?(entity instanceof EntityNPCInterface?((EntityNPCInterface)entity).wrappedNPC:WrapperEntityData.get(entity)):null); - } - - public ICustomNpc createNPC(World world) { - if(world.field_72995_K) { - return null; - } else { - EntityCustomNpc npc = new EntityCustomNpc(world); - return npc.wrappedNPC; - } - } - - public ICustomNpc spawnNPC(World world, int x, int y, int z) { - if(world.field_72995_K) { - return null; - } else { - EntityCustomNpc npc = new EntityCustomNpc(world); - npc.func_70080_a((double)x + 0.5D, (double)y, (double)z + 0.5D, 0.0F, 0.0F); - npc.ais.setStartPos((double)x, (double)y, (double)z); - npc.func_70606_j(npc.func_110138_aP()); - world.func_72838_d(npc); - return npc.wrappedNPC; - } - } - - public static NpcAPI Instance() { - if(instance == null) { - instance = new WrapperNpcAPI(); - } - - return instance; - } - - public EventBus events() { - return EVENT_BUS; - } - - public IItemStack getIItemStack(ItemStack itemstack) { - return (IItemStack)(itemstack != null && !itemstack.func_190926_b()?(IItemStack)itemstack.getCapability(ItemStackWrapper.ITEMSCRIPTEDDATA_CAPABILITY, (EnumFacing)null):ItemStackWrapper.AIR); - } - - public IWorld getIWorld(WorldServer world) { - WorldWrapper w = (WorldWrapper)worldCache.get(Integer.valueOf(world.field_73011_w.getDimension())); - if(w != null) { - w.world = world; - return w; - } else { - worldCache.put(Integer.valueOf(world.field_73011_w.getDimension()), w = WorldWrapper.createNew(world)); - return w; - } - } - - public IWorld getIWorld(int dimensionId) { - WorldServer[] var2 = CustomNpcs.Server.field_71305_c; - int var3 = var2.length; - - for(int var4 = 0; var4 < var3; ++var4) { - WorldServer world = var2[var4]; - if(world.field_73011_w.getDimension() == dimensionId) { - return this.getIWorld(world); - } - } - - throw new CustomNPCsException("Unknown dimension id: " + dimensionId, new Object[0]); - } - - public IContainer getIContainer(IInventory inventory) { - return new ContainerWrapper(inventory); - } - - public IContainer getIContainer(Container container) { - return (IContainer)(container instanceof ContainerNpcInterface?ContainerNpcInterface.getOrCreateIContainer((ContainerNpcInterface)container):new ContainerWrapper(container)); - } - - public IFactionHandler getFactions() { - this.checkWorld(); - return FactionController.instance; - } - - private void checkWorld() { - if(CustomNpcs.Server == null || CustomNpcs.Server.func_71241_aa()) { - throw new CustomNPCsException("No world is loaded right now", new Object[0]); - } - } - - public IRecipeHandler getRecipes() { - this.checkWorld(); - return RecipeController.instance; - } - - public IQuestHandler getQuests() { - this.checkWorld(); - return QuestController.instance; - } - - public IWorld[] getIWorlds() { - this.checkWorld(); - IWorld[] worlds = new IWorld[CustomNpcs.Server.field_71305_c.length]; - - for(int i = 0; i < CustomNpcs.Server.field_71305_c.length; ++i) { - worlds[i] = this.getIWorld(CustomNpcs.Server.field_71305_c[i]); - } - - return worlds; - } - - public File getGlobalDir() { - return CustomNpcs.Dir; - } - - public File getWorldDir() { - return CustomNpcs.getWorldSaveDirectory(); - } - - public void registerCommand(CommandNoppesBase command) { - CustomNpcs.NoppesCommand.registerCommand(command); - } - - public INbt getINbt(NBTTagCompound compound) { - return compound == null?new NBTWrapper(new NBTTagCompound()):new NBTWrapper(compound); - } - - public INbt stringToNbt(String str) { - if(str != null && !str.isEmpty()) { - try { - return this.getINbt(NBTJsonUtil.Convert(str)); - } catch (JsonException var3) { - throw new CustomNPCsException(var3, "Failed converting " + str, new Object[0]); - } - } else { - throw new CustomNPCsException("Cant cast empty string to nbt", new Object[0]); - } - } - - public IDamageSource getIDamageSource(DamageSource damagesource) { - return new DamageSourceWrapper(damagesource); - } - - public IDialogHandler getDialogs() { - return DialogController.instance; - } - - public ICloneHandler getClones() { - return ServerCloneController.Instance; - } - - public String executeCommand(IWorld world, String command) { - FakePlayer player = EntityNPCInterface.CommandPlayer; - player.func_70029_a(world.getMCWorld()); - player.func_70107_b(0.0D, 0.0D, 0.0D); - return NoppesUtilServer.runCommand(world.getMCWorld(), BlockPos.field_177992_a, "API", command, (EntityPlayer)null, player); - } - - public INbt getRawPlayerData(String uuid) { - return this.getINbt(PlayerData.loadPlayerData(uuid)); - } - - public IPlayerMail createMail(String sender, String subject) { - PlayerMail mail = new PlayerMail(); - mail.sender = sender; - mail.subject = subject; - return mail; - } - - public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) { - return new CustomGuiWrapper(id, width, height, pauseGame); - } - - public String getRandomName(int dictionary, int gender) { - return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender); - } -} diff --git a/src/main/java/noppes/npcs/util/LRUHashMap.java b/src/main/java/noppes/npcs/util/LRUHashMap.java deleted file mode 100644 index a843369d8..000000000 --- a/src/main/java/noppes/npcs/util/LRUHashMap.java +++ /dev/null @@ -1,22 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.util; - -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -public class LRUHashMap extends LinkedHashMap { - private final int maxSize; - - public LRUHashMap(int size) { - super(size, 0.75F, true); - this.maxSize = size; - } - - protected boolean removeEldestEntry(Entry eldest) { - return this.size() > this.maxSize; - } -} From 95d2814651282ae58ad27d70a978dd33a31ac881 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 30 Sep 2021 21:44:30 -0500 Subject: [PATCH 18/58] Backported GUI features and necessary classes from 1.12. --- CustomNPC-Plus-1.21.iml | 13 + src/main/java/noppes/npcs/CommonProxy.java | 5 + src/main/java/noppes/npcs/CustomNpcs.java | 3 + .../java/noppes/npcs/EventDataScript.java | 1 + src/main/java/noppes/npcs/EventHooks.java | 21 +- .../java/noppes/npcs/NoppesUtilServer.java | 23 + .../java/noppes/npcs/PacketHandlerServer.java | 13 + .../java/noppes/npcs/client/ClientProxy.java | 18 +- .../npcs/client/gui/EventGuiScriptList.java | 107 ++++ .../npcs/client/gui/GuiScriptEvent.java | 154 ----- .../gui/script/EventGuiNPCInterface.java | 555 ++++++++++++++++++ .../client/gui/script/GuiScriptEvent.java | 284 +++++++++ .../client/gui/script/GuiScriptGlobal.java | 57 ++ .../client/gui/script/GuiScriptInterface.java | 317 ++++++++++ .../client/gui/script/GuiScriptPlayers.java | 31 + .../client/gui/util/ITextChangeListener.java | 10 + .../npcs/constants/EnumPacketServer.java | 3 + .../containers/ContainerNpcInterface.java | 12 + .../noppes/npcs/controllers/PlayerData.java | 22 +- .../npcs/controllers/data/PlayerData.java | 289 --------- .../controllers/data/PlayerScriptData.java | 213 ++++++- .../npcs/entity/EntityNPCInterface.java | 25 +- .../npcs/scripted/CustomNPCsException.java | 16 + .../java/noppes/npcs/scripted/IContainer.java | 25 + .../java/noppes/npcs/scripted/ICustomNpc.java | 393 +++++++++++++ .../noppes/npcs/scripted/IDamageSource.java | 20 + .../java/noppes/npcs/scripted/IEntity.java | 326 ++++++++++ .../npcs/scripted/IEntityLivingBase.java | 110 ++++ .../java/noppes/npcs/scripted/IItemStack.java | 122 ++++ .../java/noppes/npcs/scripted/IPlayer.java | 183 ++++++ .../java/noppes/npcs/scripted/IWorld.java | 228 +++++++ .../java/noppes/npcs/scripted/NpcAPI.java | 78 +++ .../noppes/npcs/scripted/ScriptContainer.java | 88 +++ .../noppes/npcs/scripted/ScriptEntity.java | 2 +- .../noppes/npcs/scripted/ScriptItemStack.java | 2 +- .../npcs/scripted/ScriptLivingBase.java | 2 +- .../java/noppes/npcs/scripted/ScriptNpc.java | 6 +- .../noppes/npcs/scripted/ScriptPlayer.java | 2 +- .../noppes/npcs/scripted/ScriptWorld.java | 10 +- .../npcs/scripted/event/CustomNPCsEvent.java | 16 + .../npcs/scripted/event/ForgeEvent.java | 46 ++ .../npcs/scripted/event/PlayerEvent.java | 43 +- .../scripted/wrapper/ScriptDamageSource.java | 43 ++ .../scripted/wrapper/WrapperEntityData.java | 65 ++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 171 ++++++ .../java/noppes/npcs/util/LRUHashMap.java | 22 + 46 files changed, 3675 insertions(+), 520 deletions(-) create mode 100644 CustomNPC-Plus-1.21.iml create mode 100644 src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java delete mode 100644 src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java create mode 100644 src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/ITextChangeListener.java delete mode 100644 src/main/java/noppes/npcs/controllers/data/PlayerData.java create mode 100644 src/main/java/noppes/npcs/scripted/CustomNPCsException.java create mode 100644 src/main/java/noppes/npcs/scripted/IContainer.java create mode 100644 src/main/java/noppes/npcs/scripted/ICustomNpc.java create mode 100644 src/main/java/noppes/npcs/scripted/IDamageSource.java create mode 100644 src/main/java/noppes/npcs/scripted/IEntity.java create mode 100644 src/main/java/noppes/npcs/scripted/IEntityLivingBase.java create mode 100644 src/main/java/noppes/npcs/scripted/IItemStack.java create mode 100644 src/main/java/noppes/npcs/scripted/IPlayer.java create mode 100644 src/main/java/noppes/npcs/scripted/IWorld.java create mode 100644 src/main/java/noppes/npcs/scripted/NpcAPI.java create mode 100644 src/main/java/noppes/npcs/scripted/ScriptContainer.java create mode 100644 src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java create mode 100644 src/main/java/noppes/npcs/scripted/event/ForgeEvent.java create mode 100644 src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java create mode 100644 src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java create mode 100644 src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java create mode 100644 src/main/java/noppes/npcs/util/LRUHashMap.java diff --git a/CustomNPC-Plus-1.21.iml b/CustomNPC-Plus-1.21.iml new file mode 100644 index 000000000..b060a7da0 --- /dev/null +++ b/CustomNPC-Plus-1.21.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index 836d85f6e..c722656df 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -28,6 +28,7 @@ import noppes.npcs.containers.ContainerNPCTraderSetup; import noppes.npcs.containers.ContainerNpcItemGiver; import noppes.npcs.containers.ContainerNpcQuestReward; import noppes.npcs.containers.ContainerNpcQuestTypeItem; +import noppes.npcs.controllers.PlayerData; import noppes.npcs.entity.EntityNPCInterface; import cpw.mods.fml.common.network.IGuiHandler; @@ -41,6 +42,10 @@ public class CommonProxy implements IGuiHandler { CustomNpcs.ChannelPlayer.register(new PacketHandlerPlayer()); } + public PlayerData getPlayerData(EntityPlayer player) { + return null; + } + @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID > EnumGuiType.values().length) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 742c15966..2d7a19a05 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -308,4 +308,7 @@ public class CustomNpcs { return null; } + public static MinecraftServer getServer(){ + return MinecraftServer.getServer(); + } } diff --git a/src/main/java/noppes/npcs/EventDataScript.java b/src/main/java/noppes/npcs/EventDataScript.java index e39c11d15..486dc9ec2 100644 --- a/src/main/java/noppes/npcs/EventDataScript.java +++ b/src/main/java/noppes/npcs/EventDataScript.java @@ -12,6 +12,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import cpw.mods.fml.common.eventhandler.Event; import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityCustomNpc; diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 145834048..53af997e8 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -12,22 +12,21 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.util.DamageSource; import noppes.npcs.controllers.data.PlayerScriptData; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.PlayerEvent.AttackEvent; import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed; import noppes.npcs.scripted.event.PlayerEvent.ContainerOpen; import noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent; -import noppes.npcs.scripted.event.PlayerEvent.FactionUpdateEvent; import noppes.npcs.scripted.event.PlayerEvent.KeyPressedEvent; import noppes.npcs.scripted.event.PlayerEvent.LevelUpEvent; import noppes.npcs.scripted.event.PlayerEvent.LoginEvent; import noppes.npcs.scripted.event.PlayerEvent.LogoutEvent; import noppes.npcs.scripted.event.PlayerEvent.PickUpEvent; import noppes.npcs.scripted.event.PlayerEvent.TossEvent; -import noppes.npcs.scripted.wrapper.PlayerWrapper; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import noppes.npcs.constants.EnumScriptType; -import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.PlayerData; public class EventHooks { public EventHooks() { @@ -61,13 +60,8 @@ public class EventHooks { return WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerBreak(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.BreakEvent event) { - handler.runScript(EnumScriptType.BROKEN, event); - return WrapperNpcAPI.EVENT_BUS.post(event); - } - public static boolean onPlayerToss(PlayerScriptData handler, EntityItem entityItem) { - TossEvent event = new TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.func_92059_d())); + TossEvent event = new TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); handler.runScript(EnumScriptType.TOSS, event); return WrapperNpcAPI.EVENT_BUS.post(event); } @@ -79,7 +73,7 @@ public class EventHooks { } public static boolean onPlayerPickUp(PlayerScriptData handler, EntityItem entityItem) { - PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.func_92059_d())); + PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); handler.runScript(EnumScriptType.PICKUP, event); return WrapperNpcAPI.EVENT_BUS.post(event); } @@ -140,13 +134,6 @@ public class EventHooks { return WrapperNpcAPI.EVENT_BUS.post(event); } - public static void OnPlayerFactionChange(PlayerScriptData handler, FactionUpdateEvent event) { - if(!handler.isClient()) { - handler.runScript(EnumScriptType.FACTION_UPDATE, event); - WrapperNpcAPI.EVENT_BUS.post(event); - } - } - public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { PlayerScriptData handler = PlayerData.get(player).scriptData; KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 7d426d6f9..8cf1ec88e 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -14,6 +14,8 @@ import java.util.Map; import java.util.UUID; import java.util.zip.GZIPOutputStream; +import net.minecraft.command.ICommandManager; +import net.minecraft.command.ICommandSender; import net.minecraft.command.server.CommandBlockLogic; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -25,6 +27,7 @@ import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.rcon.RConConsoleSource; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraft.tileentity.TileEntity; @@ -33,6 +36,7 @@ import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; @@ -216,6 +220,25 @@ public class NoppesUtilServer { logic.func_145754_b("@"+name); logic.func_145755_a(executer.worldObj); } + + public static String runCommand(final World world, final BlockPos pos, final String name, String command, EntityPlayer player, final ICommandSender executer) { + if (player != null) { + command = command.replace("@dp", player.getDisplayName()); + } + + TileEntityCommandBlock tile = new TileEntityCommandBlock(); + tile.setWorldObj(world); + tile.xCoord = MathHelper.floor_double(pos.getX()); + tile.yCoord = MathHelper.floor_double(pos.getY()); + tile.zCoord = MathHelper.floor_double(pos.getZ()); + + CommandBlockLogic logic = tile.func_145993_a(); + logic.func_145752_a(command); + logic.func_145754_b("@"+name); + logic.func_145755_a(world); + + return logic.func_145749_h().getUnformattedText(); + } public static void consumeItemStack(int i, EntityPlayer player){ ItemStack item = player.inventory.getCurrentItem(); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 490c567a7..5fe882a43 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -106,6 +106,8 @@ public class PacketHandlerServer{ clonePackets(type, buffer, player); else if(item.getItem() == CustomItems.teleporter) featherPackets(type, buffer, player); + else if(type == EnumPacketServer.ScriptPlayerGet && type == EnumPacketServer.ScriptPlayerSave) + playerScriptPackets(type, buffer, player, npc); else if(item.getItem() == CustomItems.scripter) scriptPackets(type, buffer, player, npc); else if(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) @@ -128,6 +130,17 @@ public class PacketHandlerServer{ } } + private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { + NBTTagCompound compound; + if (type == EnumPacketServer.ScriptPlayerGet) { + compound = ScriptController.Instance.playerScripts.writeToNBT(new NBTTagCompound()); + compound.setTag("Languages", ScriptController.Instance.nbtLanguages()); + Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound}); + } else if (type == EnumPacketServer.ScriptPlayerSave) { + ScriptController.Instance.setPlayerScripts(Server.readNBT(buffer)); + } + } + private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { if(type == EnumPacketServer.DimensionsGet){ HashMap map = new HashMap(); diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 515a5cd34..f07d3541e 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -96,6 +96,7 @@ import noppes.npcs.client.gui.roles.GuiNpcFollowerSetup; import noppes.npcs.client.gui.roles.GuiNpcItemGiver; import noppes.npcs.client.gui.roles.GuiNpcTraderSetup; import noppes.npcs.client.gui.roles.GuiNpcTransporter; +import noppes.npcs.client.gui.script.GuiScriptGlobal; import noppes.npcs.client.model.*; import noppes.npcs.client.renderer.*; import noppes.npcs.client.renderer.blocks.BlockBannerRenderer; @@ -141,6 +142,7 @@ import noppes.npcs.containers.ContainerNPCTraderSetup; import noppes.npcs.containers.ContainerNpcItemGiver; import noppes.npcs.containers.ContainerNpcQuestReward; import noppes.npcs.containers.ContainerNpcQuestTypeItem; +import noppes.npcs.controllers.PlayerData; import noppes.npcs.entity.*; import org.lwjgl.input.Keyboard; @@ -266,6 +268,20 @@ public class ClientProxy extends CommonProxy { ((IReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener(new CustomNpcResourceListener()); } + public static PlayerData playerData = new PlayerData(); + @Override + public PlayerData getPlayerData(EntityPlayer player) { + if (player.getUniqueID() == Minecraft.getMinecraft().thePlayer.getUniqueID()) { + if (playerData.player != player) { + playerData.player = player; + } + + return playerData; + } else { + return null; + } + } + @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { @@ -369,7 +385,7 @@ public class ClientProxy extends CommonProxy { return new GuiNpcRemoteEditor(); else if(gui == EnumGuiType.ScriptEvent && Minecraft.getMinecraft().currentScreen == null) - return new GuiScriptEvent(); + return new GuiScriptGlobal(); else if(gui == EnumGuiType.PlayerMailman) return new GuiMailmanWrite((ContainerMail) container, x == 1, y == 1); diff --git a/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java new file mode 100644 index 000000000..decb5ab47 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java @@ -0,0 +1,107 @@ +package noppes.npcs.client.gui; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.world.biome.BiomeGenBase; +import noppes.npcs.EventScriptContainer; +import noppes.npcs.client.gui.util.GuiCustomScroll; +import noppes.npcs.client.gui.util.GuiNPCInterface; +import noppes.npcs.client.gui.util.GuiNpcButton; +import noppes.npcs.client.gui.util.GuiNpcLabel; +import noppes.npcs.client.gui.util.SubGuiInterface; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.entity.EntityNPCInterface; + +public class EventGuiScriptList extends SubGuiInterface{ + private GuiCustomScroll scroll1; + private GuiCustomScroll scroll2; + private EventScriptContainer container; + private List scripts; + + public EventGuiScriptList(List scripts, EventScriptContainer container){ + this.container = container; + setBackground("menubg.png"); + xSize = 346; + ySize = 216; + if(scripts == null) + scripts = new ArrayList(); + this.scripts = scripts; + } + @Override + public void initGui(){ + super.initGui(); + if(scroll1 == null){ + scroll1 = new GuiCustomScroll(this,0); + scroll1.setSize(140, 180); + } + scroll1.guiLeft = guiLeft + 4; + scroll1.guiTop = guiTop + 14; + this.addScroll(scroll1); + addLabel(new GuiNpcLabel(1, "script.availableScripts", guiLeft + 4, guiTop + 4)); + + if(scroll2 == null){ + scroll2 = new GuiCustomScroll(this,1); + scroll2.setSize(140, 180); + } + scroll2.guiLeft = guiLeft + 200; + scroll2.guiTop = guiTop + 14; + this.addScroll(scroll2); + addLabel(new GuiNpcLabel(2, "script.loadedScripts", guiLeft + 200, guiTop + 4)); + List temp = new ArrayList(scripts); + temp.removeAll(container.scripts); + scroll1.setList(temp); + scroll2.setList(container.scripts); + + addButton(new GuiNpcButton(1, guiLeft + 145, guiTop + 40, 55, 20, ">")); + addButton(new GuiNpcButton(2, guiLeft + 145, guiTop + 62, 55, 20, "<")); + + addButton(new GuiNpcButton(3, guiLeft + 145, guiTop + 90, 55, 20, ">>")); + addButton(new GuiNpcButton(4, guiLeft + 145, guiTop + 112, 55, 20, "<<")); + + addButton(new GuiNpcButton(66, guiLeft + 260, guiTop + 194, 60, 20, "gui.done")); + } + + protected void actionPerformed(GuiButton guibutton){ + GuiNpcButton button = (GuiNpcButton) guibutton; + if(button.id == 1){ + if(scroll1.hasSelected()){ + container.scripts.add(scroll1.getSelected()); + scroll1.selected = -1; + scroll1.selected = -1; + initGui(); + } + } + if(button.id == 2){ + if(scroll2.hasSelected()){ + container.scripts.remove(scroll2.getSelected()); + scroll2.selected = -1; + initGui(); + } + } + if(button.id == 3){ + container.scripts.clear(); + for(String script : scripts){ + container.scripts.add(script); + } + scroll1.selected = -1; + scroll1.selected = -1; + initGui(); + } + if(button.id == 4){ + container.scripts.clear(); + scroll1.selected = -1; + scroll1.selected = -1; + initGui(); + } + if(button.id == 66){ + close(); + } + } + @Override + public void save() { + + } + +} diff --git a/src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java b/src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java deleted file mode 100644 index 9278fcec4..000000000 --- a/src/main/java/noppes/npcs/client/gui/GuiScriptEvent.java +++ /dev/null @@ -1,154 +0,0 @@ -package noppes.npcs.client.gui; - -import net.minecraft.server.MinecraftServer; -import noppes.npcs.EventDataScript; -import noppes.npcs.EventScriptContainer; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.controllers.ScriptContainer; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class GuiScriptEvent extends GuiNPCInterface { - public boolean showScript = false; - private int activeTab = 0; - private String activeScriptTab = "init"; - public EventDataScript script; - public Map> languages = new HashMap>(); - - private static int activeConsole = 0; - - public GuiScriptEvent(){ - super(); - drawDefaultBackground = true; - closeOnEsc = true; - xSize = 420; - setBackground("menubg.png"); - - //Client.sendData(EnumPacketServer.RemoteNpcsGet); TODO: Get Player & Forge event scripts - } - - public void initGui() { - super.initGui(); - guiTop += 10; - GuiMenuTopButton top; - addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); - top.active = showScript; - addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); - top.active = !showScript; - addTopButton(new GuiMenuTopButton(15, top, "gui.website")); - - List list = new ArrayList(); - list.add("playerscript.attack"); - list.add("playerscript.break"); - list.add("playerscript.chat"); - list.add("playerscript.containerclosed"); - list.add("playerscript.containeropen"); - list.add("playerscript.damagedentity"); - list.add("playerscript.damaged"); - list.add("playerscript.killed"); - list.add("playerscript.factionupdate"); - list.add("playerscript.init"); - list.add("playerscript.interact"); - list.add("playerscript.keypressed"); - list.add("playerscript.kills"); - list.add("playerscript.levelup"); - list.add("playerscript.login"); - list.add("playerscript.logout"); - list.add("playerscript.pickup"); - list.add("playerscript.rangedlaunched"); - list.add("playerscript.toss"); - list.add("playerscript.update"); - - if(showScript) { - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(list); - hooks.selected = script.getScripts().indexOf(activeScriptTab); - addScroll(hooks); - - EventScriptContainer container = script.getScripts().get(script.getScripts().indexOf(activeScriptTab)); - - addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); - - addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); - addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); - addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); - - addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); - - addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); - - GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); - scroll.setSize(100, 120); - scroll.guiLeft = guiLeft + 315; - scroll.guiTop = guiTop + 92; - if(container != null) - scroll.setList(container.scripts); - addScroll(scroll); - } - else{ - addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); - getTopButton(14).active = true; - addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); - getTextField(2).canEdit = false; - addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); - addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); - - List l = new ArrayList(); - l.add("All"); - l.addAll(list); - addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); - - addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); - addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); - getButton(103).enabled = languages.size() > 0; - - addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); - //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, script.enabled?1:0)); - - if(MinecraftServer.getServer() != null) - addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); - } - } - - private int getScriptIndex() { - /* - int i = 0; - for(String language : languages.keySet()){ - if(language.equalsIgnoreCase(script.scriptLanguage)) - return i; - i++; - } - */ - return 0; - } - - private String getConsoleText() { - String console = ""; - /* - if(activeConsole == 0){ - for(ScriptContainer container : script.scripts.values()){ - if(!container.console.isEmpty()) - console += container.console + '\n'; - } - } - else{ - ScriptContainer container = script.scripts.get(activeConsole - 1); - if(container != null) - console = container.console; - } - */ - return console; - } - - @Override - public void save() { - - } -} diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java new file mode 100644 index 000000000..65b6154ed --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java @@ -0,0 +1,555 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.script; + +import com.google.common.collect.Lists; +import java.net.URI; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Post; +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Pre; +import net.minecraftforge.common.MinecraftForge; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.entity.EntityNPCInterface; +import org.lwjgl.input.Mouse; + +public abstract class EventGuiNPCInterface extends GuiScreen { + public EntityPlayerSP player; + public boolean drawDefaultBackground; + public EntityNPCInterface npc; + private Map buttons; + private Map topbuttons; + private Map sidebuttons; + private Map textfields; + private Map labels; + private Map scrolls; + private Map sliders; + private Map extra; + private List components; + public String title; + public ResourceLocation background; + public boolean closeOnEsc; + public int guiLeft; + public int guiTop; + public int xSize; + public int ySize; + private SubGuiInterface subgui; + public int mouseX; + public int mouseY; + public float bgScale; + private GuiButton selectedButton; + + public EventGuiNPCInterface(EntityNPCInterface npc) { + this.drawDefaultBackground = true; + this.buttons = new ConcurrentHashMap(); + this.topbuttons = new ConcurrentHashMap(); + this.sidebuttons = new ConcurrentHashMap(); + this.textfields = new ConcurrentHashMap(); + this.labels = new ConcurrentHashMap(); + this.scrolls = new ConcurrentHashMap(); + this.sliders = new ConcurrentHashMap(); + this.extra = new ConcurrentHashMap(); + this.components = new ArrayList(); + this.background = null; + this.closeOnEsc = false; + this.bgScale = 1.0F; + this.player = Minecraft.func_71410_x().field_71439_g; + this.npc = npc; + this.title = ""; + this.xSize = 200; + this.ySize = 222; + this.drawDefaultBackground = false; + this.field_146297_k = Minecraft.func_71410_x(); + this.field_146296_j = this.field_146297_k.func_175599_af(); + this.field_146289_q = this.field_146297_k.field_71466_p; + } + + public EventGuiNPCInterface() { + this((EntityNPCInterface)null); + } + + public void setBackground(String texture) { + this.background = new ResourceLocation("customnpcs", "textures/gui/" + texture); + } + + public ResourceLocation getResource(String texture) { + return new ResourceLocation("customnpcs", "textures/gui/" + texture); + } + + public void func_146280_a(Minecraft mc, int width, int height) { + super.func_146280_a(mc, width, height); + this.initPacket(); + } + + public void initPacket() { + } + + public void func_73866_w_() { + super.func_73866_w_(); + GuiNpcTextField.unfocus(); + if (this.subgui != null) { + this.subgui.func_146280_a(this.field_146297_k, this.field_146294_l, this.field_146295_m); + this.subgui.func_73866_w_(); + } + + this.guiLeft = (this.field_146294_l - this.xSize) / 2; + this.guiTop = (this.field_146295_m - this.ySize) / 2; + this.field_146292_n = Lists.newArrayList(); + this.buttons = new ConcurrentHashMap(); + this.topbuttons = new ConcurrentHashMap(); + this.sidebuttons = new ConcurrentHashMap(); + this.textfields = new ConcurrentHashMap(); + this.labels = new ConcurrentHashMap(); + this.scrolls = new ConcurrentHashMap(); + this.sliders = new ConcurrentHashMap(); + this.extra = new ConcurrentHashMap(); + this.components = new ArrayList(); + } + + public void func_73876_c() { + if (this.subgui != null) { + this.subgui.func_73876_c(); + } else { + Iterator var1 = (new ArrayList(this.textfields.values())).iterator(); + + while(var1.hasNext()) { + GuiNpcTextField tf = (GuiNpcTextField)var1.next(); + if (tf.enabled) { + tf.func_146178_a(); + } + } + + var1 = (new ArrayList(this.components)).iterator(); + + while(var1.hasNext()) { + IGui comp = (IGui)var1.next(); + comp.updateScreen(); + } + + super.func_73876_c(); + } + + } + + public void addExtra(GuiHoverText gui) { + gui.func_146280_a(this.field_146297_k, 350, 250); + this.extra.put(gui.id, gui); + } + + public void func_73864_a(int i, int j, int k) { + if (this.subgui != null) { + this.subgui.func_73864_a(i, j, k); + } else { + Iterator var4 = (new ArrayList(this.textfields.values())).iterator(); + + while(var4.hasNext()) { + GuiNpcTextField tf = (GuiNpcTextField)var4.next(); + if (tf.enabled) { + tf.func_146192_a(i, j, k); + } + } + + var4 = (new ArrayList(this.components)).iterator(); + + while(var4.hasNext()) { + IGui comp = (IGui)var4.next(); + if (comp instanceof IMouseListener) { + ((IMouseListener)comp).mouseClicked(i, j, k); + } + } + + this.mouseEvent(i, j, k); + if (k == 0) { + var4 = (new ArrayList(this.scrolls.values())).iterator(); + + while(var4.hasNext()) { + GuiCustomScroll scroll = (GuiCustomScroll)var4.next(); + scroll.func_73864_a(i, j, k); + } + + var4 = this.field_146292_n.iterator(); + + while(var4.hasNext()) { + GuiButton guibutton = (GuiButton)var4.next(); + if (guibutton.func_146116_c(this.field_146297_k, this.mouseX, this.mouseY)) { + Pre event = new Pre(this, guibutton, this.field_146292_n); + if (!MinecraftForge.EVENT_BUS.post(event)) { + guibutton = event.getButton(); + this.selectedButton = guibutton; + guibutton.func_146113_a(this.field_146297_k.func_147118_V()); + this.func_146284_a(guibutton); + if (this.equals(this.field_146297_k.field_71462_r)) { + MinecraftForge.EVENT_BUS.post(new Post(this, event.getButton(), this.field_146292_n)); + } + } + break; + } + } + } + } + + } + + public void func_146286_b(int mouseX, int mouseY, int state) { + if (this.selectedButton != null && state == 0) { + this.selectedButton.func_146118_a(mouseX, mouseY); + this.selectedButton = null; + } + + } + + public void mouseEvent(int i, int j, int k) { + } + + protected void func_146284_a(GuiButton guibutton) { + if (this.subgui != null) { + this.subgui.buttonEvent(guibutton); + } else { + this.buttonEvent(guibutton); + } + + } + + public void buttonEvent(GuiButton guibutton) { + } + + public void func_73869_a(char c, int i) { + if (this.subgui != null) { + this.subgui.func_73869_a(c, i); + } else { + boolean active = false; + Iterator var4 = this.components.iterator(); + + IGui comp; + while(var4.hasNext()) { + comp = (IGui)var4.next(); + if (comp.isActive()) { + active = true; + break; + } + } + + active = active || GuiNpcTextField.isActive(); + if (!this.closeOnEsc || i != 1 && (active || !this.isInventoryKey(i))) { + var4 = (new ArrayList(this.textfields.values())).iterator(); + + while(var4.hasNext()) { + GuiNpcTextField tf = (GuiNpcTextField)var4.next(); + tf.func_146201_a(c, i); + } + + var4 = (new ArrayList(this.components)).iterator(); + + while(var4.hasNext()) { + comp = (IGui)var4.next(); + if (comp instanceof IKeyListener) { + ((IKeyListener)comp).keyTyped(c, i); + } + } + + } else { + this.close(); + } + } + } + + public void func_146281_b() { + GuiNpcTextField.unfocus(); + } + + public void close() { + this.displayGuiScreen((GuiScreen)null); + this.field_146297_k.func_71381_h(); + this.save(); + } + + public void addButton(GuiNpcButton button) { + this.buttons.put(button.field_146127_k, button); + this.field_146292_n.add(button); + } + + public void addTopButton(GuiMenuTopButton button) { + this.topbuttons.put(button.field_146127_k, button); + this.field_146292_n.add(button); + } + + public void addSideButton(GuiMenuSideButton button) { + this.sidebuttons.put(button.field_146127_k, button); + this.field_146292_n.add(button); + } + + public GuiNpcButton getButton(int i) { + return (GuiNpcButton)this.buttons.get(i); + } + + public GuiMenuSideButton getSideButton(int i) { + return (GuiMenuSideButton)this.sidebuttons.get(i); + } + + public GuiMenuTopButton getTopButton(int i) { + return (GuiMenuTopButton)this.topbuttons.get(i); + } + + public void addTextField(GuiNpcTextField tf) { + this.textfields.put(tf.field_175208_g, tf); + } + + public GuiNpcTextField getTextField(int i) { + return (GuiNpcTextField)this.textfields.get(i); + } + + public void add(IGui gui) { + this.components.add(gui); + } + + public IGui get(int id) { + Iterator var2 = this.components.iterator(); + + IGui comp; + do { + if (!var2.hasNext()) { + return null; + } + + comp = (IGui)var2.next(); + } while(comp.getID() != id); + + return comp; + } + + public void addLabel(GuiNpcLabel label) { + this.labels.put(label.id, label); + } + + public GuiNpcLabel getLabel(int i) { + return (GuiNpcLabel)this.labels.get(i); + } + + public void addSlider(GuiNpcSlider slider) { + this.sliders.put(slider.field_146127_k, slider); + this.field_146292_n.add(slider); + } + + public GuiNpcSlider getSlider(int i) { + return (GuiNpcSlider)this.sliders.get(i); + } + + public void addScroll(GuiCustomScroll scroll) { + scroll.func_146280_a(this.field_146297_k, 350, 250); + this.scrolls.put(scroll.id, scroll); + } + + public GuiCustomScroll getScroll(int id) { + return (GuiCustomScroll)this.scrolls.get(id); + } + + public abstract void save(); + + public void func_73863_a(int mouseX, int mouseY, float partialTicks) { + this.mouseX = mouseX; + this.mouseY = mouseY; + int x = mouseX; + int y = mouseY; + if (this.subgui != null) { + y = 0; + x = 0; + } + + if (this.drawDefaultBackground && this.subgui == null) { + this.func_146276_q_(); + } + + if (this.background != null && this.field_146297_k.field_71446_o != null) { + GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.func_179094_E(); + GlStateManager.func_179109_b((float)this.guiLeft, (float)this.guiTop, 0.0F); + GlStateManager.func_179152_a(this.bgScale, this.bgScale, this.bgScale); + this.field_146297_k.field_71446_o.func_110577_a(this.background); + if (this.xSize > 256) { + this.func_73729_b(0, 0, 0, 0, 250, this.ySize); + this.func_73729_b(250, 0, 256 - (this.xSize - 250), 0, this.xSize - 250, this.ySize); + } else { + this.func_73729_b(0, 0, 0, 0, this.xSize, this.ySize); + } + + GlStateManager.func_179121_F(); + } + + this.func_73732_a(this.field_146289_q, this.title, this.field_146294_l / 2, 8, 16777215); + Iterator var6 = (new ArrayList(this.labels.values())).iterator(); + + while(var6.hasNext()) { + GuiNpcLabel label = (GuiNpcLabel)var6.next(); + label.drawLabel(this, this.field_146289_q); + } + + var6 = (new ArrayList(this.textfields.values())).iterator(); + + while(var6.hasNext()) { + GuiNpcTextField tf = (GuiNpcTextField)var6.next(); + tf.drawTextBox(x, y); + } + + var6 = (new ArrayList(this.components)).iterator(); + + while(var6.hasNext()) { + IGui comp = (IGui)var6.next(); + comp.drawScreen(x, y); + } + + var6 = (new ArrayList(this.scrolls.values())).iterator(); + + while(var6.hasNext()) { + GuiCustomScroll scroll = (GuiCustomScroll)var6.next(); + scroll.drawScreen(x, y, partialTicks, !this.hasSubGui() && scroll.isMouseOver(x, y) ? Mouse.getDWheel() : 0); + } + + var6 = (new ArrayList(this.extra.values())).iterator(); + + while(var6.hasNext()) { + GuiScreen gui = (GuiScreen)var6.next(); + gui.func_73863_a(x, y, partialTicks); + } + + super.func_73863_a(x, y, partialTicks); + if (this.subgui != null) { + this.subgui.func_73863_a(mouseX, mouseY, partialTicks); + } + + } + + public FontRenderer getFontRenderer() { + return this.field_146289_q; + } + + public void elementClicked() { + if (this.subgui != null) { + this.subgui.elementClicked(); + } + + } + + public boolean func_73868_f() { + return false; + } + + public void doubleClicked() { + } + + public boolean isInventoryKey(int i) { + return i == this.field_146297_k.field_71474_y.field_151445_Q.func_151463_i(); + } + + public void func_146276_q_() { + super.func_146276_q_(); + } + + public void displayGuiScreen(GuiScreen gui) { + this.field_146297_k.func_147108_a(gui); + } + + public void setSubGui(SubGuiInterface gui) { + this.subgui = gui; + this.subgui.npc = this.npc; + this.subgui.func_146280_a(this.field_146297_k, this.field_146294_l, this.field_146295_m); + this.subgui.parent = this; + this.func_73866_w_(); + } + + public void closeSubGui(SubGuiInterface gui) { + this.subgui = null; + } + + public boolean hasSubGui() { + return this.subgui != null; + } + + public SubGuiInterface getSubGui() { + return this.hasSubGui() && this.subgui.hasSubGui() ? this.subgui.getSubGui() : this.subgui; + } + + public void drawNpc(int x, int y) { + this.drawNpc(this.npc, x, y, 1.0F, 0); + } + + public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation) { + EntityNPCInterface npc = null; + if (entity instanceof EntityNPCInterface) { + npc = (EntityNPCInterface)entity; + } + + GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.func_179142_g(); + GlStateManager.func_179094_E(); + GlStateManager.func_179109_b((float)(this.guiLeft + x), (float)(this.guiTop + y), 50.0F); + float scale = 1.0F; + if ((double)entity.field_70131_O > 2.4D) { + scale = 2.0F / entity.field_70131_O; + } + + GlStateManager.func_179152_a(-30.0F * scale * zoomed, 30.0F * scale * zoomed, 30.0F * scale * zoomed); + GlStateManager.func_179114_b(180.0F, 0.0F, 0.0F, 1.0F); + RenderHelper.func_74519_b(); + float f2 = entity.field_70761_aq; + float f3 = entity.field_70177_z; + float f4 = entity.field_70125_A; + float f7 = entity.field_70759_as; + float f5 = (float)(this.guiLeft + x) - (float)this.mouseX; + float f6 = (float)(this.guiTop + y) - 50.0F * scale * zoomed - (float)this.mouseY; + int orientation = 0; + if (npc != null) { + orientation = npc.ais.orientation; + npc.ais.orientation = rotation; + } + + GlStateManager.func_179114_b(135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.func_179114_b(-135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.func_179114_b(-((float)Math.atan((double)(f6 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); + entity.field_70761_aq = (float)rotation; + entity.field_70177_z = (float)Math.atan((double)(f5 / 80.0F)) * 40.0F + (float)rotation; + entity.field_70125_A = -((float)Math.atan((double)(f6 / 40.0F))) * 20.0F; + entity.field_70759_as = entity.field_70177_z; + this.field_146297_k.func_175598_ae().field_78735_i = 180.0F; + this.field_146297_k.func_175598_ae().func_188391_a(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); + entity.field_70760_ar = entity.field_70761_aq = f2; + entity.field_70126_B = entity.field_70177_z = f3; + entity.field_70127_C = entity.field_70125_A = f4; + entity.field_70758_at = entity.field_70759_as = f7; + if (npc != null) { + npc.ais.orientation = orientation; + } + + GlStateManager.func_179121_F(); + RenderHelper.func_74518_a(); + GlStateManager.func_179101_C(); + GlStateManager.func_179138_g(OpenGlHelper.field_77476_b); + GlStateManager.func_179090_x(); + GlStateManager.func_179138_g(OpenGlHelper.field_77478_a); + } + + public void openLink(String link) { + try { + Class oclass = Class.forName("java.awt.Desktop"); + Object object = oclass.getMethod("getDesktop").invoke((Object)null); + oclass.getMethod("browse", URI.class).invoke(object, new URI(link)); + } catch (Throwable var4) { + } + + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java new file mode 100644 index 000000000..a108ef1bc --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java @@ -0,0 +1,284 @@ +package noppes.npcs.client.gui.script; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiConfirmOpenLink; +import net.minecraft.client.gui.GuiYesNoCallback; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.server.MinecraftServer; +import noppes.npcs.EventDataScript; +import noppes.npcs.EventScriptContainer; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.client.Client; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.EventGuiScriptList; +import noppes.npcs.client.gui.swing.GuiJTextArea; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.PlayerScriptData; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GuiScriptEvent extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener { + public boolean showScript = false; + private int activeTab = 0; + private String activeScriptTab = "init"; + private PlayerScriptData script = new PlayerScriptData((EntityPlayer)null); + public Map> languages = new HashMap>(); + + private static int activeConsole = 0; + + public GuiScriptEvent(){ + super(); + drawDefaultBackground = true; + closeOnEsc = true; + xSize = 420; + + setBackground("menubg.png"); + Client.sendData(EnumPacketServer.ScriptPlayerGet); + } + + public void initGui() { + super.initGui(); + guiTop += 10; + GuiMenuTopButton top; + addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); + top.active = showScript; + addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); + top.active = !showScript; + addTopButton(new GuiMenuTopButton(15, top, "gui.website")); + + List list = new ArrayList(); + list.add("playerscript.attack"); + list.add("playerscript.chat"); + list.add("playerscript.containerclosed"); + list.add("playerscript.containeropen"); + list.add("playerscript.damagedentity"); + list.add("playerscript.damaged"); + list.add("playerscript.killed"); + list.add("playerscript.init"); + list.add("playerscript.interact"); + list.add("playerscript.keypressed"); + list.add("playerscript.kills"); + list.add("playerscript.levelup"); + list.add("playerscript.login"); + list.add("playerscript.logout"); + list.add("playerscript.pickup"); + list.add("playerscript.rangedlaunched"); + list.add("playerscript.toss"); + list.add("playerscript.update"); + + if(showScript) { + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.setSize(68, 198); + hooks.guiLeft = guiLeft + 4; + hooks.guiTop = guiTop + 14; + hooks.setUnsortedList(list); + hooks.selected = script.getScripts().indexOf(activeScriptTab); + addScroll(hooks); + + EventScriptContainer container = script.getScripts().get(script.getScripts().indexOf(activeScriptTab)); + + addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); + + addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); + addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); + addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); + + addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); + + addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); + + GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); + scroll.setSize(100, 120); + scroll.guiLeft = guiLeft + 315; + scroll.guiTop = guiTop + 92; + if(container != null) + scroll.setList(container.scripts); + addScroll(scroll); + } + else{ + addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); + getTopButton(14).active = true; + addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); + getTextField(2).canEdit = false; + addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); + addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); + + List l = new ArrayList(); + l.add("All"); + l.addAll(list); + addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); + + addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); + addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); + getButton(103).enabled = languages.size() > 0; + + addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); + //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, script.enabled?1:0)); + + if(MinecraftServer.getServer() != null) + addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); + } + } + + private int getScriptIndex() { + int i = 0; + for(String language : languages.keySet()){ + if(language.equalsIgnoreCase(script.getLanguage())) + return i; + i++; + } + return 0; + } + + private String getConsoleText() { + String console = ""; + if(activeConsole == 0){ + for(EventScriptContainer container : script.scripts){ + if(!container.console.isEmpty()) + for(Long l : container.console.keySet()) + console += container.console.get(l) + '\n'; + } + } + else{ + EventScriptContainer container = script.scripts.get(activeConsole - 1); + if(container != null) + console = container.console.toString(); + } + return console; + } + + @Override + public void confirmClicked(boolean flag, int i){ + if(flag) + openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); + displayGuiScreen(this); + } + + @Override + protected void actionPerformed(GuiButton guibutton) { + if(guibutton.id == 13){ + showScript = true; + initGui(); + } + if(guibutton.id == 14){ + setScript(); + showScript = false; + initGui(); + } + if(guibutton.id == 15){ + GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true); + mc.displayGuiScreen(guiyesno); + } + if (guibutton.id == 100) { + NoppesStringUtils.setClipboardContents(getTextField(2).getText()); + } + if (guibutton.id == 101) { + getTextField(2).setText(NoppesStringUtils.getClipboardContents()); + } + if (guibutton.id == 102) { + getTextField(2).setText(""); + if(!showScript){ + if(activeConsole == 0){ + for(EventScriptContainer container : script.scripts) + for(Long l : container.console.keySet()) + container.console.put(l,""); + } + else{ + System.out.println("test"); + EventScriptContainer container = script.scripts.get(activeConsole - 1); + System.out.println("test2"); + if(container != null) + for(Long l : container.console.keySet()) + container.console.put(l,""); + } + } + } + if (guibutton.id == 103) { + script.setLanguage(((GuiNpcButton)guibutton).displayString); + } + if (guibutton.id == 104) { + script.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); + } + if (guibutton.id == 105) { + activeConsole = ((GuiNpcButton)guibutton).getValue(); + initGui(); + } + if (guibutton.id == 106) { + NoppesUtil.openFolder(ScriptController.Instance.dir); + } + if (guibutton.id == 107) { + EventScriptContainer container = script.scripts.get(activeTab); + if(container == null) + script.scripts.set(activeTab, container = new EventScriptContainer(new EventDataScript())); + setSubGui(new EventGuiScriptList(languages.get(script.getLanguage()), container)); + } + if (guibutton.id == 108) { + EventScriptContainer container = script.scripts.get(activeTab); + if(container != null){ + setScript(); + this.AWTWindow = new GuiJTextArea(container.script).setListener(this); + } + } + } + + private void setScript(){ + if(showScript){ + EventScriptContainer container = script.scripts.get(activeTab); + if(container == null) + script.scripts.set(activeTab, container = new EventScriptContainer(new EventDataScript())); + String text = getTextField(2).getText(); + text = text.replace("\r\n", "\n"); + text = text.replace("\r", "\n"); + container.script = text; + } + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + if(scroll.id == 1){ + setScript(); + activeTab = scroll.selected; + initGui(); + } + } + + @Override + public void saveText(String text) { + EventScriptContainer container = script.scripts.get(activeTab); + if(container != null) + container.script = text; + initGui(); + } + + @Override + public void setGuiData(NBTTagCompound compound) { + script.readFromNBT(compound); + NBTTagList data = compound.getTagList("Languages", 10); + Map> languages = new HashMap>(); + for(int i = 0; i < data.tagCount(); i++){ + NBTTagCompound comp = data.getCompoundTagAt(i); + List scripts = new ArrayList(); + NBTTagList list = comp.getTagList("Scripts", 8); + for(int j = 0; j < list.tagCount(); j++){ + scripts.add(list.getStringTagAt(j)); + } + languages.put(comp.getString("Language"), scripts); + } + this.languages = languages; + initGui(); + } + + @Override + public void save() { + Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java new file mode 100644 index 000000000..a1fa86401 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -0,0 +1,57 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.script; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.util.GuiNPCInterface; +import noppes.npcs.client.gui.util.GuiNpcButton; + +public class GuiScriptGlobal extends GuiNPCInterface { + private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png"); + + public GuiScriptGlobal() { + this.xSize = 176; + this.ySize = 222; + this.drawDefaultBackground = false; + this.title = ""; + } + + public void initGui() { + super.initGui(); + this.addButton(new GuiNpcButton(0, this.guiLeft + 38, this.guiTop + 20, 100, 20, "Players")); + //this.addButton(new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge")); + } + + public void drawScreen(int i, int j, float f) { + this.drawDefaultBackground(); + //GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.renderEngine.bindTexture(this.resource); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); + super.drawScreen(i, j, f); + } + + protected void actionPerformed(GuiButton guibutton) { + if (guibutton.id == 0) { + this.displayGuiScreen(new GuiScriptPlayers()); + } + /* + if (guibutton.id == 1) { + this.displayGuiScreen(new GuiScriptForge()); + } + */ + } + + public void keyTyped(char c, int i) { + if (i == 1 || this.isInventoryKey(i)) { + this.close(); + } + + } + + public void save() { + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java new file mode 100644 index 000000000..7e4c0676c --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -0,0 +1,317 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.script; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiConfirmOpenLink; +import net.minecraft.client.gui.GuiYesNo; +import net.minecraft.client.gui.GuiYesNoCallback; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.server.MinecraftServer; +import noppes.npcs.EventDataScript; +import noppes.npcs.EventScriptContainer; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.EventGuiScriptList; +import noppes.npcs.client.gui.swing.GuiJTextArea; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.IScriptHandler; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.PlayerScriptData; + +public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITextChangeListener, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener { + private int activeTab = 0; + public IScriptHandler handler; + private String activeScriptTab = "init"; + public Map> languages = new HashMap(); + + public boolean showScript = false; + private static int activeConsole = 0; + + public GuiScriptInterface() { + this.drawDefaultBackground = true; + this.closeOnEsc = true; + this.xSize = 420; + this.setBackground("menubg.png"); + } + + public void initGui() { + super.initGui(); + guiTop += 10; + GuiMenuTopButton top; + addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); + top.active = showScript; + addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); + top.active = !showScript; + addTopButton(new GuiMenuTopButton(15, top, "gui.website")); + + List list = new ArrayList(); + list.add("playerscript.attack"); + list.add("playerscript.chat"); + list.add("playerscript.containerclosed"); + list.add("playerscript.containeropen"); + list.add("playerscript.damagedentity"); + list.add("playerscript.damaged"); + list.add("playerscript.killed"); + list.add("playerscript.init"); + list.add("playerscript.interact"); + list.add("playerscript.keypressed"); + list.add("playerscript.kills"); + list.add("playerscript.levelup"); + list.add("playerscript.login"); + list.add("playerscript.logout"); + list.add("playerscript.pickup"); + list.add("playerscript.rangedlaunched"); + list.add("playerscript.toss"); + list.add("playerscript.update"); + + if(showScript) { + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.setSize(68, 198); + hooks.guiLeft = guiLeft + 4; + hooks.guiTop = guiTop + 14; + hooks.setUnsortedList(list); + hooks.selected = activeTab; + addScroll(hooks); + + EventScriptContainer container = handler.getScripts().get(activeTab); + + addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); + + addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); + addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); + addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); + + addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); + + addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); + + GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); + scroll.setSize(100, 120); + scroll.guiLeft = guiLeft + 315; + scroll.guiTop = guiTop + 92; + if(container != null) + scroll.setList(container.scripts); + addScroll(scroll); + } + else{ + addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); + getTopButton(14).active = true; + addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); + getTextField(2).canEdit = false; + addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); + addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); + + List l = new ArrayList(); + l.add("All"); + l.addAll(list); + addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); + + addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); + addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); + getButton(103).enabled = languages.size() > 0; + + addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); + //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, handler.enabled?1:0)); + + if(MinecraftServer.getServer() != null) + addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); + } + } + + private String getConsoleText() { + Map map = this.handler.getConsoleText(); + StringBuilder builder = new StringBuilder(); + Iterator var3 = map.entrySet().iterator(); + + while(var3.hasNext()) { + Entry entry = (Entry)var3.next(); + builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n"); + } + + return builder.toString(); + } + + private int getScriptIndex() { + int i = 0; + + for(Iterator var2 = this.languages.keySet().iterator(); var2.hasNext(); ++i) { + String language = (String)var2.next(); + if (language.equalsIgnoreCase(this.handler.getLanguage())) { + return i; + } + } + + return 0; + } + + public void func_73878_a(boolean flag, int i) { + if (flag) { + if (i == 0) { + this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); + } + + if (i == 1) { + this.openLink("http://www.kodevelopment.nl/customnpcs/api/"); + } + + if (i == 2) { + this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); + } + + if (i == 3) { + this.openLink("http://www.minecraftforge.net/forum/index.php/board,122.0.html"); + } + + if (i == 10) { + this.handler.getScripts().remove(this.activeTab - 1); + this.activeTab = 0; + } + } + + this.displayGuiScreen(this); + } + + protected void actionPerformed(GuiButton guibutton) { + if(guibutton.id == 13){ + showScript = true; + initGui(); + } + if(guibutton.id == 14){ + setScript(); + showScript = false; + initGui(); + } + if(guibutton.id == 15){ + GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true); + mc.displayGuiScreen(guiyesno); + } + if (guibutton.id == 100) { + NoppesStringUtils.setClipboardContents(getTextField(2).getText()); + } + if (guibutton.id == 101) { + getTextField(2).setText(NoppesStringUtils.getClipboardContents()); + } + if (guibutton.id == 102) { + getTextField(2).setText(""); + if(!showScript){ + if(activeConsole == 0){ + for(EventScriptContainer container : handler.getScripts()) + for(Long l : container.console.keySet()) + container.console.put(l,""); + } + else{ + System.out.println("test"); + EventScriptContainer container = handler.getScripts().get(activeConsole - 1); + System.out.println("test2"); + if(container != null) + for(Long l : container.console.keySet()) + container.console.put(l,""); + } + } + } + if (guibutton.id == 103) { + handler.setLanguage(((GuiNpcButton)guibutton).displayString); + } + if (guibutton.id == 104) { + handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); + } + if (guibutton.id == 105) { + activeConsole = ((GuiNpcButton)guibutton).getValue(); + initGui(); + } + if (guibutton.id == 106) { + NoppesUtil.openFolder(ScriptController.Instance.dir); + } + if (guibutton.id == 107) { + EventScriptContainer container = handler.getScripts().get(activeTab); + if(container == null) + handler.getScripts().set(activeTab, container = new EventScriptContainer(new EventDataScript())); + setSubGui(new EventGuiScriptList(languages.get(handler.getLanguage()), container)); + } + if (guibutton.id == 108) { + EventScriptContainer container = handler.getScripts().get(activeTab); + if(container != null){ + setScript(); + this.AWTWindow = new GuiJTextArea(container.script).setListener(this); + } + } + } + + private void setScript() { + if (this.activeTab > 0) { + EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if (container == null) { + this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); + } + + String text = this.getConsoleText(); + text = text.replace("\r\n", "\n"); + text = text.replace("\r", "\n"); + container.script = text; + } + + } + + public void setGuiData(NBTTagCompound compound) { + NBTTagList data = compound.getTagList("Languages", 10); + Map> languages = new HashMap(); + + for(int i = 0; i < data.tagCount(); ++i) { + NBTTagCompound comp = data.getCompoundTagAt(i); + List scripts = new ArrayList(); + NBTTagList list = comp.getTagList("Scripts", 8); + + for(int j = 0; j < list.tagCount(); ++j) { + scripts.add(list.getStringTagAt(j)); + } + + languages.put(comp.getString("Language"), scripts); + } + + this.languages = languages; + this.initGui(); + } + + public void save() { + this.setScript(); + } + + public void textUpdate(String text) { + EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if (container != null) { + container.script = text; + } + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + if(scroll.id == 1){ + setScript(); + activeTab = scroll.selected; + initGui(); + } + } + + @Override + public void saveText(String text) { + EventScriptContainer container = handler.getScripts().get(activeTab); + if(container != null) + container.script = text; + initGui(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java new file mode 100644 index 000000000..026d6661b --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -0,0 +1,31 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.script; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.client.Client; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.PlayerScriptData; + +public class GuiScriptPlayers extends GuiScriptInterface { + private PlayerScriptData script = new PlayerScriptData((EntityPlayer)null); + + public GuiScriptPlayers() { + this.handler = this.script; + Client.sendData(EnumPacketServer.ScriptPlayerGet, new Object[0]); + } + + public void setGuiData(NBTTagCompound compound) { + this.script.readFromNBT(compound); + super.setGuiData(compound); + } + + public void save() { + super.save(); + Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/util/ITextChangeListener.java b/src/main/java/noppes/npcs/client/gui/util/ITextChangeListener.java new file mode 100644 index 000000000..7a5a2d302 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/ITextChangeListener.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface ITextChangeListener { + void textUpdate(String var1); +} diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index c15f88eda..ea1d395c1 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -34,6 +34,9 @@ public enum EnumPacketServer { ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, + ScriptPlayerSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptPlayerGet(false), + LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED), ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true), PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA), diff --git a/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java b/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java index 5577cd847..3ddf2d0d1 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java +++ b/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java @@ -2,10 +2,15 @@ package noppes.npcs.containers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; import net.minecraft.util.MathHelper; +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.ScriptContainer; public class ContainerNpcInterface extends Container{ private int posX, posZ; + public EntityPlayer player; + public IContainer scriptContainer; public ContainerNpcInterface(EntityPlayer player){ posX = MathHelper.floor_double(player.posX); @@ -18,4 +23,11 @@ public class ContainerNpcInterface extends Container{ return !player.isDead && posX == MathHelper.floor_double(player.posX) && posZ == MathHelper.floor_double(player.posZ); } + public static IContainer getOrCreateIContainer(ContainerNpcInterface container) { + if (container.scriptContainer != null) { + return container.scriptContainer; + } else { + return container.scriptContainer = new ScriptContainer(container); + } + } } diff --git a/src/main/java/noppes/npcs/controllers/PlayerData.java b/src/main/java/noppes/npcs/controllers/PlayerData.java index 675c0d089..29d4420fd 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/PlayerData.java @@ -3,9 +3,12 @@ package noppes.npcs.controllers; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; +import noppes.npcs.CustomNpcs; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.data.PlayerScriptData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleCompanion; @@ -18,7 +21,8 @@ public class PlayerData implements IExtendedEntityProperties{ public PlayerFactionData factionData = new PlayerFactionData(); public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); public PlayerMailData mailData = new PlayerMailData(); - + public PlayerScriptData scriptData; + public EntityNPCInterface editingNpc; public NBTTagCompound cloned; @@ -138,4 +142,20 @@ public class PlayerData implements IExtendedEntityProperties{ world.spawnEntityInWorld(npc); } + public static PlayerData get(EntityPlayer player) { + if(player.worldObj.isRemote) { + return CustomNpcs.proxy.getPlayerData(player); + } else { + PlayerData data = new PlayerData(); + if(data.player == null) { + data.player = player; + data.scriptData = new PlayerScriptData(player); + NBTTagCompound compound = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName()); + + data.setNBT(compound); + } + + return data; + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java deleted file mode 100644 index 8e799073e..000000000 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ /dev/null @@ -1,289 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs.controllers.data; - -import java.io.File; -import java.io.FileInputStream; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityInject; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.event.AttachCapabilitiesEvent; -import noppes.npcs.CustomNpcs; -import noppes.npcs.LogWriter; -import noppes.npcs.controllers.data.PlayerBankData; -import noppes.npcs.controllers.data.PlayerDialogData; -import noppes.npcs.controllers.data.PlayerFactionData; -import noppes.npcs.controllers.data.PlayerItemGiverData; -import noppes.npcs.controllers.data.PlayerMailData; -import noppes.npcs.controllers.data.PlayerQuestData; -import noppes.npcs.controllers.data.PlayerScriptData; -import noppes.npcs.controllers.data.PlayerTransportData; -import noppes.npcs.entity.EntityCustomNpc; -import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.entity.data.DataTimers; -import noppes.npcs.roles.RoleCompanion; -import noppes.npcs.util.CustomNPCsScheduler; -import noppes.npcs.util.NBTJsonUtil; - -public class PlayerData implements ICapabilityProvider { - @CapabilityInject(PlayerData.class) - public static Capability PLAYERDATA_CAPABILITY = null; - public PlayerDialogData dialogData = new PlayerDialogData(); - public PlayerBankData bankData = new PlayerBankData(); - public PlayerQuestData questData = new PlayerQuestData(); - public PlayerTransportData transportData = new PlayerTransportData(); - public PlayerFactionData factionData = new PlayerFactionData(); - public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); - public PlayerMailData mailData = new PlayerMailData(); - public PlayerScriptData scriptData; - public DataTimers timers = new DataTimers(this); - public EntityNPCInterface editingNpc; - public NBTTagCompound cloned; - public NBTTagCompound scriptStoreddata = new NBTTagCompound(); - public EntityPlayer player; - public String playername = ""; - public String uuid = ""; - private EntityNPCInterface activeCompanion = null; - public int companionID = 0; - public int playerLevel = 0; - public boolean updateClient = false; - public int dialogId = -1; - private static final ResourceLocation key = new ResourceLocation("customnpcs", "playerdata"); - - public PlayerData() { - } - - public void setNBT(NBTTagCompound data) { - this.dialogData.loadNBTData(data); - this.bankData.loadNBTData(data); - this.questData.loadNBTData(data); - this.transportData.loadNBTData(data); - this.factionData.loadNBTData(data); - this.itemgiverData.loadNBTData(data); - this.mailData.loadNBTData(data); - this.timers.readFromNBT(data); - if(this.player != null) { - this.playername = this.player.func_70005_c_(); - this.uuid = this.player.getPersistentID().toString(); - } else { - this.playername = data.func_74779_i("PlayerName"); - this.uuid = data.func_74779_i("UUID"); - } - - this.companionID = data.func_74762_e("PlayerCompanionId"); - if(data.func_74764_b("PlayerCompanion") && !this.hasCompanion()) { - EntityCustomNpc npc = new EntityCustomNpc(this.player.field_70170_p); - npc.func_70037_a(data.func_74775_l("PlayerCompanion")); - npc.func_70107_b(this.player.field_70165_t, this.player.field_70163_u, this.player.field_70161_v); - if(npc.advanced.role == 6) { - this.setCompanion(npc); - ((RoleCompanion)npc.roleInterface).setSitting(false); - this.player.field_70170_p.func_72838_d(npc); - } - } - - this.scriptStoreddata = data.func_74775_l("ScriptStoreddata"); - } - - public NBTTagCompound getSyncNBT() { - NBTTagCompound compound = new NBTTagCompound(); - this.dialogData.saveNBTData(compound); - this.questData.saveNBTData(compound); - this.factionData.saveNBTData(compound); - return compound; - } - - public NBTTagCompound getNBT() { - if(this.player != null) { - this.playername = this.player.func_70005_c_(); - this.uuid = this.player.getPersistentID().toString(); - } - - NBTTagCompound compound = new NBTTagCompound(); - this.dialogData.saveNBTData(compound); - this.bankData.saveNBTData(compound); - this.questData.saveNBTData(compound); - this.transportData.saveNBTData(compound); - this.factionData.saveNBTData(compound); - this.itemgiverData.saveNBTData(compound); - this.mailData.saveNBTData(compound); - this.timers.writeToNBT(compound); - compound.func_74778_a("PlayerName", this.playername); - compound.func_74778_a("UUID", this.uuid); - compound.func_74768_a("PlayerCompanionId", this.companionID); - compound.func_74782_a("ScriptStoreddata", this.scriptStoreddata); - if(this.hasCompanion()) { - NBTTagCompound nbt = new NBTTagCompound(); - if(this.activeCompanion.func_184198_c(nbt)) { - compound.func_74782_a("PlayerCompanion", nbt); - } - } - - return compound; - } - - public boolean hasCompanion() { - return this.activeCompanion != null && !this.activeCompanion.field_70128_L; - } - - public void setCompanion(EntityNPCInterface npc) { - if(npc == null || npc.advanced.role == 6) { - ++this.companionID; - this.activeCompanion = npc; - if(npc != null) { - ((RoleCompanion)npc.roleInterface).companionID = this.companionID; - } - - this.save(false); - } - } - - public void updateCompanion(World world) { - if(this.hasCompanion() && world != this.activeCompanion.field_70170_p) { - RoleCompanion role = (RoleCompanion)this.activeCompanion.roleInterface; - role.owner = this.player; - if(role.isFollowing()) { - NBTTagCompound nbt = new NBTTagCompound(); - this.activeCompanion.func_184198_c(nbt); - this.activeCompanion.field_70128_L = true; - EntityCustomNpc npc = new EntityCustomNpc(world); - npc.func_70037_a(nbt); - npc.func_70107_b(this.player.field_70165_t, this.player.field_70163_u, this.player.field_70161_v); - this.setCompanion(npc); - ((RoleCompanion)npc.roleInterface).setSitting(false); - world.func_72838_d(npc); - } - } - } - - public boolean hasCapability(Capability capability, EnumFacing facing) { - return capability == PLAYERDATA_CAPABILITY; - } - - public T getCapability(Capability capability, EnumFacing facing) { - return this.hasCapability(capability, facing)?this:null; - } - - public static void register(AttachCapabilitiesEvent event) { - if(event.getObject() instanceof EntityPlayer) { - event.addCapability(key, new PlayerData()); - } - - } - - public synchronized void save(boolean update) { - NBTTagCompound compound = this.getNBT(); - String filename = this.uuid + ".json"; - CustomNPCsScheduler.runTack(() -> { - try { - File e = CustomNpcs.getWorldSaveDirectory("playerdata"); - File file = new File(e, filename + "_new"); - File file1 = new File(e, filename); - NBTJsonUtil.SaveFile(file, compound); - if(file1.exists()) { - file1.delete(); - } - - file.renameTo(file1); - } catch (Exception var5) { - LogWriter.except(var5); - } - - }); - if(update) { - this.updateClient = true; - } - - } - - public static NBTTagCompound loadPlayerDataOld(String player) { - File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata"); - String filename = player; - if(player.isEmpty()) { - filename = "noplayername"; - } - - filename = filename + ".dat"; - - File e; - try { - e = new File(saveDir, filename); - if(e.exists()) { - NBTTagCompound comp = CompressedStreamTools.func_74796_a(new FileInputStream(e)); - e.delete(); - e = new File(saveDir, filename + "_old"); - if(e.exists()) { - e.delete(); - } - - return comp; - } - } catch (Exception var6) { - LogWriter.except(var6); - } - - try { - e = new File(saveDir, filename + "_old"); - if(e.exists()) { - return CompressedStreamTools.func_74796_a(new FileInputStream(e)); - } - } catch (Exception var5) { - LogWriter.except(var5); - } - - return new NBTTagCompound(); - } - - public static NBTTagCompound loadPlayerData(String player) { - File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata"); - String filename = player; - if(player.isEmpty()) { - filename = "noplayername"; - } - - filename = filename + ".json"; - File file = null; - - try { - file = new File(saveDir, filename); - if(file.exists()) { - return NBTJsonUtil.LoadFile(file); - } - } catch (Exception var5) { - LogWriter.error("Error loading: " + file.getAbsolutePath(), var5); - } - - return new NBTTagCompound(); - } - - public static PlayerData get(EntityPlayer player) { - if(player.field_70170_p.field_72995_K) { - return CustomNpcs.proxy.getPlayerData(player); - } else { - PlayerData data = (PlayerData)player.getCapability(PLAYERDATA_CAPABILITY, (EnumFacing)null); - if(data.player == null) { - data.player = player; - data.playerLevel = player.field_71068_ca; - data.scriptData = new PlayerScriptData(player); - NBTTagCompound compound = loadPlayerData(player.getPersistentID().toString()); - if(compound.func_82582_d()) { - compound = loadPlayerDataOld(player.func_70005_c_()); - } - - data.setNBT(compound); - } - - return data; - } - } -} diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java b/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java index 3935bb78e..dbc26740e 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java @@ -5,13 +5,11 @@ package noppes.npcs.controllers.data; -import com.google.common.base.MoreObjects; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.lang.reflect.Array; +import java.util.*; import java.util.Map.Entry; + +import com.google.common.base.Preconditions; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; @@ -24,8 +22,10 @@ import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; +import javax.annotation.CheckForNull; + public class PlayerScriptData implements IScriptHandler { - private List scripts = new ArrayList(); + public List scripts = new ArrayList(); private String scriptLanguage = "ECMAScript"; private EntityPlayer player; private ScriptPlayer playerAPI; @@ -137,12 +137,209 @@ public class PlayerScriptData implements IScriptHandler { return this.scripts; } + public static final class ToStringHelper { + private final String className; + private final PlayerScriptData.ToStringHelper.ValueHolder holderHead; + private PlayerScriptData.ToStringHelper.ValueHolder holderTail; + private boolean omitNullValues; + private boolean omitEmptyValues; + + private ToStringHelper(String className) { + this.holderHead = new PlayerScriptData.ToStringHelper.ValueHolder(); + this.holderTail = this.holderHead; + this.omitNullValues = false; + this.omitEmptyValues = false; + this.className = (String) Preconditions.checkNotNull(className); + } + + public PlayerScriptData.ToStringHelper omitNullValues() { + this.omitNullValues = true; + return this; + } + + public PlayerScriptData.ToStringHelper add(String name, @CheckForNull Object value) { + return this.addHolder(name, value); + } + + public PlayerScriptData.ToStringHelper add(String name, boolean value) { + return this.addUnconditionalHolder(name, String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper add(String name, char value) { + return this.addUnconditionalHolder(name, String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper add(String name, double value) { + return this.addUnconditionalHolder(name, String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper add(String name, float value) { + return this.addUnconditionalHolder(name, String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper add(String name, int value) { + return this.addUnconditionalHolder(name, String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper add(String name, long value) { + return this.addUnconditionalHolder(name, String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper addValue(@CheckForNull Object value) { + return this.addHolder(value); + } + + public PlayerScriptData.ToStringHelper addValue(boolean value) { + return this.addUnconditionalHolder(String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper addValue(char value) { + return this.addUnconditionalHolder(String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper addValue(double value) { + return this.addUnconditionalHolder(String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper addValue(float value) { + return this.addUnconditionalHolder(String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper addValue(int value) { + return this.addUnconditionalHolder(String.valueOf(value)); + } + + public PlayerScriptData.ToStringHelper addValue(long value) { + return this.addUnconditionalHolder(String.valueOf(value)); + } + + private static boolean isEmpty(Object value) { + if (value instanceof CharSequence) { + return ((CharSequence)value).length() == 0; + } else if (value instanceof Collection) { + return ((Collection)value).isEmpty(); + } else if (value instanceof Map) { + return ((Map)value).isEmpty(); + } else if (value instanceof Optional) { + return !((Optional)value).isPresent(); + } else if (value instanceof OptionalInt) { + return !((OptionalInt)value).isPresent(); + } else if (value instanceof OptionalLong) { + return !((OptionalLong)value).isPresent(); + } else if (value instanceof OptionalDouble) { + return !((OptionalDouble)value).isPresent(); + } else if (value instanceof com.google.common.base.Optional) { + return !((com.google.common.base.Optional)value).isPresent(); + } else if (value.getClass().isArray()) { + return Array.getLength(value) == 0; + } else { + return false; + } + } + + public String toString() { + boolean omitNullValuesSnapshot = this.omitNullValues; + boolean omitEmptyValuesSnapshot = this.omitEmptyValues; + String nextSeparator = ""; + StringBuilder builder = (new StringBuilder(32)).append(this.className).append('{'); + + for(PlayerScriptData.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { + Object value = valueHolder.value; + if (!(valueHolder instanceof PlayerScriptData.ToStringHelper.UnconditionalValueHolder)) { + if (value == null) { + if (omitNullValuesSnapshot) { + continue; + } + } else if (omitEmptyValuesSnapshot && isEmpty(value)) { + continue; + } + } + + builder.append(nextSeparator); + nextSeparator = ", "; + if (valueHolder.name != null) { + builder.append(valueHolder.name).append('='); + } + + if (value != null && value.getClass().isArray()) { + Object[] objectArray = new Object[]{value}; + String arrayString = Arrays.deepToString(objectArray); + builder.append(arrayString, 1, arrayString.length() - 1); + } else { + builder.append(value); + } + } + + return builder.append('}').toString(); + } + + private PlayerScriptData.ToStringHelper.ValueHolder addHolder() { + PlayerScriptData.ToStringHelper.ValueHolder valueHolder = new PlayerScriptData.ToStringHelper.ValueHolder(); + this.holderTail = this.holderTail.next = valueHolder; + return valueHolder; + } + + private PlayerScriptData.ToStringHelper addHolder(@CheckForNull Object value) { + PlayerScriptData.ToStringHelper.ValueHolder valueHolder = this.addHolder(); + valueHolder.value = value; + return this; + } + + private PlayerScriptData.ToStringHelper addHolder(String name, @CheckForNull Object value) { + PlayerScriptData.ToStringHelper.ValueHolder valueHolder = this.addHolder(); + valueHolder.value = value; + valueHolder.name = (String)Preconditions.checkNotNull(name); + return this; + } + + private PlayerScriptData.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() { + PlayerScriptData.ToStringHelper.UnconditionalValueHolder valueHolder = new PlayerScriptData.ToStringHelper.UnconditionalValueHolder(); + this.holderTail = this.holderTail.next = valueHolder; + return valueHolder; + } + + private PlayerScriptData.ToStringHelper addUnconditionalHolder(Object value) { + PlayerScriptData.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); + valueHolder.value = value; + return this; + } + + private PlayerScriptData.ToStringHelper addUnconditionalHolder(String name, Object value) { + PlayerScriptData.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); + valueHolder.value = value; + valueHolder.name = (String)Preconditions.checkNotNull(name); + return this; + } + + private static final class UnconditionalValueHolder extends PlayerScriptData.ToStringHelper.ValueHolder { + private UnconditionalValueHolder() { + super(); + } + } + + private static class ValueHolder { + @CheckForNull + String name; + @CheckForNull + Object value; + @CheckForNull + PlayerScriptData.ToStringHelper.ValueHolder next; + + private ValueHolder() { + } + } + } + + public static PlayerScriptData.ToStringHelper toStringHelper(Object self) { + return new PlayerScriptData.ToStringHelper(self.getClass().getSimpleName()); + } + public String noticeString() { if(this.player == null) { return "Global script"; } else { BlockPos pos = new BlockPos(this.player); - return MoreObjects.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); + return PlayerScriptData.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index c8e4731d2..2108e317e 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -98,14 +98,12 @@ import noppes.npcs.roles.JobInterface; import noppes.npcs.roles.RoleCompanion; import noppes.npcs.roles.RoleFollower; import noppes.npcs.roles.RoleInterface; -import noppes.npcs.scripted.ScriptEventAttack; -import noppes.npcs.scripted.ScriptEventDamaged; -import noppes.npcs.scripted.ScriptEventKilled; -import noppes.npcs.scripted.ScriptEventTarget; +import noppes.npcs.scripted.*; import noppes.npcs.util.GameProfileAlt; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; public abstract class EntityNPCInterface extends EntityCreature implements IEntityAdditionalSpawnData, ICommandSender, IRangedAttackMob, IBossDisplayData{ + public ICustomNpc wrappedNPC; private static final GameProfileAlt chateventProfile = new GameProfileAlt(); private static FakePlayer chateventPlayer; @@ -133,6 +131,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti private int taskCount = 1; public int lastInteract = 0; + public static FakePlayer CommandPlayer; + public Faction faction; //should only be used server side private EntityAIRangedAttack aiRange; @@ -170,6 +170,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti setFaction(faction.id); setSize(1, 1); this.updateTasks(); + + if (!this.isRemote()) { + this.wrappedNPC = new ScriptNpc(this); + } } catch(Exception e){ e.printStackTrace(); @@ -1512,7 +1516,18 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti } display.readToNBT(compound); } - + + public Entity func_174793_f() { + if (this.worldObj.isRemote) { + return this; + } else { + EntityUtil.Copy(this, CommandPlayer); + CommandPlayer.setWorld(this.worldObj); + CommandPlayer.setPosition(this.posX, this.posY, this.posZ); + return CommandPlayer; + } + } + @Override public String getCommandSenderName() { return display.name; diff --git a/src/main/java/noppes/npcs/scripted/CustomNPCsException.java b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java new file mode 100644 index 000000000..7952cd18d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/CustomNPCsException.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +public class CustomNPCsException extends RuntimeException { + public CustomNPCsException(String message, Object... obs) { + super(String.format(message, obs)); + } + + public CustomNPCsException(Exception ex, String message, Object... obs) { + super(String.format(message, obs), ex); + } +} diff --git a/src/main/java/noppes/npcs/scripted/IContainer.java b/src/main/java/noppes/npcs/scripted/IContainer.java new file mode 100644 index 000000000..1d0862d7a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IContainer.java @@ -0,0 +1,25 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; + +public interface IContainer { + int getSize(); + + IItemStack getSlot(int var1); + + void setSlot(int slot, IItemStack item); + + IInventory getMCInventory(); + + Container getMCContainer(); + + int count(IItemStack var1, boolean var2, boolean var3); + + IItemStack[] getItems(); +} diff --git a/src/main/java/noppes/npcs/scripted/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/ICustomNpc.java new file mode 100644 index 000000000..814b3536b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ICustomNpc.java @@ -0,0 +1,393 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.entity.EntityCreature; +import net.minecraft.item.ItemStack; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.constants.EnumAnimation; +import noppes.npcs.constants.EnumJobType; +import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.Line; +import noppes.npcs.scripted.IItemStack; +import noppes.npcs.scripted.constants.AnimationType; +import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.roles.*; +import noppes.npcs.util.ValueUtil; + +public interface ICustomNpc { + /** + * @return Returns the current npcs size 1-30 + */ + public int getSize(); + + /** + * @param size The size of the npc (1-30) default is 5 + */ + public void setSize(int size); + + /** + * @return Returns the current npcs modelType of the NPC + */ + public int getModelType(); + + /** + * @param modelType The modelType of the NPC. 0: Steve, 1: Steve64, 2: Alex + */ + public void setModelType(int modelType); + + /** + * @return The npcs name + */ + public String getName(); + + public void setRotation(float rotation); + /** + * @param name The name of the npc + */ + public void setName(String name); + + /** + * @since 1.7.10 + * @return The npcs title + */ + public String getTitle(); + + /** + * @since 1.7.10 + * @param title The title of the npc + */ + public void setTitle(String title); + + /** + * @return The npcs texture + */ + public String getTexture(); + + /** + * @param texture The texture of the npc + */ + public void setTexture(String texture); + + /** + * @return Home position x + */ + public int getHomeX(); + + /** + * @param x The home x position + */ + public void setHomeX(int x); + + /** + * @return Home position x + */ + public int getHomeY(); + + /** + * @param y The home y position + */ + public void setHomeY(int y); + + /** + * @return Home position x + */ + public int getHomeZ(); + + /** + * @param z The home x position + */ + public void setHomeZ(int z); + + /** + * @param x The home x position + * @param y The home y position + * @param z The home z position + */ + public void setHome(int x, int y, int z); + /** + * @param health New max health + */ + public void setMaxHealth(int health); + + /** + * @param bo Whether or not the npc will try to return to his home position + */ + public void setReturnToHome(boolean bo); + + /** + * @return Whether or not the npc returns home + */ + public boolean getReturnToHome(); + + /** + * @return The faction of the npc + */ + public ScriptFaction getFaction(); + + /** + * @param id The id of the new faction + */ + public void setFaction(int id); + + public int getType(); + + public boolean typeOf(int type); + + /** + * @param target The targeted npc + * @param item The item you want to shoot + * @param accuracy Accuracy of the shot (0-100) + */ + public void shootItem(ScriptLivingBase target, ScriptItemStack item, int accuracy); + + /** + * @param message The message the npc will say + */ + public void say(String message); + + /** + * @param message The message the npc will say + */ + public void say(ScriptPlayer player, String message); + + /** + * Kill the npc, doesnt't despawn it + */ + public void kill(); + + /** + * Basically completely resets the npc. This will also call the Init script + */ + public void reset(); + + /** + * @return Returns the npcs current role + */ + public ScriptRoleInterface getRole(); + + /** + * @return Returns the npcs current job + */ + public ScriptJobInterface getJob(); + + /** + * @return The item held in the right hand + */ + public ScriptItemStack getRightItem(); + + /** + * @param item Item to be held in the right hand + */ + public void setRightItem(ScriptItemStack item); + + /** + * @return The item held in the left hand + */ + public ScriptItemStack getLefttItem(); + + /** + * @param item Item to be held in the left hand + */ + public void setLeftItem(ScriptItemStack item); + + /** + * @return Returns the projectile the npc uses + */ + public ScriptItemStack getProjectileItem(); + + /** + * @param item Item to be used as projectile + */ + public void setProjectileItem(ScriptItemStack item); + + /** + * @param slot The armor slot to return. 0:head, 1:body, 2:legs, 3:boots + * @return Returns the worn armor in slot + */ + public ScriptItemStack getArmor(int slot); + + /** + * @param slot The armor slot to set. 0:head, 1:body, 2:legs, 3:boots + * @param item Item to be set as armor + */ + public void setArmor(int slot, ScriptItemStack item); + + /** + * @param type The AnimationType + */ + public void setAnimation(int type); + + /** + * @param type The visibility type of the npc, 0:visible, 1:invisible, 2:semi-visible + */ + public void setVisibleType(int type); + + /** + * @return The visibility type of the npc, 0:visible, 1:invisible, 2:semi-visible + */ + public int getVisibleType(); + + /** + * @param type The visibility type of the name, 0:visible, 1:invisible, 2:when-attacking + */ + public void setShowName(int type); + + /** + * @return Returns the visibility type of the name, 0:visible, 1:invisible, 2:when-attacking + */ + public int getShowName(); + + /** + * @return Returns the visiblity of the boss bar, 0:invisible, 1:visible, 2:when-attacking + */ + public int getShowBossBar(); + + /** + * @param type The visibility type of the boss bar, 0:invisible, 1:visible, 2:when-attacking + */ + public void setShowBossBar(int type); + + /** + * @return The melee strength + */ + public int getMeleeStrength(); + + /** + * @param strength The melee strength + */ + public void setMeleeStrength(int strength); + + /** + * @return The melee speed + */ + public int getMeleeSpeed(); + + /** + * @param speed The melee speed + */ + public void setMeleeSpeed(int speed); + + /** + * @return The ranged strength + */ + public int getRangedStrength(); + + /** + * @param strength The ranged strength + */ + public void setRangedStrength(int strength); + + /** + * @return The ranged speed + */ + public int getRangedSpeed(); + + /** + * @param speed The ranged speed + */ + public void setRangedSpeed(int speed); + + /** + * @return The ranged burst count + */ + public int getRangedBurst(); + + /** + * @param count The ranged burst count + */ + public void setRangedBurst(int count); + + /** + * @param player The player to give the item to + * @param item The item given to the player + */ + public void giveItem(ScriptPlayer player, ScriptItemStack item); + + + /** + * On servers the enable-command-block option in the server.properties needs to be set to true + * @param command The command to be executed + */ + public void executeCommand(String command); + + public void setHeadScale(float x, float y, float z); + + public void setBodyScale(float x, float y, float z); + + public void setArmsScale(float x, float y, float z); + + public void setLegsScale(float x, float y, float z); + + /** + * @since 1.7.10c + * @param resistance Explosion resistance (0-2) default is 1 + */ + public void setExplosionResistance(float resistance); + + /** + * @since 1.7.10c + * @return Returns Explosion Resistance + */ + public float getExplosionResistance(); + + /** + * @param resistance Melee resistance (0-2) default is 1 + */ + public void setMeleeResistance(float resistance); + + /** + * @return Returns Melee Resistance + */ + public float getMeleeResistance(); + + /** + * @param resistance Arrow resistance (0-2) default is 1 + */ + public void setArrowResistance(float resistance); + + /** + * @return Returns Arrow Resistance + */ + public float getArrowResistance(); + + /** + * @param resistance Knockback resistance (0-2) default is 1 + */ + public void setKnockbackResistance(float resistance); + + /** + * @return Returns Knockback Resistance + */ + public float getKnockbackResistance(); + + /** + * @param type Retaliation type. 0:normal, 1:panic, 2:retreat, 3:nothing + */ + public void setRetaliateType(int type); + + /** + * @return Returns the combat health regen per second + */ + public int getCombatRegen(); + + /** + * @param regen The combat health regen per second + */ + public void setCombatRegen(int regen); + + /** + * @return Returns the health regen per second when not in combat + */ + public int getHealthRegen(); + + /** + * @param regen The health regen per second when not in combat + */ + public void setHealthRegen(int regen); + + public long getAge(); +} diff --git a/src/main/java/noppes/npcs/scripted/IDamageSource.java b/src/main/java/noppes/npcs/scripted/IDamageSource.java new file mode 100644 index 000000000..2d7ab3e4a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IDamageSource.java @@ -0,0 +1,20 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.util.DamageSource; + +public interface IDamageSource { + String getType(); + + boolean isProjectile(); + + IEntity getTrueSource(); + + IEntity getImmediateSource(); + + DamageSource getMCDamageSource(); +} diff --git a/src/main/java/noppes/npcs/scripted/IEntity.java b/src/main/java/noppes/npcs/scripted/IEntity.java new file mode 100644 index 000000000..6a8d8f07f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IEntity.java @@ -0,0 +1,326 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.IItemStack; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.ScriptEntity; +import noppes.npcs.scripted.ScriptEntityParticle; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.constants.EntityType; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public interface IEntity { + /** + * @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" + * @param HEXcolor The particle's color as a HEX integer + * @param amount The amount of particles to spawn + * @param maxAge The particle's maximum age in MC ticks + + * @param x The particle's x position + * @param y The particle's y position + * @param z The particle's z position + + * @param motionX The particle's speed in the x axis + * @param motionY The particle's speed in the y axis + * @param motionZ The particle's speed in the z axis + * @param gravity The particle's gravity + + * @param scale1 The particle's starting scale + * @param scale2 The particle's ending scale + * @param scaleRate Multiplier for the particle's scale growth rate + * @param scaleRateStart The time at which the particle begins growing/shrinking + + * @param alpha1 The particle's starting transparency + * @param alpha2 The particle's ending transparency + * @param scaleRate Multiplier for the particle's transparency growth rate + * @param alphaRateStart The time at which the particle begins appearing/fading + */ + public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge, + double x, double y, double z, + double motionX, double motionY, double motionZ, float gravity, + float scale1, float scale2, float scaleRate, int scaleRateStart, + float alpha1, float alpha2, float alphaRate, int alphaRateStart + ); + + public double getYOffset(); + + /** + * @return The entities width + */ + public double getWidth(); + + /** + * @return The entities height + */ + public double getHeight(); + + /** + * @return The entities x position + */ + public double getX(); + + /** + * @param x The entities x position + */ + public void setX(double x); + + /** + * @return The entities y position + */ + public double getY(); + + /** + * @param y The entities y position + */ + public void setY(double y); + + /** + * @return The entities x position + */ + public double getZ(); + + /** + * @param z The entities x position + */ + public void setZ(double z); + + /** + * @return The block x position + */ + public int getBlockX(); + + /** + * @return The block y position + */ + public int getBlockY(); + + /** + * @return The block z position + */ + public int getBlockZ(); + + /** + * @param x The x position + * @param y The y position + * @param z The z position + */ + public void setPosition(double x, double y, double z); + + + /** + * @param range The search range for entities around this entity + * @return Array of entities within range + */ + public ScriptEntity[] getSurroundingEntities(int range); + + /** + * @param range The search range for entities around this entity + * @param type The EntityType you want to find + * @return Array of entities within range + */ + public ScriptEntity[] getSurroundingEntities(int range, int type); + + /** + * @return Whether the entity is alive or not + */ + public boolean isAlive(); + + /** + * @param key Get temp data for this key + * @return Returns the stored temp data + */ + public Object getTempData(String key); + + /** + * Tempdata gets cleared when the entity gets unloaded or the world restarts + * @param key The key for the data stored + * @param value The data stored + */ + public void setTempData(String key, Object value); + + /** + * @param key The key thats going to be tested against the temp data + * @return Whether or not temp data containes the key + */ + public boolean hasTempData(String key); + + /** + * @param key The key for the temp data to be removed + */ + public void removeTempData(String key); + + /** + * Remove all tempdata + */ + public void clearTempData(); + + /** + * @param key The key of the data to be returned + * @return Returns the stored data + */ + public Object getStoredData(String key); + + /** + * Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved + * @param key The key for the data stored + * @param value The data stored. This data can be either a Number or a String. Other data is not stored + */ + public void setStoredData(String key, Object value); + + /** + * @param key The key of the data to be checked + * @return Returns whether or not the stored data contains the key + */ + public boolean hasStoredData(String key); + + /** + * @param key The key of the data to be removed + */ + public void removeStoredData(String key); + + /** + * Remove all stored data + */ + public void clearStoredData(); + + /** + * @return The age of this entity in ticks + */ + public long getAge(); + + /** + * Despawns this entity. Removes it permanently + */ + public void despawn(); + + /** + * @return Return whether or not this entity is standing in water + */ + public boolean inWater(); + + /** + * @return Return whether or not this entity is standing in lava + */ + public boolean inLava(); + + /** + * @return Return whether or not this entity is standing in fire + */ + public boolean inFire(); + + /** + * @return Return whether or not this entity is on fire + */ + public boolean isBurning(); + + /** + * @param ticks Amount of world ticks this entity will burn. 20 ticks equals 1 second + */ + public void setBurning(int ticks); + + /** + * Removes fire from this entity + */ + public void extinguish(); + + /** + * @return Name as which it's registered in minecraft + */ + public String getTypeName(); + + /** + * @param item Item to be dropped + */ + public void dropItem(ScriptItemStack item); + + /** + * @return Return the rider + */ + public ScriptEntity getRider(); + + /** + * @param entity The entity to ride this entity + */ + public void setRider(ScriptEntity entity); + + /** + * @return Return the entity, this entity is riding + */ + public ScriptEntity getMount(); + + /** + * @param entity The entity this entity will mount + */ + public void setMount(ScriptEntity entity); + + /** + * @see noppes.npcs.scripted.constants.EntityType + * @return Returns the EntityType of this entity + */ + public int getType(); + + /** + * @since 1.7.10c + * @param type @EntityType to check + * @return Returns whether the entity is type of the given @EntityType + */ + public boolean typeOf(int type); + + /** + * @param rotation The rotation to be set (0-360) + */ + public void setRotation(float rotation); + + /** + * @return Current rotation of the npc + */ + public float getRotation(); + + /** + * @param power How strong the knockback is + * @param direction The direction in which he flies back (0-360). Usually based on getRotation() + */ + public void knockback(int power, float direction); + + /** + * @since 1.7.10c + * @return Returns whether or not this entity is sneaking + */ + public boolean isSneaking(); + + /** + * @since 1.7.10c + * @return Returns whether or not this entity is sprinting + */ + public boolean isSprinting(); + + /** + * @since 1.7.10c + * Expert users only + * @return Returns minecrafts entity + */ + public Entity getMCEntity(); +} diff --git a/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java b/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java new file mode 100644 index 000000000..953c3dc2d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java @@ -0,0 +1,110 @@ +package noppes.npcs.scripted; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.constants.EntityType; + +public interface IEntityLivingBase { + /** + * @return The entity's current health + */ + public float getHealth(); + + /** + * @param health The new health of this entity + */ + public void setHealth(float health); + + /** + * @return Entity's max health + */ + public float getMaxHealth(); + /** + * @return Whether or not this entity is attacking something + */ + public boolean isAttacking(); + + /** + * @param living Entity which this entity will attack + */ + public void setAttackTarget(ScriptLivingBase living); + + /** + * @return The entity which this entity is attacking + */ + public ScriptLivingBase getAttackTarget(); + + public int getType(); + + public boolean typeOf(int type); + + /** + * @param entity Entity to check + * @return Whether or not this entity can see the given entity + */ + public boolean canSeeEntity(ScriptEntity entity); + + /** + * Expert use only + * @return Returns the minecraft entity object + */ + public EntityLivingBase getMinecraftEntity(); + + /** + * Makes the entity swing its hand + */ + public void swingHand(); + + /** + * Works the same as the /effect command + * @param effect + * @param duration The duration in seconds + * @param strength The amplifier of the potion effect + * @param hideParticles Whether or not you want to hide potion particles + */ + public void addPotionEffect(int effect, int duration, int strength, boolean hideParticles); + + /** + * Clears all potion effects + */ + public void clearPotionEffects(); + + /** + * @since 1.7.10c + * @param effect Potion effect to check + * @return Returns -1 if its not active. Otherwise returns the strenght of the potion + */ + public int getPotionEffect(int effect); + + /** + * Note not all Living Entities support this + * @since 1.7.10c + * @return The item the entity is holding + */ + public ScriptItemStack getHeldItem(); + + /** + * Note not all Living Entities support this + * @since 1.7.10c + * @param item The item to be set + */ + public void setHeldItem(ScriptItemStack item); + + /** + * Note not all Living Entities support this + * @param slot Slot of what armor piece to get, 0:boots, 1:pants, 2:body, 3:head + * @return The item in the given slot + */ + public ScriptItemStack getArmor(int slot); + + /** + * Note not all Living Entities support this + * @since 1.7.10c + * @param slot Slot of what armor piece to set, 0:boots, 1:pants, 2:body, 3:head + * @param item Item to be set + */ + public void setArmor(int slot, ScriptItemStack item); +} diff --git a/src/main/java/noppes/npcs/scripted/IItemStack.java b/src/main/java/noppes/npcs/scripted/IItemStack.java new file mode 100644 index 000000000..51617cb81 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IItemStack.java @@ -0,0 +1,122 @@ +package noppes.npcs.scripted; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; + +import java.util.ArrayList; +import java.util.List; + +public interface IItemStack { + /** + * @return The minecraft name for this item + */ + public String getName(); + + /** + * @return Returns the stacksize + */ + public int getStackSize(); + + /** + * @return Return whether or not the item has a custom name + */ + public boolean hasCustomName(); + + /** + * @param name The custom name this item will get + */ + public void setCustomName(String name); + + /** + * @return Return the ingame displayed name. This is either the item name or the custom name if it has one. + */ + public String getDisplayName(); + + /** + * @return Get the items ingame name. Use this incase the item ingame has custom name and you want the original name. + */ + public String getItemName(); + + /** + * @param size The size of the itemstack. A number between 1 and 64 + */ + public void setStackSize(int size); + + /** + * @return Returns the item damage of this item. For tools this is the durability for other items the color and more. + */ + public int getItemDamage(); + + /** + * @param value The value to be set as item damage. For tools this is the durability for other items the color and more. + */ + public void setItemDamage(int value); + + /** + * @param key The key of this NBTTag + * @param value The value to be stored. Can be a Number or String + */ + public void setTag(String key, Object value); + + /** + * @param key The key of the NBTTag + * @return Returns whether or not the key exists + */ + public boolean hasTag(String key); + + /** + * @param key The key of the NBTTag + * @return Returns the value associated with the key. Returns null of it doesnt exist + */ + public Object getTag(String key); + + public boolean isEnchanted(); + + /** + * @since 1.7.10d + * @param id The enchantment id + * @return + */ + public boolean hasEnchant(int id); + + /** + * @since 1.7.10d + * @return Returns whether this item is a book + */ + public boolean isWrittenBook(); + + /** + * @since 1.7.10d + * @return Returns the books title + */ + public String getBookTitle(); + + /** + * @since 1.7.10d + * @return Returns the books author + */ + public String getBookAuthor(); + + /** + * @since 1.7.10d + * @return If the item is a book, returns a string array with book pages + */ + public String[] getBookText(); + + /** + * @return Returns whether or not this item is a block + */ + public boolean isBlock(); + /** + * No support is given for this method. Dont use if you dont know what you are doing. + * @return Minecraft ItemStack + */ + public ItemStack getMCItemStack(); +} diff --git a/src/main/java/noppes/npcs/scripted/IPlayer.java b/src/main/java/noppes/npcs/scripted/IPlayer.java new file mode 100644 index 000000000..6e35dd1e8 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IPlayer.java @@ -0,0 +1,183 @@ +package noppes.npcs.scripted; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.stats.Achievement; +import net.minecraft.stats.StatBase; +import net.minecraft.stats.StatList; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.WorldSettings; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.Server; +import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.controllers.*; +import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.util.ValueUtil; + +public interface IPlayer { + /** + * @return Returns the displayed name of the player + */ + public String getDisplayName(); + + /** + * @return Returns the players name + */ + public String getName(); + + public void setPosition(double x, double y, double z); + + public boolean hasFinishedQuest(int id); + + public boolean hasActiveQuest(int id); + + public boolean hasReadDialog(int id); + + /** + * Add the quest from active quest list + * @param id The Quest ID + */ + public void startQuest(int id); + + /** + * Add the quest from finished quest list + * @param id The Quest ID + */ + public void finishQuest(int id); + /** + * Removes the quest from active quest list + * @param id The Quest ID + */ + public void stopQuest(int id); + + /** + * Removes the quest from active and finished quest list + * @param id The Quest ID + */ + public void removeQuest(int id); + + public int getType(); + + public boolean typeOf(int type); + /** + * @param faction The faction id + * @param points The points to increase. Use negative values to decrease + */ + public void addFactionPoints(int faction, int points); + + /** + * @param faction The faction id + * @return points + */ + public int getFactionPoints(int faction); + + /** + * @param message The message you want to send + */ + public void sendMessage(String message); + + /** + * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure + */ + public int getMode(); + + /** + * @param type The gamemode type. 0:SURVIVAL, 1:CREATIVE, 2:ADVENTURE + */ + public void setMode(int type); + + /** + * @param item The item to be checked + * @return How many of this item the player has + */ + public int inventoryItemCount(ScriptItemStack item); + + /** + * @since 1.7.10d + * @return Returns a IItemStack array size 36 + */ + public ScriptItemStack[] getInventory(); + + /** + * @param item The Item type to be removed + * @param amount How many will be removed + * @return Returns true if the items were removed succesfully. Returns false incase a bigger amount than what the player has was given + */ + public boolean removeItem(ScriptItemStack item, int amount); + + /** + * @since 1.7.10c + * @param id The items name + * @param damage The damage value + * @param amount How many will be removed + * @return Returns true if the items were removed succesfully. Returns false incase a bigger amount than what the player has was given or item doesnt exist + */ + public boolean removeItem(String id, int damage, int amount); + + /** + * @since 1.7.10c + * @param item Item to be added + * @param amount The amount of the item to be added + * @return Returns whether or not it gave the item succesfully + */ + public boolean giveItem(ScriptItemStack item, int amount); + + /** + * @since 1.7.10c + * @param id The items name + * @param damage The damage value + * @param amount The amount of the item to be added + * @return Returns whether or not it gave the item succesfully + */ + public boolean giveItem(String id, int damage, int amount); + + /** + * Same as the /spawnpoint command + * @param x The x position + * @param y The y position + * @param z The z position + */ + public void setSpawnpoint(int x, int y, int z); + + public void resetSpawnpoint(); + + /** + * @param item The item to be removed from the players inventory + */ + public void removeAllItems(ScriptItemStack item); + + + /** + * @param achievement The achievement id. For a complete list see http://minecraft.gamepedia.com/Achievements + * @return Returns whether or not the player has this achievement + */ + public boolean hasAchievement(String achievement); + + /** + * @param permission Bukkit/Cauldron permission + * @return Returns whether or not the player has the permission + */ + public boolean hasBukkitPermission(String permission); + + /** + * @since 1.7.10c + * @return Returns the exp level + */ + public int getExpLevel(); + + /** + * @since 1.7.10c + * @param level The new exp level you want to set + */ + public void setExpLevel(int level); + + /** + * Requires pixelmon to be installed + * @since 1.7.10d + */ + public ScriptPixelmonPlayerData getPixelmonData(); +} diff --git a/src/main/java/noppes/npcs/scripted/IWorld.java b/src/main/java/noppes/npcs/scripted/IWorld.java new file mode 100644 index 000000000..291624518 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IWorld.java @@ -0,0 +1,228 @@ +package noppes.npcs.scripted; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.blocks.tiles.TileBigSign; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.ServerCloneController; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public interface IWorld { + /** + * @return The worlds time + */ + public long getTime(); + + /** + * @return The total world time + */ + public long getTotalTime(); + + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @return The block at the given position. Returns null if there isn't a block + */ + public ScriptItemStack getBlock(int x, int y, int z); + + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @return Text from signs + * @since 1.7.10d + */ + public String getSignText(int x, int y, int z); + + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @param item The block to be set + */ + public void setBlock(int x, int y, int z, ScriptItemStack item); + + /** + * @param x World position x + * @param y World position y + * @param z World position z + */ + public void removeBlock(int x, int y, int z); + + /** + * @param name The name of the player to be returned + * @return The Player with name. Null is returned when the player isnt found + */ + public ScriptPlayer getPlayer(String name); + + /** + * @param time The world time to be set + */ + public void setTime(long time); + + /** + * @return Whether or not its daytime + */ + public boolean isDay(); + + /** + * @return Whether or not its currently raining + */ + public boolean isRaining(); + + /** + * @param bo Set if it's raining + */ + public void setRaining(boolean bo); + + /** + * @param x The x position + * @param y The y position + * @param z The z position + */ + public void thunderStrike(double x, double y, double z); + + /** + * Sends a packet from the server to the client everytime its called. Probably should not use this too much. + * @param particle Particle name. Particle name list: http://minecraft.gamepedia.com/Particles + * @param x The x position + * @param y The y position + * @param z The z position + * @param dx Usually used for the x motion + * @param dy Usually used for the y motion + * @param dz Usually used for the z motion + * @param speed Speed of the particles, usually between 0 and 1 + * @param count Particle count + */ + public void spawnParticle(String particle, double x, double y, double z, double dx, double dy, double dz, double speed, int count); + + /** + * @param id The items name + * @param damage The damage value + * @param size The number of items in the item + * @return Returns the item + */ + public ScriptItemStack createItem(String id, int damage, int size); + + /** + * @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" + * @return Returns ScriptEntityParticle object + */ + public ScriptEntityParticle createEntityParticle(String directory); + + /** + * @param key Get temp data for this key + * @return Returns the stored temp data + */ + public Object getTempData(String key); + + /** + * Tempdata gets cleared when the server restarts. All worlds share the same temp data. + * @param key The key for the data stored + * @param value The data stored + */ + public void setTempData(String key, Object value); + + /** + * @param key The key thats going to be tested against the temp data + * @return Whether or not temp data containes the key + */ + public boolean hasTempData(String key); + + /** + * @param key The key for the temp data to be removed + */ + public void removeTempData(String key); + + /** + * Removes all tempdata + */ + public void clearTempData(); + + /** + * @param key The key of the data to be returned + * @return Returns the stored data + */ + public Object getStoredData(String key); + + /** + * Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved + * @param key The key for the data stored + * @param value The data stored. This data can be either a Number or a String. Other data is not stored + */ + public void setStoredData(String key, Object value); + + /** + * @param key The key of the data to be checked + * @return Returns whether or not the stored data contains the key + */ + public boolean hasStoredData(String key); + + /** + * @param key The key of the data to be removed + */ + public void removeStoredData(String key); + + /** + * Remove all stored data + */ + public void clearStoredData(); + + /** + * @param x Position x + * @param y Position y + * @param z Position z + * @param range Range of the explosion + * @param fire Whether or not the explosion does fire damage + * @param grief Whether or not the explosion does damage to blocks + */ + public void explode(double x, double y, double z, float range, boolean fire, boolean grief); + + public ScriptPlayer[] getAllServerPlayers(); + + /** + * @since 1.7.10c + * @param x Position x + * @param z Position z + * @return Returns the name of the biome + */ + public String getBiomeName(int x, int z); + + /** + * Lets you spawn a server side cloned entity + * @param x The x position the clone will be spawned at + * @param y The y position the clone will be spawned at + * @param z The z position the clone will be spawned at + * @param tab The tab in which the clone is + * @param name Name of the cloned entity + * @return Returns the entity which was spawned + */ + public ScriptEntity spawnClone(int x, int y, int z, int tab, String name); + + public ScriptScoreboard getScoreboard(); + + /** + * @since 1.7.10c + * Expert use only + * @return Returns minecraft world object + */ + public World getMCWorld(); +} diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java new file mode 100644 index 000000000..3bb0e16bf --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -0,0 +1,78 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +import java.io.File; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.eventhandler.EventBus; +import net.minecraft.entity.Entity; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; + +public abstract class NpcAPI { + private static NpcAPI instance = null; + + public NpcAPI() { + } + + public abstract ICustomNpc createNPC(World var1); + + public abstract ICustomNpc spawnNPC(World var1, int var2, int var3, int var4); + + public abstract IEntity getIEntity(Entity var1); + + public abstract IContainer getIContainer(IInventory var1); + + public abstract IContainer getIContainer(Container var1); + + public abstract IItemStack getIItemStack(ItemStack var1); + + public abstract IWorld getIWorld(WorldServer var1); + + public abstract IWorld getIWorld(int var1); + + public abstract IWorld[] getIWorlds(); + + public abstract IDamageSource getIDamageSource(DamageSource var1); + + public abstract EventBus events(); + + public abstract File getGlobalDir(); + + public abstract File getWorldDir(); + + public static boolean IsAvailable() { + return Loader.isModLoaded("customnpcs"); + } + + public static NpcAPI Instance() { + if (instance != null) { + return instance; + } else if (!IsAvailable()) { + return null; + } else { + try { + Class c = Class.forName("noppes.npcs.api.wrapper.WrapperNpcAPI"); + instance = (NpcAPI) c.getMethod("Instance").invoke((Object) null); + } catch (Exception var1) { + var1.printStackTrace(); + } + + return instance; + } + } + + public abstract String executeCommand(IWorld var1, String var2); + + public abstract String getRandomName(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptContainer.java b/src/main/java/noppes/npcs/scripted/ScriptContainer.java new file mode 100644 index 000000000..722eeafea --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptContainer.java @@ -0,0 +1,88 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.IItemStack; + +public class ScriptContainer implements IContainer { + private IInventory inventory; + private Container container; + + public ScriptContainer(IInventory inventory) { + this.inventory = inventory; + } + + public ScriptContainer(Container container) { + this.container = container; + } + + public int getSize() { + return this.inventory != null ? this.inventory.getSizeInventory() : this.container.inventorySlots.size(); + } + + public IItemStack getSlot(int slot) { + if (slot >= 0 && slot < this.getSize()) { + return this.inventory != null ? NpcAPI.Instance().getIItemStack(this.inventory.getStackInSlot(slot)) : NpcAPI.Instance().getIItemStack(this.container.getSlot(slot).getStack()); + } else { + throw new CustomNPCsException("Slot is out of range " + slot, new Object[0]); + } + } + + public void setSlot(int slot, IItemStack item) { + if (slot >= 0 && slot < this.getSize()) { + ItemStack itemstack = item == null ? new ItemStack(Block.getBlockById(0)) : item.getMCItemStack(); + if (this.inventory != null) { + this.inventory.setInventorySlotContents(slot, itemstack); + } else { + this.container.putStackInSlot(slot, itemstack); + this.container.detectAndSendChanges(); + } + + } else { + throw new CustomNPCsException("Slot is out of range " + slot, new Object[0]); + } + } + + public int count(IItemStack item, boolean ignoreDamage, boolean ignoreNBT) { + int count = 0; + + for(int i = 0; i < this.getSize(); ++i) { + IItemStack toCompare = this.getSlot(i); + if (NoppesUtilPlayer.compareItems(item.getMCItemStack(), toCompare.getMCItemStack(), ignoreDamage, ignoreNBT)) { + count += toCompare.getStackSize(); + } + } + + return count; + } + + public IInventory getMCInventory() { + return this.inventory; + } + + public Container getMCContainer() { + return this.container; + } + + public IItemStack[] getItems() { + IItemStack[] items = new IItemStack[this.getSize()]; + + for(int i = 0; i < this.getSize(); ++i) { + items[i] = this.getSlot(i); + } + + return items; + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 0d24236d9..1b2d70959 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -27,7 +27,7 @@ import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.EntityType; -public class ScriptEntity { +public class ScriptEntity implements IEntity{ protected Entity entity; private Map tempData = new HashMap(); diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 5be275499..477346d08 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -14,7 +14,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; -public class ScriptItemStack { +public class ScriptItemStack implements IItemStack { protected ItemStack item; public ScriptItemStack(ItemStack item){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java index 070433b6f..776c3f0f1 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java @@ -21,7 +21,7 @@ import net.minecraft.util.MathHelper; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.constants.EntityType; -public class ScriptLivingBase extends ScriptEntity{ +public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{ protected EntityLivingBase entity; public ScriptLivingBase(EntityLivingBase entity){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/ScriptNpc.java index 6134ce704..5e5582db4 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/ScriptNpc.java @@ -31,12 +31,12 @@ import noppes.npcs.scripted.roles.ScriptRoleTrader; import noppes.npcs.scripted.roles.ScriptRoleTransporter; import noppes.npcs.util.ValueUtil; -public class ScriptNpc extends ScriptLiving{ +public class ScriptNpc extends ScriptLiving implements ICustomNpc{ protected EntityCustomNpc npc; - public ScriptNpc(EntityCustomNpc npc){ + public ScriptNpc(EntityNPCInterface npc){ super(npc); - this.npc = npc; + this.npc = (EntityCustomNpc)npc; } /** diff --git a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java index 2b98f0c7d..c9a4c6995 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java @@ -25,7 +25,7 @@ import noppes.npcs.controllers.QuestData; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.util.ValueUtil; -public class ScriptPlayer extends ScriptLivingBase{ +public class ScriptPlayer extends ScriptLivingBase implements IPlayer{ protected EntityPlayerMP player; public ScriptPlayer(EntityPlayerMP player){ super(player); diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index db047e28b..b47dc19b4 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -26,13 +26,17 @@ import noppes.npcs.blocks.tiles.TileSign; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; -public class ScriptWorld{ +public class ScriptWorld implements IWorld{ private static Map tempData = new HashMap(); - protected WorldServer world; + public WorldServer world; public ScriptWorld(WorldServer world){ this.world = world; } - + + public static ScriptWorld createNew(WorldServer world) { + return new ScriptWorld(world); + } + /** * @return The worlds time */ diff --git a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java new file mode 100644 index 000000000..52ddb6a94 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted.event; + +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.controllers.ScriptController; + +public class CustomNPCsEvent extends Event { + public final ScriptController API = ScriptController.Instance; + + public CustomNPCsEvent() { + } +} diff --git a/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java b/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java new file mode 100644 index 000000000..d858a7b56 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java @@ -0,0 +1,46 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.event; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.scripted.IWorld; +import noppes.npcs.scripted.IEntity; + +@Cancelable +public class ForgeEvent extends CustomNPCsEvent { + public final Event event; + + public ForgeEvent(Event event) { + this.event = event; + } + + @Cancelable + public static class WorldEvent extends ForgeEvent { + public final IWorld world; + + public WorldEvent(net.minecraftforge.event.world.WorldEvent event, IWorld world) { + super(event); + this.world = world; + } + } + + @Cancelable + public static class EntityEvent extends ForgeEvent { + public final IEntity entity; + + public EntityEvent(net.minecraftforge.event.entity.EntityEvent event, IEntity entity) { + super(event); + this.entity = entity; + } + } + + public static class InitEvent extends ForgeEvent { + public InitEvent() { + super((Event)null); + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 9b6d3d337..a4f2f9b9f 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -1,24 +1,22 @@ // // Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) +// (powered by FernFlower decompiler) // package noppes.npcs.scripted.event; +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; -import net.minecraftforge.fml.common.eventhandler.Cancelable; import noppes.npcs.scripted.IContainer; import noppes.npcs.scripted.IDamageSource; import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.block.IBlock; -import noppes.npcs.scripted.entity.IEntity; -import noppes.npcs.scripted.entity.IEntityLivingBase; -import noppes.npcs.scripted.entity.IPlayer; -import noppes.npcs.scripted.event.CustomNPCsEvent; -import noppes.npcs.scripted.handler.data.IFaction; -import noppes.npcs.scripted.item.IItemStack; +import noppes.npcs.scripted.IEntity; +import noppes.npcs.scripted.IEntityLivingBase; +import noppes.npcs.scripted.IPlayer; +import noppes.npcs.scripted.IItemStack; public class PlayerEvent extends CustomNPCsEvent { public final IPlayer player; @@ -27,19 +25,6 @@ public class PlayerEvent extends CustomNPCsEvent { this.player = player; } - public static class FactionUpdateEvent extends PlayerEvent { - public final IFaction faction; - public int points; - public boolean init; - - public FactionUpdateEvent(IPlayer player, IFaction faction, int points, boolean init) { - super(player); - this.faction = faction; - this.points = points; - this.init = init; - } - } - @Cancelable public static class ChatEvent extends PlayerEvent { public String message; @@ -130,7 +115,7 @@ public class PlayerEvent extends CustomNPCsEvent { public DiedEvent(IPlayer player, DamageSource damagesource, Entity entity) { super(player); this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); - this.type = damagesource.field_76373_n; + this.type = damagesource.getDamageType(); this.source = NpcAPI.Instance().getIEntity(entity); } } @@ -194,18 +179,6 @@ public class PlayerEvent extends CustomNPCsEvent { } } - @Cancelable - public static class BreakEvent extends PlayerEvent { - public final IBlock block; - public int exp; - - public BreakEvent(IPlayer player, IBlock block, int exp) { - super(player); - this.block = block; - this.exp = exp; - } - } - @Cancelable public static class AttackEvent extends PlayerEvent { public final int type; diff --git a/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java b/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java new file mode 100644 index 000000000..94b5aef7a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java @@ -0,0 +1,43 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.wrapper; + +import net.minecraft.util.DamageSource; +import noppes.npcs.scripted.IDamageSource; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.IEntity; + +public class ScriptDamageSource implements IDamageSource { + private DamageSource source; + + public ScriptDamageSource(DamageSource source) { + this.source = source; + } + + public String getType() { + return this.source.getDamageType(); + } + + public boolean isUnblockable() { + return this.source.isUnblockable(); + } + + public boolean isProjectile() { + return this.source.isProjectile(); + } + + public DamageSource getMCDamageSource() { + return this.source; + } + + public IEntity getTrueSource() { + return NpcAPI.Instance().getIEntity(this.source.getEntity()); + } + + public IEntity getImmediateSource() { + return NpcAPI.Instance().getIEntity(this.source.getSourceOfDamage()); + } +} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java new file mode 100644 index 000000000..201867d80 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java @@ -0,0 +1,65 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.wrapper; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityTameable; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.LogWriter; +import noppes.npcs.scripted.*; +import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.entity.EntityProjectile; + +public class WrapperEntityData{ + public IEntity base; + private static final ResourceLocation key = new ResourceLocation("customnpcs", "entitydata"); + + public WrapperEntityData(IEntity base) { + this.base = base; + } + + public static IEntity get(Entity entity) { + if (entity == null) { + return null; + } else { + WrapperEntityData data = new WrapperEntityData(new ScriptEntity(entity)); + if (data == null) { + return getData(entity).base; + } else { + return data.base; + } + } + } + + private static WrapperEntityData getData(Entity entity) { + if (entity != null && entity.worldObj != null && !entity.worldObj.isRemote) { + if (entity instanceof EntityPlayerMP) { + return new WrapperEntityData(new ScriptPlayer((EntityPlayerMP)entity)); + } else if (PixelmonHelper.isPixelmon(entity)) { + return new WrapperEntityData(new ScriptPixelmon((EntityTameable)entity)); + } else if (entity instanceof EntityAnimal) { + return new WrapperEntityData(new ScriptAnimal((EntityAnimal)entity)); + } else if (entity instanceof EntityMob) { + return new WrapperEntityData(new ScriptMonster((EntityMob)entity)); + } else if (entity instanceof EntityLiving) { + return new WrapperEntityData(new ScriptLiving((EntityLiving)entity)); + } else if (entity instanceof EntityLivingBase) { + return new WrapperEntityData(new ScriptLivingBase((EntityLivingBase)entity)); + } + } + return null; + } +} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java new file mode 100644 index 000000000..ad2243075 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -0,0 +1,171 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.wrapper; + +import java.io.File; +import java.util.Map; + +import cpw.mods.fml.common.eventhandler.EventBus; +import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.FakePlayer; +import noppes.npcs.CustomNpcs; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.scripted.*; +import noppes.npcs.containers.ContainerNpcInterface; +import noppes.npcs.controllers.DialogController; +import noppes.npcs.controllers.FactionController; +import noppes.npcs.controllers.QuestController; +import noppes.npcs.controllers.RecipeController; +import noppes.npcs.controllers.ServerCloneController; +import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.util.LRUHashMap; +import noppes.npcs.util.NBTJsonUtil; +import noppes.npcs.util.JsonException; + +public class WrapperNpcAPI extends NpcAPI { + private static final Map worldCache = new LRUHashMap(10); + public static final EventBus EVENT_BUS = new EventBus(); + private static NpcAPI instance = null; + + public WrapperNpcAPI() { + } + + public static void clearCache() { + worldCache.clear(); + } + + public IEntity getIEntity(Entity entity) { + if (entity != null && !entity.worldObj.isRemote) { + return (IEntity)(entity instanceof EntityNPCInterface ? ((EntityNPCInterface)entity).wrappedNPC : WrapperEntityData.get(entity)); + } else { + return null; + } + } + + public ICustomNpc createNPC(World world) { + if (world.isRemote) { + return null; + } else { + EntityCustomNpc npc = new EntityCustomNpc(world); + return npc.wrappedNPC; + } + } + + public ICustomNpc spawnNPC(World world, int x, int y, int z) { + if (world.isRemote) { + return null; + } else { + EntityCustomNpc npc = new EntityCustomNpc(world); + npc.setPositionAndRotation((double)x + 0.5D, (double)y, (double)z + 0.5D, 0.0F, 0.0F); + npc.setHealth(npc.getMaxHealth()); + world.spawnEntityInWorld(npc); + return npc.wrappedNPC; + } + } + + public static NpcAPI Instance() { + if (instance == null) { + instance = new WrapperNpcAPI(); + } + + return instance; + } + + public EventBus events() { + return EVENT_BUS; + } + + public IItemStack getIItemStack(ItemStack itemstack) { + return (IItemStack)(itemstack != null && itemstack.stackSize > 0 ? new ScriptItemStack(itemstack) : new ScriptItemStack(new ItemStack(Item.getItemById(0)))); + + } + + public IWorld getIWorld(WorldServer world) { + ScriptWorld w = (ScriptWorld)worldCache.get(world.provider.dimensionId); + if (w != null) { + w.world = world; + return w; + } else { + worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world)); + return w; + } + } + + public IWorld getIWorld(int dimensionId) { + WorldServer[] var2 = CustomNpcs.getServer().worldServers; + int var3 = var2.length; + + for(int var4 = 0; var4 < var3; ++var4) { + WorldServer world = var2[var4]; + if (world.provider.dimensionId == dimensionId) { + return this.getIWorld(world); + } + } + + throw new CustomNPCsException("Unknown dimension id: " + dimensionId, new Object[0]); + } + + public IContainer getIContainer(IInventory inventory) { + return new ScriptContainer(inventory); + } + + public IContainer getIContainer(Container container) { + return (IContainer)(container instanceof ContainerNpcInterface ? ContainerNpcInterface.getOrCreateIContainer((ContainerNpcInterface)container) : new ScriptContainer(container)); + } + + private void checkWorld() { + if (CustomNpcs.getServer() == null || CustomNpcs.getServer().isServerStopped()) { + throw new CustomNPCsException("No world is loaded right now", new Object[0]); + } + } + + public IWorld[] getIWorlds() { + this.checkWorld(); + IWorld[] worlds = new IWorld[CustomNpcs.getServer().worldServers.length]; + + for(int i = 0; i < CustomNpcs.getServer().worldServers.length; ++i) { + worlds[i] = this.getIWorld(CustomNpcs.getServer().worldServers[i]); + } + + return worlds; + } + + public File getGlobalDir() { + return CustomNpcs.Dir; + } + + public File getWorldDir() { + return CustomNpcs.getWorldSaveDirectory(); + } + + public IDamageSource getIDamageSource(DamageSource damagesource) { + return new ScriptDamageSource(damagesource); + } + + public String executeCommand(IWorld world, String command) { + FakePlayer player = EntityNPCInterface.CommandPlayer; + player.setWorld(world.getMCWorld()); + player.setPosition(0.0D, 0.0D, 0.0D); + return NoppesUtilServer.runCommand(world.getMCWorld(), BlockPos.ORIGIN, "API", command, (EntityPlayer)null, player); + } + public String getRandomName(int dictionary, int gender) { + return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender); + } +} diff --git a/src/main/java/noppes/npcs/util/LRUHashMap.java b/src/main/java/noppes/npcs/util/LRUHashMap.java new file mode 100644 index 000000000..0fe23a99f --- /dev/null +++ b/src/main/java/noppes/npcs/util/LRUHashMap.java @@ -0,0 +1,22 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.util; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +public class LRUHashMap extends LinkedHashMap { + private final int maxSize; + + public LRUHashMap(int size) { + super(size, 0.75F, true); + this.maxSize = size; + } + + protected boolean removeEldestEntry(Entry eldest) { + return this.size() > this.maxSize; + } +} From 44bd1692d1e7620e948872d8d998ac9f96e163af Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 1 Oct 2021 01:17:12 -0500 Subject: [PATCH 19/58] GUI's properly implemented, script data still needs work. --- CustomNPC-Plus-1.21.iml | 77 ++- build.gradle | 3 + .../java/noppes/npcs/PacketHandlerServer.java | 6 +- .../gui/script/EventGuiNPCInterface.java | 225 ++++----- .../client/gui/script/EventGuiScriptList.java | 111 ++++ .../client/gui/script/GuiScriptEvent.java | 284 ----------- .../client/gui/script/GuiScriptGlobal.java | 14 +- .../client/gui/script/GuiScriptInterface.java | 336 ++++++------- .../npcs/client/gui/util/GuiCustomScroll.java | 3 + .../npcs/client/gui/util/GuiTextArea.java | 473 ++++++++++++++++++ .../noppes/npcs/client/gui/util/IGui.java | 16 + .../npcs/client/gui/util/IKeyListener.java | 10 + .../npcs/client/gui/util/IMouseListener.java | 10 + .../npcs/client/gui/util/TextContainer.java | 225 +++++++++ .../java/noppes/npcs/config/TrueTypeFont.java | 340 +++++++++++++ 15 files changed, 1538 insertions(+), 595 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java delete mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/IGui.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/IKeyListener.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/IMouseListener.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/TextContainer.java create mode 100644 src/main/java/noppes/npcs/config/TrueTypeFont.java diff --git a/CustomNPC-Plus-1.21.iml b/CustomNPC-Plus-1.21.iml index b060a7da0..371deae12 100644 --- a/CustomNPC-Plus-1.21.iml +++ b/CustomNPC-Plus-1.21.iml @@ -1,13 +1,86 @@ - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5695c93b2..4698f6eab 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,9 @@ minecraft { runDir = "eclipse" } +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + dependencies { // you may put jars on which you depend on in ./libs // or you may define them like so.. diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 5fe882a43..48c533168 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -106,7 +106,7 @@ public class PacketHandlerServer{ clonePackets(type, buffer, player); else if(item.getItem() == CustomItems.teleporter) featherPackets(type, buffer, player); - else if(type == EnumPacketServer.ScriptPlayerGet && type == EnumPacketServer.ScriptPlayerSave) + else if(type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) playerScriptPackets(type, buffer, player, npc); else if(item.getItem() == CustomItems.scripter) scriptPackets(type, buffer, player, npc); @@ -132,11 +132,11 @@ public class PacketHandlerServer{ private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { NBTTagCompound compound; - if (type == EnumPacketServer.ScriptPlayerGet) { + if(type == EnumPacketServer.ScriptPlayerGet) { compound = ScriptController.Instance.playerScripts.writeToNBT(new NBTTagCompound()); compound.setTag("Languages", ScriptController.Instance.nbtLanguages()); Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound}); - } else if (type == EnumPacketServer.ScriptPlayerSave) { + } else if(type == EnumPacketServer.ScriptPlayerSave) { ScriptController.Instance.setPlayerScripts(Server.readNBT(buffer)); } } diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java index 65b6154ed..83f24a15a 100644 --- a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java @@ -17,9 +17,9 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Post; @@ -28,6 +28,7 @@ import net.minecraftforge.common.MinecraftForge; import noppes.npcs.client.gui.util.*; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; public abstract class EventGuiNPCInterface extends GuiScreen { public EntityPlayerSP player; @@ -69,15 +70,15 @@ public abstract class EventGuiNPCInterface extends GuiScreen { this.background = null; this.closeOnEsc = false; this.bgScale = 1.0F; - this.player = Minecraft.func_71410_x().field_71439_g; + this.player = Minecraft.getMinecraft().thePlayer; this.npc = npc; this.title = ""; this.xSize = 200; this.ySize = 222; this.drawDefaultBackground = false; - this.field_146297_k = Minecraft.func_71410_x(); - this.field_146296_j = this.field_146297_k.func_175599_af(); - this.field_146289_q = this.field_146297_k.field_71466_p; + this.mc = Minecraft.getMinecraft(); + this.itemRender = RenderItem.getInstance(); + this.fontRendererObj = this.mc.fontRenderer; } public EventGuiNPCInterface() { @@ -92,25 +93,25 @@ public abstract class EventGuiNPCInterface extends GuiScreen { return new ResourceLocation("customnpcs", "textures/gui/" + texture); } - public void func_146280_a(Minecraft mc, int width, int height) { - super.func_146280_a(mc, width, height); + public void setWorldAndResolution(Minecraft mc, int width, int height) { + super.setWorldAndResolution(mc, width, height); this.initPacket(); } public void initPacket() { } - public void func_73866_w_() { - super.func_73866_w_(); + public void initGui() { + super.initGui(); GuiNpcTextField.unfocus(); if (this.subgui != null) { - this.subgui.func_146280_a(this.field_146297_k, this.field_146294_l, this.field_146295_m); - this.subgui.func_73866_w_(); + this.subgui.setWorldAndResolution(this.mc, this.width, this.height); + this.subgui.initGui(); } - this.guiLeft = (this.field_146294_l - this.xSize) / 2; - this.guiTop = (this.field_146295_m - this.ySize) / 2; - this.field_146292_n = Lists.newArrayList(); + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; + this.buttonList = Lists.newArrayList(); this.buttons = new ConcurrentHashMap(); this.topbuttons = new ConcurrentHashMap(); this.sidebuttons = new ConcurrentHashMap(); @@ -122,16 +123,16 @@ public abstract class EventGuiNPCInterface extends GuiScreen { this.components = new ArrayList(); } - public void func_73876_c() { + public void updateScreen() { if (this.subgui != null) { - this.subgui.func_73876_c(); + this.subgui.updateScreen(); } else { Iterator var1 = (new ArrayList(this.textfields.values())).iterator(); while(var1.hasNext()) { GuiNpcTextField tf = (GuiNpcTextField)var1.next(); if (tf.enabled) { - tf.func_146178_a(); + tf.updateCursorCounter(); } } @@ -142,26 +143,26 @@ public abstract class EventGuiNPCInterface extends GuiScreen { comp.updateScreen(); } - super.func_73876_c(); + super.updateScreen(); } } public void addExtra(GuiHoverText gui) { - gui.func_146280_a(this.field_146297_k, 350, 250); + gui.setWorldAndResolution(this.mc, 350, 250); this.extra.put(gui.id, gui); } - public void func_73864_a(int i, int j, int k) { + public void mouseClicked(int i, int j, int k) { if (this.subgui != null) { - this.subgui.func_73864_a(i, j, k); + this.subgui.mouseClicked(i, j, k); } else { Iterator var4 = (new ArrayList(this.textfields.values())).iterator(); while(var4.hasNext()) { GuiNpcTextField tf = (GuiNpcTextField)var4.next(); if (tf.enabled) { - tf.func_146192_a(i, j, k); + tf.mouseClicked(i, j, k); } } @@ -180,22 +181,21 @@ public abstract class EventGuiNPCInterface extends GuiScreen { while(var4.hasNext()) { GuiCustomScroll scroll = (GuiCustomScroll)var4.next(); - scroll.func_73864_a(i, j, k); + scroll.mouseClicked(i, j, k); } - var4 = this.field_146292_n.iterator(); + var4 = this.buttonList.iterator(); while(var4.hasNext()) { GuiButton guibutton = (GuiButton)var4.next(); - if (guibutton.func_146116_c(this.field_146297_k, this.mouseX, this.mouseY)) { - Pre event = new Pre(this, guibutton, this.field_146292_n); + if (guibutton.mousePressed(this.mc, this.mouseX, this.mouseY)) { + Pre event = new Pre(this, guibutton, this.buttonList); if (!MinecraftForge.EVENT_BUS.post(event)) { - guibutton = event.getButton(); this.selectedButton = guibutton; - guibutton.func_146113_a(this.field_146297_k.func_147118_V()); - this.func_146284_a(guibutton); - if (this.equals(this.field_146297_k.field_71462_r)) { - MinecraftForge.EVENT_BUS.post(new Post(this, event.getButton(), this.field_146292_n)); + guibutton.func_146113_a(this.mc.getSoundHandler()); + this.actionPerformed(guibutton); + if (this.equals(this.mc.currentScreen)) { + MinecraftForge.EVENT_BUS.post(new Post(this, guibutton, this.buttonList)); } } break; @@ -206,9 +206,9 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } - public void func_146286_b(int mouseX, int mouseY, int state) { + public void mouseReleased(int mouseX, int mouseY, int state) { if (this.selectedButton != null && state == 0) { - this.selectedButton.func_146118_a(mouseX, mouseY); + this.selectedButton.mouseReleased(mouseX, mouseY); this.selectedButton = null; } @@ -217,7 +217,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { public void mouseEvent(int i, int j, int k) { } - protected void func_146284_a(GuiButton guibutton) { + protected void actionPerformed(GuiButton guibutton) { if (this.subgui != null) { this.subgui.buttonEvent(guibutton); } else { @@ -225,13 +225,11 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } } + public void buttonEvent(GuiButton guibutton){}; - public void buttonEvent(GuiButton guibutton) { - } - - public void func_73869_a(char c, int i) { + public void keyTyped(char c, int i) { if (this.subgui != null) { - this.subgui.func_73869_a(c, i); + this.subgui.keyTyped(c, i); } else { boolean active = false; Iterator var4 = this.components.iterator(); @@ -251,7 +249,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { while(var4.hasNext()) { GuiNpcTextField tf = (GuiNpcTextField)var4.next(); - tf.func_146201_a(c, i); + tf.textboxKeyTyped(c, i); } var4 = (new ArrayList(this.components)).iterator(); @@ -269,29 +267,29 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } } - public void func_146281_b() { + public void onGuiClosed() { GuiNpcTextField.unfocus(); } public void close() { this.displayGuiScreen((GuiScreen)null); - this.field_146297_k.func_71381_h(); + this.mc.setIngameFocus(); this.save(); } public void addButton(GuiNpcButton button) { - this.buttons.put(button.field_146127_k, button); - this.field_146292_n.add(button); + this.buttons.put(button.id, button); + this.buttonList.add(button); } public void addTopButton(GuiMenuTopButton button) { - this.topbuttons.put(button.field_146127_k, button); - this.field_146292_n.add(button); + this.topbuttons.put(button.id, button); + this.buttonList.add(button); } public void addSideButton(GuiMenuSideButton button) { - this.sidebuttons.put(button.field_146127_k, button); - this.field_146292_n.add(button); + this.sidebuttons.put(button.id, button); + this.buttonList.add(button); } public GuiNpcButton getButton(int i) { @@ -307,7 +305,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void addTextField(GuiNpcTextField tf) { - this.textfields.put(tf.field_175208_g, tf); + this.textfields.put(tf.id, tf); } public GuiNpcTextField getTextField(int i) { @@ -342,8 +340,8 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void addSlider(GuiNpcSlider slider) { - this.sliders.put(slider.field_146127_k, slider); - this.field_146292_n.add(slider); + this.sliders.put(slider.id, slider); + this.buttonList.add(slider); } public GuiNpcSlider getSlider(int i) { @@ -351,7 +349,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void addScroll(GuiCustomScroll scroll) { - scroll.func_146280_a(this.field_146297_k, 350, 250); + scroll.setWorldAndResolution(this.mc, 350, 250); this.scrolls.put(scroll.id, scroll); } @@ -361,7 +359,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { public abstract void save(); - public void func_73863_a(int mouseX, int mouseY, float partialTicks) { + public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.mouseX = mouseX; this.mouseY = mouseY; int x = mouseX; @@ -372,31 +370,31 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } if (this.drawDefaultBackground && this.subgui == null) { - this.func_146276_q_(); + this.drawDefaultBackground(); } - if (this.background != null && this.field_146297_k.field_71446_o != null) { - GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.func_179094_E(); - GlStateManager.func_179109_b((float)this.guiLeft, (float)this.guiTop, 0.0F); - GlStateManager.func_179152_a(this.bgScale, this.bgScale, this.bgScale); - this.field_146297_k.field_71446_o.func_110577_a(this.background); + if (this.background != null && this.mc.renderEngine != null) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPushMatrix(); + GL11.glTranslatef((float) this.guiLeft, (float) this.guiTop, 0.0F); + GL11.glScalef(this.bgScale, this.bgScale, this.bgScale); + this.mc.renderEngine.bindTexture(this.background); if (this.xSize > 256) { - this.func_73729_b(0, 0, 0, 0, 250, this.ySize); - this.func_73729_b(250, 0, 256 - (this.xSize - 250), 0, this.xSize - 250, this.ySize); + this.drawTexturedModalRect(0, 0, 0, 0, 250, this.ySize); + this.drawTexturedModalRect(250, 0, 256 - (this.xSize - 250), 0, this.xSize - 250, this.ySize); } else { - this.func_73729_b(0, 0, 0, 0, this.xSize, this.ySize); + this.drawTexturedModalRect(0, 0, 0, 0, this.xSize, this.ySize); } - GlStateManager.func_179121_F(); + GL11.glPopMatrix(); } - this.func_73732_a(this.field_146289_q, this.title, this.field_146294_l / 2, 8, 16777215); + this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 8, 16777215); Iterator var6 = (new ArrayList(this.labels.values())).iterator(); while(var6.hasNext()) { GuiNpcLabel label = (GuiNpcLabel)var6.next(); - label.drawLabel(this, this.field_146289_q); + label.drawLabel(this, this.fontRendererObj); } var6 = (new ArrayList(this.textfields.values())).iterator(); @@ -424,18 +422,18 @@ public abstract class EventGuiNPCInterface extends GuiScreen { while(var6.hasNext()) { GuiScreen gui = (GuiScreen)var6.next(); - gui.func_73863_a(x, y, partialTicks); + gui.drawScreen(x, y, partialTicks); } - super.func_73863_a(x, y, partialTicks); + super.drawScreen(x, y, partialTicks); if (this.subgui != null) { - this.subgui.func_73863_a(mouseX, mouseY, partialTicks); + this.subgui.drawScreen(mouseX, mouseY, partialTicks); } } public FontRenderer getFontRenderer() { - return this.field_146289_q; + return this.fontRendererObj; } public void elementClicked() { @@ -445,7 +443,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } - public boolean func_73868_f() { + public boolean doesGuiPauseGame() { return false; } @@ -453,23 +451,23 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public boolean isInventoryKey(int i) { - return i == this.field_146297_k.field_71474_y.field_151445_Q.func_151463_i(); + return i == this.mc.gameSettings.keyBindInventory.getKeyCode(); } - public void func_146276_q_() { - super.func_146276_q_(); + public void drawDefaultBackground() { + super.drawDefaultBackground(); } public void displayGuiScreen(GuiScreen gui) { - this.field_146297_k.func_147108_a(gui); + this.mc.displayGuiScreen(gui); } public void setSubGui(SubGuiInterface gui) { this.subgui = gui; this.subgui.npc = this.npc; - this.subgui.func_146280_a(this.field_146297_k, this.field_146294_l, this.field_146295_m); + this.subgui.setWorldAndResolution(this.mc, this.width, this.height); this.subgui.parent = this; - this.func_73866_w_(); + this.initGui(); } public void closeSubGui(SubGuiInterface gui) { @@ -489,58 +487,41 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation) { - EntityNPCInterface npc = null; - if (entity instanceof EntityNPCInterface) { - npc = (EntityNPCInterface)entity; - } - - GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.func_179142_g(); - GlStateManager.func_179094_E(); - GlStateManager.func_179109_b((float)(this.guiLeft + x), (float)(this.guiTop + y), 50.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glColorMaterial(0,1); + GL11.glPushMatrix(); + GL11.glTranslatef((float)(this.guiLeft + x), (float)(this.guiTop + y), 50.0F); float scale = 1.0F; - if ((double)entity.field_70131_O > 2.4D) { - scale = 2.0F / entity.field_70131_O; + if ((double)entity.height > 2.4D) { + scale = 2.0F / entity.height; } - GlStateManager.func_179152_a(-30.0F * scale * zoomed, 30.0F * scale * zoomed, 30.0F * scale * zoomed); - GlStateManager.func_179114_b(180.0F, 0.0F, 0.0F, 1.0F); - RenderHelper.func_74519_b(); - float f2 = entity.field_70761_aq; - float f3 = entity.field_70177_z; - float f4 = entity.field_70125_A; - float f7 = entity.field_70759_as; + GL11.glScalef(-30.0F * scale * zoomed, 30.0F * scale * zoomed, 30.0F * scale * zoomed); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + RenderHelper.enableStandardItemLighting(); + float f2 = entity.renderYawOffset; + float f3 = entity.rotationYaw; + float f4 = entity.rotationPitch; + float f7 = entity.rotationYawHead; float f5 = (float)(this.guiLeft + x) - (float)this.mouseX; float f6 = (float)(this.guiTop + y) - 50.0F * scale * zoomed - (float)this.mouseY; - int orientation = 0; - if (npc != null) { - orientation = npc.ais.orientation; - npc.ais.orientation = rotation; - } - GlStateManager.func_179114_b(135.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.func_179114_b(-135.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.func_179114_b(-((float)Math.atan((double)(f6 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); - entity.field_70761_aq = (float)rotation; - entity.field_70177_z = (float)Math.atan((double)(f5 / 80.0F)) * 40.0F + (float)rotation; - entity.field_70125_A = -((float)Math.atan((double)(f6 / 40.0F))) * 20.0F; - entity.field_70759_as = entity.field_70177_z; - this.field_146297_k.func_175598_ae().field_78735_i = 180.0F; - this.field_146297_k.func_175598_ae().func_188391_a(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); - entity.field_70760_ar = entity.field_70761_aq = f2; - entity.field_70126_B = entity.field_70177_z = f3; - entity.field_70127_C = entity.field_70125_A = f4; - entity.field_70758_at = entity.field_70759_as = f7; - if (npc != null) { - npc.ais.orientation = orientation; - } + GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-((float) Math.atan((double) (f6 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); + entity.renderYawOffset = (float)rotation; + entity.rotationYaw = (float)Math.atan((double)(f5 / 80.0F)) * 40.0F + (float)rotation; + entity.rotationPitch = -((float)Math.atan((double)(f6 / 40.0F))) * 20.0F; + entity.rotationYawHead = entity.rotationYaw; + RenderItem.getInstance().zLevel = 180.0F; + RenderItem.getInstance().doRender(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); + entity.prevRenderYawOffset = entity.renderYawOffset = f2; + entity.prevRotationYaw = entity.rotationYaw = f3; + entity.prevRotationPitch = entity.rotationPitch = f4; + entity.prevRotationYawHead = entity.rotationYawHead = f7; - GlStateManager.func_179121_F(); - RenderHelper.func_74518_a(); - GlStateManager.func_179101_C(); - GlStateManager.func_179138_g(OpenGlHelper.field_77476_b); - GlStateManager.func_179090_x(); - GlStateManager.func_179138_g(OpenGlHelper.field_77478_a); + GL11.glPopMatrix(); + RenderHelper.disableStandardItemLighting(); } public void openLink(String link) { diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java new file mode 100644 index 000000000..533a7654f --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java @@ -0,0 +1,111 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.script; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.EventScriptContainer; +import noppes.npcs.client.gui.util.GuiCustomScroll; +import noppes.npcs.client.gui.util.GuiNpcButton; +import noppes.npcs.client.gui.util.GuiNpcLabel; +import noppes.npcs.client.gui.util.SubGuiInterface; + +public class EventGuiScriptList extends SubGuiInterface { + private GuiCustomScroll scroll1; + private GuiCustomScroll scroll2; + private EventScriptContainer container; + private List scripts; + + public EventGuiScriptList(List scripts, EventScriptContainer container) { + this.container = container; + this.setBackground("menubg.png"); + this.xSize = 346; + this.ySize = 216; + if(scripts == null) { + scripts = new ArrayList(); + } + + this.scripts = (List)scripts; + } + + public void initGui() { + super.initGui(); + if(this.scroll1 == null) { + this.scroll1 = new GuiCustomScroll(this, 0); + this.scroll1.setSize(140, 180); + } + + this.scroll1.guiLeft = this.guiLeft + 4; + this.scroll1.guiTop = this.guiTop + 14; + this.addScroll(this.scroll1); + this.addLabel(new GuiNpcLabel(1, "script.availableScripts", this.guiLeft + 4, this.guiTop + 4)); + if(this.scroll2 == null) { + this.scroll2 = new GuiCustomScroll(this, 1); + this.scroll2.setSize(140, 180); + } + + this.scroll2.guiLeft = this.guiLeft + 200; + this.scroll2.guiTop = this.guiTop + 14; + this.addScroll(this.scroll2); + this.addLabel(new GuiNpcLabel(2, "script.loadedScripts", this.guiLeft + 200, this.guiTop + 4)); + ArrayList temp = new ArrayList(this.scripts); + temp.removeAll(this.container.scripts); + this.scroll1.setList(temp); + this.scroll2.setList(this.container.scripts); + this.addButton(new GuiNpcButton(1, this.guiLeft + 145, this.guiTop + 40, 55, 20, ">")); + this.addButton(new GuiNpcButton(2, this.guiLeft + 145, this.guiTop + 62, 55, 20, "<")); + this.addButton(new GuiNpcButton(3, this.guiLeft + 145, this.guiTop + 90, 55, 20, ">>")); + this.addButton(new GuiNpcButton(4, this.guiLeft + 145, this.guiTop + 112, 55, 20, "<<")); + this.addButton(new GuiNpcButton(66, this.guiLeft + 260, this.guiTop + 194, 60, 20, "gui.done")); + } + + protected void actionPerformed(GuiButton guibutton) { + GuiNpcButton button = (GuiNpcButton)guibutton; + if(button.id == 1 && this.scroll1.hasSelected()) { + this.container.scripts.add(this.scroll1.getSelected()); + this.scroll1.selected = -1; + this.scroll1.selected = -1; + this.initGui(); + } + + if(button.id == 2 && this.scroll2.hasSelected()) { + this.container.scripts.remove(this.scroll2.getSelected()); + this.scroll2.selected = -1; + this.initGui(); + } + + if(button.id == 3) { + this.container.scripts.clear(); + Iterator var3 = this.scripts.iterator(); + + while(var3.hasNext()) { + String script = (String)var3.next(); + this.container.scripts.add(script); + } + + this.scroll1.selected = -1; + this.scroll1.selected = -1; + this.initGui(); + } + + if(button.id == 4) { + this.container.scripts.clear(); + this.scroll1.selected = -1; + this.scroll1.selected = -1; + this.initGui(); + } + + if(button.id == 66) { + this.close(); + } + + } + + public void save() { + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java deleted file mode 100644 index a108ef1bc..000000000 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java +++ /dev/null @@ -1,284 +0,0 @@ -package noppes.npcs.client.gui.script; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiConfirmOpenLink; -import net.minecraft.client.gui.GuiYesNoCallback; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.server.MinecraftServer; -import noppes.npcs.EventDataScript; -import noppes.npcs.EventScriptContainer; -import noppes.npcs.NoppesStringUtils; -import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.EventGuiScriptList; -import noppes.npcs.client.gui.swing.GuiJTextArea; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.controllers.ScriptContainer; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.PlayerScriptData; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class GuiScriptEvent extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener { - public boolean showScript = false; - private int activeTab = 0; - private String activeScriptTab = "init"; - private PlayerScriptData script = new PlayerScriptData((EntityPlayer)null); - public Map> languages = new HashMap>(); - - private static int activeConsole = 0; - - public GuiScriptEvent(){ - super(); - drawDefaultBackground = true; - closeOnEsc = true; - xSize = 420; - - setBackground("menubg.png"); - Client.sendData(EnumPacketServer.ScriptPlayerGet); - } - - public void initGui() { - super.initGui(); - guiTop += 10; - GuiMenuTopButton top; - addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); - top.active = showScript; - addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); - top.active = !showScript; - addTopButton(new GuiMenuTopButton(15, top, "gui.website")); - - List list = new ArrayList(); - list.add("playerscript.attack"); - list.add("playerscript.chat"); - list.add("playerscript.containerclosed"); - list.add("playerscript.containeropen"); - list.add("playerscript.damagedentity"); - list.add("playerscript.damaged"); - list.add("playerscript.killed"); - list.add("playerscript.init"); - list.add("playerscript.interact"); - list.add("playerscript.keypressed"); - list.add("playerscript.kills"); - list.add("playerscript.levelup"); - list.add("playerscript.login"); - list.add("playerscript.logout"); - list.add("playerscript.pickup"); - list.add("playerscript.rangedlaunched"); - list.add("playerscript.toss"); - list.add("playerscript.update"); - - if(showScript) { - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(list); - hooks.selected = script.getScripts().indexOf(activeScriptTab); - addScroll(hooks); - - EventScriptContainer container = script.getScripts().get(script.getScripts().indexOf(activeScriptTab)); - - addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); - - addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); - addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); - addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); - - addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); - - addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); - - GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); - scroll.setSize(100, 120); - scroll.guiLeft = guiLeft + 315; - scroll.guiTop = guiTop + 92; - if(container != null) - scroll.setList(container.scripts); - addScroll(scroll); - } - else{ - addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); - getTopButton(14).active = true; - addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); - getTextField(2).canEdit = false; - addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); - addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); - - List l = new ArrayList(); - l.add("All"); - l.addAll(list); - addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); - - addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); - addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); - getButton(103).enabled = languages.size() > 0; - - addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); - //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, script.enabled?1:0)); - - if(MinecraftServer.getServer() != null) - addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); - } - } - - private int getScriptIndex() { - int i = 0; - for(String language : languages.keySet()){ - if(language.equalsIgnoreCase(script.getLanguage())) - return i; - i++; - } - return 0; - } - - private String getConsoleText() { - String console = ""; - if(activeConsole == 0){ - for(EventScriptContainer container : script.scripts){ - if(!container.console.isEmpty()) - for(Long l : container.console.keySet()) - console += container.console.get(l) + '\n'; - } - } - else{ - EventScriptContainer container = script.scripts.get(activeConsole - 1); - if(container != null) - console = container.console.toString(); - } - return console; - } - - @Override - public void confirmClicked(boolean flag, int i){ - if(flag) - openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); - displayGuiScreen(this); - } - - @Override - protected void actionPerformed(GuiButton guibutton) { - if(guibutton.id == 13){ - showScript = true; - initGui(); - } - if(guibutton.id == 14){ - setScript(); - showScript = false; - initGui(); - } - if(guibutton.id == 15){ - GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true); - mc.displayGuiScreen(guiyesno); - } - if (guibutton.id == 100) { - NoppesStringUtils.setClipboardContents(getTextField(2).getText()); - } - if (guibutton.id == 101) { - getTextField(2).setText(NoppesStringUtils.getClipboardContents()); - } - if (guibutton.id == 102) { - getTextField(2).setText(""); - if(!showScript){ - if(activeConsole == 0){ - for(EventScriptContainer container : script.scripts) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } - else{ - System.out.println("test"); - EventScriptContainer container = script.scripts.get(activeConsole - 1); - System.out.println("test2"); - if(container != null) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } - } - } - if (guibutton.id == 103) { - script.setLanguage(((GuiNpcButton)guibutton).displayString); - } - if (guibutton.id == 104) { - script.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); - } - if (guibutton.id == 105) { - activeConsole = ((GuiNpcButton)guibutton).getValue(); - initGui(); - } - if (guibutton.id == 106) { - NoppesUtil.openFolder(ScriptController.Instance.dir); - } - if (guibutton.id == 107) { - EventScriptContainer container = script.scripts.get(activeTab); - if(container == null) - script.scripts.set(activeTab, container = new EventScriptContainer(new EventDataScript())); - setSubGui(new EventGuiScriptList(languages.get(script.getLanguage()), container)); - } - if (guibutton.id == 108) { - EventScriptContainer container = script.scripts.get(activeTab); - if(container != null){ - setScript(); - this.AWTWindow = new GuiJTextArea(container.script).setListener(this); - } - } - } - - private void setScript(){ - if(showScript){ - EventScriptContainer container = script.scripts.get(activeTab); - if(container == null) - script.scripts.set(activeTab, container = new EventScriptContainer(new EventDataScript())); - String text = getTextField(2).getText(); - text = text.replace("\r\n", "\n"); - text = text.replace("\r", "\n"); - container.script = text; - } - } - - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { - if(scroll.id == 1){ - setScript(); - activeTab = scroll.selected; - initGui(); - } - } - - @Override - public void saveText(String text) { - EventScriptContainer container = script.scripts.get(activeTab); - if(container != null) - container.script = text; - initGui(); - } - - @Override - public void setGuiData(NBTTagCompound compound) { - script.readFromNBT(compound); - NBTTagList data = compound.getTagList("Languages", 10); - Map> languages = new HashMap>(); - for(int i = 0; i < data.tagCount(); i++){ - NBTTagCompound comp = data.getCompoundTagAt(i); - List scripts = new ArrayList(); - NBTTagList list = comp.getTagList("Scripts", 8); - for(int j = 0; j < list.tagCount(); j++){ - scripts.add(list.getStringTagAt(j)); - } - languages.put(comp.getString("Language"), scripts); - } - this.languages = languages; - initGui(); - } - - @Override - public void save() { - Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); - } -} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java index a1fa86401..e554014e4 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -9,8 +9,9 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; +import org.lwjgl.opengl.GL11; -public class GuiScriptGlobal extends GuiNPCInterface { +public class GuiScriptGlobal extends EventGuiNPCInterface { private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png"); public GuiScriptGlobal() { @@ -23,12 +24,12 @@ public class GuiScriptGlobal extends GuiNPCInterface { public void initGui() { super.initGui(); this.addButton(new GuiNpcButton(0, this.guiLeft + 38, this.guiTop + 20, 100, 20, "Players")); - //this.addButton(new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge")); + this.addButton(new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge")); } public void drawScreen(int i, int j, float f) { this.drawDefaultBackground(); - //GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(this.resource); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); super.drawScreen(i, j, f); @@ -38,18 +39,15 @@ public class GuiScriptGlobal extends GuiNPCInterface { if (guibutton.id == 0) { this.displayGuiScreen(new GuiScriptPlayers()); } - /* - if (guibutton.id == 1) { + /*if (guibutton.id == 1) { this.displayGuiScreen(new GuiScriptForge()); - } - */ + }*/ } public void keyTyped(char c, int i) { if (i == 1 || this.isInventoryKey(i)) { this.close(); } - } public void save() { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 7e4c0676c..375a45cb5 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -1,6 +1,6 @@ // // Source code recreated from a .class file by IntelliJ IDEA -// (powered by FernFlower decompiler) +// (powered by Fernflower decompiler) // package noppes.npcs.client.gui.script; @@ -16,31 +16,20 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiConfirmOpenLink; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.server.MinecraftServer; -import noppes.npcs.EventDataScript; import noppes.npcs.EventScriptContainer; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.EventGuiScriptList; -import noppes.npcs.client.gui.swing.GuiJTextArea; import noppes.npcs.client.gui.util.*; import noppes.npcs.controllers.IScriptHandler; -import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.PlayerScriptData; -public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITextChangeListener, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener { +public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener { private int activeTab = 0; public IScriptHandler handler; - private String activeScriptTab = "init"; public Map> languages = new HashMap(); - public boolean showScript = false; - private static int activeConsole = 0; - public GuiScriptInterface() { this.drawDefaultBackground = true; this.closeOnEsc = true; @@ -49,98 +38,91 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe } public void initGui() { + this.xSize = (int)((double)this.width * 0.88D); + this.ySize = (int)((double)this.xSize * 0.56D); + if((double)this.ySize > (double)this.height * 0.95D) { + this.ySize = (int)((double)this.height * 0.95D); + this.xSize = (int)((double)this.ySize / 0.56D); + } + + this.bgScale = (float)this.xSize / 400.0F; super.initGui(); - guiTop += 10; + this.guiTop += 10; + int yoffset = (int)((double)this.ySize * 0.02D); GuiMenuTopButton top; - addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); - top.active = showScript; - addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); - top.active = !showScript; - addTopButton(new GuiMenuTopButton(15, top, "gui.website")); + this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings")); - List list = new ArrayList(); - list.add("playerscript.attack"); - list.add("playerscript.chat"); - list.add("playerscript.containerclosed"); - list.add("playerscript.containeropen"); - list.add("playerscript.damagedentity"); - list.add("playerscript.damaged"); - list.add("playerscript.killed"); - list.add("playerscript.init"); - list.add("playerscript.interact"); - list.add("playerscript.keypressed"); - list.add("playerscript.kills"); - list.add("playerscript.levelup"); - list.add("playerscript.login"); - list.add("playerscript.logout"); - list.add("playerscript.pickup"); - list.add("playerscript.rangedlaunched"); - list.add("playerscript.toss"); - list.add("playerscript.update"); - - if(showScript) { - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(list); - hooks.selected = activeTab; - addScroll(hooks); - - EventScriptContainer container = handler.getScripts().get(activeTab); - - addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); - - addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); - addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); - addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); - - addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); - - addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); - - GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); - scroll.setSize(100, 120); - scroll.guiLeft = guiLeft + 315; - scroll.guiTop = guiTop + 92; - if(container != null) - scroll.setList(container.scripts); - addScroll(scroll); + for(int ta = 0; ta < this.handler.getScripts().size(); ++ta) { + EventScriptContainer var10000 = (EventScriptContainer)this.handler.getScripts().get(ta); + this.addTopButton(top = new GuiMenuTopButton(ta + 1, top, ta + 1 + "")); } - else{ - addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); - getTopButton(14).active = true; - addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); - getTextField(2).canEdit = false; - addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); - addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); - List l = new ArrayList(); - l.add("All"); - l.addAll(list); - addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); - - addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); - addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); - getButton(103).enabled = languages.size() > 0; - - addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); - //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, handler.enabled?1:0)); - - if(MinecraftServer.getServer() != null) - addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); + if(this.handler.getScripts().size() < 16) { + this.addTopButton(new GuiMenuTopButton(12, top, "+")); } + + top = this.getTopButton(this.activeTab); + if(top == null) { + this.activeTab = 0; + top = this.getTopButton(0); + } + + top.active = true; + if(this.activeTab > 0) { + EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + GuiTextArea left = new GuiTextArea(2, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); + //left.enableCodeHighlighting(); + //left.setListener(this); + this.add(left); + int left1 = this.guiLeft + this.xSize - 104; + this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear")); + this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste")); + this.addButton(new GuiNpcButton(100, left1, this.guiTop + 21 + yoffset, 60, 20, "gui.copy")); + this.addButton(new GuiNpcButton(105, left1 + 61, this.guiTop + 21 + yoffset, 60, 20, "gui.remove")); + this.addButton(new GuiNpcButton(107, left1, this.guiTop + 66 + yoffset, 80, 20, "script.loadscript")); + GuiCustomScroll scroll = (new GuiCustomScroll(this, 0)).setUnselectable(); + scroll.setSize(100, (int)((double)this.ySize * 0.54D) - yoffset * 2); + scroll.guiLeft = left1; + scroll.guiTop = this.guiTop + 88 + yoffset; + if(var7 != null) { + scroll.setList(var7.scripts); + } + + this.addScroll(scroll); + } else { + GuiTextArea var8 = new GuiTextArea(2, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText()); + var8.enabled = false; + this.add(var8); + int var9 = this.guiLeft + this.xSize - 150; + this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy")); + this.addButton(new GuiNpcButton(102, var9, this.guiTop + 146, 60, 20, "gui.clear")); + this.addLabel(new GuiNpcLabel(1, "script.language", var9, this.guiTop + 15)); + this.addButton(new GuiNpcButton(103, var9 + 60, this.guiTop + 10, 80, 20, (String[])this.languages.keySet().toArray(new String[this.languages.keySet().size()]), this.getScriptIndex())); + this.getButton(103).enabled = this.languages.size() > 0; + this.addLabel(new GuiNpcLabel(2, "gui.enabled", var9, this.guiTop + 36)); + this.addButton(new GuiNpcButton(104, var9 + 60, this.guiTop + 31, 50, 20, new String[]{"gui.no", "gui.yes"}, this.handler.getEnabled()?1:0)); + if(this.player.worldObj.isRemote) { + this.addButton(new GuiNpcButton(106, var9, this.guiTop + 55, 150, 20, "script.openfolder")); + } + + this.addButton(new GuiNpcButton(109, var9, this.guiTop + 78, 80, 20, "gui.website")); + this.addButton(new GuiNpcButton(112, var9 + 81, this.guiTop + 78, 80, 20, "gui.forum")); + this.addButton(new GuiNpcButton(110, var9, this.guiTop + 99, 80, 20, "script.apidoc")); + this.addButton(new GuiNpcButton(111, var9 + 81, this.guiTop + 99, 80, 20, "script.apisrc")); + } + + this.xSize = 420; + this.ySize = 256; } private String getConsoleText() { - Map map = this.handler.getConsoleText(); + Map map = this.handler.getConsoleText(); StringBuilder builder = new StringBuilder(); Iterator var3 = map.entrySet().iterator(); while(var3.hasNext()) { - Entry entry = (Entry)var3.next(); - builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n"); + Entry entry = (Entry)var3.next(); + builder.insert(0, new Date(((Long)entry.getKey()).longValue()) + (String)entry.getValue() + "\n"); } return builder.toString(); @@ -151,7 +133,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe for(Iterator var2 = this.languages.keySet().iterator(); var2.hasNext(); ++i) { String language = (String)var2.next(); - if (language.equalsIgnoreCase(this.handler.getLanguage())) { + if(language.equalsIgnoreCase(this.handler.getLanguage())) { return i; } } @@ -159,25 +141,25 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe return 0; } - public void func_73878_a(boolean flag, int i) { - if (flag) { - if (i == 0) { + public void confirmClicked(boolean flag, int i) { + if(flag) { + if(i == 0) { this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); } - if (i == 1) { + if(i == 1) { this.openLink("http://www.kodevelopment.nl/customnpcs/api/"); } - if (i == 2) { + if(i == 2) { this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); } - if (i == 3) { + if(i == 3) { this.openLink("http://www.minecraftforge.net/forum/index.php/board,122.0.html"); } - if (i == 10) { + if(i == 10) { this.handler.getScripts().remove(this.activeTab - 1); this.activeTab = 0; } @@ -187,79 +169,97 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe } protected void actionPerformed(GuiButton guibutton) { - if(guibutton.id == 13){ - showScript = true; - initGui(); + if(guibutton.id >= 0 && guibutton.id < 12) { + this.setScript(); + this.activeTab = guibutton.id; + this.initGui(); } - if(guibutton.id == 14){ - setScript(); - showScript = false; - initGui(); + + if(guibutton.id == 12) { + this.handler.getScripts().add(new EventScriptContainer(this.handler)); + this.activeTab = this.handler.getScripts().size(); + this.initGui(); } - if(guibutton.id == 15){ - GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true); - mc.displayGuiScreen(guiyesno); + + if(guibutton.id == 109) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true)); } - if (guibutton.id == 100) { - NoppesStringUtils.setClipboardContents(getTextField(2).getText()); + + if(guibutton.id == 110) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/customnpcs/api/", 1, true)); } - if (guibutton.id == 101) { - getTextField(2).setText(NoppesStringUtils.getClipboardContents()); + + if(guibutton.id == 111) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://github.com/Noppes/CustomNPCsAPI", 2, true)); } - if (guibutton.id == 102) { - getTextField(2).setText(""); - if(!showScript){ - if(activeConsole == 0){ - for(EventScriptContainer container : handler.getScripts()) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } - else{ - System.out.println("test"); - EventScriptContainer container = handler.getScripts().get(activeConsole - 1); - System.out.println("test2"); - if(container != null) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } + + if(guibutton.id == 112) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.minecraftforge.net/forum/index.php/board,122.0.html", 3, true)); + } + + if(guibutton.id == 100) { + NoppesStringUtils.setClipboardContents(((GuiTextArea)this.get(2)).getText()); + } + + if(guibutton.id == 101) { + ((GuiTextArea)this.get(2)).setText(NoppesStringUtils.getClipboardContents()); + } + + EventScriptContainer container; + if(guibutton.id == 102) { + if(this.activeTab > 0) { + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container.script = ""; + } else { + this.handler.clearConsole(); } + + this.initGui(); } - if (guibutton.id == 103) { - handler.setLanguage(((GuiNpcButton)guibutton).displayString); + + if(guibutton.id == 103) { + this.handler.setLanguage(((GuiNpcButton)guibutton).displayString); } - if (guibutton.id == 104) { - handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); + + if(guibutton.id == 104) { + this.handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); } - if (guibutton.id == 105) { - activeConsole = ((GuiNpcButton)guibutton).getValue(); - initGui(); + + if(guibutton.id == 105) { + GuiYesNo container1 = new GuiYesNo(this, "", ((GuiNpcButton)guibutton).displayString, 10); + this.displayGuiScreen(container1); } - if (guibutton.id == 106) { + + if(guibutton.id == 106) { NoppesUtil.openFolder(ScriptController.Instance.dir); } - if (guibutton.id == 107) { - EventScriptContainer container = handler.getScripts().get(activeTab); - if(container == null) - handler.getScripts().set(activeTab, container = new EventScriptContainer(new EventDataScript())); - setSubGui(new EventGuiScriptList(languages.get(handler.getLanguage()), container)); - } - if (guibutton.id == 108) { - EventScriptContainer container = handler.getScripts().get(activeTab); - if(container != null){ - setScript(); - this.AWTWindow = new GuiJTextArea(container.script).setListener(this); - } - } - } - private void setScript() { - if (this.activeTab > 0) { - EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - if (container == null) { + if(guibutton.id == 107) { + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if(container == null) { this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); } - String text = this.getConsoleText(); + this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.handler.getLanguage()), container)); + } + + if(guibutton.id == 108) { + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if(container != null) { + this.setScript(); + } + } + + } + + private void setScript() { + if(this.activeTab > 0) { + EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if(container == null) { + this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); + } + + String text = ((GuiTextArea)this.get(2)).getText(); text = text.replace("\r\n", "\n"); text = text.replace("\r", "\n"); container.script = text; @@ -269,11 +269,11 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe public void setGuiData(NBTTagCompound compound) { NBTTagList data = compound.getTagList("Languages", 10); - Map> languages = new HashMap(); + HashMap languages = new HashMap(); for(int i = 0; i < data.tagCount(); ++i) { NBTTagCompound comp = data.getCompoundTagAt(i); - List scripts = new ArrayList(); + ArrayList scripts = new ArrayList(); NBTTagList list = comp.getTagList("Scripts", 8); for(int j = 0; j < list.tagCount(); ++j) { @@ -293,25 +293,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe public void textUpdate(String text) { EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - if (container != null) { + if(container != null) { container.script = text; } - } - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { - if(scroll.id == 1){ - setScript(); - activeTab = scroll.selected; - initGui(); - } - } - - @Override - public void saveText(String text) { - EventScriptContainer container = handler.getScripts().get(activeTab); - if(container != null) - container.script = text; - initGui(); } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index f567c7043..362400803 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -280,4 +280,7 @@ public class GuiCustomScroll extends GuiScreen return this; } + public boolean isMouseOver(int x, int y) { + return x >= this.guiLeft && x <= this.guiLeft + this.xSize && y >= this.guiTop && y <= this.guiTop + this.ySize; + } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java new file mode 100644 index 000000000..5103da22e --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java @@ -0,0 +1,473 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +import java.awt.Font; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraftforge.client.GuiIngameForge; +import noppes.npcs.CustomNpcs; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.client.gui.util.TextContainer.LineData; +import noppes.npcs.config.TrueTypeFont; +import org.lwjgl.input.Mouse; + +public class GuiTextArea extends Gui implements IGui, IKeyListener, IMouseListener { + public int id; + public int x; + public int y; + public int width; + public int height; + private int cursorCounter; + private ITextChangeListener listener; + private static TrueTypeFont font; + public String text = null; + private TextContainer container = null; + public boolean active = false; + public boolean enabled = true; + public boolean visible = true; + public boolean clicked = false; + public boolean doubleClicked = false; + public boolean clickScrolling = false; + private int startSelection; + private int endSelection; + private int cursorPosition; + private int scrolledLine = 0; + private boolean enableCodeHighlighting = false; + private static final char colorChar = '\uffff'; + public List undoList = new ArrayList(); + public List redoList = new ArrayList(); + public boolean undoing = false; + private long lastClicked = 0L; + + public GuiTextArea(int id, int x, int y, int width, int height, String text) { + this.id = id; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.undoing = true; + this.setText(text); + this.undoing = false; + font.setSpecial('\uffff'); + } + + public void drawScreen(int xMouse, int yMouse) { + if(this.visible) { + drawRect(this.x - 1, this.y - 1, this.x + this.width + 1, this.y + this.height + 1, -6250336); + drawRect(this.x, this.y, this.x + this.width, this.y + this.height, -16777216); + this.container.visibleLines = this.height / this.container.lineHeight; + int startBracket; + if(this.clicked) { + this.clicked = Mouse.isButtonDown(0); + startBracket = this.getSelectionPos(xMouse, yMouse); + if(startBracket != this.cursorPosition) { + if(this.doubleClicked) { + this.startSelection = this.endSelection = this.cursorPosition; + this.doubleClicked = false; + } + + this.setCursor(startBracket, true); + } + } else if(this.doubleClicked) { + this.doubleClicked = false; + } + + if(this.clickScrolling) { + this.clickScrolling = Mouse.isButtonDown(0); + startBracket = this.container.linesCount - this.container.visibleLines; + this.scrolledLine = Math.min(Math.max((int)(1.0F * (float)startBracket * (float)(yMouse - this.y) / (float)this.height), 0), startBracket); + } + + startBracket = 0; + int endBracket = 0; + if(this.endSelection - this.startSelection == 1 || this.startSelection == this.endSelection && this.startSelection < this.text.length()) { + char list = this.text.charAt(this.startSelection); + int wordHightLight = 0; + if(list == 123) { + wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '{', '}'); + } else if(list == 91) { + wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '[', ']'); + } else if(list == 40) { + wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '(', ')'); + } else if(list == 125) { + wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '{', '}'); + } else if(list == 93) { + wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '[', ']'); + } else if(list == 41) { + wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '(', ')'); + } + + if(wordHightLight != 0) { + startBracket = this.startSelection; + endBracket = this.startSelection + wordHightLight; + } + } + + ArrayList var15 = new ArrayList(this.container.lines); + String var18 = null; + if(this.startSelection != this.endSelection) { + Matcher sbSize = this.container.regexWord.matcher(this.text); + + while(sbSize.find()) { + if(sbSize.start() == this.startSelection && sbSize.end() == this.endSelection) { + var18 = this.text.substring(this.startSelection, this.endSelection); + } + } + } + + int var16; + for(var16 = 0; var16 < var15.size(); ++var16) { + LineData posX = (LineData)var15.get(var16); + String posY = posX.text; + int w = posY.length(); + int yPos; + int posX1; + int posY1; + if(startBracket != endBracket) { + if(startBracket >= posX.start && startBracket < posX.end) { + yPos = font.width(posY.substring(0, startBracket - posX.start)); + posX1 = font.width(posY.substring(0, startBracket - posX.start + 1)) + 1; + posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728001024); + } + + if(endBracket >= posX.start && endBracket < posX.end) { + yPos = font.width(posY.substring(0, endBracket - posX.start)); + posX1 = font.width(posY.substring(0, endBracket - posX.start + 1)) + 1; + posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728001024); + } + } + + if(var16 >= this.scrolledLine && var16 < this.scrolledLine + this.container.visibleLines) { + if(var18 != null) { + Matcher var20 = this.container.regexWord.matcher(posY); + + while(var20.find()) { + if(posY.substring(var20.start(), var20.end()).equals(var18)) { + posX1 = font.width(posY.substring(0, var20.start())); + posY1 = font.width(posY.substring(0, var20.end())) + 1; + int posY2 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + posX1, posY2, this.x + 1 + posY1, posY2 + this.container.lineHeight + 1, -1728033792); + } + } + } + + if(this.startSelection != this.endSelection && this.endSelection > posX.start && this.startSelection <= posX.end && this.startSelection < posX.end) { + yPos = font.width(posY.substring(0, Math.max(this.startSelection - posX.start, 0))); + posX1 = font.width(posY.substring(0, Math.min(this.endSelection - posX.start, w))) + 1; + posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728052993); + } + + yPos = this.y + (var16 - this.scrolledLine) * this.container.lineHeight + 1; + font.draw(posX.getFormattedString(), (float)(this.x + 1), (float)yPos, -2039584); + if(this.active && this.isEnabled() && this.cursorCounter / 6 % 2 == 0 && this.cursorPosition >= posX.start && this.cursorPosition < posX.end) { + posX1 = this.x + font.width(posY.substring(0, this.cursorPosition - posX.start)); + drawRect(posX1 + 1, yPos, posX1 + 2, yPos + 1 + this.container.lineHeight, -3092272); + } + } + } + + if(this.hasVerticalScrollbar()) { + Minecraft.getMinecraft().renderEngine.bindTexture(GuiCustomScroll.resource); + + var16 = Math.max((int)(1.0F * (float)this.container.visibleLines / (float)this.container.linesCount * (float)this.height), 2); + int var17 = this.x + this.width - 6; + int var19 = (int)((float)this.y + 1.0F * (float)this.scrolledLine / (float)this.container.linesCount * (float)(this.height - 4)) + 1; + drawRect(var17, var19, var17 + 5, var19 + var16, -2039584); + } + + } + } + + private int findClosingBracket(String str, char s, char e) { + int found = 0; + char[] chars = str.toCharArray(); + + for(int i = 0; i < chars.length; ++i) { + char c = chars[i]; + if(c == s) { + ++found; + } else if(c == e) { + --found; + if(found == 0) { + return i; + } + } + } + + return 0; + } + + private int findOpeningBracket(String str, char s, char e) { + int found = 0; + char[] chars = str.toCharArray(); + + for(int i = chars.length - 1; i >= 0; --i) { + char c = chars[i]; + if(c == e) { + ++found; + } else if(c == s) { + --found; + if(found == 0) { + return i - chars.length + 1; + } + } + } + + return 0; + } + + private int getSelectionPos(int xMouse, int yMouse) { + xMouse -= this.x + 1; + yMouse -= this.y + 1; + ArrayList list = new ArrayList(this.container.lines); + + for(int i = 0; i < list.size(); ++i) { + LineData data = (LineData)list.get(i); + if(i >= this.scrolledLine && i < this.scrolledLine + this.container.visibleLines) { + int yPos = (i - this.scrolledLine) * this.container.lineHeight; + if(yMouse >= yPos && yMouse < yPos + this.container.lineHeight) { + int lineWidth = 0; + char[] chars = data.text.toCharArray(); + + for(int j = 1; j <= chars.length; ++j) { + int w = font.width(data.text.substring(0, j)); + if(xMouse < lineWidth + (w - lineWidth) / 2) { + return data.start + j - 1; + } + + lineWidth = w; + } + + return data.end - 1; + } + } + } + + return this.container.text.length(); + } + + public int getID() { + return this.id; + } + + + public void keyTyped(char c, int i) { + if(this.active && this.isEnabled()) { + if(i == 15) { + this.addText(" "); + } + + if(i == 28) { + this.addText(Character.toString('\n') + this.getIndentCurrentLine()); + } + + if(ChatAllowedCharacters.isAllowedCharacter(c)) { + this.addText(Character.toString(c)); + } + } + } + + private String getIndentCurrentLine() { + Iterator var1 = this.container.lines.iterator(); + + LineData data; + do { + if(!var1.hasNext()) { + return ""; + } + + data = (LineData)var1.next(); + } while(this.cursorPosition <= data.start || this.cursorPosition > data.end); + + int i; + for(i = 0; i < data.text.length() && data.text.charAt(i) == 32; ++i) { + ; + } + + return data.text.substring(0, i); + } + + private void setCursor(int i, boolean select) { + i = Math.min(Math.max(i, 0), this.text.length()); + if(i != this.cursorPosition) { + if(!select) { + this.endSelection = this.startSelection = this.cursorPosition = i; + } else { + int diff = this.cursorPosition - i; + if(this.cursorPosition == this.startSelection) { + this.startSelection -= diff; + } else if(this.cursorPosition == this.endSelection) { + this.endSelection -= diff; + } + + if(this.startSelection > this.endSelection) { + int j = this.endSelection; + this.endSelection = this.startSelection; + this.startSelection = j; + } + + this.cursorPosition = i; + } + } + } + + private void addText(String s) { + this.setText(this.getSelectionBeforeText() + s + this.getSelectionAfterText()); + this.endSelection = this.startSelection = this.cursorPosition = this.startSelection + s.length(); + } + + private int cursorUp() { + for(int i = 0; i < this.container.lines.size(); ++i) { + LineData data = (LineData)this.container.lines.get(i); + if(this.cursorPosition >= data.start && this.cursorPosition < data.end) { + if(i == 0) { + return 0; + } + + int var10000 = this.cursorPosition - data.start; + return this.getSelectionPos(this.x + 1 + font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i - 1 - this.scrolledLine) * this.container.lineHeight); + } + } + + return 0; + } + + private int cursorDown() { + for(int i = 0; i < this.container.lines.size(); ++i) { + LineData data = (LineData)this.container.lines.get(i); + if(this.cursorPosition >= data.start && this.cursorPosition < data.end) { + int var10000 = this.cursorPosition - data.start; + return this.getSelectionPos(this.x + 1 + font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i + 1 - this.scrolledLine) * this.container.lineHeight); + } + } + + return this.text.length(); + } + + public String getSelectionBeforeText() { + return this.startSelection == 0?"":this.text.substring(0, this.startSelection); + } + + public String getSelectionAfterText() { + return this.text.substring(this.endSelection); + } + + public boolean mouseClicked(int xMouse, int yMouse, int mouseButton) { + this.active = xMouse >= this.x && xMouse < this.x + this.width && yMouse >= this.y && yMouse < this.y + this.height; + if(this.active) { + this.startSelection = this.endSelection = this.cursorPosition = this.getSelectionPos(xMouse, yMouse); + this.clicked = mouseButton == 0; + this.doubleClicked = false; + long time = System.currentTimeMillis(); + if(this.clicked && this.container.linesCount * this.container.lineHeight > this.height && xMouse > this.x + this.width - 8) { + this.clicked = false; + this.clickScrolling = true; + } else if(time - this.lastClicked < 500L) { + this.doubleClicked = true; + Matcher m = this.container.regexWord.matcher(this.text); + + while(m.find()) { + if(this.cursorPosition > m.start() && this.cursorPosition < m.end()) { + this.startSelection = m.start(); + this.endSelection = m.end(); + break; + } + } + } + + this.lastClicked = time; + } + + return this.active; + } + + public void updateScreen() { + ++this.cursorCounter; + int k2 = Mouse.getDWheel(); + if(k2 != 0) { + this.scrolledLine += k2 > 0?-1:1; + this.scrolledLine = Math.max(Math.min(this.scrolledLine, this.container.linesCount - this.height / this.container.lineHeight), 0); + } + + } + + public void setText(String text) { + text = text.replace("\r", ""); + if(this.text == null || !this.text.equals(text)) { + if(this.listener != null) { + this.listener.textUpdate(text); + } + + if(!this.undoing) { + this.undoList.add(new GuiTextArea.UndoData(this.text, this.cursorPosition)); + this.redoList.clear(); + } + + this.text = text; + this.container = new TextContainer(text); + this.container.init(font, this.width, this.height); + if(this.enableCodeHighlighting) { + this.container.formatCodeText(); + } + + if(this.scrolledLine > this.container.linesCount - this.container.visibleLines) { + this.scrolledLine = Math.max(0, this.container.linesCount - this.container.visibleLines); + } + + } + } + + public String getText() { + return this.text; + } + + public boolean isEnabled() { + return this.enabled && this.visible; + } + + public boolean hasVerticalScrollbar() { + return this.container.visibleLines < this.container.linesCount; + } + + public void enableCodeHighlighting() { + this.enableCodeHighlighting = true; + this.container.formatCodeText(); + } + + public void setListener(ITextChangeListener listener) { + this.listener = listener; + } + + public boolean isActive() { + return this.active; + } + + static { + font = new TrueTypeFont(new Font("Arial Unicode MS", 0, CustomNpcs.FontSize), 1.0F); + } + + class UndoData { + public String text; + public int cursorPosition; + + public UndoData(String text, int cursorPosition) { + this.text = text; + this.cursorPosition = cursorPosition; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/util/IGui.java b/src/main/java/noppes/npcs/client/gui/util/IGui.java new file mode 100644 index 000000000..cc0d20135 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/IGui.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface IGui { + int getID(); + + void drawScreen(int var1, int var2); + + void updateScreen(); + + boolean isActive(); +} diff --git a/src/main/java/noppes/npcs/client/gui/util/IKeyListener.java b/src/main/java/noppes/npcs/client/gui/util/IKeyListener.java new file mode 100644 index 000000000..643352735 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/IKeyListener.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface IKeyListener { + void keyTyped(char var1, int var2); +} diff --git a/src/main/java/noppes/npcs/client/gui/util/IMouseListener.java b/src/main/java/noppes/npcs/client/gui/util/IMouseListener.java new file mode 100644 index 000000000..7204139b4 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/IMouseListener.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface IMouseListener { + boolean mouseClicked(int var1, int var2, int var3); +} diff --git a/src/main/java/noppes/npcs/client/gui/util/TextContainer.java b/src/main/java/noppes/npcs/client/gui/util/TextContainer.java new file mode 100644 index 000000000..8d8fc3b6d --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/TextContainer.java @@ -0,0 +1,225 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import noppes.npcs.config.TrueTypeFont; + +public class TextContainer { + private static final char colorChar = '\uffff'; + private static final Comparator MarkUpComparator = (o1, o2) -> { + return o1.start > o2.start?1:(o1.start < o2.start?-1:0); + }; + public final Pattern regexString = Pattern.compile("([\"\'])(?:(?=(\\\\?))\\2.)*?\\1", 8); + public final Pattern regexFunction = Pattern.compile("\\b(if|else|switch|with|for|while|in|var|const|let|throw|then|function|continue|break|foreach|return|try|catch|finally|do|this|typeof|instanceof|new)(?=[^\\w])"); + public final Pattern regexWord = Pattern.compile("[\\p{L}-]+|\\n|$"); + public final Pattern regexNumber = Pattern.compile("\\b-?(?:0[xX][\\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?(?:[fFbBdDlLsS])?|NaN|null|Infinity|unidentified|true|false)\\b"); + public final Pattern regexComment = Pattern.compile("\\/\\*[\\s\\S]*?(?:\\*\\/|$)|\\/\\/.*|#.*"); + public String text; + public List makeup = new ArrayList(); + public List lines = new ArrayList(); + private TrueTypeFont font; + public int lineHeight; + public int totalHeight; + public int visibleLines = 1; + public int linesCount; + + public TextContainer(String text) { + this.text = text; + text.replaceAll("\\r?\\n|\\r", "\n"); + double l = 1.0D; + } + + public void init(TrueTypeFont font, int width, int height) { + this.font = font; + this.lineHeight = font.height(this.text); + if(this.lineHeight == 0) { + this.lineHeight = 12; + } + + String[] split = this.text.split("\n"); + int totalChars = 0; + String[] var6 = split; + int var7 = split.length; + + for(int var8 = 0; var8 < var7; ++var8) { + String l = var6[var8]; + StringBuilder line = new StringBuilder(); + Matcher m = this.regexWord.matcher(l); + + for(int i = 0; m.find(); i = m.start()) { + String word = l.substring(i, m.start()); + if(font.width(line + word) > width - 10) { + this.lines.add(new TextContainer.LineData(line.toString(), totalChars, totalChars + line.length())); + totalChars += line.length(); + line = new StringBuilder(); + } + + line.append(word); + } + + this.lines.add(new TextContainer.LineData(line.toString(), totalChars, totalChars + line.length() + 1)); + totalChars += line.length() + 1; + } + + this.linesCount = this.lines.size(); + this.totalHeight = this.linesCount * this.lineHeight; + this.visibleLines = Math.max(height / this.lineHeight, 1); + } + + public void formatCodeText() { + TextContainer.MarkUp markup = null; + + for(int start = 0; (markup = this.getNextMatching(start)) != null; start = markup.end) { + this.makeup.add(markup); + } + + } + + private TextContainer.MarkUp getNextMatching(int start) { + TextContainer.MarkUp markup = null; + String s = this.text.substring(start); + Matcher matcher = this.regexNumber.matcher(s); + if(matcher.find()) { + markup = new TextContainer.MarkUp(matcher.start(), matcher.end(), '6', 0); + } + + matcher = this.regexFunction.matcher(s); + TextContainer.MarkUp markup2; + if(matcher.find()) { + markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '2', 0); + if(this.compareMarkUps(markup, markup2)) { + markup = markup2; + } + } + + matcher = this.regexString.matcher(s); + if(matcher.find()) { + markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '4', 7); + if(this.compareMarkUps(markup, markup2)) { + markup = markup2; + } + } + + matcher = this.regexComment.matcher(s); + if(matcher.find()) { + markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '8', 7); + if(this.compareMarkUps(markup, markup2)) { + markup = markup2; + } + } + + if(markup != null) { + markup.start += start; + markup.end += start; + } + + return markup; + } + + public boolean compareMarkUps(TextContainer.MarkUp mu1, TextContainer.MarkUp mu2) { + return mu1 == null?true:mu1.start > mu2.start; + } + + public void addMakeUp(int start, int end, char c, int level) { + if(this.removeConflictingMarkUp(start, end, level)) { + this.makeup.add(new TextContainer.MarkUp(start, end, c, level)); + } + } + + private boolean removeConflictingMarkUp(int start, int end, int level) { + ArrayList conflicting = new ArrayList(); + Iterator var5 = this.makeup.iterator(); + + while(true) { + TextContainer.MarkUp m; + do { + if(!var5.hasNext()) { + this.makeup.removeAll(conflicting); + return true; + } + + m = (TextContainer.MarkUp)var5.next(); + } while((start < m.start || start > m.end) && (end < m.start || end > m.end) && (start >= m.start || end <= m.start)); + + if(level < m.level || level == m.level && m.start <= start) { + return false; + } + + conflicting.add(m); + } + } + + public String getFormattedString() { + StringBuilder builder = new StringBuilder(this.text); + Iterator var2 = this.makeup.iterator(); + + while(var2.hasNext()) { + TextContainer.MarkUp entry = (TextContainer.MarkUp)var2.next(); + builder.insert(entry.start, Character.toString('\uffff') + Character.toString(entry.c)); + builder.insert(entry.end, Character.toString('\uffff') + Character.toString('r')); + } + + return builder.toString(); + } + + class MarkUp { + public int start; + public int end; + public int level; + public char c; + + public MarkUp(int start, int end, char c, int level) { + this.start = start; + this.end = end; + this.c = c; + this.level = level; + } + } + + class LineData { + public String text; + public int start; + public int end; + + public LineData(String text, int start, int end) { + this.text = text; + this.start = start; + this.end = end; + } + + public String getFormattedString() { + StringBuilder builder = new StringBuilder(this.text); + int found = 0; + Iterator var3 = TextContainer.this.makeup.iterator(); + + while(var3.hasNext()) { + TextContainer.MarkUp entry = (TextContainer.MarkUp)var3.next(); + if(entry.start >= this.start && entry.start < this.end) { + builder.insert(entry.start - this.start + found * 2, Character.toString('\uffff') + Character.toString(entry.c)); + ++found; + } + + if(entry.start < this.start && entry.end > this.start) { + builder.insert(0, Character.toString('\uffff') + Character.toString(entry.c)); + ++found; + } + + if(entry.end >= this.start && entry.end < this.end) { + builder.insert(entry.end - this.start + found * 2, Character.toString('\uffff') + Character.toString('r')); + ++found; + } + } + + return builder.toString(); + } + } +} diff --git a/src/main/java/noppes/npcs/config/TrueTypeFont.java b/src/main/java/noppes/npcs/config/TrueTypeFont.java new file mode 100644 index 000000000..15cbd65dd --- /dev/null +++ b/src/main/java/noppes/npcs/config/TrueTypeFont.java @@ -0,0 +1,340 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.config; + +import java.awt.Font; +import java.awt.FontFormatException; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.util.LRUHashMap; +import org.lwjgl.opengl.GL11; + +public class TrueTypeFont { + private static final int MaxWidth = 512; + private static final List allFonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()); + private List usedFonts = new ArrayList(); + private LinkedHashMap textcache = new LRUHashMap(100); + private Map glyphcache = new HashMap(); + private List textures = new ArrayList(); + private Font font; + private int lineHeight = 1; + private Graphics2D globalG = (Graphics2D)(new BufferedImage(1, 1, 2)).getGraphics(); + public float scale = 1.0F; + private int specialChar = 167; + + public TrueTypeFont(Font font, float scale) { + this.font = font; + this.scale = scale; + this.globalG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + this.lineHeight = this.globalG.getFontMetrics(font).getHeight(); + } + + public TrueTypeFont(ResourceLocation resource, int fontSize, float scale) throws IOException, FontFormatException { + InputStream stream = Minecraft.getMinecraft().getResourceManager().getResource(resource).getInputStream(); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + Font font = Font.createFont(0, stream); + ge.registerFont(font); + this.font = font.deriveFont(0, (float)fontSize); + this.scale = scale; + this.globalG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + this.lineHeight = this.globalG.getFontMetrics(font).getHeight(); + } + + public void setSpecial(char c) { + this.specialChar = c; + } + + public void draw(String text, float x, float y, int color) { + TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text); + float r = (float)(color >> 16 & 255) / 255.0F; + float g = (float)(color >> 8 & 255) / 255.0F; + float b = (float)(color & 255) / 255.0F; + GL11.glColor4f(r, g, b, 1.0F); + //GlStateManager.func_179147_l(); + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, 0.0F); + GL11.glScalef(this.scale, this.scale, 1.0F); + float i = 0.0F; + Iterator var10 = cache.glyphs.iterator(); + + while(var10.hasNext()) { + TrueTypeFont.Glyph gl = (TrueTypeFont.Glyph)var10.next(); + if(gl.type != TrueTypeFont.GlyphType.NORMAL) { + if(gl.type == TrueTypeFont.GlyphType.RESET) { + GL11.glColor4f(r, g, b, 1.0F); + } else if(gl.type == TrueTypeFont.GlyphType.COLOR) { + GL11.glColor4f((float) (gl.color >> 16 & 255) / 255.0F, (float) (gl.color >> 8 & 255) / 255.0F, (float) (gl.color & 255) / 255.0F, 1.0F); + } + } else { + GL11.glBindTexture(gl.texture, gl.texture); + this.drawTexturedModalRect(i, 0.0F, (float)gl.x * this.textureScale(), (float)gl.y * this.textureScale(), (float)gl.width * this.textureScale(), (float)gl.height * this.textureScale()); + i += (float)gl.width * this.textureScale(); + } + } + + //GlStateManager.func_179084_k(); + GL11.glPopMatrix(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + } + + private TrueTypeFont.GlyphCache getOrCreateCache(String text) { + TrueTypeFont.GlyphCache cache = (TrueTypeFont.GlyphCache)this.textcache.get(text); + if(cache != null) { + return cache; + } else { + cache = new TrueTypeFont.GlyphCache(); + + for(int i = 0; i < text.length(); ++i) { + char c = text.charAt(i); + if(c == this.specialChar && i + 1 < text.length()) { + char g = text.toLowerCase(Locale.ENGLISH).charAt(i + 1); + int index = "0123456789abcdefklmnor".indexOf(g); + if(index >= 0) { + TrueTypeFont.Glyph g1 = new TrueTypeFont.Glyph(); + if(index < 16) { + g1.type = TrueTypeFont.GlyphType.COLOR; + //g1.color = Minecraft.getMinecraft().fontRenderer.func_175064_b(g); + g1.color = 0; + } else if(index == 16) { + g1.type = TrueTypeFont.GlyphType.RANDOM; + } else if(index == 17) { + g1.type = TrueTypeFont.GlyphType.BOLD; + } else if(index == 18) { + g1.type = TrueTypeFont.GlyphType.STRIKETHROUGH; + } else if(index == 19) { + g1.type = TrueTypeFont.GlyphType.UNDERLINE; + } else if(index == 20) { + g1.type = TrueTypeFont.GlyphType.ITALIC; + } else { + g1.type = TrueTypeFont.GlyphType.RESET; + } + + cache.glyphs.add(g1); + ++i; + continue; + } + } + + TrueTypeFont.Glyph var8 = this.getOrCreateGlyph(c); + cache.glyphs.add(var8); + cache.width += var8.width; + cache.height = Math.max(cache.height, var8.height); + } + + this.textcache.put(text, cache); + return cache; + } + } + + private TrueTypeFont.Glyph getOrCreateGlyph(char c) { + TrueTypeFont.Glyph g = (TrueTypeFont.Glyph)this.glyphcache.get(Character.valueOf(c)); + if(g != null) { + return g; + } else { + TrueTypeFont.TextureCache cache = this.getCurrentTexture(); + Font font = this.getFontForChar(c); + FontMetrics metrics = this.globalG.getFontMetrics(font); + g = new TrueTypeFont.Glyph(); + g.width = Math.max(metrics.charWidth(c), 1); + g.height = Math.max(metrics.getHeight(), 1); + if(cache.x + g.width >= 512) { + cache.x = 0; + cache.y += this.lineHeight + 1; + if(cache.y >= 512) { + cache.full = true; + cache = this.getCurrentTexture(); + } + } + + g.x = cache.x; + g.y = cache.y; + cache.x += g.width + 3; + this.lineHeight = Math.max(this.lineHeight, g.height); + cache.g.setFont(font); + cache.g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + cache.g.drawString(c + "", g.x, g.y + metrics.getAscent()); + g.texture = cache.textureId; + TextureUtil.uploadTextureImage(cache.textureId, cache.bufferedImage); + this.glyphcache.put(Character.valueOf(c), g); + return g; + } + } + + private TrueTypeFont.TextureCache getCurrentTexture() { + TrueTypeFont.TextureCache cache = null; + Iterator var2 = this.textures.iterator(); + + while(var2.hasNext()) { + TrueTypeFont.TextureCache t = (TrueTypeFont.TextureCache)var2.next(); + if(!t.full) { + cache = t; + break; + } + } + + if(cache == null) { + this.textures.add(cache = new TrueTypeFont.TextureCache()); + } + + return cache; + } + + public void drawCentered(String text, float x, float y, int color) { + this.draw(text, x - (float)this.width(text) / 2.0F, y, color); + } + + private Font getFontForChar(char c) { + if(this.font.canDisplay(c)) { + return this.font; + } else { + Iterator fa = this.usedFonts.iterator(); + + Font f; + do { + if(!fa.hasNext()) { + Font fa1 = new Font("Arial Unicode MS", 0, this.font.getSize()); + if(fa1.canDisplay(c)) { + return fa1; + } + + Iterator f2 = allFonts.iterator(); + + Font f1; + do { + if(!f2.hasNext()) { + return this.font; + } + + f1 = (Font)f2.next(); + } while(!f1.canDisplay(c)); + + this.usedFonts.add(f1 = f1.deriveFont(0, (float)this.font.getSize())); + return f1; + } + + f = (Font)fa.next(); + } while(!f.canDisplay(c)); + + return f; + } + } + + public void drawTexturedModalRect(float p_73729_1_, float p_73729_2_, float p_73729_3_, float p_73729_4_, float p_73729_5_, float p_73729_6_) + { + float f = 0.00390625F; + float f1 = 0.00390625F; + byte zLevel = 0; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.draw(); + } + + public int width(String text) { + TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text); + return (int)((float)cache.width * this.scale * this.textureScale()); + } + + public int height(String text) { + if(text != null && !text.trim().isEmpty()) { + TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text); + return Math.max(1, (int)((float)cache.height * this.scale * this.textureScale())); + } else { + return (int)((float)this.lineHeight * this.scale * this.textureScale()); + } + } + + private float textureScale() { + return 0.5F; + } + + public void dispose() { + Iterator var1 = this.textures.iterator(); + + while(var1.hasNext()) { + TrueTypeFont.TextureCache cache = (TrueTypeFont.TextureCache)var1.next(); + GL11.glDeleteTextures(cache.textureId); + } + + this.textcache.clear(); + } + + public String getFontName() { + return this.font.getFontName(); + } + + class GlyphCache { + public int width; + public int height; + List glyphs = new ArrayList(); + + GlyphCache() { + } + } + + class Glyph { + TrueTypeFont.GlyphType type; + int color; + int x; + int y; + int height; + int width; + int texture; + + Glyph() { + this.type = TrueTypeFont.GlyphType.NORMAL; + this.color = -1; + } + } + + class TextureCache { + int x; + int y; + int textureId = GL11.glGenTextures(); + BufferedImage bufferedImage = new BufferedImage(512, 512, 2); + Graphics2D g; + boolean full; + + TextureCache() { + this.g = (Graphics2D)this.bufferedImage.getGraphics(); + } + } + + static enum GlyphType { + NORMAL, + COLOR, + RANDOM, + BOLD, + STRIKETHROUGH, + UNDERLINE, + ITALIC, + RESET, + OTHER; + + private GlyphType() { + } + } +} From 6aa98aecf383ee5a4ee5cc45aa255790bf6f0843 Mon Sep 17 00:00:00 2001 From: luisc Date: Sat, 2 Oct 2021 08:47:13 -0500 Subject: [PATCH 20/58] Work on Player Event Script GUIs --- .../client/gui/player/GuiMailmanWrite.java | 2 +- .../gui/questtypes/GuiNpcQuestTypeKill.java | 6 ++--- .../gui/script/EventGuiNPCInterface.java | 3 +-- .../client/gui/script/GuiScriptInterface.java | 15 ++++++++++--- .../gui/util/GuiContainerNPCInterface.java | 2 +- .../npcs/client/gui/util/GuiNPCInterface.java | 2 +- .../npcs/client/gui/util/GuiNpcTextArea.java | 22 ++++++++++++++++++- .../npcs/client/gui/util/GuiNpcTextField.java | 2 +- 8 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java b/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java index 369fcd163..bccb11d4e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java @@ -240,7 +240,7 @@ public class GuiMailmanWrite extends GuiContainerNPCInterface implements ITextfi */ public void keyTyped(char par1, int par2) { - if(!GuiNpcTextField.isActive() && canEdit) + if(!GuiNpcTextField.isFieldActive() && canEdit) this.keyTypedInBook(par1, par2); else super.keyTyped(par1, par2); diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java index 201b177d9..386caec09 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java @@ -10,10 +10,8 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.world.World; -import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.ICustomScrollListener; -import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; @@ -84,7 +82,7 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi addScroll(scroll); this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 140, 98, 20, "gui.back")); - scroll.visible = GuiNpcTextField.isActive(); + scroll.visible = GuiNpcTextField.isFieldActive(); } protected void actionPerformed(GuiButton guibutton) { @@ -96,7 +94,7 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi public void mouseClicked(int i, int j, int k) { super.mouseClicked(i, j, k); - scroll.visible = GuiNpcTextField.isActive(); + scroll.visible = GuiNpcTextField.isFieldActive(); } public void save() { } diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java index 83f24a15a..bf99073f3 100644 --- a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java @@ -17,7 +17,6 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.EntityLivingBase; @@ -243,7 +242,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } } - active = active || GuiNpcTextField.isActive(); + active = active || GuiNpcTextField.isFieldActive(); if (!this.closeOnEsc || i != 1 && (active || !this.isInventoryKey(i))) { var4 = (new ArrayList(this.textfields.values())).iterator(); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 375a45cb5..c03ffd2a6 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -70,10 +70,14 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo top.active = true; if(this.activeTab > 0) { EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - GuiTextArea left = new GuiTextArea(2, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); - //left.enableCodeHighlighting(); - //left.setListener(this); + GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); this.add(left); + /* + GuiTextArea left = new GuiTextArea(2, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); + left.enableCodeHighlighting(); + left.setListener(this); + this.add(left); + */ int left1 = this.guiLeft + this.xSize - 104; this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear")); this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste")); @@ -90,9 +94,14 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo this.addScroll(scroll); } else { + GuiNpcTextArea var8 = new GuiNpcTextArea(2, this, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText()); + var8.enabled = false; + this.add(var8); + /* GuiTextArea var8 = new GuiTextArea(2, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText()); var8.enabled = false; this.add(var8); + */ int var9 = this.guiLeft + this.xSize - 150; this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy")); this.addButton(new GuiNpcButton(102, var9, this.guiTop + 146, 60, 20, "gui.clear")); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java index dbfa56b76..236556aa3 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiContainerNPCInterface.java @@ -109,7 +109,7 @@ public abstract class GuiContainerNPCInterface extends GuiContainer for(GuiNpcTextField tf : new ArrayList(textfields.values())) tf.textboxKeyTyped(c, i); - if (closeOnEsc && (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode() && !GuiNpcTextField.isActive())) + if (closeOnEsc && (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode() && !GuiNpcTextField.isFieldActive())) close(); } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 9adce5233..cb6e52ce0 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -144,7 +144,7 @@ public abstract class GuiNPCInterface extends GuiScreen for(GuiNpcTextField tf : textfields.values()) tf.textboxKeyTyped(c, i); - if (closeOnEsc && (i == 1 || !GuiNpcTextField.isActive() && isInventoryKey(i))){ + if (closeOnEsc && (i == 1 || !GuiNpcTextField.isFieldActive() && isInventoryKey(i))){ close(); } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java index 07837b115..e7560b25c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java @@ -15,7 +15,7 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -public class GuiNpcTextArea extends GuiNpcTextField{ +public class GuiNpcTextArea extends GuiNpcTextField implements IGui{ public boolean inMenu = true; public boolean numbersOnly = false; private int posX,posY,width,height; @@ -307,4 +307,24 @@ public class GuiNpcTextArea extends GuiNpcTextField{ } drawTexturedModalRect(x, y, width, 11, 5, 1); } + + @Override + public int getID() { + return 0; + } + + @Override + public void drawScreen(int var1, int var2) { + + } + + @Override + public void updateScreen() { + + } + + @Override + public boolean isActive() { + return isFieldActive(); + } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java index 4aef50d55..5b0ba8454 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java @@ -27,7 +27,7 @@ public class GuiNpcTextField extends GuiTextField{ listener = (ITextfieldListener) parent; } - public static boolean isActive(){ + public static boolean isFieldActive(){ return activeTextfield != null; } From 1ee14920ffbdf7a80680218829efc0403f0ff5ee Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 11 Oct 2021 06:49:30 -0500 Subject: [PATCH 21/58] Scripted player tick events are functional, GUI for player events is complete. Global player events run as they should now, just need to start implementing more of them. --- src/main/java/noppes/npcs/CustomNpcs.java | 6 + src/main/java/noppes/npcs/DataScript.java | 35 +- .../java/noppes/npcs/EventDataScript.java | 144 ----- src/main/java/noppes/npcs/EventHooks.java | 128 +++-- .../noppes/npcs/EventScriptContainer.java | 234 -------- src/main/java/noppes/npcs/NBTTags.java | 9 +- .../java/noppes/npcs/PacketHandlerServer.java | 2 +- .../noppes/npcs/PlayerScriptContainer.java | 139 +++++ .../noppes/npcs/ScriptPlayerEventHandler.java | 384 +++++++++++++ .../npcs/client/gui/EventGuiScriptList.java | 10 +- .../gui/script/EventGuiNPCInterface.java | 535 ------------------ .../client/gui/script/EventGuiScriptList.java | 6 +- .../client/gui/script/GuiScriptGlobal.java | 2 +- .../client/gui/script/GuiScriptInterface.java | 108 +++- .../client/gui/script/GuiScriptPlayers.java | 4 +- .../npcs/controllers/IScriptHandler.java | 6 +- .../noppes/npcs/controllers/PlayerData.java | 17 +- .../npcs/controllers/ScriptController.java | 47 +- .../controllers/data/ForgeDataScript.java | 179 ++++++ ...rScriptData.java => PlayerDataScript.java} | 157 +++-- .../npcs/entity/EntityNPCInterface.java | 2 +- .../noppes/npcs/entity/data/DataTimers.java | 130 +++++ .../java/noppes/npcs/scripted/ITimers.java | 20 + .../java/noppes/npcs/scripted/NpcAPI.java | 2 +- .../npcs/scripted/event/CustomNPCsEvent.java | 6 +- .../assets/customnpcs/lang/en_US.lang | 2 +- 26 files changed, 1223 insertions(+), 1091 deletions(-) delete mode 100644 src/main/java/noppes/npcs/EventDataScript.java delete mode 100644 src/main/java/noppes/npcs/EventScriptContainer.java create mode 100644 src/main/java/noppes/npcs/PlayerScriptContainer.java create mode 100644 src/main/java/noppes/npcs/ScriptPlayerEventHandler.java delete mode 100644 src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java create mode 100644 src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java rename src/main/java/noppes/npcs/controllers/data/{PlayerScriptData.java => PlayerDataScript.java} (66%) create mode 100644 src/main/java/noppes/npcs/entity/data/DataTimers.java create mode 100644 src/main/java/noppes/npcs/scripted/ITimers.java diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 2d7a19a05..7b19fc433 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -59,6 +59,7 @@ import noppes.npcs.entity.old.EntityNpcMonsterMale; import noppes.npcs.entity.old.EntityNpcNagaFemale; import noppes.npcs.entity.old.EntityNpcNagaMale; import noppes.npcs.entity.old.EntityNpcSkeleton; +import noppes.npcs.scripted.wrapper.WrapperNpcAPI; @Mod(modid = "customnpcs", name = "CustomNpcs", version = "1.2.1") public class CustomNpcs { @@ -173,8 +174,10 @@ public class CustomNpcs { NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy); MinecraftForge.EVENT_BUS.register(new ServerEventsHandler()); + //MinecraftForge.EVENT_BUS.register((new ScriptPlayerEventHandler()).registerForgeEvents()); MinecraftForge.EVENT_BUS.register(new ScriptController()); + FMLCommonHandler.instance().bus().register(new ScriptPlayerEventHandler()); FMLCommonHandler.instance().bus().register(new ServerTickHandler()); registerNpc(EntityNPCHumanMale.class, "npchumanmale"); @@ -244,7 +247,10 @@ public class CustomNpcs { new SpawnController(); new LinkedNpcController(); ScriptController.Instance.loadStoredData(); + ScriptController.Instance.loadForgeScripts(); + ScriptController.Instance.loadPlayerScripts(); ScriptController.HasStart = false; + WrapperNpcAPI.clearCache(); Set names = Block.blockRegistry.getKeys(); for(String name : names){ diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/DataScript.java index d36b0be7c..bea4219bb 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/DataScript.java @@ -111,13 +111,29 @@ public class DataScript { script.engine.put(obs[i].toString(), ob); } - return callScript(script); + //return callScript(script); + ScriptEngine engine = script.engine; + engine.put("npc", dummyNpc); + engine.put("world", dummyWorld); + ScriptEvent result = (ScriptEvent) engine.get("event"); + if(result == null) + engine.put("event", result = new ScriptEvent()); + engine.put("EntityType", entities); + engine.put("RoleType", roles); + engine.put("JobType", jobs); + script.run(engine); + + if(clientNeedsUpdate){ + npc.updateClient = true; + clientNeedsUpdate = false; + } + if(aiNeedsUpdate){ + npc.updateAI = true; + aiNeedsUpdate = false; + } + return result.isCancelled(); } - - public boolean isEnabled(){ - return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty(); - } - + /* private boolean callScript(ScriptContainer script){ ScriptEngine engine = script.engine; engine.put("npc", dummyNpc); @@ -129,7 +145,7 @@ public class DataScript { engine.put("RoleType", roles); engine.put("JobType", jobs); script.run(engine); - + if(clientNeedsUpdate){ npc.updateClient = true; clientNeedsUpdate = false; @@ -140,6 +156,11 @@ public class DataScript { } return result.isCancelled(); } + */ + + public boolean isEnabled(){ + return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty(); + } public void setWorld(World world) { if(world instanceof WorldServer) diff --git a/src/main/java/noppes/npcs/EventDataScript.java b/src/main/java/noppes/npcs/EventDataScript.java deleted file mode 100644 index 486dc9ec2..000000000 --- a/src/main/java/noppes/npcs/EventDataScript.java +++ /dev/null @@ -1,144 +0,0 @@ -package noppes.npcs; - -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListenableFutureTask; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.Entity; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.constants.EnumScriptType; -import noppes.npcs.controllers.IScriptHandler; -import noppes.npcs.controllers.ScriptContainer; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.entity.EntityCustomNpc; -import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.ScriptEvent; -import noppes.npcs.scripted.ScriptNpc; -import noppes.npcs.scripted.ScriptWorld; -import noppes.npcs.scripted.constants.EntityType; -import noppes.npcs.scripted.constants.JobType; -import noppes.npcs.scripted.constants.RoleType; -import org.apache.commons.lang3.Validate; - -import javax.script.ScriptEngine; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.Executors; - -public class EventDataScript implements IScriptHandler { - private List scripts = new ArrayList(); - private String scriptLanguage = "ECMAScript"; - public long lastInited = -1L; - public boolean hadInteract = true; - private boolean enabled = false; - - public EventDataScript() { - } - - public void clear() { - this.scripts = new ArrayList(); - } - - public void readFromNBT(NBTTagCompound compound) { - this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); - this.scriptLanguage = compound.getString("ScriptLanguage"); - this.enabled = compound.getBoolean("ScriptEnabled"); - } - - public NBTTagCompound writeToNBT(NBTTagCompound compound) { - compound.setTag("Scripts", NBTTags.NBTScript(this.scripts)); - compound.setString("ScriptLanguage", this.scriptLanguage); - compound.setBoolean("ScriptEnabled", this.enabled); - return compound; - } - - public void runScript(EnumScriptType type, Event event) { - } - - public void runScript(String type, Event event) { - if(this.isEnabled()) { - Minecraft.getMinecraft().func_152344_a(() -> { - if (ScriptController.Instance.lastLoaded > this.lastInited) { - this.lastInited = ScriptController.Instance.lastLoaded; - if (!type.equals("init")) { - EventHooks.onForgeInit(this); - } - } - - Iterator var3 = this.scripts.iterator(); - - while (var3.hasNext()) { - EventScriptContainer script = (EventScriptContainer) var3.next(); - script.run(type, event); - } - - }); - } - } - - public boolean isEnabled() { - return this.enabled && ScriptController.HasStart && this.scripts.size() > 0; - } - - public boolean isClient() { - return false; - } - - public boolean getEnabled() { - return this.enabled; - } - - public void setEnabled(boolean bo) { - this.enabled = bo; - } - - public String getLanguage() { - return this.scriptLanguage; - } - - public void setLanguage(String lang) { - this.scriptLanguage = lang; - } - - public List getScripts() { - return this.scripts; - } - - public String noticeString() { - return "ForgeScript"; - } - - public Map getConsoleText() { - TreeMap map = new TreeMap(); - int tab = 0; - Iterator var3 = this.getScripts().iterator(); - - while(var3.hasNext()) { - EventScriptContainer script = (EventScriptContainer)var3.next(); - ++tab; - Iterator var5 = script.console.entrySet().iterator(); - - while(var5.hasNext()) { - Map.Entry entry = (Map.Entry)var5.next(); - map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue()); - } - } - - return map; - } - - public void clearConsole() { - Iterator var1 = this.getScripts().iterator(); - - while(var1.hasNext()) { - EventScriptContainer script = (EventScriptContainer)var1.next(); - script.console.clear(); - } - - } -} diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 53af997e8..070676d01 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -5,14 +5,25 @@ package noppes.npcs; +import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.util.DamageSource; -import noppes.npcs.controllers.data.PlayerScriptData; +import net.minecraft.world.WorldServer; +import net.minecraftforge.event.entity.EntityEvent; +import net.minecraftforge.event.world.WorldEvent; +import noppes.npcs.controllers.IScriptHandler; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.ForgeDataScript; +import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.scripted.IEntity; +import noppes.npcs.scripted.IWorld; import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptPlayer; +import noppes.npcs.scripted.event.ForgeEvent; import noppes.npcs.scripted.event.PlayerEvent.AttackEvent; import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed; @@ -27,117 +38,156 @@ import noppes.npcs.scripted.event.PlayerEvent.TossEvent; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.PlayerData; +import org.apache.commons.lang3.StringUtils; public class EventHooks { public EventHooks() { } - public static void onForgeInit(EventDataScript handler) { + public static void onForgeInit(IScriptHandler handler) { noppes.npcs.scripted.event.ForgeEvent.InitEvent event = new noppes.npcs.scripted.event.ForgeEvent.InitEvent(); - handler.runScript(EnumScriptType.INIT, event); + handler.callScript(EnumScriptType.INIT, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerInit(PlayerScriptData handler) { + public static void onPlayerInit(PlayerDataScript handler) { noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(handler.getPlayer()); - handler.runScript(EnumScriptType.INIT, event); + handler.callScript(EnumScriptType.INIT, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerTick(PlayerScriptData handler) { + public static void onPlayerTick(PlayerDataScript handler) { noppes.npcs.scripted.event.PlayerEvent.UpdateEvent event = new noppes.npcs.scripted.event.PlayerEvent.UpdateEvent(handler.getPlayer()); - handler.runScript(EnumScriptType.TICK, event); + handler.callScript(EnumScriptType.TICK, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerInteract(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) { - handler.runScript(EnumScriptType.INTERACT, event); + public static boolean onPlayerInteract(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) { + handler.callScript(EnumScriptType.INTERACT, event); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerAttack(PlayerScriptData handler, AttackEvent event) { - handler.runScript(EnumScriptType.ATTACK, event); + public static boolean onPlayerAttack(PlayerDataScript handler, AttackEvent event) { + handler.callScript(EnumScriptType.ATTACK, event); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerToss(PlayerScriptData handler, EntityItem entityItem) { + public static boolean onPlayerToss(PlayerDataScript handler, EntityItem entityItem) { TossEvent event = new TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); - handler.runScript(EnumScriptType.TOSS, event); + handler.callScript(EnumScriptType.TOSS, event); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerLevelUp(PlayerScriptData handler, int change) { + public static void onPlayerLevelUp(PlayerDataScript handler, int change) { LevelUpEvent event = new LevelUpEvent(handler.getPlayer(), change); - handler.runScript(EnumScriptType.LEVEL_UP, event); + handler.callScript(EnumScriptType.LEVEL_UP, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerPickUp(PlayerScriptData handler, EntityItem entityItem) { + public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) { PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); - handler.runScript(EnumScriptType.PICKUP, event); + handler.callScript(EnumScriptType.PICKUP, event); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerContainerOpen(PlayerScriptData handler, Container container) { + public static void onPlayerContainerOpen(PlayerDataScript handler, Container container) { ContainerOpen event = new ContainerOpen(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); - handler.runScript(EnumScriptType.CONTAINER_OPEN, event); + handler.callScript(EnumScriptType.CONTAINER_OPEN, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerContainerClose(PlayerScriptData handler, Container container) { + public static void onPlayerContainerClose(PlayerDataScript handler, Container container) { ContainerClosed event = new ContainerClosed(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); - handler.runScript(EnumScriptType.CONTAINER_CLOSED, event); + handler.callScript(EnumScriptType.CONTAINER_CLOSED, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerDeath(PlayerScriptData handler, DamageSource source, Entity entity) { + public static void onPlayerDeath(PlayerDataScript handler, DamageSource source, Entity entity) { noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(handler.getPlayer(), source, entity); - handler.runScript(EnumScriptType.KILLED, event); + handler.callScript(EnumScriptType.KILLED, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerKills(PlayerScriptData handler, EntityLivingBase entityLiving) { + public static void onPlayerKills(PlayerDataScript handler, EntityLivingBase entityLiving) { noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent event = new noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent(handler.getPlayer(), entityLiving); - handler.runScript(EnumScriptType.KILLS, event); + handler.callScript(EnumScriptType.KILLS, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerDamaged(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) { - handler.runScript(EnumScriptType.DAMAGED, event); + public static boolean onPlayerDamaged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) { + handler.callScript(EnumScriptType.DAMAGED, event); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerLogin(PlayerScriptData handler) { + public static void onPlayerLogin(PlayerDataScript handler) { LoginEvent event = new LoginEvent(handler.getPlayer()); - handler.runScript(EnumScriptType.LOGIN, event); + handler.callScript(EnumScriptType.LOGIN, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerLogout(PlayerScriptData handler) { + public static void onPlayerLogout(PlayerDataScript handler) { LogoutEvent event = new LogoutEvent(handler.getPlayer()); - handler.runScript(EnumScriptType.LOGOUT, event); + handler.callScript(EnumScriptType.LOGOUT, event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerChat(PlayerScriptData handler, ChatEvent event) { - handler.runScript(EnumScriptType.CHAT, event); + public static void onPlayerChat(PlayerDataScript handler, ChatEvent event) { + handler.callScript(EnumScriptType.CHAT, event, "message", event.message); WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerRanged(PlayerScriptData handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) { - handler.runScript(EnumScriptType.RANGED_LAUNCHED, event); + public static boolean onPlayerRanged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) { + handler.callScript(EnumScriptType.RANGED_LAUNCHED, event); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerDamagedEntity(PlayerScriptData handler, DamagedEntityEvent event) { - handler.runScript(EnumScriptType.DAMAGED_ENTITY, event); + public static boolean onPlayerDamagedEntity(PlayerDataScript handler, DamagedEntityEvent event) { + handler.callScript(EnumScriptType.DAMAGED_ENTITY, event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { - PlayerScriptData handler = PlayerData.get(player).scriptData; + PlayerDataScript handler = PlayerData.get(player).scriptData; KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); - handler.runScript(EnumScriptType.KEY_PRESSED, event); + handler.callScript(EnumScriptType.KEY_PRESSED, event); WrapperNpcAPI.EVENT_BUS.post(event); } + + public static void onPlayerTimer(PlayerData data, int id) { + PlayerDataScript handler = data.scriptData; + noppes.npcs.scripted.event.PlayerEvent.TimerEvent event = new noppes.npcs.scripted.event.PlayerEvent.TimerEvent(handler.getPlayer(), id); + handler.callScript(EnumScriptType.TIMER, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onForgeEntityEvent(EntityEvent event) { + IEntity e = NpcAPI.Instance().getIEntity(event.entity); + onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.EntityEvent(event, e), event); + } + + public static void onForgeEvent(ForgeEvent ev, Event event) { + ForgeDataScript data = ScriptController.Instance.forgeScripts; + if(data.isEnabled()) { + String eventName = event.getClass().getName(); + int i = eventName.lastIndexOf("."); + eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); + if(event.isCancelable()) { + ev.setCanceled(event.isCanceled()); + } + + data.callScript(eventName, event); + WrapperNpcAPI.EVENT_BUS.post(ev); + if(event.isCancelable()) { + event.setCanceled(ev.isCanceled()); + } + + } + } + + public static void onForgeWorldEvent(WorldEvent event) { + if(ScriptController.Instance.forgeScripts.isEnabled()) { + IWorld e = NpcAPI.Instance().getIWorld((WorldServer)event.world); + onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.WorldEvent(event, e), event); + } + } } diff --git a/src/main/java/noppes/npcs/EventScriptContainer.java b/src/main/java/noppes/npcs/EventScriptContainer.java deleted file mode 100644 index b88844e57..000000000 --- a/src/main/java/noppes/npcs/EventScriptContainer.java +++ /dev/null @@ -1,234 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// - -package noppes.npcs; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.TreeMap; -import java.util.Map.Entry; -import javax.script.Invocable; -import javax.script.ScriptEngine; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; -import noppes.npcs.CustomNpcs; -import noppes.npcs.NBTTags; -import noppes.npcs.NoppesUtilServer; -import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.constants.EnumScriptType; -import noppes.npcs.controllers.IScriptHandler; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.scripted.constants.*; - -public class EventScriptContainer { - private static final String lock = "lock"; - public static EventScriptContainer Current; - private static String CurrentType; - private static final HashMap Data = new HashMap(); - public String fullscript = ""; - public String script = ""; - public TreeMap console = new TreeMap(); - public boolean errored = false; - public List scripts = new ArrayList(); - private HashSet unknownFunctions = new HashSet(); - public long lastCreated = 0L; - private String currentScriptLanguage = null; - private ScriptEngine engine = null; - private IScriptHandler handler = null; - private boolean init = false; - private static Method luaCoerce; - private static Method luaCall; - - private static void FillMap(Class c) { - try { - Data.put(c.getSimpleName(), c.newInstance()); - } catch (Exception var8) { - ; - } - - Field[] declaredFields = c.getDeclaredFields(); - Field[] var2 = declaredFields; - int var3 = declaredFields.length; - - for(int var4 = 0; var4 < var3; ++var4) { - Field field = var2[var4]; - - try { - if(Modifier.isStatic(field.getModifiers()) && field.getType() == Integer.TYPE) { - Data.put(c.getSimpleName() + "_" + field.getName(), Integer.valueOf(field.getInt((Object)null))); - } - } catch (Exception var7) { - ; - } - } - - } - - public EventScriptContainer(IScriptHandler handler) { - this.handler = handler; - } - - public void readFromNBT(NBTTagCompound compound) { - this.script = compound.getString("Script"); - this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10)); - this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10)); - this.lastCreated = 0L; - } - - public NBTTagCompound writeToNBT(NBTTagCompound compound) { - compound.setString("Script", this.script); - compound.setTag("Console", NBTTags.NBTLongStringMap(this.console)); - compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts)); - return compound; - } - - private String getFullCode() { - if(!this.init) { - this.fullscript = this.script; - if(!this.fullscript.isEmpty()) { - this.fullscript = this.fullscript + "\n"; - } - - Iterator var1 = this.scripts.iterator(); - - while(var1.hasNext()) { - String loc = (String)var1.next(); - String code = (String)ScriptController.Instance.scripts.get(loc); - if(code != null && !code.isEmpty()) { - this.fullscript = this.fullscript + code + "\n"; - } - } - - this.unknownFunctions = new HashSet(); - } - - return this.fullscript; - } - - public void run(EnumScriptType type, Event event) { - this.run((String)type.function, (Object)event); - } - - public void run(String type, Object event) { - if(!this.errored && this.hasCode() && !this.unknownFunctions.contains(type) /*&& CustomNpcs.EnableScripting*/) { - this.setEngine(currentScriptLanguage.toLowerCase()); - if(this.engine != null) { - if(ScriptController.Instance.lastLoaded > this.lastCreated) { - this.lastCreated = ScriptController.Instance.lastLoaded; - this.init = false; - } - - String var3 = "lock"; - synchronized("lock") { - Current = this; - CurrentType = type; - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - this.engine.getContext().setWriter(pw); - this.engine.getContext().setErrorWriter(pw); - - try { - if(!this.init) { - this.engine.eval(this.getFullCode()); - this.init = true; - } - - if(this.engine.getFactory().getLanguageName().equals("lua")) { - Object e = this.engine.get(type); - if(e != null) { - if(luaCoerce == null) { - luaCoerce = Class.forName("org.luaj.vm2.lib.jse.CoerceJavaToLua").getMethod("coerce", new Class[]{Object.class}); - luaCall = e.getClass().getMethod("call", new Class[]{Class.forName("org.luaj.vm2.LuaValue")}); - } - - luaCall.invoke(e, new Object[]{luaCoerce.invoke((Object)null, new Object[]{event})}); - } else { - this.unknownFunctions.add(type); - } - } else { - ((Invocable)this.engine).invokeFunction(type, new Object[]{event}); - } - } catch (NoSuchMethodException var13) { - this.unknownFunctions.add(type); - } catch (Throwable var14) { - this.errored = true; - var14.printStackTrace(pw); - //NoppesUtilServer.NotifyOPs(this.handler.noticeString() + " script errored", new Object[0]); - } finally { - this.appandConsole(sw.getBuffer().toString().trim()); - pw.close(); - Current = null; - } - - } - } - } - } - - public void appandConsole(String message) { - if(message != null && !message.isEmpty()) { - long time = System.currentTimeMillis(); - if(this.console.containsKey(Long.valueOf(time))) { - message = (String)this.console.get(Long.valueOf(time)) + "\n" + message; - } - - this.console.put(Long.valueOf(time), message); - - while(this.console.size() > 40) { - this.console.remove(this.console.firstKey()); - } - - } - } - - public boolean hasCode() { - return !this.getFullCode().isEmpty(); - } - - public void setEngine(String scriptLanguage) { - if(this.currentScriptLanguage == null || !this.currentScriptLanguage.equals(scriptLanguage)) { - this.engine = ScriptController.Instance.getEngineByName(scriptLanguage); - if(this.engine == null) { - this.errored = true; - } else { - Iterator var2 = Data.entrySet().iterator(); - - while(var2.hasNext()) { - Entry entry = (Entry)var2.next(); - this.engine.put((String)entry.getKey(), entry.getValue()); - } - - //this.engine.put("dump", new Dump(this, (1)null)); - //this.engine.put("log", new Log(this, (1)null)); - this.currentScriptLanguage = scriptLanguage; - this.init = false; - } - } - } - - public boolean isValid() { - return this.init && !this.errored; - } - - static { - FillMap(AnimationType.class); - FillMap(EntityType.class); - FillMap(RoleType.class); - FillMap(JobType.class); - //FillMap(SideType.class); - //FillMap(TacticalType.class); - //FillMap(PotionType.class); - //FillMap(ParticleType.class); - Data.put("PosZero", new BlockPos(BlockPos.ORIGIN)); - } -} diff --git a/src/main/java/noppes/npcs/NBTTags.java b/src/main/java/noppes/npcs/NBTTags.java index 60fa0df7d..fbf2fedf4 100644 --- a/src/main/java/noppes/npcs/NBTTags.java +++ b/src/main/java/noppes/npcs/NBTTags.java @@ -6,7 +6,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; -import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagList; import noppes.npcs.controllers.IScriptHandler; @@ -409,12 +408,12 @@ public class NBTTags { } } - public static List GetScript(NBTTagList list, IScriptHandler handler) { + public static List GetScript(NBTTagList list, IScriptHandler handler) { ArrayList scripts = new ArrayList(); for(int i = 0; i < list.tagCount(); ++i) { NBTTagCompound compoundd = list.getCompoundTagAt(i); - EventScriptContainer script = new EventScriptContainer(handler); + PlayerScriptContainer script = new PlayerScriptContainer(handler); script.readFromNBT(compoundd); scripts.add(script); } @@ -422,12 +421,12 @@ public class NBTTags { return scripts; } - public static NBTTagList NBTScript(List scripts) { + public static NBTTagList NBTScript(List scripts) { NBTTagList list = new NBTTagList(); Iterator var2 = scripts.iterator(); while(var2.hasNext()) { - EventScriptContainer script = (EventScriptContainer)var2.next(); + PlayerScriptContainer script = (PlayerScriptContainer)var2.next(); NBTTagCompound compound = new NBTTagCompound(); script.writeToNBT(compound); list.appendTag(compound); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 48c533168..8a12e60d0 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -135,7 +135,7 @@ public class PacketHandlerServer{ if(type == EnumPacketServer.ScriptPlayerGet) { compound = ScriptController.Instance.playerScripts.writeToNBT(new NBTTagCompound()); compound.setTag("Languages", ScriptController.Instance.nbtLanguages()); - Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound}); + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else if(type == EnumPacketServer.ScriptPlayerSave) { ScriptController.Instance.setPlayerScripts(Server.readNBT(buffer)); } diff --git a/src/main/java/noppes/npcs/PlayerScriptContainer.java b/src/main/java/noppes/npcs/PlayerScriptContainer.java new file mode 100644 index 000000000..8d3938ca0 --- /dev/null +++ b/src/main/java/noppes/npcs/PlayerScriptContainer.java @@ -0,0 +1,139 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.TreeMap; +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.Invocable; +import javax.script.ScriptEngine; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.IScriptHandler; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.constants.*; + +public class PlayerScriptContainer { + public static PlayerScriptContainer Current; + public String type = "init"; + public String fullscript = ""; + public String script = ""; + public TreeMap console = new TreeMap(); + public boolean errored = false; + public List scripts = new ArrayList(); + public long lastCreated = 0L; + private String currentScriptLanguage = null; + public ScriptEngine engine = null; + private IScriptHandler handler = null; + private CompiledScript compScript = null; + private boolean init = false; + + public PlayerScriptContainer(IScriptHandler handler) { + this.handler = handler; + } + + public void readFromNBT(NBTTagCompound compound) { + this.script = compound.getString("Script"); + this.type = compound.getString("Type"); + this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10)); + this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10)); + this.lastCreated = 0L; + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setString("Script", this.script); + compound.setString("Type", this.type); + compound.setTag("Console", NBTTags.NBTLongStringMap(this.console)); + compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts)); + return compound; + } + + private String getFullCode() { + if(!this.init) { + this.fullscript = this.script; + if(!this.fullscript.isEmpty()) { + this.fullscript = this.fullscript + "\n"; + } + + Iterator var1 = this.scripts.iterator(); + + while(var1.hasNext()) { + String loc = (String)var1.next(); + String code = (String)ScriptController.Instance.scripts.get(loc); + if(code != null && !code.isEmpty()) { + this.fullscript = this.fullscript + code + "\n"; + } + } + } + + return this.fullscript; + } + public void run(ScriptEngine engine){ + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + engine.getContext().setWriter(pw); + engine.getContext().setErrorWriter(pw); + try { + if(compScript == null && engine instanceof Compilable) + compScript = ((Compilable)engine).compile(getFullCode()); + + if(compScript != null){ + compScript.eval(engine.getContext()); + } + else + engine.eval(getFullCode()); + + } catch (Exception e) { + errored = true; + appandConsole(e.getMessage()); + } + appandConsole(sw.getBuffer().toString().trim()); + } + + public void setType(String type) { + this.type = type; + } + + public void appandConsole(String message) { + if(message != null && !message.isEmpty()) { + long time = System.currentTimeMillis(); + if(this.console.containsKey(Long.valueOf(time))) { + message = (String)this.console.get(Long.valueOf(time)) + "\n" + message; + } + + this.console.put(Long.valueOf(time), message); + + while(this.console.size() > 40) { + this.console.remove(this.console.firstKey()); + } + + } + } + + public boolean hasCode() { + return !this.getFullCode().isEmpty(); + } + + public void setEngine(String scriptLanguage) { + if(currentScriptLanguage != null && currentScriptLanguage.equals(scriptLanguage)) + return; + engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase()); + currentScriptLanguage = scriptLanguage; + } +} diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java new file mode 100644 index 000000000..6b29d7749 --- /dev/null +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -0,0 +1,384 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs; + +import com.google.common.reflect.ClassPath; +import com.google.common.reflect.ClassPath.ClassInfo; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Vector; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.network.FMLNetworkEvent; +import cpw.mods.fml.relauncher.Side; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.ServerChatEvent; +import net.minecraftforge.event.entity.EntityEvent; +import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.event.world.WorldEvent.PotentialSpawns; +import noppes.npcs.controllers.PlayerData; +import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.event.ForgeEvent; +import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.controllers.ScriptController; + +public class ScriptPlayerEventHandler { + public ScriptPlayerEventHandler() { + } + @SubscribeEvent + public void onServerTick(TickEvent.PlayerTickEvent event) { + if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { + EntityPlayer player = event.player; + PlayerData data = PlayerData.get(player); + if(player.ticksExisted % 10 == 0) { + EventHooks.onPlayerTick(data.scriptData); + } + + if(data.playerLevel != player.experienceLevel) { + EventHooks.onPlayerLevelUp(data.scriptData, data.playerLevel - player.experienceLevel); + data.playerLevel = player.experienceLevel; + } + + data.timers.update(); + } + } + /* + @SubscribeEvent + public void invoke(LeftClickBlock event) { + if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + AttackEvent ev = new AttackEvent(handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); + event.setCanceled(EventHooks.onPlayerAttack(handler, ev)); + if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { + ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); + noppes.npcs.api.event.ItemEvent.AttackEvent eve = new noppes.npcs.api.event.ItemEvent.AttackEvent(isw, handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); + eve.setCanceled(event.isCanceled()); + event.setCanceled(EventHooks.onScriptItemAttack(isw, eve)); + } + + } + } + + @SubscribeEvent + public void invoke(RightClickBlock event) { + if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + if(event.getItemStack().func_77973_b() == CustomItems.nbt_book) { + ((ItemNbtBook)event.getItemStack().func_77973_b()).blockEvent(event); + event.setCanceled(true); + } else { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + handler.hadInteract = true; + InteractEvent ev = new InteractEvent(handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); + event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); + if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { + ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); + noppes.npcs.api.event.ItemEvent.InteractEvent eve = new noppes.npcs.api.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); + event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); + } + + } + } + } + + @SubscribeEvent + public void invoke(EntityInteractEvent event) { + if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + if(event.getItemStack().func_77973_b() == CustomItems.nbt_book) { + ((ItemNbtBook)event.getItemStack().func_77973_b()).entityEvent(event); + event.setCanceled(true); + } else { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + InteractEvent ev = new InteractEvent(handler.getPlayer(), 1, NpcAPI.Instance().getIEntity(event.getTarget())); + event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); + if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { + ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); + noppes.npcs.api.event.ItemEvent.InteractEvent eve = new noppes.npcs.api.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 1, NpcAPI.Instance().getIEntity(event.getTarget())); + event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); + } + + } + } + } + + @SubscribeEvent + public void invoke(RightClickItem event) { + if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + if(event.entityPlayer.func_184812_l_() && event.entityPlayer.func_70093_af() && event.getItemStack().func_77973_b() == CustomItems.scripted_item) { + NoppesUtilServer.sendOpenGui(event.entityPlayer, EnumGuiType.ScriptItem, (EntityNPCInterface)null); + } else { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + if(handler.hadInteract) { + handler.hadInteract = false; + } else { + InteractEvent ev = new InteractEvent(handler.getPlayer(), 0, (Object)null); + event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); + if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { + ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); + noppes.npcs.api.event.ItemEvent.InteractEvent eve = new noppes.npcs.api.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 0, (Object)null); + event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); + } + + } + } + } + } + + @SubscribeEvent + public void invoke(ArrowLooseEvent event) { + if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + RangedLaunchedEvent ev = new RangedLaunchedEvent(handler.getPlayer()); + event.setCanceled(EventHooks.onPlayerRanged(handler, ev)); + } + } + + @SubscribeEvent + public void invoke(BreakEvent event) { + if(!event.getPlayer().field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.getPlayer()).scriptData; + noppes.npcs.api.event.PlayerEvent.BreakEvent ev = new noppes.npcs.api.event.PlayerEvent.BreakEvent(handler.getPlayer(), NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos()), event.getExpToDrop()); + event.setCanceled(EventHooks.onPlayerBreak(handler, ev)); + event.setExpToDrop(ev.exp); + } + } + + @SubscribeEvent + public void invoke(ItemTossEvent event) { + if(event.getPlayer().field_70170_p instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.getPlayer()).scriptData; + event.setCanceled(EventHooks.onPlayerToss(handler, event.getEntityItem())); + } + } + + @SubscribeEvent + public void invoke(EntityItemPickupEvent event) { + if(event.entityPlayer.field_70170_p instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + event.setCanceled(EventHooks.onPlayerPickUp(handler, event.getItem())); + } + } + + @SubscribeEvent + public void invoke(Open event) { + if(event.entityPlayer.field_70170_p instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerContainerOpen(handler, event.getContainer()); + } + } + + @SubscribeEvent + public void invoke(Close event) { + if(event.entityPlayer.field_70170_p instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerContainerClose(handler, event.getContainer()); + } + } + + @SubscribeEvent + public void invoke(LivingDeathEvent event) { + if(event.getEntityLiving().field_70170_p instanceof WorldServer) { + Entity source = NoppesUtilServer.GetDamageSourcee(event.getSource()); + PlayerDataScript handler; + if(event.getEntityLiving() instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.getEntityLiving()).scriptData; + EventHooks.onPlayerDeath(handler, event.getSource(), source); + } + + if(source instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)source).scriptData; + EventHooks.onPlayerKills(handler, event.getEntityLiving()); + } + + } + } + + @SubscribeEvent + public void invoke(LivingHurtEvent event) { + if(event.getEntityLiving().field_70170_p instanceof WorldServer) { + Entity source = NoppesUtilServer.GetDamageSourcee(event.getSource()); + PlayerDataScript handler; + if(event.getEntityLiving() instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.getEntityLiving()).scriptData; + DamagedEvent pevent = new DamagedEvent(handler.getPlayer(), source, event.getAmount(), event.getSource()); + event.setCanceled(EventHooks.onPlayerDamaged(handler, pevent)); + event.setAmount(pevent.damage); + } + + if(source instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)source).scriptData; + DamagedEntityEvent pevent1 = new DamagedEntityEvent(handler.getPlayer(), event.getEntityLiving(), event.getAmount(), event.getSource()); + event.setCanceled(EventHooks.onPlayerDamagedEntity(handler, pevent1)); + event.setAmount(pevent1.damage); + } + + } + } + + @SubscribeEvent + public void invoke(LivingAttackEvent event) { + if(event.getEntityLiving().field_70170_p instanceof WorldServer) { + Entity source = NoppesUtilServer.GetDamageSourcee(event.getSource()); + if(source instanceof EntityPlayer) { + PlayerDataScript handler = PlayerData.get((EntityPlayer)source).scriptData; + ItemStack item = ((EntityPlayer)source).func_184614_ca(); + IEntity target = NpcAPI.Instance().getIEntity(event.getEntityLiving()); + AttackEvent ev = new AttackEvent(handler.getPlayer(), 1, target); + event.setCanceled(EventHooks.onPlayerAttack(handler, ev)); + if(item.func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { + ItemScriptedWrapper isw = ItemScripted.GetWrapper(item); + noppes.npcs.api.event.ItemEvent.AttackEvent eve = new noppes.npcs.api.event.ItemEvent.AttackEvent(isw, handler.getPlayer(), 1, target); + eve.setCanceled(event.isCanceled()); + event.setCanceled(EventHooks.onScriptItemAttack(isw, eve)); + } + } + + } + } + + @SubscribeEvent + public void invoke(PlayerLoggedInEvent event) { + if(event.player.field_70170_p instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + EventHooks.onPlayerLogin(handler); + } + } + + @SubscribeEvent + public void invoke(PlayerLoggedOutEvent event) { + if(event.player.field_70170_p instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + EventHooks.onPlayerLogout(handler); + } + } + */ + + @SubscribeEvent( + priority = EventPriority.HIGHEST + ) + public void invoke(ServerChatEvent event) { + if(event.player.worldObj instanceof WorldServer && event.player != EntityNPCInterface.chateventPlayer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + String message = event.message; + noppes.npcs.scripted.event.PlayerEvent.ChatEvent ev = new noppes.npcs.scripted.event.PlayerEvent.ChatEvent(handler.getPlayer(), event.message); + EventHooks.onPlayerChat(handler, ev); + event.setCanceled(ev.isCanceled()); + if(!message.equals(ev.message)) { + ChatComponentTranslation chat = new ChatComponentTranslation("", new Object[0]); + chat.appendSibling(ForgeHooks.newChatWithLinks(ev.message)); + event.component = chat; + } + } + } + + public ScriptPlayerEventHandler registerForgeEvents() { + ScriptPlayerEventHandler.ForgeEventHandler handler = new ScriptPlayerEventHandler.ForgeEventHandler(); + + try { + Method e = handler.getClass().getMethod("forgeEntity", new Class[]{Event.class}); + Method register = MinecraftForge.EVENT_BUS.getClass().getDeclaredMethod("register", new Class[]{Class.class, Object.class, Method.class, ModContainer.class}); + register.setAccessible(true); + ArrayList list = new ArrayList(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.fml.common")); + Iterator e1 = list.iterator(); + + while(true) { + ClassInfo classLoader; + String classes; + do { + if(!e1.hasNext()) { + if(PixelmonHelper.Enabled) { + try { + Field e2 = ClassLoader.class.getDeclaredField("classes"); + e2.setAccessible(true); + ClassLoader classLoader1 = Thread.currentThread().getContextClassLoader(); + ArrayList classes1 = new ArrayList((Vector)e2.get(classLoader1)); + Iterator infoClass1 = classes1.iterator(); + + while(infoClass1.hasNext()) { + Class c2 = (Class)infoClass1.next(); + } + } catch (Exception var12) { + var12.printStackTrace(); + } + + return this; + } + + return this; + } + + classLoader = (ClassInfo)e1.next(); + classes = classLoader.getName(); + } while(classes.startsWith("net.minecraftforge.event.terraingen")); + + Class infoClass = classLoader.load(); + ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses())); + if(c.isEmpty()) { + c.add(infoClass); + } + + Iterator var10 = c.iterator(); + while(var10.hasNext()) { + Class c1 = (Class)var10.next(); + if(!EntityConstructing.class.isAssignableFrom(c1) && !PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers())) { + register.invoke(MinecraftForge.EVENT_BUS, new Object[]{c1, handler, e, Loader.instance().activeModContainer()}); + } + } + } + } catch (Exception var13) { + var13.printStackTrace(); + return this; + } + } + + public class ForgeEventHandler { + public ForgeEventHandler() { + } + + @SubscribeEvent + public void forgeEntity(Event event) { + if(CustomNpcs.getServer() != null && ScriptController.Instance.forgeScripts.isEnabled()) { + if(event instanceof EntityEvent) { + EntityEvent ev2 = (EntityEvent)event; + if(ev2.entity != null && ev2.entity.worldObj instanceof WorldServer) { + EventHooks.onForgeEntityEvent(ev2); + } + } else if(event instanceof WorldEvent) { + WorldEvent ev1 = (WorldEvent)event; + if(ev1.world instanceof WorldServer) { + EventHooks.onForgeWorldEvent(ev1); + } + } else if(!(event instanceof TickEvent) || ((TickEvent)event).side != Side.CLIENT) { + if(event instanceof PlayerEvent) { + PlayerEvent ev = (PlayerEvent)event; + if(!(ev.player.worldObj instanceof WorldServer)) { + return; + } + } + + EventHooks.onForgeEvent(new ForgeEvent(event), event); + } + } + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java index decb5ab47..0dbc6b2d1 100644 --- a/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java +++ b/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java @@ -4,23 +4,19 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.client.gui.GuiButton; -import net.minecraft.world.biome.BiomeGenBase; -import noppes.npcs.EventScriptContainer; +import noppes.npcs.PlayerScriptContainer; import noppes.npcs.client.gui.util.GuiCustomScroll; -import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.SubGuiInterface; -import noppes.npcs.controllers.ScriptContainer; -import noppes.npcs.entity.EntityNPCInterface; public class EventGuiScriptList extends SubGuiInterface{ private GuiCustomScroll scroll1; private GuiCustomScroll scroll2; - private EventScriptContainer container; + private PlayerScriptContainer container; private List scripts; - public EventGuiScriptList(List scripts, EventScriptContainer container){ + public EventGuiScriptList(List scripts, PlayerScriptContainer container){ this.container = container; setBackground("menubg.png"); xSize = 346; diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java deleted file mode 100644 index bf99073f3..000000000 --- a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java +++ /dev/null @@ -1,535 +0,0 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by FernFlower decompiler) -// - -package noppes.npcs.client.gui.script; - -import com.google.common.collect.Lists; -import java.net.URI; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Post; -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Pre; -import net.minecraftforge.common.MinecraftForge; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.entity.EntityNPCInterface; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -public abstract class EventGuiNPCInterface extends GuiScreen { - public EntityPlayerSP player; - public boolean drawDefaultBackground; - public EntityNPCInterface npc; - private Map buttons; - private Map topbuttons; - private Map sidebuttons; - private Map textfields; - private Map labels; - private Map scrolls; - private Map sliders; - private Map extra; - private List components; - public String title; - public ResourceLocation background; - public boolean closeOnEsc; - public int guiLeft; - public int guiTop; - public int xSize; - public int ySize; - private SubGuiInterface subgui; - public int mouseX; - public int mouseY; - public float bgScale; - private GuiButton selectedButton; - - public EventGuiNPCInterface(EntityNPCInterface npc) { - this.drawDefaultBackground = true; - this.buttons = new ConcurrentHashMap(); - this.topbuttons = new ConcurrentHashMap(); - this.sidebuttons = new ConcurrentHashMap(); - this.textfields = new ConcurrentHashMap(); - this.labels = new ConcurrentHashMap(); - this.scrolls = new ConcurrentHashMap(); - this.sliders = new ConcurrentHashMap(); - this.extra = new ConcurrentHashMap(); - this.components = new ArrayList(); - this.background = null; - this.closeOnEsc = false; - this.bgScale = 1.0F; - this.player = Minecraft.getMinecraft().thePlayer; - this.npc = npc; - this.title = ""; - this.xSize = 200; - this.ySize = 222; - this.drawDefaultBackground = false; - this.mc = Minecraft.getMinecraft(); - this.itemRender = RenderItem.getInstance(); - this.fontRendererObj = this.mc.fontRenderer; - } - - public EventGuiNPCInterface() { - this((EntityNPCInterface)null); - } - - public void setBackground(String texture) { - this.background = new ResourceLocation("customnpcs", "textures/gui/" + texture); - } - - public ResourceLocation getResource(String texture) { - return new ResourceLocation("customnpcs", "textures/gui/" + texture); - } - - public void setWorldAndResolution(Minecraft mc, int width, int height) { - super.setWorldAndResolution(mc, width, height); - this.initPacket(); - } - - public void initPacket() { - } - - public void initGui() { - super.initGui(); - GuiNpcTextField.unfocus(); - if (this.subgui != null) { - this.subgui.setWorldAndResolution(this.mc, this.width, this.height); - this.subgui.initGui(); - } - - this.guiLeft = (this.width - this.xSize) / 2; - this.guiTop = (this.height - this.ySize) / 2; - this.buttonList = Lists.newArrayList(); - this.buttons = new ConcurrentHashMap(); - this.topbuttons = new ConcurrentHashMap(); - this.sidebuttons = new ConcurrentHashMap(); - this.textfields = new ConcurrentHashMap(); - this.labels = new ConcurrentHashMap(); - this.scrolls = new ConcurrentHashMap(); - this.sliders = new ConcurrentHashMap(); - this.extra = new ConcurrentHashMap(); - this.components = new ArrayList(); - } - - public void updateScreen() { - if (this.subgui != null) { - this.subgui.updateScreen(); - } else { - Iterator var1 = (new ArrayList(this.textfields.values())).iterator(); - - while(var1.hasNext()) { - GuiNpcTextField tf = (GuiNpcTextField)var1.next(); - if (tf.enabled) { - tf.updateCursorCounter(); - } - } - - var1 = (new ArrayList(this.components)).iterator(); - - while(var1.hasNext()) { - IGui comp = (IGui)var1.next(); - comp.updateScreen(); - } - - super.updateScreen(); - } - - } - - public void addExtra(GuiHoverText gui) { - gui.setWorldAndResolution(this.mc, 350, 250); - this.extra.put(gui.id, gui); - } - - public void mouseClicked(int i, int j, int k) { - if (this.subgui != null) { - this.subgui.mouseClicked(i, j, k); - } else { - Iterator var4 = (new ArrayList(this.textfields.values())).iterator(); - - while(var4.hasNext()) { - GuiNpcTextField tf = (GuiNpcTextField)var4.next(); - if (tf.enabled) { - tf.mouseClicked(i, j, k); - } - } - - var4 = (new ArrayList(this.components)).iterator(); - - while(var4.hasNext()) { - IGui comp = (IGui)var4.next(); - if (comp instanceof IMouseListener) { - ((IMouseListener)comp).mouseClicked(i, j, k); - } - } - - this.mouseEvent(i, j, k); - if (k == 0) { - var4 = (new ArrayList(this.scrolls.values())).iterator(); - - while(var4.hasNext()) { - GuiCustomScroll scroll = (GuiCustomScroll)var4.next(); - scroll.mouseClicked(i, j, k); - } - - var4 = this.buttonList.iterator(); - - while(var4.hasNext()) { - GuiButton guibutton = (GuiButton)var4.next(); - if (guibutton.mousePressed(this.mc, this.mouseX, this.mouseY)) { - Pre event = new Pre(this, guibutton, this.buttonList); - if (!MinecraftForge.EVENT_BUS.post(event)) { - this.selectedButton = guibutton; - guibutton.func_146113_a(this.mc.getSoundHandler()); - this.actionPerformed(guibutton); - if (this.equals(this.mc.currentScreen)) { - MinecraftForge.EVENT_BUS.post(new Post(this, guibutton, this.buttonList)); - } - } - break; - } - } - } - } - - } - - public void mouseReleased(int mouseX, int mouseY, int state) { - if (this.selectedButton != null && state == 0) { - this.selectedButton.mouseReleased(mouseX, mouseY); - this.selectedButton = null; - } - - } - - public void mouseEvent(int i, int j, int k) { - } - - protected void actionPerformed(GuiButton guibutton) { - if (this.subgui != null) { - this.subgui.buttonEvent(guibutton); - } else { - this.buttonEvent(guibutton); - } - - } - public void buttonEvent(GuiButton guibutton){}; - - public void keyTyped(char c, int i) { - if (this.subgui != null) { - this.subgui.keyTyped(c, i); - } else { - boolean active = false; - Iterator var4 = this.components.iterator(); - - IGui comp; - while(var4.hasNext()) { - comp = (IGui)var4.next(); - if (comp.isActive()) { - active = true; - break; - } - } - - active = active || GuiNpcTextField.isFieldActive(); - if (!this.closeOnEsc || i != 1 && (active || !this.isInventoryKey(i))) { - var4 = (new ArrayList(this.textfields.values())).iterator(); - - while(var4.hasNext()) { - GuiNpcTextField tf = (GuiNpcTextField)var4.next(); - tf.textboxKeyTyped(c, i); - } - - var4 = (new ArrayList(this.components)).iterator(); - - while(var4.hasNext()) { - comp = (IGui)var4.next(); - if (comp instanceof IKeyListener) { - ((IKeyListener)comp).keyTyped(c, i); - } - } - - } else { - this.close(); - } - } - } - - public void onGuiClosed() { - GuiNpcTextField.unfocus(); - } - - public void close() { - this.displayGuiScreen((GuiScreen)null); - this.mc.setIngameFocus(); - this.save(); - } - - public void addButton(GuiNpcButton button) { - this.buttons.put(button.id, button); - this.buttonList.add(button); - } - - public void addTopButton(GuiMenuTopButton button) { - this.topbuttons.put(button.id, button); - this.buttonList.add(button); - } - - public void addSideButton(GuiMenuSideButton button) { - this.sidebuttons.put(button.id, button); - this.buttonList.add(button); - } - - public GuiNpcButton getButton(int i) { - return (GuiNpcButton)this.buttons.get(i); - } - - public GuiMenuSideButton getSideButton(int i) { - return (GuiMenuSideButton)this.sidebuttons.get(i); - } - - public GuiMenuTopButton getTopButton(int i) { - return (GuiMenuTopButton)this.topbuttons.get(i); - } - - public void addTextField(GuiNpcTextField tf) { - this.textfields.put(tf.id, tf); - } - - public GuiNpcTextField getTextField(int i) { - return (GuiNpcTextField)this.textfields.get(i); - } - - public void add(IGui gui) { - this.components.add(gui); - } - - public IGui get(int id) { - Iterator var2 = this.components.iterator(); - - IGui comp; - do { - if (!var2.hasNext()) { - return null; - } - - comp = (IGui)var2.next(); - } while(comp.getID() != id); - - return comp; - } - - public void addLabel(GuiNpcLabel label) { - this.labels.put(label.id, label); - } - - public GuiNpcLabel getLabel(int i) { - return (GuiNpcLabel)this.labels.get(i); - } - - public void addSlider(GuiNpcSlider slider) { - this.sliders.put(slider.id, slider); - this.buttonList.add(slider); - } - - public GuiNpcSlider getSlider(int i) { - return (GuiNpcSlider)this.sliders.get(i); - } - - public void addScroll(GuiCustomScroll scroll) { - scroll.setWorldAndResolution(this.mc, 350, 250); - this.scrolls.put(scroll.id, scroll); - } - - public GuiCustomScroll getScroll(int id) { - return (GuiCustomScroll)this.scrolls.get(id); - } - - public abstract void save(); - - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - this.mouseX = mouseX; - this.mouseY = mouseY; - int x = mouseX; - int y = mouseY; - if (this.subgui != null) { - y = 0; - x = 0; - } - - if (this.drawDefaultBackground && this.subgui == null) { - this.drawDefaultBackground(); - } - - if (this.background != null && this.mc.renderEngine != null) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPushMatrix(); - GL11.glTranslatef((float) this.guiLeft, (float) this.guiTop, 0.0F); - GL11.glScalef(this.bgScale, this.bgScale, this.bgScale); - this.mc.renderEngine.bindTexture(this.background); - if (this.xSize > 256) { - this.drawTexturedModalRect(0, 0, 0, 0, 250, this.ySize); - this.drawTexturedModalRect(250, 0, 256 - (this.xSize - 250), 0, this.xSize - 250, this.ySize); - } else { - this.drawTexturedModalRect(0, 0, 0, 0, this.xSize, this.ySize); - } - - GL11.glPopMatrix(); - } - - this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 8, 16777215); - Iterator var6 = (new ArrayList(this.labels.values())).iterator(); - - while(var6.hasNext()) { - GuiNpcLabel label = (GuiNpcLabel)var6.next(); - label.drawLabel(this, this.fontRendererObj); - } - - var6 = (new ArrayList(this.textfields.values())).iterator(); - - while(var6.hasNext()) { - GuiNpcTextField tf = (GuiNpcTextField)var6.next(); - tf.drawTextBox(x, y); - } - - var6 = (new ArrayList(this.components)).iterator(); - - while(var6.hasNext()) { - IGui comp = (IGui)var6.next(); - comp.drawScreen(x, y); - } - - var6 = (new ArrayList(this.scrolls.values())).iterator(); - - while(var6.hasNext()) { - GuiCustomScroll scroll = (GuiCustomScroll)var6.next(); - scroll.drawScreen(x, y, partialTicks, !this.hasSubGui() && scroll.isMouseOver(x, y) ? Mouse.getDWheel() : 0); - } - - var6 = (new ArrayList(this.extra.values())).iterator(); - - while(var6.hasNext()) { - GuiScreen gui = (GuiScreen)var6.next(); - gui.drawScreen(x, y, partialTicks); - } - - super.drawScreen(x, y, partialTicks); - if (this.subgui != null) { - this.subgui.drawScreen(mouseX, mouseY, partialTicks); - } - - } - - public FontRenderer getFontRenderer() { - return this.fontRendererObj; - } - - public void elementClicked() { - if (this.subgui != null) { - this.subgui.elementClicked(); - } - - } - - public boolean doesGuiPauseGame() { - return false; - } - - public void doubleClicked() { - } - - public boolean isInventoryKey(int i) { - return i == this.mc.gameSettings.keyBindInventory.getKeyCode(); - } - - public void drawDefaultBackground() { - super.drawDefaultBackground(); - } - - public void displayGuiScreen(GuiScreen gui) { - this.mc.displayGuiScreen(gui); - } - - public void setSubGui(SubGuiInterface gui) { - this.subgui = gui; - this.subgui.npc = this.npc; - this.subgui.setWorldAndResolution(this.mc, this.width, this.height); - this.subgui.parent = this; - this.initGui(); - } - - public void closeSubGui(SubGuiInterface gui) { - this.subgui = null; - } - - public boolean hasSubGui() { - return this.subgui != null; - } - - public SubGuiInterface getSubGui() { - return this.hasSubGui() && this.subgui.hasSubGui() ? this.subgui.getSubGui() : this.subgui; - } - - public void drawNpc(int x, int y) { - this.drawNpc(this.npc, x, y, 1.0F, 0); - } - - public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glColorMaterial(0,1); - GL11.glPushMatrix(); - GL11.glTranslatef((float)(this.guiLeft + x), (float)(this.guiTop + y), 50.0F); - float scale = 1.0F; - if ((double)entity.height > 2.4D) { - scale = 2.0F / entity.height; - } - - GL11.glScalef(-30.0F * scale * zoomed, 30.0F * scale * zoomed, 30.0F * scale * zoomed); - GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); - RenderHelper.enableStandardItemLighting(); - float f2 = entity.renderYawOffset; - float f3 = entity.rotationYaw; - float f4 = entity.rotationPitch; - float f7 = entity.rotationYawHead; - float f5 = (float)(this.guiLeft + x) - (float)this.mouseX; - float f6 = (float)(this.guiTop + y) - 50.0F * scale * zoomed - (float)this.mouseY; - - GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-((float) Math.atan((double) (f6 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); - entity.renderYawOffset = (float)rotation; - entity.rotationYaw = (float)Math.atan((double)(f5 / 80.0F)) * 40.0F + (float)rotation; - entity.rotationPitch = -((float)Math.atan((double)(f6 / 40.0F))) * 20.0F; - entity.rotationYawHead = entity.rotationYaw; - RenderItem.getInstance().zLevel = 180.0F; - RenderItem.getInstance().doRender(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); - entity.prevRenderYawOffset = entity.renderYawOffset = f2; - entity.prevRotationYaw = entity.rotationYaw = f3; - entity.prevRotationPitch = entity.rotationPitch = f4; - entity.prevRotationYawHead = entity.rotationYawHead = f7; - - GL11.glPopMatrix(); - RenderHelper.disableStandardItemLighting(); - } - - public void openLink(String link) { - try { - Class oclass = Class.forName("java.awt.Desktop"); - Object object = oclass.getMethod("getDesktop").invoke((Object)null); - oclass.getMethod("browse", URI.class).invoke(object, new URI(link)); - } catch (Throwable var4) { - } - - } -} diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java index 533a7654f..af60efd49 100644 --- a/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.minecraft.client.gui.GuiButton; -import noppes.npcs.EventScriptContainer; +import noppes.npcs.PlayerScriptContainer; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; @@ -18,10 +18,10 @@ import noppes.npcs.client.gui.util.SubGuiInterface; public class EventGuiScriptList extends SubGuiInterface { private GuiCustomScroll scroll1; private GuiCustomScroll scroll2; - private EventScriptContainer container; + private PlayerScriptContainer container; private List scripts; - public EventGuiScriptList(List scripts, EventScriptContainer container) { + public EventGuiScriptList(List scripts, PlayerScriptContainer container) { this.container = container; this.setBackground("menubg.png"); this.xSize = 346; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java index e554014e4..84ade08f8 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -11,7 +11,7 @@ import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import org.lwjgl.opengl.GL11; -public class GuiScriptGlobal extends EventGuiNPCInterface { +public class GuiScriptGlobal extends GuiNPCInterface { private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png"); public GuiScriptGlobal() { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index c03ffd2a6..f55d0b884 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -18,14 +18,16 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.EventScriptContainer; +import noppes.npcs.PlayerScriptContainer; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.swing.GuiJTextArea; import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; -public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener { +public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener { private int activeTab = 0; public IScriptHandler handler; public Map> languages = new HashMap(); @@ -38,7 +40,7 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo } public void initGui() { - this.xSize = (int)((double)this.width * 0.88D); + //this.xSize = (int)((double)this.width * 0.88D); this.ySize = (int)((double)this.xSize * 0.56D); if((double)this.ySize > (double)this.height * 0.95D) { this.ySize = (int)((double)this.height * 0.95D); @@ -53,7 +55,7 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings")); for(int ta = 0; ta < this.handler.getScripts().size(); ++ta) { - EventScriptContainer var10000 = (EventScriptContainer)this.handler.getScripts().get(ta); + PlayerScriptContainer var10000 = (PlayerScriptContainer)this.handler.getScripts().get(ta); this.addTopButton(top = new GuiMenuTopButton(ta + 1, top, ta + 1 + "")); } @@ -67,17 +69,43 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo top = this.getTopButton(0); } + List list = new ArrayList(); + list.add("playerscript.init"); + list.add("playerscript.tick"); + list.add("playerscript.interact"); + list.add("playerscript.damaged"); + list.add("playerscript.killed"); + list.add("playerscript.attack"); + list.add("playerscript.kills"); + list.add("playerscript.chat"); + list.add("playerscript.toss"); + list.add("playerscript.containeropen"); + list.add("playerscript.containerclosed"); + list.add("playerscript.login"); + list.add("playerscript.logout"); + list.add("playerscript.chat"); + list.add("playerscript.damagedentity"); + list.add("playerscript.factionupdate"); + list.add("playerscript.keypressed"); + list.add("playerscript.levelup"); + list.add("playerscript.pickup"); + list.add("playerscript.rangedlaunched"); + //list.add("playerscript.break"); + top.active = true; if(this.activeTab > 0) { - EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); - this.add(left); - /* - GuiTextArea left = new GuiTextArea(2, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); - left.enableCodeHighlighting(); - left.setListener(this); - this.add(left); - */ + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.setSize(68, 198); + hooks.guiLeft = guiLeft + 4; + hooks.guiTop = guiTop + 14; + hooks.setUnsortedList(list); + hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),list); + addScroll(hooks); + + PlayerScriptContainer var7 = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + 72 + yoffset, this.guiTop + yoffset, this.xSize - 180 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); + this.addTextField(left); int left1 = this.guiLeft + this.xSize - 104; this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear")); this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste")); @@ -96,12 +124,7 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo } else { GuiNpcTextArea var8 = new GuiNpcTextArea(2, this, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText()); var8.enabled = false; - this.add(var8); - /* - GuiTextArea var8 = new GuiTextArea(2, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText()); - var8.enabled = false; - this.add(var8); - */ + this.addTextField(var8); int var9 = this.guiLeft + this.xSize - 150; this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy")); this.addButton(new GuiNpcButton(102, var9, this.guiTop + 146, 60, 20, "gui.clear")); @@ -124,6 +147,20 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo this.ySize = 256; } + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + this.handler.getScripts().get(this.activeTab - 1).setType(scroll.getSelected().replace("playerscript.","")); + } + + private int getScriptHook(PlayerScriptContainer playerScriptContainer, List list) { + for(String s : list) { + if (s.replace("playerscript.", "").equals(playerScriptContainer.type)) { + return list.indexOf(s); + } + } + return 0; + } + private String getConsoleText() { Map map = this.handler.getConsoleText(); StringBuilder builder = new StringBuilder(); @@ -185,7 +222,7 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo } if(guibutton.id == 12) { - this.handler.getScripts().add(new EventScriptContainer(this.handler)); + this.handler.getScripts().add(new PlayerScriptContainer(this.handler)); this.activeTab = this.handler.getScripts().size(); this.initGui(); } @@ -207,17 +244,17 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo } if(guibutton.id == 100) { - NoppesStringUtils.setClipboardContents(((GuiTextArea)this.get(2)).getText()); + NoppesStringUtils.setClipboardContents((this.getTextField(2)).getText()); } if(guibutton.id == 101) { - ((GuiTextArea)this.get(2)).setText(NoppesStringUtils.getClipboardContents()); + (this.getTextField(2)).setText(NoppesStringUtils.getClipboardContents()); } - EventScriptContainer container; + PlayerScriptContainer container; if(guibutton.id == 102) { if(this.activeTab > 0) { - container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); container.script = ""; } else { this.handler.clearConsole(); @@ -244,18 +281,19 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo } if(guibutton.id == 107) { - container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container == null) { - this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); + this.handler.getScripts().add(container = new PlayerScriptContainer(this.handler)); } this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.handler.getLanguage()), container)); } if(guibutton.id == 108) { - container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container != null) { this.setScript(); + this.AWTWindow = new GuiJTextArea(container.script).setListener(this); } } @@ -263,12 +301,12 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo private void setScript() { if(this.activeTab > 0) { - EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + PlayerScriptContainer container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container == null) { - this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); + this.handler.getScripts().add(container = new PlayerScriptContainer(this.handler)); } - String text = ((GuiTextArea)this.get(2)).getText(); + String text = (this.getTextField(2)).getText(); text = text.replace("\r\n", "\n"); text = text.replace("\r", "\n"); container.script = text; @@ -301,10 +339,18 @@ public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNo } public void textUpdate(String text) { - EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + PlayerScriptContainer container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container != null) { container.script = text; } } + + @Override + public void saveText(String text) { + PlayerScriptContainer container = handler.getScripts().get(activeTab); + if(container != null) + container.script = text; + initGui(); + } } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java index 026d6661b..9e3256f27 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -9,10 +9,10 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.controllers.data.PlayerScriptData; +import noppes.npcs.controllers.data.PlayerDataScript; public class GuiScriptPlayers extends GuiScriptInterface { - private PlayerScriptData script = new PlayerScriptData((EntityPlayer)null); + private PlayerDataScript script = new PlayerDataScript((EntityPlayer)null); public GuiScriptPlayers() { this.handler = this.script; diff --git a/src/main/java/noppes/npcs/controllers/IScriptHandler.java b/src/main/java/noppes/npcs/controllers/IScriptHandler.java index 0932afb3d..72d9cb003 100644 --- a/src/main/java/noppes/npcs/controllers/IScriptHandler.java +++ b/src/main/java/noppes/npcs/controllers/IScriptHandler.java @@ -8,11 +8,11 @@ package noppes.npcs.controllers; import java.util.List; import java.util.Map; import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.EventScriptContainer; +import noppes.npcs.PlayerScriptContainer; import noppes.npcs.constants.EnumScriptType; public interface IScriptHandler { - void runScript(EnumScriptType var1, Event var2); + void callScript(EnumScriptType var1, Event var2, Object... obs); boolean isClient(); @@ -24,7 +24,7 @@ public interface IScriptHandler { void setLanguage(String var1); - List getScripts(); + List getScripts(); String noticeString(); diff --git a/src/main/java/noppes/npcs/controllers/PlayerData.java b/src/main/java/noppes/npcs/controllers/PlayerData.java index 29d4420fd..605a5723e 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/PlayerData.java @@ -3,14 +3,14 @@ package noppes.npcs.controllers; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import noppes.npcs.CustomNpcs; import noppes.npcs.constants.EnumRoleType; -import noppes.npcs.controllers.data.PlayerScriptData; +import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.RoleCompanion; public class PlayerData implements IExtendedEntityProperties{ @@ -21,7 +21,9 @@ public class PlayerData implements IExtendedEntityProperties{ public PlayerFactionData factionData = new PlayerFactionData(); public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); public PlayerMailData mailData = new PlayerMailData(); - public PlayerScriptData scriptData; + public PlayerDataScript scriptData; + public int playerLevel = 0; + public DataTimers timers = new DataTimers(this); public EntityNPCInterface editingNpc; public NBTTagCompound cloned; @@ -55,8 +57,8 @@ public class PlayerData implements IExtendedEntityProperties{ transportData.loadNBTData(data); factionData.loadNBTData(data); itemgiverData.loadNBTData(data); - mailData.loadNBTData(data); - + mailData.loadNBTData(data); + timers.readFromNBT(data); if(player != null){ playername = player.getCommandSenderName(); @@ -91,7 +93,8 @@ public class PlayerData implements IExtendedEntityProperties{ factionData.saveNBTData(compound); itemgiverData.saveNBTData(compound); mailData.saveNBTData(compound); - + timers.writeToNBT(compound); + compound.setString("PlayerName", playername); compound.setString("UUID", uuid); compound.setInteger("PlayerCompanionId", companionID); @@ -149,7 +152,7 @@ public class PlayerData implements IExtendedEntityProperties{ PlayerData data = new PlayerData(); if(data.player == null) { data.player = player; - data.scriptData = new PlayerScriptData(player); + data.scriptData = new PlayerDataScript(player); NBTTagCompound compound = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName()); data.setNBT(compound); diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index ae61d1043..b426ac053 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -28,7 +28,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; -import noppes.npcs.controllers.data.PlayerScriptData; +import noppes.npcs.controllers.data.ForgeDataScript; +import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.ScriptAnimal; import noppes.npcs.scripted.ScriptEntity; @@ -56,9 +57,11 @@ public class ScriptController { private boolean loaded = false; public boolean shouldSave = false; - public PlayerScriptData playerScripts = new PlayerScriptData((EntityPlayer)null); + public PlayerDataScript playerScripts = new PlayerDataScript((EntityPlayer)null); public long lastPlayerUpdate = 0L; + public ForgeDataScript forgeScripts = new ForgeDataScript(); + public ScriptController(){ loaded = false; Instance = this; @@ -74,8 +77,44 @@ public class ScriptController { } } + private File forgeScriptsFile() { + return new File(this.dir, "forge_scripts.json"); + } + + public boolean loadForgeScripts() { + this.forgeScripts.clear(); + File file = this.forgeScriptsFile(); + + try { + if(!file.exists()) { + return false; + } else { + this.forgeScripts.readFromNBT(NBTJsonUtil.LoadFile(file)); + return true; + } + } catch (Exception var3) { + LogWriter.error("Error loading: " + file.getAbsolutePath(), var3); + return false; + } + } + + public void setForgeScripts(NBTTagCompound compound) { + this.forgeScripts.readFromNBT(compound); + File file = this.forgeScriptsFile(); + + try { + NBTJsonUtil.SaveFile(file, compound); + this.forgeScripts.lastInited = -1L; + } catch (IOException var4) { + var4.printStackTrace(); + } catch (JsonException var5) { + var5.printStackTrace(); + } + + } + private File playerScriptsFile() { - return new File(this.dir, "player_scripts.json"); + return new File(dir, "player_scripts.json"); } public boolean loadPlayerScripts() { @@ -87,6 +126,7 @@ public class ScriptController { return false; } else { this.playerScripts.readFromNBT(NBTJsonUtil.LoadFile(file)); + shouldSave = false; return true; } } catch (Exception var3) { @@ -107,7 +147,6 @@ public class ScriptController { } catch (JsonException var5) { var5.printStackTrace(); } - } private void loadCategories(){ diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java new file mode 100644 index 000000000..d9bec4c3f --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -0,0 +1,179 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.controllers.data; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.Map.Entry; + +import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.EventHooks; +import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.NBTTags; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.controllers.IScriptHandler; +import noppes.npcs.controllers.ScriptController; + +import javax.script.ScriptEngine; + +public class ForgeDataScript implements IScriptHandler { + private List scripts = new ArrayList(); + private String scriptLanguage = "ECMAScript"; + public long lastInited = -1L; + public boolean hadInteract = true; + private boolean enabled = false; + + public ForgeDataScript() { + } + + public void clear() { + this.scripts = new ArrayList(); + } + + public void readFromNBT(NBTTagCompound compound) { + this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); + this.scriptLanguage = compound.getString("ScriptLanguage"); + this.enabled = compound.getBoolean("ScriptEnabled"); + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setTag("Scripts", NBTTags.NBTScript(this.scripts)); + compound.setString("ScriptLanguage", this.scriptLanguage); + compound.setBoolean("ScriptEnabled", this.enabled); + return compound; + } + + public void callScript(EnumScriptType type, Event event, Object... obs) { + if(this.isEnabled()) { +// CustomNpcs.getServer().func_152344_a(() -> { + Minecraft.getMinecraft().func_152344_a(() -> { + if (ScriptController.Instance.lastLoaded > this.lastInited) { + this.lastInited = ScriptController.Instance.lastLoaded; + if (!type.equals("init")) { + EventHooks.onForgeInit(this); + } + } + + Iterator var3 = this.scripts.iterator(); + + while (var3.hasNext()) { + PlayerScriptContainer script = (PlayerScriptContainer) var3.next(); + if(script.type != type.function) + continue; + + script.setEngine(scriptLanguage); + if(script.engine == null) + return; + for(int i = 0; i + 1 < obs.length; i += 2){ + Object ob = obs[i + 1]; + if(ob instanceof Entity) + ob = ScriptController.Instance.getScriptForEntity((Entity)ob); + script.engine.put(obs[i].toString(), ob); + } + ScriptEngine engine = script.engine; + + //script.run(EnumScriptType.valueOf(type), event); + script.run(engine); + } + }); + } + } + + public void callScript(String type, Event event) { + if(this.isEnabled()) { +// CustomNpcs.getServer().func_152344_a(() -> { + Minecraft.getMinecraft().func_152344_a(() -> { + if (ScriptController.Instance.lastLoaded > this.lastInited) { + this.lastInited = ScriptController.Instance.lastLoaded; + if (!type.equals("init")) { + EventHooks.onForgeInit(this); + } + } + + Iterator var3 = this.scripts.iterator(); + + while (var3.hasNext()) { + PlayerScriptContainer script = (PlayerScriptContainer) var3.next(); + //script.run(EnumScriptType.valueOf(type), event); + + script.setEngine(scriptLanguage); + if(script.engine == null) + return; + ScriptEngine engine = script.engine; + + script.run(engine); + } + }); + } + } + + public boolean isEnabled() { + return this.enabled && ScriptController.HasStart && this.scripts.size() > 0; + } + + public boolean isClient() { + return false; + } + + public boolean getEnabled() { + return this.enabled; + } + + public void setEnabled(boolean bo) { + this.enabled = bo; + } + + public String getLanguage() { + return this.scriptLanguage; + } + + public void setLanguage(String lang) { + this.scriptLanguage = lang; + } + + public List getScripts() { + return this.scripts; + } + + public String noticeString() { + return "ForgeScript"; + } + + public Map getConsoleText() { + TreeMap map = new TreeMap(); + int tab = 0; + Iterator var3 = this.getScripts().iterator(); + + while(var3.hasNext()) { + PlayerScriptContainer script = (PlayerScriptContainer)var3.next(); + ++tab; + Iterator var5 = script.console.entrySet().iterator(); + + while(var5.hasNext()) { + Entry entry = (Entry)var5.next(); + map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue()); + } + } + + return map; + } + + public void clearConsole() { + Iterator var1 = this.getScripts().iterator(); + + while(var1.hasNext()) { + PlayerScriptContainer script = (PlayerScriptContainer)var1.next(); + script.console.clear(); + } + + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java similarity index 66% rename from src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java rename to src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index dbc26740e..e648f8b15 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerScriptData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -10,23 +10,32 @@ import java.util.*; import java.util.Map.Entry; import com.google.common.base.Preconditions; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.world.WorldServer; import noppes.npcs.EventHooks; -import noppes.npcs.EventScriptContainer; +import noppes.npcs.PlayerScriptContainer; import noppes.npcs.NBTTags; import noppes.npcs.scripted.ScriptPlayer; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.ScriptWorld; +import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.event.PlayerEvent; import javax.annotation.CheckForNull; +import javax.script.ScriptEngine; -public class PlayerScriptData implements IScriptHandler { - public List scripts = new ArrayList(); - private String scriptLanguage = "ECMAScript"; +public class PlayerDataScript implements IScriptHandler { + public List scripts = new ArrayList(); + public String scriptLanguage = "ECMAScript"; private EntityPlayer player; private ScriptPlayer playerAPI; private long lastPlayerUpdate = 0L; @@ -36,8 +45,20 @@ public class PlayerScriptData implements IScriptHandler { private static Map console = new TreeMap(); private static List errored = new ArrayList(); - public PlayerScriptData(EntityPlayer player) { - this.player = player; + public ScriptPlayer dummyPlayer; + public ScriptWorld dummyWorld; + private final static EntityType entities = new EntityType(); + private final static JobType jobs = new JobType(); + private final static RoleType roles = new RoleType(); + + public PlayerDataScript(EntityPlayer player) { + if(player != null) { + this.player = player; + if (player instanceof EntityPlayer) + dummyPlayer = new ScriptPlayer((EntityPlayerMP) player); + if (player.worldObj instanceof WorldServer) + dummyWorld = new ScriptWorld((WorldServer) player.worldObj); + } } public void clear() { @@ -61,9 +82,9 @@ public class PlayerScriptData implements IScriptHandler { return compound; } - public void runScript(EnumScriptType type, Event event) { + public void callScript(EnumScriptType type, Event event, Object... obs) { if(this.isEnabled()) { - EventScriptContainer script; + PlayerScriptContainer script; if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) { this.lastInited = ScriptController.Instance.lastLoaded; errored.clear(); @@ -72,9 +93,10 @@ public class PlayerScriptData implements IScriptHandler { Iterator i = ScriptController.Instance.playerScripts.scripts.iterator(); while(i.hasNext()) { - script = ( EventScriptContainer)i.next(); - EventScriptContainer s = new EventScriptContainer(this); + script = (PlayerScriptContainer)i.next(); + PlayerScriptContainer s = new PlayerScriptContainer(this); s.readFromNBT(script.writeToNBT(new NBTTagCompound())); + this.scripts.add(s); } } @@ -86,23 +108,34 @@ public class PlayerScriptData implements IScriptHandler { } for(int var7 = 0; var7 < this.scripts.size(); ++var7) { - script = (EventScriptContainer)this.scripts.get(var7); + script = (PlayerScriptContainer)this.scripts.get(var7); + + if(!script.type.equals(type.function)) + continue; + if(!errored.contains(Integer.valueOf(var7))) { - script.run(type, event); - if(script.errored) { - errored.add(Integer.valueOf(var7)); + if(script == null || script.errored || !script.hasCode()) + return; + script.setEngine(scriptLanguage); + if(script.engine == null) + return; + for(int i = 0; i + 1 < obs.length; i += 2){ + Object ob = obs[i + 1]; + if(ob instanceof Entity) + ob = ScriptController.Instance.getScriptForEntity((Entity)ob); + script.engine.put(obs[i].toString(), ob); } - Iterator var8 = script.console.entrySet().iterator(); - - while(var8.hasNext()) { - Entry entry = (Entry)var8.next(); - if(!console.containsKey(entry.getKey())) { - console.put((Long)entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue()); - } - } - - script.console.clear(); + ScriptEngine engine = script.engine; + engine.put("player", dummyPlayer); + engine.put("world", dummyWorld); + PlayerEvent result = (PlayerEvent) engine.get("event"); + if(result == null) + engine.put("event", result = new PlayerEvent(this.getPlayer())); + engine.put("EntityType", entities); + engine.put("RoleType", roles); + engine.put("JobType", jobs); + script.run(engine); } } @@ -133,83 +166,83 @@ public class PlayerScriptData implements IScriptHandler { this.scriptLanguage = lang; } - public List getScripts() { + public List getScripts() { return this.scripts; } public static final class ToStringHelper { private final String className; - private final PlayerScriptData.ToStringHelper.ValueHolder holderHead; - private PlayerScriptData.ToStringHelper.ValueHolder holderTail; + private final PlayerDataScript.ToStringHelper.ValueHolder holderHead; + private PlayerDataScript.ToStringHelper.ValueHolder holderTail; private boolean omitNullValues; private boolean omitEmptyValues; private ToStringHelper(String className) { - this.holderHead = new PlayerScriptData.ToStringHelper.ValueHolder(); + this.holderHead = new PlayerDataScript.ToStringHelper.ValueHolder(); this.holderTail = this.holderHead; this.omitNullValues = false; this.omitEmptyValues = false; this.className = (String) Preconditions.checkNotNull(className); } - public PlayerScriptData.ToStringHelper omitNullValues() { + public PlayerDataScript.ToStringHelper omitNullValues() { this.omitNullValues = true; return this; } - public PlayerScriptData.ToStringHelper add(String name, @CheckForNull Object value) { + public PlayerDataScript.ToStringHelper add(String name, @CheckForNull Object value) { return this.addHolder(name, value); } - public PlayerScriptData.ToStringHelper add(String name, boolean value) { + public PlayerDataScript.ToStringHelper add(String name, boolean value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerScriptData.ToStringHelper add(String name, char value) { + public PlayerDataScript.ToStringHelper add(String name, char value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerScriptData.ToStringHelper add(String name, double value) { + public PlayerDataScript.ToStringHelper add(String name, double value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerScriptData.ToStringHelper add(String name, float value) { + public PlayerDataScript.ToStringHelper add(String name, float value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerScriptData.ToStringHelper add(String name, int value) { + public PlayerDataScript.ToStringHelper add(String name, int value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerScriptData.ToStringHelper add(String name, long value) { + public PlayerDataScript.ToStringHelper add(String name, long value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public PlayerScriptData.ToStringHelper addValue(@CheckForNull Object value) { + public PlayerDataScript.ToStringHelper addValue(@CheckForNull Object value) { return this.addHolder(value); } - public PlayerScriptData.ToStringHelper addValue(boolean value) { + public PlayerDataScript.ToStringHelper addValue(boolean value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerScriptData.ToStringHelper addValue(char value) { + public PlayerDataScript.ToStringHelper addValue(char value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerScriptData.ToStringHelper addValue(double value) { + public PlayerDataScript.ToStringHelper addValue(double value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerScriptData.ToStringHelper addValue(float value) { + public PlayerDataScript.ToStringHelper addValue(float value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerScriptData.ToStringHelper addValue(int value) { + public PlayerDataScript.ToStringHelper addValue(int value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public PlayerScriptData.ToStringHelper addValue(long value) { + public PlayerDataScript.ToStringHelper addValue(long value) { return this.addUnconditionalHolder(String.valueOf(value)); } @@ -243,9 +276,9 @@ public class PlayerScriptData implements IScriptHandler { String nextSeparator = ""; StringBuilder builder = (new StringBuilder(32)).append(this.className).append('{'); - for(PlayerScriptData.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { + for(PlayerDataScript.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { Object value = valueHolder.value; - if (!(valueHolder instanceof PlayerScriptData.ToStringHelper.UnconditionalValueHolder)) { + if (!(valueHolder instanceof PlayerDataScript.ToStringHelper.UnconditionalValueHolder)) { if (value == null) { if (omitNullValuesSnapshot) { continue; @@ -273,45 +306,45 @@ public class PlayerScriptData implements IScriptHandler { return builder.append('}').toString(); } - private PlayerScriptData.ToStringHelper.ValueHolder addHolder() { - PlayerScriptData.ToStringHelper.ValueHolder valueHolder = new PlayerScriptData.ToStringHelper.ValueHolder(); + private PlayerDataScript.ToStringHelper.ValueHolder addHolder() { + PlayerDataScript.ToStringHelper.ValueHolder valueHolder = new PlayerDataScript.ToStringHelper.ValueHolder(); this.holderTail = this.holderTail.next = valueHolder; return valueHolder; } - private PlayerScriptData.ToStringHelper addHolder(@CheckForNull Object value) { - PlayerScriptData.ToStringHelper.ValueHolder valueHolder = this.addHolder(); + private PlayerDataScript.ToStringHelper addHolder(@CheckForNull Object value) { + PlayerDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); valueHolder.value = value; return this; } - private PlayerScriptData.ToStringHelper addHolder(String name, @CheckForNull Object value) { - PlayerScriptData.ToStringHelper.ValueHolder valueHolder = this.addHolder(); + private PlayerDataScript.ToStringHelper addHolder(String name, @CheckForNull Object value) { + PlayerDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); valueHolder.value = value; valueHolder.name = (String)Preconditions.checkNotNull(name); return this; } - private PlayerScriptData.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() { - PlayerScriptData.ToStringHelper.UnconditionalValueHolder valueHolder = new PlayerScriptData.ToStringHelper.UnconditionalValueHolder(); + private PlayerDataScript.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() { + PlayerDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = new PlayerDataScript.ToStringHelper.UnconditionalValueHolder(); this.holderTail = this.holderTail.next = valueHolder; return valueHolder; } - private PlayerScriptData.ToStringHelper addUnconditionalHolder(Object value) { - PlayerScriptData.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); + private PlayerDataScript.ToStringHelper addUnconditionalHolder(Object value) { + PlayerDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); valueHolder.value = value; return this; } - private PlayerScriptData.ToStringHelper addUnconditionalHolder(String name, Object value) { - PlayerScriptData.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); + private PlayerDataScript.ToStringHelper addUnconditionalHolder(String name, Object value) { + PlayerDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); valueHolder.value = value; valueHolder.name = (String)Preconditions.checkNotNull(name); return this; } - private static final class UnconditionalValueHolder extends PlayerScriptData.ToStringHelper.ValueHolder { + private static final class UnconditionalValueHolder extends PlayerDataScript.ToStringHelper.ValueHolder { private UnconditionalValueHolder() { super(); } @@ -323,15 +356,15 @@ public class PlayerScriptData implements IScriptHandler { @CheckForNull Object value; @CheckForNull - PlayerScriptData.ToStringHelper.ValueHolder next; + PlayerDataScript.ToStringHelper.ValueHolder next; private ValueHolder() { } } } - public static PlayerScriptData.ToStringHelper toStringHelper(Object self) { - return new PlayerScriptData.ToStringHelper(self.getClass().getSimpleName()); + public static PlayerDataScript.ToStringHelper toStringHelper(Object self) { + return new PlayerDataScript.ToStringHelper(self.getClass().getSimpleName()); } public String noticeString() { @@ -339,7 +372,7 @@ public class PlayerScriptData implements IScriptHandler { return "Global script"; } else { BlockPos pos = new BlockPos(this.player); - return PlayerScriptData.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); + return PlayerDataScript.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 2108e317e..2eb18c6f5 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -106,7 +106,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public ICustomNpc wrappedNPC; private static final GameProfileAlt chateventProfile = new GameProfileAlt(); - private static FakePlayer chateventPlayer; + public static FakePlayer chateventPlayer; public DataDisplay display; public DataStats stats; public DataAI ai; diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java new file mode 100644 index 000000000..bdad6f419 --- /dev/null +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -0,0 +1,130 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.entity.data; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import noppes.npcs.EventHooks; +import noppes.npcs.scripted.ITimers; +import noppes.npcs.controllers.PlayerData; +import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.CustomNPCsException; + +public class DataTimers implements ITimers { + private Object parent; + private Map timers = new HashMap(); + + public DataTimers(Object parent) { + this.parent = parent; + } + + public void start(int id, int ticks, boolean repeat) { + if(this.timers.containsKey(Integer.valueOf(id))) { + throw new CustomNPCsException("There is already a timer with id: " + id, new Object[0]); + } else { + this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat)); + } + } + + public void forceStart(int id, int ticks, boolean repeat) { + this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat)); + } + + public boolean has(int id) { + return this.timers.containsKey(Integer.valueOf(id)); + } + + public boolean stop(int id) { + return this.timers.remove(Integer.valueOf(id)) != null; + } + + public void reset(int id) { + DataTimers.Timer timer = (DataTimers.Timer)this.timers.get(Integer.valueOf(id)); + if(timer == null) { + throw new CustomNPCsException("There is no timer with id: " + id, new Object[0]); + } else { + timer.ticks = 0; + } + } + + public void writeToNBT(NBTTagCompound compound) { + NBTTagList list = new NBTTagList(); + Iterator var3 = this.timers.values().iterator(); + + while(var3.hasNext()) { + DataTimers.Timer timer = (DataTimers.Timer)var3.next(); + NBTTagCompound c = new NBTTagCompound(); + c.setInteger("ID", timer.id); + c.setInteger("TimerTicks", timer.id); + c.setBoolean("Repeat", timer.repeat); + c.setInteger("Ticks", timer.ticks); + list.appendTag(c); + } + + compound.setTag("NpcsTimers", list); + } + + public void readFromNBT(NBTTagCompound compound) { + HashMap timers = new HashMap(); + NBTTagList list = compound.getTagList("NpcsTimers", 10); + + for(int i = 0; i < list.tagCount(); ++i) { + NBTTagCompound c = list.getCompoundTagAt(i); + DataTimers.Timer t = new DataTimers.Timer(c.getInteger("ID"), c.getInteger("TimerTicks"), c.getBoolean("Repeat")); + t.ticks = c.getInteger("Ticks"); + timers.put(Integer.valueOf(t.id), t); + } + + this.timers = timers; + } + + public void update() { + Iterator var1 = (new ArrayList(this.timers.values())).iterator(); + + while(var1.hasNext()) { + DataTimers.Timer timer = (DataTimers.Timer)var1.next(); + timer.update(); + } + + } + + public void clear() { + this.timers = new HashMap(); + } + + class Timer { + public int id; + private boolean repeat; + private int timerTicks; + private int ticks = 0; + + public Timer(int id, int ticks, boolean repeat) { + this.id = id; + this.repeat = repeat; + this.timerTicks = ticks; + this.ticks = ticks; + } + + public void update() { + if(this.ticks-- <= 0) { + if(this.repeat) { + this.ticks = this.timerTicks; + } else { + DataTimers.this.stop(this.id); + } + + Object ob = DataTimers.this.parent; + if(ob instanceof PlayerData) { + EventHooks.onPlayerTimer((PlayerData)ob, this.id); + } + } + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/ITimers.java b/src/main/java/noppes/npcs/scripted/ITimers.java new file mode 100644 index 000000000..24d1de2fe --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ITimers.java @@ -0,0 +1,20 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +public interface ITimers { + void start(int var1, int var2, boolean var3); + + void forceStart(int var1, int var2, boolean var3); + + boolean has(int var1); + + boolean stop(int var1); + + void reset(int var1); + + void clear(); +} diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 3bb0e16bf..ef2eaf454 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -62,7 +62,7 @@ public abstract class NpcAPI { return null; } else { try { - Class c = Class.forName("noppes.npcs.api.wrapper.WrapperNpcAPI"); + Class c = Class.forName("noppes.npcs.scripted.wrapper.WrapperNpcAPI"); instance = (NpcAPI) c.getMethod("Instance").invoke((Object) null); } catch (Exception var1) { var1.printStackTrace(); diff --git a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java index 52ddb6a94..9aa5c5aa4 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java @@ -6,10 +6,10 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.NpcAPI; -public class CustomNPCsEvent extends Event { - public final ScriptController API = ScriptController.Instance; +public class CustomNPCsEvent extends Event{ + public final NpcAPI API = NpcAPI.Instance(); public CustomNPCsEvent() { } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 7c458469d..0fec0fea7 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -482,7 +482,7 @@ playerscript.logout=Logout playerscript.pickup=Pickup playerscript.rangedlaunched=Range Launched playerscript.toss=Toss -playerscript.update=Update +playerscript.tick=Update item.npcWand.name=Npc Wand item.npcMobCloner.name=Mob Cloner From 6c8c7671b87436ea6fd350f28fa1a7e263ca1678 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 11 Oct 2021 07:16:10 -0500 Subject: [PATCH 22/58] Implemented KeyPressed event. --- src/main/java/noppes/npcs/EventHooks.java | 2 +- .../java/noppes/npcs/PacketHandlerPlayer.java | 24 ++++++------ .../noppes/npcs/ScriptPlayerEventHandler.java | 4 +- .../noppes/npcs/client/ClientTickHandler.java | 39 ++++++++++++++++++- .../client/gui/script/GuiScriptInterface.java | 2 +- .../npcs/constants/EnumPlayerPacket.java | 2 +- .../assets/customnpcs/lang/en_US.lang | 2 +- 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 070676d01..7040a7403 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -149,7 +149,7 @@ public class EventHooks { public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { PlayerDataScript handler = PlayerData.get(player).scriptData; KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); - handler.callScript(EnumScriptType.KEY_PRESSED, event); + handler.callScript(EnumScriptType.KEY_PRESSED, event, "key", button, "isCtrlPressed", isCtrlPressed, "isAltPressed", isAltPressed, "isShiftPressed", isShiftPressed, "isMetaPressed", isMetaPressed); WrapperNpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 63053e684..c10242985 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -22,13 +22,7 @@ import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.containers.ContainerMail; -import noppes.npcs.controllers.BankData; -import noppes.npcs.controllers.PlayerDataController; -import noppes.npcs.controllers.PlayerFactionData; -import noppes.npcs.controllers.PlayerMail; -import noppes.npcs.controllers.PlayerMailData; -import noppes.npcs.controllers.PlayerQuestController; -import noppes.npcs.controllers.PlayerQuestData; +import noppes.npcs.controllers.*; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleCompanion; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -66,18 +60,24 @@ public class PacketHandlerPlayer{ if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner()) return; NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc); + } else if(type == EnumPlayerPacket.KeyPressed) { + if(ScriptController.Instance.languages.isEmpty()) { + return; + } + + EventHooks.onPlayerKeyPressed(player, buffer.readInt(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean()); } else if(type == EnumPlayerPacket.FollowerHire){ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); if(npc == null || npc.advanced.role != EnumRoleType.Follower) return; - NoppesUtilPlayer.hireFollower(player,npc); + NoppesUtilPlayer.hireFollower(player, npc); } else if(type == EnumPlayerPacket.FollowerExtend){ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); if(npc == null || npc.advanced.role != EnumRoleType.Follower) return; - NoppesUtilPlayer.extendFollower(player,npc); + NoppesUtilPlayer.extendFollower(player, npc); Server.sendData(player, EnumPacketClient.GUI_DATA, npc.roleInterface.writeToNBT(new NBTTagCompound())); } else if(type == EnumPlayerPacket.FollowerState){ @@ -124,17 +124,17 @@ public class PacketHandlerPlayer{ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); if(npc == null) return; - NoppesUtilPlayer.dialogSelected(buffer.readInt(),buffer.readInt(),player,npc); + NoppesUtilPlayer.dialogSelected(buffer.readInt(), buffer.readInt(), player, npc); } else if(type == EnumPlayerPacket.CheckQuestCompletion){ PlayerQuestData playerdata = PlayerDataController.instance.getPlayerData(player).questData; - playerdata.checkQuestCompletion(player,null); + playerdata.checkQuestCompletion(player, null); } else if(type == EnumPlayerPacket.QuestLog){ NoppesUtilPlayer.sendQuestLogData(player); } else if(type == EnumPlayerPacket.QuestCompletion){ - NoppesUtilPlayer.questCompletion(player,buffer.readInt()); + NoppesUtilPlayer.questCompletion(player, buffer.readInt()); } else if(type == EnumPlayerPacket.FactionsGet){ PlayerFactionData data = PlayerDataController.instance.getPlayerData(player).factionData; diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 6b29d7749..20b837e37 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -272,11 +272,12 @@ public class ScriptPlayerEventHandler { } */ + /* @SubscribeEvent( priority = EventPriority.HIGHEST ) public void invoke(ServerChatEvent event) { - if(event.player.worldObj instanceof WorldServer && event.player != EntityNPCInterface.chateventPlayer) { + if(event.player.getEntityWorld() instanceof WorldServer && event.player != EntityNPCInterface.chateventPlayer) { PlayerDataScript handler = PlayerData.get(event.player).scriptData; String message = event.message; noppes.npcs.scripted.event.PlayerEvent.ChatEvent ev = new noppes.npcs.scripted.event.PlayerEvent.ChatEvent(handler.getPlayer(), event.message); @@ -289,6 +290,7 @@ public class ScriptPlayerEventHandler { } } } + */ public ScriptPlayerEventHandler registerForgeEvents() { ScriptPlayerEventHandler.ForgeEventHandler handler = new ScriptPlayerEventHandler.ForgeEventHandler(); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 06cd83b1a..cb965a6c3 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -14,11 +14,14 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import org.lwjgl.input.Keyboard; public class ClientTickHandler{ - private World prevWorld; private boolean otherContainer = false; + private int buttonPressed = -1; + private long buttonTime = 0L; + private final int[] ignoreKeys = new int[]{157, 29, 54, 42, 184, 56, 220, 219}; @SubscribeEvent(priority = EventPriority.LOWEST) public void onClientTick(TickEvent.ClientTickEvent event){ @@ -50,6 +53,40 @@ public class ClientTickHandler{ else if(mc.currentScreen instanceof GuiQuestLog) mc.setIngameFocus(); } + + int key = Keyboard.getEventKey(); + long time = Keyboard.getEventNanoseconds(); + if(Keyboard.getEventKeyState()) { + if(!this.isIgnoredKey(key)) { + this.buttonTime = time; + this.buttonPressed = key; + } + } else { + Minecraft mc = Minecraft.getMinecraft(); + if(key == this.buttonPressed && time - this.buttonTime < 500000000L && mc.currentScreen == null) { + boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); + boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42); + boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56); + boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219); + NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, new Object[]{Integer.valueOf(key), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed)}); + } + + this.buttonPressed = -1; + this.buttonTime = 0L; + } } + private boolean isIgnoredKey(int key) { + int[] var2 = this.ignoreKeys; + int var3 = var2.length; + + for(int var4 = 0; var4 < var3; ++var4) { + int i = var2[var4]; + if(i == key) { + return true; + } + } + + return false; + } } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index f55d0b884..a2678f8a6 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -86,7 +86,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb list.add("playerscript.chat"); list.add("playerscript.damagedentity"); list.add("playerscript.factionupdate"); - list.add("playerscript.keypressed"); + list.add("playerscript.keyPressed"); list.add("playerscript.levelup"); list.add("playerscript.pickup"); list.add("playerscript.rangedlaunched"); diff --git a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java index c891d3d78..f8b59d746 100644 --- a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java +++ b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java @@ -1,5 +1,5 @@ package noppes.npcs.constants; public enum EnumPlayerPacket { - FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, QuestCompletion, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, CompanionTalentExp + FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, QuestCompletion, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, CompanionTalentExp } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 0fec0fea7..88d48c094 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -474,7 +474,7 @@ playerscript.killed=Killed playerscript.factionupdate=Faction Updated playerscript.init=Init playerscript.interact=Interact -playerscript.keypressed=Key Pressed +playerscript.keyPressed=Key Pressed playerscript.kills=Kills playerscript.levelup=Level Up playerscript.login=Login From 6752f8baec0567aa4de4e6fc29a7d6ddbc368cbc Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 12 Oct 2021 02:57:32 -0500 Subject: [PATCH 23/58] Implemented several more events for players, including a click event, key event, fall event, and the basic entity living hurt, killed, and kills events, among others. --- src/main/java/noppes/npcs/CustomNpcs.java | 5 +- src/main/java/noppes/npcs/EventHooks.java | 89 ++++-- .../java/noppes/npcs/NoppesUtilServer.java | 18 ++ .../java/noppes/npcs/PacketHandlerPlayer.java | 10 +- .../noppes/npcs/ScriptPlayerEventHandler.java | 253 +++++++----------- .../noppes/npcs/client/ClientTickHandler.java | 10 + .../client/gui/script/GuiScriptInterface.java | 22 +- .../npcs/constants/EnumPlayerPacket.java | 2 +- .../noppes/npcs/constants/EnumScriptType.java | 12 +- .../noppes/npcs/controllers/PlayerData.java | 1 + .../controllers/data/ForgeDataScript.java | 2 +- .../npcs/entity/EntityNPCInterface.java | 7 +- .../java/noppes/npcs/scripted/IAnimal.java | 11 + .../java/noppes/npcs/scripted/IBlock.java | 41 +++ .../java/noppes/npcs/scripted/ICustomNpc.java | 2 +- .../java/noppes/npcs/scripted/IEntity.java | 2 +- .../noppes/npcs/scripted/IEntityLiving.java | 18 ++ .../npcs/scripted/IEntityLivingBase.java | 4 +- .../java/noppes/npcs/scripted/IMonster.java | 11 + .../java/noppes/npcs/scripted/IPixelmon.java | 11 + .../java/noppes/npcs/scripted/IPlayer.java | 2 +- src/main/java/noppes/npcs/scripted/IPos.java | 58 ++++ .../java/noppes/npcs/scripted/NpcAPI.java | 2 + .../noppes/npcs/scripted/ScriptAnimal.java | 4 +- .../noppes/npcs/scripted/ScriptBlock.java | 112 ++++++++ .../noppes/npcs/scripted/ScriptBlockPos.java | 117 ++++++++ .../noppes/npcs/scripted/ScriptEntity.java | 8 +- .../noppes/npcs/scripted/ScriptLiving.java | 6 +- .../npcs/scripted/ScriptLivingBase.java | 8 +- .../noppes/npcs/scripted/ScriptMonster.java | 4 +- .../java/noppes/npcs/scripted/ScriptNpc.java | 6 +- .../noppes/npcs/scripted/ScriptPixelmon.java | 8 +- .../noppes/npcs/scripted/ScriptPlayer.java | 6 +- .../npcs/scripted/event/PlayerEvent.java | 111 +++++++- .../npcs/scripted/roles/ScriptJobHealer.java | 3 +- .../scripted/roles/ScriptRoleFollower.java | 4 +- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 4 + .../assets/customnpcs/lang/en_US.lang | 18 +- 38 files changed, 763 insertions(+), 249 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/IAnimal.java create mode 100644 src/main/java/noppes/npcs/scripted/IBlock.java create mode 100644 src/main/java/noppes/npcs/scripted/IEntityLiving.java create mode 100644 src/main/java/noppes/npcs/scripted/IMonster.java create mode 100644 src/main/java/noppes/npcs/scripted/IPixelmon.java create mode 100644 src/main/java/noppes/npcs/scripted/IPos.java create mode 100644 src/main/java/noppes/npcs/scripted/ScriptBlock.java create mode 100644 src/main/java/noppes/npcs/scripted/ScriptBlockPos.java diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 7b19fc433..5d27c249a 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -174,10 +174,11 @@ public class CustomNpcs { NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy); MinecraftForge.EVENT_BUS.register(new ServerEventsHandler()); - //MinecraftForge.EVENT_BUS.register((new ScriptPlayerEventHandler()).registerForgeEvents()); MinecraftForge.EVENT_BUS.register(new ScriptController()); - FMLCommonHandler.instance().bus().register(new ScriptPlayerEventHandler()); + ScriptPlayerEventHandler scriptPlayerEventHandler = new ScriptPlayerEventHandler(); + MinecraftForge.EVENT_BUS.register(scriptPlayerEventHandler); + FMLCommonHandler.instance().bus().register(scriptPlayerEventHandler.registerForgeEvents()); FMLCommonHandler.instance().bus().register(new ServerTickHandler()); registerNpc(EntityNPCHumanMale.class, "npchumanmale"); diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 7040a7403..47a1c7078 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -9,21 +9,22 @@ import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityEvent; +import net.minecraftforge.event.entity.player.PlayerUseItemEvent; import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; -import noppes.npcs.scripted.IEntity; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.ScriptPlayer; +import noppes.npcs.scripted.*; import noppes.npcs.scripted.event.ForgeEvent; +import noppes.npcs.scripted.event.PlayerEvent; import noppes.npcs.scripted.event.PlayerEvent.AttackEvent; import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed; @@ -40,6 +41,8 @@ import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.PlayerData; import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; + public class EventHooks { public EventHooks() { } @@ -63,62 +66,84 @@ public class EventHooks { } public static boolean onPlayerInteract(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) { - handler.callScript(EnumScriptType.INTERACT, event); + handler.callScript(EnumScriptType.INTERACT, event, "target", event.target, "type", event.type); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerAttack(PlayerDataScript handler, AttackEvent event) { - handler.callScript(EnumScriptType.ATTACK, event); + public static boolean onStartUsingItem(PlayerDataScript handler, int duration, ItemStack item){ + PlayerEvent.StartUsingItem event = new PlayerEvent.StartUsingItem(handler.getPlayer(), item, duration); + handler.callScript(EnumScriptType.START_USING_ITEM, event, "duration", event.duration, "item", event.item); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static boolean onPlayerToss(PlayerDataScript handler, EntityItem entityItem) { - TossEvent event = new TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); - handler.callScript(EnumScriptType.TOSS, event); + public static boolean onUsingItem(PlayerDataScript handler, int duration, ItemStack item){ + PlayerEvent.UsingItem event = new PlayerEvent.UsingItem(handler.getPlayer(), item, duration); + handler.callScript(EnumScriptType.USING_ITEM, event, "duration", event.duration, "item", event.item); return WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerLevelUp(PlayerDataScript handler, int change) { - LevelUpEvent event = new LevelUpEvent(handler.getPlayer(), change); - handler.callScript(EnumScriptType.LEVEL_UP, event); + public static boolean onStopUsingItem(PlayerDataScript handler, int duration, ItemStack item){ + PlayerEvent.StopUsingItem event = new PlayerEvent.StopUsingItem(handler.getPlayer(), item, duration); + handler.callScript(EnumScriptType.STOP_USING_ITEM, event, "duration", event.duration, "item", event.item); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onFinishUsingItem(PlayerDataScript handler, int duration, ItemStack item){ + PlayerEvent.FinishUsingItem event = new PlayerEvent.FinishUsingItem(handler.getPlayer(), item, duration); + handler.callScript(EnumScriptType.FINISH_USING_ITEM, event, "duration", event.duration, "item", event.item); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerDropItems(PlayerDataScript handler, ArrayList entityItems) { + IItemStack[] items = new IItemStack[entityItems.size()]; + for(int i = 0; i < entityItems.size(); i++){ items[i] = NpcAPI.Instance().getIItemStack(entityItems.get(i).getEntityItem()); } + + TossEvent event = new TossEvent(handler.getPlayer(), items); + handler.callScript(EnumScriptType.DROP, event, "items", event.items); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerPickupXP(PlayerDataScript handler, EntityXPOrb orb) { + PlayerEvent.PickupXPEvent event = new PlayerEvent.PickupXPEvent(handler.getPlayer(), orb); + handler.callScript(EnumScriptType.PICKUP_XP, event, "amount", event.amount); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) { PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); - handler.callScript(EnumScriptType.PICKUP, event); + handler.callScript(EnumScriptType.PICKUP, event, "item", event.item); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerContainerOpen(PlayerDataScript handler, Container container) { ContainerOpen event = new ContainerOpen(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); - handler.callScript(EnumScriptType.CONTAINER_OPEN, event); - WrapperNpcAPI.EVENT_BUS.post(event); - } - - public static void onPlayerContainerClose(PlayerDataScript handler, Container container) { - ContainerClosed event = new ContainerClosed(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); - handler.callScript(EnumScriptType.CONTAINER_CLOSED, event); + handler.callScript(EnumScriptType.CONTAINER_OPEN, event, "container", event.container); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerDeath(PlayerDataScript handler, DamageSource source, Entity entity) { noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(handler.getPlayer(), source, entity); - handler.callScript(EnumScriptType.KILLED, event); + handler.callScript(EnumScriptType.KILLED, event, "source", event.source, "damageSource", event.damageSource, "type", event.type); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerKills(PlayerDataScript handler, EntityLivingBase entityLiving) { noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent event = new noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent(handler.getPlayer(), entityLiving); - handler.callScript(EnumScriptType.KILLS, event); + handler.callScript(EnumScriptType.KILLS, event, "entity", event.entity); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerDamaged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) { - handler.callScript(EnumScriptType.DAMAGED, event); + handler.callScript(EnumScriptType.DAMAGED, event, "damage", event.damage, "source", event.source, "damageSource", event.damageSource); return WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onPlayerFall(PlayerDataScript handler, float distance) { + PlayerEvent.FallEvent event = new PlayerEvent.FallEvent(handler.getPlayer(),distance); + handler.callScript(EnumScriptType.FALL, event, "distance", event.distance); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerLogin(PlayerDataScript handler) { LoginEvent event = new LoginEvent(handler.getPlayer()); handler.callScript(EnumScriptType.LOGIN, event); @@ -137,15 +162,22 @@ public class EventHooks { } public static boolean onPlayerRanged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) { - handler.callScript(EnumScriptType.RANGED_LAUNCHED, event); + handler.callScript(EnumScriptType.RANGED_LAUNCHED, event, "bow", event.bow, "charge", event.charge); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerDamagedEntity(PlayerDataScript handler, DamagedEntityEvent event) { - handler.callScript(EnumScriptType.DAMAGED_ENTITY, event); + handler.callScript(EnumScriptType.DAMAGED_ENTITY, event, "target", event.target, "damage", event.damage, "damageSource", event.damageSource, ""); return WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel) { + PlayerDataScript handler = PlayerData.get(player).scriptData; + PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent(handler.getPlayer(), button, mouseWheel); + handler.callScript(EnumScriptType.MOUSE_CLICKED, event, "button", event.button, "mouseWheel", event.mouseWheel); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { PlayerDataScript handler = PlayerData.get(player).scriptData; KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); @@ -160,6 +192,11 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } + public static boolean onPlayerBreak(PlayerDataScript handler, PlayerEvent.BreakEvent event) { + handler.callScript(EnumScriptType.BREAK, event, "block", event.block, "xp", event.exp); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onForgeEntityEvent(EntityEvent event) { IEntity e = NpcAPI.Instance().getIEntity(event.entity); onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.EntityEvent(event, e), event); diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 8cf1ec88e..4f46d54bb 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -23,6 +23,8 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -34,6 +36,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityCommandBlock; import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -697,4 +700,19 @@ public class NoppesUtilServer { } return null; } + + public static Entity GetDamageSourcee(DamageSource damagesource) { + Object entity = damagesource.getEntity(); + if(entity == null) { + entity = damagesource.getSourceOfDamage(); + } + + if(entity instanceof EntityArrow && ((EntityArrow)entity).shootingEntity instanceof EntityLivingBase) { + entity = ((EntityArrow)entity).shootingEntity; + } else if(entity instanceof EntityThrowable) { + entity = ((EntityThrowable)entity).getThrower(); + } + + return (Entity)entity; + } } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index c10242985..36709bdb6 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -60,13 +60,21 @@ public class PacketHandlerPlayer{ if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner()) return; NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc); - } else if(type == EnumPlayerPacket.KeyPressed) { + } + else if(type == EnumPlayerPacket.KeyPressed) { if(ScriptController.Instance.languages.isEmpty()) { return; } EventHooks.onPlayerKeyPressed(player, buffer.readInt(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean()); } + else if(type == EnumPlayerPacket.MouseClicked) { + if(ScriptController.Instance.languages.isEmpty()) { + return; + } + + EventHooks.onPlayerMouseClicked(player, buffer.readInt(), buffer.readInt()); + } else if(type == EnumPlayerPacket.FollowerHire){ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); if(npc == null || npc.advanced.role != EnumRoleType.Follower) diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 20b837e37..9f73fdaab 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -20,27 +20,35 @@ import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.eventhandler.Event; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.network.FMLNetworkEvent; import cpw.mods.fml.relauncher.Side; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingFallEvent; +import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.event.entity.player.*; +import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent.PotentialSpawns; import noppes.npcs.controllers.PlayerData; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.ForgeEvent; import noppes.npcs.controllers.PixelmonHelper; import noppes.npcs.controllers.ScriptController; +import org.lwjgl.input.Mouse; public class ScriptPlayerEventHandler { public ScriptPlayerEventHandler() { @@ -50,163 +58,127 @@ public class ScriptPlayerEventHandler { if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; PlayerData data = PlayerData.get(player); - if(player.ticksExisted % 10 == 0) { - EventHooks.onPlayerTick(data.scriptData); - } - - if(data.playerLevel != player.experienceLevel) { - EventHooks.onPlayerLevelUp(data.scriptData, data.playerLevel - player.experienceLevel); - data.playerLevel = player.experienceLevel; - } + //if(player.ticksExisted % 10 == 0) { + EventHooks.onPlayerTick(data.scriptData); + //} data.timers.update(); } } - /* - @SubscribeEvent - public void invoke(LeftClickBlock event) { - if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { - PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - AttackEvent ev = new AttackEvent(handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); - event.setCanceled(EventHooks.onPlayerAttack(handler, ev)); - if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { - ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); - noppes.npcs.api.event.ItemEvent.AttackEvent eve = new noppes.npcs.api.event.ItemEvent.AttackEvent(isw, handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); - eve.setCanceled(event.isCanceled()); - event.setCanceled(EventHooks.onScriptItemAttack(isw, eve)); - } - - } - } - - @SubscribeEvent - public void invoke(RightClickBlock event) { - if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { - if(event.getItemStack().func_77973_b() == CustomItems.nbt_book) { - ((ItemNbtBook)event.getItemStack().func_77973_b()).blockEvent(event); - event.setCanceled(true); - } else { - PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - handler.hadInteract = true; - InteractEvent ev = new InteractEvent(handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); - event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); - if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { - ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); - noppes.npcs.api.event.ItemEvent.InteractEvent eve = new noppes.npcs.api.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos())); - event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); - } - - } - } - } @SubscribeEvent public void invoke(EntityInteractEvent event) { - if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { - if(event.getItemStack().func_77973_b() == CustomItems.nbt_book) { - ((ItemNbtBook)event.getItemStack().func_77973_b()).entityEvent(event); - event.setCanceled(true); - } else { - PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - InteractEvent ev = new InteractEvent(handler.getPlayer(), 1, NpcAPI.Instance().getIEntity(event.getTarget())); - event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); - if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { - ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); - noppes.npcs.api.event.ItemEvent.InteractEvent eve = new noppes.npcs.api.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 1, NpcAPI.Instance().getIEntity(event.getTarget())); - event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); - } - - } - } - } - - @SubscribeEvent - public void invoke(RightClickItem event) { - if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { - if(event.entityPlayer.func_184812_l_() && event.entityPlayer.func_70093_af() && event.getItemStack().func_77973_b() == CustomItems.scripted_item) { - NoppesUtilServer.sendOpenGui(event.entityPlayer, EnumGuiType.ScriptItem, (EntityNPCInterface)null); - } else { - PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - if(handler.hadInteract) { - handler.hadInteract = false; - } else { - InteractEvent ev = new InteractEvent(handler.getPlayer(), 0, (Object)null); - event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); - if(event.getItemStack().func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { - ItemScriptedWrapper isw = ItemScripted.GetWrapper(event.getItemStack()); - noppes.npcs.api.event.ItemEvent.InteractEvent eve = new noppes.npcs.api.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 0, (Object)null); - event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); - } - - } - } + if(!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + noppes.npcs.scripted.event.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.PlayerEvent.InteractEvent(handler.getPlayer(), 1, NpcAPI.Instance().getIEntity(event.target)); + event.setCanceled(EventHooks.onPlayerInteract(handler, ev)); } } @SubscribeEvent public void invoke(ArrowLooseEvent event) { - if(!event.entityPlayer.field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + if(!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - RangedLaunchedEvent ev = new RangedLaunchedEvent(handler.getPlayer()); - event.setCanceled(EventHooks.onPlayerRanged(handler, ev)); + noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent ev = new noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent(handler.getPlayer(), event.bow, event.charge); + EventHooks.onPlayerRanged(handler, ev); } } @SubscribeEvent - public void invoke(BreakEvent event) { - if(!event.getPlayer().field_70170_p.field_72995_K && event.getWorld() instanceof WorldServer) { + public void invoke(BlockEvent.BreakEvent event) { + if(!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.getPlayer()).scriptData; - noppes.npcs.api.event.PlayerEvent.BreakEvent ev = new noppes.npcs.api.event.PlayerEvent.BreakEvent(handler.getPlayer(), NpcAPI.Instance().getIBlock(event.getWorld(), event.getPos()), event.getExpToDrop()); + noppes.npcs.scripted.event.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.PlayerEvent.BreakEvent(handler.getPlayer(), NpcAPI.Instance().getIBlock(event.world, new BlockPos(event.x,event.y,event.z)), event.getExpToDrop()); event.setCanceled(EventHooks.onPlayerBreak(handler, ev)); event.setExpToDrop(ev.exp); } } @SubscribeEvent - public void invoke(ItemTossEvent event) { - if(event.getPlayer().field_70170_p instanceof WorldServer) { - PlayerDataScript handler = PlayerData.get(event.getPlayer()).scriptData; - event.setCanceled(EventHooks.onPlayerToss(handler, event.getEntityItem())); + public void invoke(PlayerUseItemEvent.Start event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + event.setCanceled(EventHooks.onStartUsingItem(handler, event.duration, event.item)); + } + } + @SubscribeEvent + public void invoke(PlayerUseItemEvent.Tick event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + event.setCanceled(EventHooks.onUsingItem(handler, event.duration, event.item)); + } + } + @SubscribeEvent + public void invoke(PlayerUseItemEvent.Stop event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + event.setCanceled(EventHooks.onStopUsingItem(handler, event.duration, event.item)); + } + } + @SubscribeEvent + public void invoke(PlayerUseItemEvent.Finish event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onFinishUsingItem(handler, event.duration, event.item); } } @SubscribeEvent - public void invoke(EntityItemPickupEvent event) { - if(event.entityPlayer.field_70170_p instanceof WorldServer) { + public void invoke(PlayerDropsEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - event.setCanceled(EventHooks.onPlayerPickUp(handler, event.getItem())); + event.setCanceled(EventHooks.onPlayerDropItems(handler, event.drops)); } } @SubscribeEvent - public void invoke(Open event) { - if(event.entityPlayer.field_70170_p instanceof WorldServer) { + public void invoke(PlayerPickupXpEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - EventHooks.onPlayerContainerOpen(handler, event.getContainer()); + EventHooks.onPlayerPickupXP(handler, event.orb); } } @SubscribeEvent - public void invoke(Close event) { - if(event.entityPlayer.field_70170_p instanceof WorldServer) { + public void invoke(PlayerEvent.ItemPickupEvent event) { + if(event.player.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + EventHooks.onPlayerPickUp(handler, event.pickedUp); + } + } + + @SubscribeEvent + public void invoke(PlayerOpenContainerEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - EventHooks.onPlayerContainerClose(handler, event.getContainer()); + EventHooks.onPlayerContainerOpen(handler, event.entityPlayer.openContainer); + } + } + + @SubscribeEvent + public void invoke(LivingFallEvent event) { + if(event.entityLiving.worldObj instanceof WorldServer) { + PlayerDataScript handler; + if (event.entityLiving instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.entityLiving).scriptData; + EventHooks.onPlayerFall(handler, event.distance); + } } } @SubscribeEvent public void invoke(LivingDeathEvent event) { - if(event.getEntityLiving().field_70170_p instanceof WorldServer) { - Entity source = NoppesUtilServer.GetDamageSourcee(event.getSource()); + if(event.entityLiving.worldObj instanceof WorldServer) { + Entity source = NoppesUtilServer.GetDamageSourcee(event.source); PlayerDataScript handler; - if(event.getEntityLiving() instanceof EntityPlayer) { - handler = PlayerData.get((EntityPlayer)event.getEntityLiving()).scriptData; - EventHooks.onPlayerDeath(handler, event.getSource(), source); + if(event.entityLiving instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.entityLiving).scriptData; + EventHooks.onPlayerDeath(handler, event.source, source); } if(source instanceof EntityPlayer) { handler = PlayerData.get((EntityPlayer)source).scriptData; - EventHooks.onPlayerKills(handler, event.getEntityLiving()); + EventHooks.onPlayerKills(handler, event.entityLiving); } } @@ -214,70 +186,47 @@ public class ScriptPlayerEventHandler { @SubscribeEvent public void invoke(LivingHurtEvent event) { - if(event.getEntityLiving().field_70170_p instanceof WorldServer) { - Entity source = NoppesUtilServer.GetDamageSourcee(event.getSource()); + if(event.entityLiving.worldObj instanceof WorldServer) { + Entity source = NoppesUtilServer.GetDamageSourcee(event.source); PlayerDataScript handler; - if(event.getEntityLiving() instanceof EntityPlayer) { - handler = PlayerData.get((EntityPlayer)event.getEntityLiving()).scriptData; - DamagedEvent pevent = new DamagedEvent(handler.getPlayer(), source, event.getAmount(), event.getSource()); + if(event.entityLiving instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.entityLiving).scriptData; + noppes.npcs.scripted.event.PlayerEvent.DamagedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.DamagedEvent(handler.getPlayer(), source, event.ammount, event.source); event.setCanceled(EventHooks.onPlayerDamaged(handler, pevent)); - event.setAmount(pevent.damage); + event.ammount = pevent.damage; } if(source instanceof EntityPlayer) { handler = PlayerData.get((EntityPlayer)source).scriptData; - DamagedEntityEvent pevent1 = new DamagedEntityEvent(handler.getPlayer(), event.getEntityLiving(), event.getAmount(), event.getSource()); + noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent(handler.getPlayer(), event.entityLiving, event.ammount, event.source); event.setCanceled(EventHooks.onPlayerDamagedEntity(handler, pevent1)); - event.setAmount(pevent1.damage); + event.ammount = pevent1.damage; } } } @SubscribeEvent - public void invoke(LivingAttackEvent event) { - if(event.getEntityLiving().field_70170_p instanceof WorldServer) { - Entity source = NoppesUtilServer.GetDamageSourcee(event.getSource()); - if(source instanceof EntityPlayer) { - PlayerDataScript handler = PlayerData.get((EntityPlayer)source).scriptData; - ItemStack item = ((EntityPlayer)source).func_184614_ca(); - IEntity target = NpcAPI.Instance().getIEntity(event.getEntityLiving()); - AttackEvent ev = new AttackEvent(handler.getPlayer(), 1, target); - event.setCanceled(EventHooks.onPlayerAttack(handler, ev)); - if(item.func_77973_b() == CustomItems.scripted_item && !event.isCanceled()) { - ItemScriptedWrapper isw = ItemScripted.GetWrapper(item); - noppes.npcs.api.event.ItemEvent.AttackEvent eve = new noppes.npcs.api.event.ItemEvent.AttackEvent(isw, handler.getPlayer(), 1, target); - eve.setCanceled(event.isCanceled()); - event.setCanceled(EventHooks.onScriptItemAttack(isw, eve)); - } - } - - } - } - - @SubscribeEvent - public void invoke(PlayerLoggedInEvent event) { - if(event.player.field_70170_p instanceof WorldServer) { + public void invoke(PlayerEvent.PlayerLoggedInEvent event) { + if(event.player.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.player).scriptData; EventHooks.onPlayerLogin(handler); } } @SubscribeEvent - public void invoke(PlayerLoggedOutEvent event) { - if(event.player.field_70170_p instanceof WorldServer) { + public void invoke(PlayerEvent.PlayerLoggedOutEvent event) { + if(event.player.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.player).scriptData; EventHooks.onPlayerLogout(handler); } } - */ - /* @SubscribeEvent( priority = EventPriority.HIGHEST ) - public void invoke(ServerChatEvent event) { - if(event.player.getEntityWorld() instanceof WorldServer && event.player != EntityNPCInterface.chateventPlayer) { + public void invoke(net.minecraftforge.event.ServerChatEvent event) { + if(event.player.worldObj instanceof WorldServer && !event.player.equals(EntityNPCInterface.chateventPlayer)) { PlayerDataScript handler = PlayerData.get(event.player).scriptData; String message = event.message; noppes.npcs.scripted.event.PlayerEvent.ChatEvent ev = new noppes.npcs.scripted.event.PlayerEvent.ChatEvent(handler.getPlayer(), event.message); @@ -290,7 +239,6 @@ public class ScriptPlayerEventHandler { } } } - */ public ScriptPlayerEventHandler registerForgeEvents() { ScriptPlayerEventHandler.ForgeEventHandler handler = new ScriptPlayerEventHandler.ForgeEventHandler(); @@ -299,8 +247,9 @@ public class ScriptPlayerEventHandler { Method e = handler.getClass().getMethod("forgeEntity", new Class[]{Event.class}); Method register = MinecraftForge.EVENT_BUS.getClass().getDeclaredMethod("register", new Class[]{Class.class, Object.class, Method.class, ModContainer.class}); register.setAccessible(true); - ArrayList list = new ArrayList(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); - list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.fml.common")); + ArrayList list = new ArrayList(); + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common")); + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); Iterator e1 = list.iterator(); while(true) { @@ -333,6 +282,10 @@ public class ScriptPlayerEventHandler { classes = classLoader.getName(); } while(classes.startsWith("net.minecraftforge.event.terraingen")); + if(classes.startsWith("cpw.mods.fml.common.gameevent")){ + ; + } + Class infoClass = classLoader.load(); ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses())); if(c.isEmpty()) { diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index cb965a6c3..f12b44967 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -15,6 +15,7 @@ import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; public class ClientTickHandler{ private World prevWorld; @@ -44,6 +45,15 @@ public class ClientTickHandler{ } } + @SubscribeEvent + public void onMouse(InputEvent.MouseInputEvent event){ + Minecraft mc = Minecraft.getMinecraft(); + if(mc.currentScreen != null || (Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0)) + return; + + NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, new Object[]{Mouse.getEventButton(),Mouse.getEventDWheel()}); + } + @SubscribeEvent public void onKey(InputEvent.KeyInputEvent event){ if(ClientProxy.QuestLog.isPressed()){ diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index a2678f8a6..d8ac18fad 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -75,22 +75,26 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb list.add("playerscript.interact"); list.add("playerscript.damaged"); list.add("playerscript.killed"); - list.add("playerscript.attack"); list.add("playerscript.kills"); list.add("playerscript.chat"); - list.add("playerscript.toss"); - list.add("playerscript.containeropen"); - list.add("playerscript.containerclosed"); + list.add("playerscript.drop"); + list.add("playerscript.containerOpen"); list.add("playerscript.login"); list.add("playerscript.logout"); list.add("playerscript.chat"); list.add("playerscript.damagedentity"); - list.add("playerscript.factionupdate"); list.add("playerscript.keyPressed"); - list.add("playerscript.levelup"); - list.add("playerscript.pickup"); - list.add("playerscript.rangedlaunched"); - //list.add("playerscript.break"); + list.add("playerscript.mouseClicked"); + list.add("playerscript.pickUp"); + list.add("playerscript.rangedLaunched"); + list.add("playerscript.pickupXP"); + list.add("playerscript.timer"); + list.add("playerscript.startItem"); + list.add("playerscript.usingItem"); + list.add("playerscript.stopItem"); + list.add("playerscript.finishItem"); + list.add("playerscript.fall"); + list.add("playerscript.break"); top.active = true; if(this.activeTab > 0) { diff --git a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java index f8b59d746..e1a1b95e2 100644 --- a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java +++ b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java @@ -1,5 +1,5 @@ package noppes.npcs.constants; public enum EnumPlayerPacket { - FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, QuestCompletion, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, CompanionTalentExp + FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, QuestCompletion, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, MouseClicked, CompanionTalentExp } diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index e66f9709b..6fb48d2bd 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -26,6 +26,7 @@ public enum EnumScriptType { DOOR_TOGGLE("doorToggle"), TIMER("timer"), TOSS("toss"), + DROP("drop"), CONTAINER_OPEN("containerOpen"), CONTAINER_CLOSED("containerClosed"), LOGIN("login"), @@ -40,7 +41,6 @@ public enum EnumScriptType { ATTACK("attack"), PROJECTILE_TICK("projectileTick"), PROJECTILE_IMPACT("projectileImpact"), - FACTION_UPDATE("factionUpdate"), LEVEL_UP("levelUp"), QUEST_START("questStart"), QUEST_COMPLETED("questCompleted"), @@ -52,7 +52,15 @@ public enum EnumScriptType { CUSTOM_GUI_CLOSED("customGuiClosed"), CUSTOM_GUI_BUTTON("customGuiButton"), CUSTOM_GUI_SLOT("customGuiSlot"), - CUSTOM_GUI_SCROLL("customGuiScroll"); + CUSTOM_GUI_SCROLL("customGuiScroll"), + PICKUP_XP("pickupXP"), + MOUSE_CLICKED("mouseClicked"), + START_USING_ITEM("startItem"), + USING_ITEM("usingItem"), + STOP_USING_ITEM("stopItem"), + FINISH_USING_ITEM("finishItem"), + FALL("fall"), + BREAK("break"); public String function; diff --git a/src/main/java/noppes/npcs/controllers/PlayerData.java b/src/main/java/noppes/npcs/controllers/PlayerData.java index 605a5723e..69634c971 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/PlayerData.java @@ -152,6 +152,7 @@ public class PlayerData implements IExtendedEntityProperties{ PlayerData data = new PlayerData(); if(data.player == null) { data.player = player; + data.playerLevel = player.experienceLevel; data.scriptData = new PlayerDataScript(player); NBTTagCompound compound = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName()); diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index d9bec4c3f..effccff93 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -90,7 +90,7 @@ public class ForgeDataScript implements IScriptHandler { public void callScript(String type, Event event) { if(this.isEnabled()) { -// CustomNpcs.getServer().func_152344_a(() -> { + //CustomNpcs.getServer().func_152344_a(() -> { Minecraft.getMinecraft().func_152344_a(() -> { if (ScriptController.Instance.lastLoaded > this.lastInited) { this.lastInited = ScriptController.Instance.lastLoaded; diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 2eb18c6f5..7d69e39e5 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -3,7 +3,6 @@ package noppes.npcs.entity; import io.netty.buffer.ByteBuf; import java.io.IOException; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -28,7 +27,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.pathfinding.PathNavigate; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; @@ -63,9 +61,6 @@ import noppes.npcs.ai.EntityAIMoveIndoors; import noppes.npcs.ai.EntityAIPanic; import noppes.npcs.ai.EntityAIWander; import noppes.npcs.ai.EntityAIWatchClosest; -import noppes.npcs.ai.pathfinder.FlyingMoveHelper; -import noppes.npcs.ai.pathfinder.PathNavigateFlying; -import noppes.npcs.ai.pathfinder.PathNavigateGround; import noppes.npcs.ai.selector.NPCAttackSelector; import noppes.npcs.ai.target.EntityAIClearTarget; import noppes.npcs.ai.target.EntityAIClosestTarget; @@ -525,7 +520,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if(event.getTarget() == null) entity = null; else - entity = event.getTarget().getMinecraftEntity(); + entity = event.getTarget().getMCEntity(); } if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking() && !isRemote()){ Line line = advanced.getAttackLine(); diff --git a/src/main/java/noppes/npcs/scripted/IAnimal.java b/src/main/java/noppes/npcs/scripted/IAnimal.java new file mode 100644 index 000000000..c5f8ade49 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IAnimal.java @@ -0,0 +1,11 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.entity.passive.EntityAnimal; + +public interface IAnimal extends IEntityLiving { +} diff --git a/src/main/java/noppes/npcs/scripted/IBlock.java b/src/main/java/noppes/npcs/scripted/IBlock.java new file mode 100644 index 000000000..9b1ce2f8a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IBlock.java @@ -0,0 +1,41 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; + +public interface IBlock { + int getX(); + + int getY(); + + int getZ(); + + IPos getPos(); + + String getName(); + + void remove(); + + boolean isAir(); + + IBlock setBlock(String var1); + + IBlock setBlock(IBlock var1); + + boolean isContainer(); + + IContainer getContainer(); + + IWorld getWorld(); + + TileEntity getMCTileEntity(); + + Block getMCBlock(); + + String getDisplayName(); +} diff --git a/src/main/java/noppes/npcs/scripted/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/ICustomNpc.java index 814b3536b..43f3b15d4 100644 --- a/src/main/java/noppes/npcs/scripted/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/ICustomNpc.java @@ -18,7 +18,7 @@ import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.roles.*; import noppes.npcs.util.ValueUtil; -public interface ICustomNpc { +public interface ICustomNpc extends IEntityLiving { /** * @return Returns the current npcs size 1-30 */ diff --git a/src/main/java/noppes/npcs/scripted/IEntity.java b/src/main/java/noppes/npcs/scripted/IEntity.java index 6a8d8f07f..39926aac2 100644 --- a/src/main/java/noppes/npcs/scripted/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/IEntity.java @@ -322,5 +322,5 @@ public interface IEntity { * Expert users only * @return Returns minecrafts entity */ - public Entity getMCEntity(); + public T getMCEntity(); } diff --git a/src/main/java/noppes/npcs/scripted/IEntityLiving.java b/src/main/java/noppes/npcs/scripted/IEntityLiving.java new file mode 100644 index 000000000..cc321c196 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IEntityLiving.java @@ -0,0 +1,18 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.entity.EntityLiving; + +public interface IEntityLiving extends IEntityLivingBase { + boolean isNavigating(); + + void clearNavigation(); + + void navigateTo(double var1, double var3, double var5, double var7); + + T getMCEntity(); +} diff --git a/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java b/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java index 953c3dc2d..14a4dec97 100644 --- a/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java @@ -7,7 +7,7 @@ import net.minecraft.potion.PotionEffect; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.constants.EntityType; -public interface IEntityLivingBase { +public interface IEntityLivingBase extends IEntity { /** * @return The entity's current health */ @@ -51,7 +51,7 @@ public interface IEntityLivingBase { * Expert use only * @return Returns the minecraft entity object */ - public EntityLivingBase getMinecraftEntity(); + public T getMCEntity(); /** * Makes the entity swing its hand diff --git a/src/main/java/noppes/npcs/scripted/IMonster.java b/src/main/java/noppes/npcs/scripted/IMonster.java new file mode 100644 index 000000000..2da043c5c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IMonster.java @@ -0,0 +1,11 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.entity.monster.EntityMob; + +public interface IMonster extends IEntityLiving { +} diff --git a/src/main/java/noppes/npcs/scripted/IPixelmon.java b/src/main/java/noppes/npcs/scripted/IPixelmon.java new file mode 100644 index 000000000..7458347b3 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IPixelmon.java @@ -0,0 +1,11 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.entity.passive.EntityTameable; + +public interface IPixelmon extends IAnimal { +} diff --git a/src/main/java/noppes/npcs/scripted/IPlayer.java b/src/main/java/noppes/npcs/scripted/IPlayer.java index 6e35dd1e8..60e454082 100644 --- a/src/main/java/noppes/npcs/scripted/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/IPlayer.java @@ -18,7 +18,7 @@ import noppes.npcs.controllers.*; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.util.ValueUtil; -public interface IPlayer { +public interface IPlayer extends IEntityLivingBase { /** * @return Returns the displayed name of the player */ diff --git a/src/main/java/noppes/npcs/scripted/IPos.java b/src/main/java/noppes/npcs/scripted/IPos.java new file mode 100644 index 000000000..581a62d8d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/IPos.java @@ -0,0 +1,58 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.util.math.BlockPos; + +public interface IPos { + int getX(); + + int getY(); + + int getZ(); + + IPos up(); + + IPos up(int var1); + + IPos down(); + + IPos down(int var1); + + IPos north(); + + IPos north(int var1); + + IPos east(); + + IPos east(int var1); + + IPos south(); + + IPos south(int var1); + + IPos west(); + + IPos west(int var1); + + IPos add(int var1, int var2, int var3); + + IPos add(IPos var1); + + IPos subtract(int var1, int var2, int var3); + + IPos subtract(IPos var1); + + double[] normalize(); + + BlockPos getMCBlockPos(); + + IPos offset(int var1); + + IPos offset(int var1, int var2); + + double distanceTo(IPos var1); +} diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index ef2eaf454..327e155ba 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -31,6 +31,8 @@ public abstract class NpcAPI { public abstract IEntity getIEntity(Entity var1); + public abstract IBlock getIBlock(World var1, BlockPos var2); + public abstract IContainer getIContainer(IInventory var1); public abstract IContainer getIContainer(Container var1); diff --git a/src/main/java/noppes/npcs/scripted/ScriptAnimal.java b/src/main/java/noppes/npcs/scripted/ScriptAnimal.java index 232d230bd..585fd777a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptAnimal.java +++ b/src/main/java/noppes/npcs/scripted/ScriptAnimal.java @@ -3,9 +3,9 @@ package noppes.npcs.scripted; import net.minecraft.entity.passive.EntityAnimal; import noppes.npcs.scripted.constants.EntityType; -public class ScriptAnimal extends ScriptLiving{ +public class ScriptAnimal extends ScriptLiving implements IAnimal { - public ScriptAnimal(EntityAnimal entity) { + public ScriptAnimal(T entity) { super(entity); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java new file mode 100644 index 000000000..e74850582 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -0,0 +1,112 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import java.util.Map; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.inventory.IInventory; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import noppes.npcs.util.LRUHashMap; + +public class ScriptBlock implements IBlock { + private static final Map blockCache = new LRUHashMap(400); + protected final IWorld world; + protected final Block block; + protected final BlockPos pos; + protected final ScriptBlockPos bPos; + protected TileEntity tile; + + public ScriptBlock(World world, Block block, BlockPos pos) { + this.world = NpcAPI.Instance().getIWorld((WorldServer)world); + this.block = block; + this.pos = pos; + this.bPos = new ScriptBlockPos(pos); + } + + public IPos getPos() { + return this.bPos; + } + + public int getX() { + return this.pos.getX(); + } + + public int getY() { + return this.pos.getY(); + } + + public int getZ() { + return this.pos.getZ(); + } + + public void remove() { + this.world.getMCWorld().setBlockToAir(getX(), getY(), getZ()); + } + + public boolean isAir() { + return this.block.isAir(this.world.getMCWorld(), getX(), getY(), getZ()); + } + + public ScriptBlock setBlock(String name) { + Block block = (Block)Block.blockRegistry.getObject(new ResourceLocation(name)); + if(block == null) { + return this; + } else { + this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block); + return new ScriptBlock(this.world.getMCWorld(), block, this.pos); + } + } + + public ScriptBlock setBlock(IBlock block) { + this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block.getMCBlock()); + return new ScriptBlock(this.world.getMCWorld(), block.getMCBlock(), this.pos); + } + + public boolean isContainer() { + return this.tile != null && this.tile instanceof IInventory?((IInventory)this.tile).getSizeInventory() > 0:false; + } + + public IContainer getContainer() { + if(!this.isContainer()) { + throw new CustomNPCsException("This block is not a container", new Object[0]); + } else { + return NpcAPI.Instance().getIContainer((IInventory)this.tile); + } + } + + public String getName() { + return Block.blockRegistry.getNameForObject(this.block) + ""; + } + + public String getDisplayName() { + return this.tile == null?this.getName():this.tile.blockType.getItemIconName(); + } + + public IWorld getWorld() { + return this.world; + } + + public Block getMCBlock() { + return this.block; + } + + public static void clearCache() { + blockCache.clear(); + } + + public boolean hasTileEntity() { + return this.tile != null; + } + + public TileEntity getMCTileEntity() { + return this.tile; + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java b/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java new file mode 100644 index 000000000..3dcb87c1a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java @@ -0,0 +1,117 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +public class ScriptBlockPos implements IPos { + private BlockPos blockPos; + + public ScriptBlockPos(BlockPos pos) { + this.blockPos = pos; + } + + public int getX() { + return this.blockPos.getX(); + } + + public int getY() { + return this.blockPos.getY(); + } + + public int getZ() { + return this.blockPos.getZ(); + } + + public IPos up() { + return new ScriptBlockPos(this.blockPos.up()); + } + + public IPos up(int n) { + return new ScriptBlockPos(this.blockPos.up(n)); + } + + public IPos down() { + return new ScriptBlockPos(this.blockPos.down()); + } + + public IPos down(int n) { + return new ScriptBlockPos(this.blockPos.down(n)); + } + + public IPos north() { + return new ScriptBlockPos(this.blockPos.north()); + } + + public IPos north(int n) { + return new ScriptBlockPos(this.blockPos.north(n)); + } + + public IPos east() { + return new ScriptBlockPos(this.blockPos.east()); + } + + public IPos east(int n) { + return new ScriptBlockPos(this.blockPos.east(n)); + } + + public IPos south() { + return new ScriptBlockPos(this.blockPos.south()); + } + + public IPos south(int n) { + return new ScriptBlockPos(this.blockPos.south(n)); + } + + public IPos west() { + return new ScriptBlockPos(this.blockPos.west()); + } + + public IPos west(int n) { + return new ScriptBlockPos(this.blockPos.west(n)); + } + + public IPos add(int x, int y, int z) { + return new ScriptBlockPos(this.blockPos.add(x, y, z)); + } + + public IPos add(IPos pos) { + return new ScriptBlockPos(this.blockPos.add(pos.getMCBlockPos())); + } + + public IPos subtract(int x, int y, int z) { + return new ScriptBlockPos(this.blockPos.add(-x, -y, -z)); + } + + public IPos subtract(IPos pos) { + return new ScriptBlockPos(this.blockPos.add(-pos.getX(), -pos.getY(), -pos.getZ())); + } + + public IPos offset(int direction) { + return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction])); + } + + public IPos offset(int direction, int n) { + return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction], n)); + } + + public BlockPos getMCBlockPos() { + return this.blockPos; + } + + public double[] normalize() { + double d = Math.sqrt((double)(this.blockPos.getX() * this.blockPos.getX() + this.blockPos.getY() * this.blockPos.getY() + this.blockPos.getZ() * this.blockPos.getZ())); + return new double[]{(double)this.getX() / d, (double)this.getY() / d, (double)this.getZ() / d}; + } + + public double distanceTo(IPos pos) { + double d0 = (double)(this.getX() - pos.getX()); + double d1 = (double)(this.getY() - pos.getY()); + double d2 = (double)(this.getZ() - pos.getZ()); + return Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 1b2d70959..c95abd0e8 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -27,11 +27,11 @@ import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.EntityType; -public class ScriptEntity implements IEntity{ - protected Entity entity; +public class ScriptEntity implements IEntity{ + protected T entity; private Map tempData = new HashMap(); - public ScriptEntity(Entity entity){ + public ScriptEntity(T entity){ this.entity = entity; } @@ -483,7 +483,7 @@ public class ScriptEntity implements IEntity{ * Expert users only * @return Returns minecrafts entity */ - public Entity getMCEntity(){ + public T getMCEntity(){ return entity; } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptLiving.java b/src/main/java/noppes/npcs/scripted/ScriptLiving.java index 2809ebc24..8abbfd8ee 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptLiving.java +++ b/src/main/java/noppes/npcs/scripted/ScriptLiving.java @@ -8,10 +8,10 @@ import net.minecraft.item.ItemStack; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.constants.EntityType; -public class ScriptLiving extends ScriptLivingBase{ +public class ScriptLiving extends ScriptLivingBase implements IEntityLiving { - private EntityLiving entity; - public ScriptLiving(EntityLiving entity) { + private T entity; + public ScriptLiving(T entity) { super(entity); this.entity = entity; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java index 776c3f0f1..ace51679e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java @@ -21,10 +21,10 @@ import net.minecraft.util.MathHelper; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.constants.EntityType; -public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{ - protected EntityLivingBase entity; +public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{ + protected T entity; - public ScriptLivingBase(EntityLivingBase entity){ + public ScriptLivingBase(T entity){ super(entity); this.entity = entity; } @@ -95,7 +95,7 @@ public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{ * Expert use only * @return Returns the minecraft entity object */ - public EntityLivingBase getMinecraftEntity(){ + public T getMCEntity(){ return entity; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptMonster.java b/src/main/java/noppes/npcs/scripted/ScriptMonster.java index 12f504a66..60cccd200 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptMonster.java +++ b/src/main/java/noppes/npcs/scripted/ScriptMonster.java @@ -4,9 +4,9 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.entity.monster.EntityMob; import noppes.npcs.scripted.constants.EntityType; -public class ScriptMonster extends ScriptLiving{ +public class ScriptMonster extends ScriptLiving implements IMonster { - public ScriptMonster(EntityMob entity) { + public ScriptMonster(T entity) { super(entity); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/ScriptNpc.java index 5e5582db4..073c1af98 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/ScriptNpc.java @@ -31,10 +31,10 @@ import noppes.npcs.scripted.roles.ScriptRoleTrader; import noppes.npcs.scripted.roles.ScriptRoleTransporter; import noppes.npcs.util.ValueUtil; -public class ScriptNpc extends ScriptLiving implements ICustomNpc{ +public class ScriptNpc extends ScriptLiving implements ICustomNpc { protected EntityCustomNpc npc; - - public ScriptNpc(EntityNPCInterface npc){ + + public ScriptNpc(T npc){ super(npc); this.npc = (EntityCustomNpc)npc; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptPixelmon.java b/src/main/java/noppes/npcs/scripted/ScriptPixelmon.java index f3d1ef628..57400dfcb 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPixelmon.java @@ -6,16 +6,16 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.controllers.PixelmonHelper; import noppes.npcs.util.ValueUtil; -public class ScriptPixelmon extends ScriptAnimal{ - private EntityTameable pixelmon; +public class ScriptPixelmon extends ScriptAnimal implements IPixelmon { + private T pixelmon; private NBTTagCompound compound = null; - public ScriptPixelmon(EntityTameable pixelmon){ + public ScriptPixelmon(T pixelmon){ super(pixelmon); this.pixelmon = pixelmon; compound = new NBTTagCompound(); pixelmon.writeEntityToNBT(compound); } - public ScriptPixelmon(EntityTameable pixelmon, NBTTagCompound compound){ + public ScriptPixelmon(T pixelmon, NBTTagCompound compound){ this(pixelmon); this.compound = compound; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java index c9a4c6995..b34f0b1cc 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java @@ -25,9 +25,9 @@ import noppes.npcs.controllers.QuestData; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.util.ValueUtil; -public class ScriptPlayer extends ScriptLivingBase implements IPlayer{ - protected EntityPlayerMP player; - public ScriptPlayer(EntityPlayerMP player){ +public class ScriptPlayer extends ScriptLivingBase implements IPlayer { + protected T player; + public ScriptPlayer(T player){ super(player); this.player = player; } diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index a4f2f9b9f..cb0247ac9 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -9,14 +9,10 @@ import cpw.mods.fml.common.eventhandler.Cancelable; import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.IDamageSource; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.IEntity; -import noppes.npcs.scripted.IEntityLivingBase; -import noppes.npcs.scripted.IPlayer; -import noppes.npcs.scripted.IItemStack; +import noppes.npcs.scripted.*; public class PlayerEvent extends CustomNPCsEvent { public final IPlayer player; @@ -52,6 +48,26 @@ public class PlayerEvent extends CustomNPCsEvent { } } + public static class MouseClickedEvent extends PlayerEvent { + public final int button; + public final int mouseWheel; + + public MouseClickedEvent(IPlayer player, int button, int mouseWheel){ + super(player); + this.button = button; + this.mouseWheel = mouseWheel; + } + } + + public static class PickupXPEvent extends PlayerEvent { + public final int amount; + + public PickupXPEvent(IPlayer player, EntityXPOrb orb) { + super(player); + this.amount = orb.xpValue; + } + } + public static class LevelUpEvent extends PlayerEvent { public final int change; @@ -97,12 +113,21 @@ public class PlayerEvent extends CustomNPCsEvent { } } + public static class FallEvent extends PlayerEvent { + public final float distance; + + public FallEvent(IPlayer player, float distance){ + super(player); + this.distance = distance; + } + } + public static class KilledEntityEvent extends PlayerEvent { public final IEntityLivingBase entity; public KilledEntityEvent(IPlayer player, EntityLivingBase entity) { super(player); - this.entity = (IEntityLivingBase)NpcAPI.Instance().getIEntity(entity); + this.entity = new ScriptLivingBase<>(entity);//NpcAPI.Instance().getIEntity(entity); } } @@ -122,8 +147,13 @@ public class PlayerEvent extends CustomNPCsEvent { @Cancelable public static class RangedLaunchedEvent extends PlayerEvent { - public RangedLaunchedEvent(IPlayer player) { + public final IItemStack bow; + public int charge; + + public RangedLaunchedEvent(IPlayer player, ItemStack bow, int charge) { super(player); + this.bow = NpcAPI.Instance().getIItemStack(bow); + this.charge = charge; } } @@ -171,11 +201,11 @@ public class PlayerEvent extends CustomNPCsEvent { @Cancelable public static class TossEvent extends PlayerEvent { - public final IItemStack item; + public final IItemStack[] items; - public TossEvent(IPlayer player, IItemStack item) { + public TossEvent(IPlayer player, IItemStack[] items) { super(player); - this.item = item; + this.items = items; } } @@ -214,4 +244,61 @@ public class PlayerEvent extends CustomNPCsEvent { super(player); } } + + public static class StartUsingItem extends PlayerEvent { + public final IItemStack item; + public final int duration; + + public StartUsingItem(IPlayer player, ItemStack item, int duration){ + super(player); + + this.item = NpcAPI.Instance().getIItemStack(item); + this.duration = duration; + } + } + public static class UsingItem extends PlayerEvent { + public final IItemStack item; + public final int duration; + + public UsingItem(IPlayer player, ItemStack item, int duration){ + super(player); + + this.item = NpcAPI.Instance().getIItemStack(item); + this.duration = duration; + } + } + public static class StopUsingItem extends PlayerEvent { + public final IItemStack item; + public final int duration; + + public StopUsingItem(IPlayer player, ItemStack item, int duration){ + super(player); + + this.item = NpcAPI.Instance().getIItemStack(item); + this.duration = duration; + } + } + public static class FinishUsingItem extends PlayerEvent { + public final IItemStack item; + public final int duration; + + public FinishUsingItem(IPlayer player, ItemStack item, int duration){ + super(player); + + this.item = NpcAPI.Instance().getIItemStack(item); + this.duration = duration; + } + } + + @Cancelable + public static class BreakEvent extends PlayerEvent { + public final IBlock block; + public int exp; + + public BreakEvent(IPlayer player, IBlock block, int exp) { + super(player); + this.block = block; + this.exp = exp; + } + } } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java index 8c6c934ce..13bceb0f5 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java @@ -1,7 +1,6 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.roles.JobGuard; import noppes.npcs.roles.JobHealer; import noppes.npcs.scripted.ScriptLivingBase; import noppes.npcs.scripted.constants.JobType; @@ -14,7 +13,7 @@ public class ScriptJobHealer extends ScriptJobInterface{ } public void heal(ScriptLivingBase entity, float amount){ - job.heal(entity.getMinecraftEntity(), amount); + job.heal(entity.getMCEntity(), amount); } @Override diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java index 3b65007c6..fa105d022 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java @@ -19,11 +19,11 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ * @param player Player who is set as the owner. If null given everything resets */ public void setOwner(ScriptPlayer player){ - if(player == null || player.getMinecraftEntity() == null){ + if(player == null || player.getMCEntity() == null){ role.setOwner(null); return; } - EntityPlayer mcplayer = (EntityPlayer) player.getMinecraftEntity(); + EntityPlayer mcplayer = (EntityPlayer) player.getMCEntity(); role.setOwner(mcplayer); } diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index ad2243075..455e53a87 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -59,6 +59,10 @@ public class WrapperNpcAPI extends NpcAPI { } } + public IBlock getIBlock(World world, BlockPos pos) { + return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); + } + public ICustomNpc createNPC(World world) { if (world.isRemote) { return null; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 88d48c094..bb3254e55 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -467,7 +467,7 @@ playerscript.attack=Attack playerscript.break=Break playerscript.chat=Chat playerscript.containerclosed=Closed Container -playerscript.containeropen=Open Container +playerscript.containerOpen=Open Container playerscript.damagedentity=Damaged Entity playerscript.damaged=Hurt playerscript.killed=Killed @@ -476,13 +476,21 @@ playerscript.init=Init playerscript.interact=Interact playerscript.keyPressed=Key Pressed playerscript.kills=Kills -playerscript.levelup=Level Up +playerscript.levelUp=Level Up playerscript.login=Login playerscript.logout=Logout -playerscript.pickup=Pickup -playerscript.rangedlaunched=Range Launched -playerscript.toss=Toss +playerscript.pickUp=Pickup +playerscript.rangedLaunched=Range Launched +playerscript.drop=Drop Items playerscript.tick=Update +playerscript.pickupXP=Pickup XP +playerscript.timer=Timer +playerscript.mouseClicked=Mouse Click +playerscript.startItem=Item Start +playerscript.usingItem=Using Item +playerscript.stopItem=Item Stop +playerscript.finishItem=Item Finish +playerscript.fall=Fall item.npcWand.name=Npc Wand item.npcMobCloner.name=Mob Cloner From 699182f4c0f8af846fb62c573b5c9244eff4674c Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 12 Oct 2021 03:23:56 -0500 Subject: [PATCH 24/58] Added ScriptBlock and ScriptNbt support to scripting API --- src/main/java/noppes/npcs/scripted/INbt.java | 76 +++++++ .../java/noppes/npcs/scripted/IWorld.java | 5 +- .../java/noppes/npcs/scripted/NpcAPI.java | 2 + .../noppes/npcs/scripted/ScriptBlock.java | 7 + .../noppes/npcs/scripted/ScriptEntity.java | 9 + .../noppes/npcs/scripted/ScriptItemStack.java | 15 ++ .../java/noppes/npcs/scripted/ScriptNbt.java | 214 ++++++++++++++++++ .../noppes/npcs/scripted/ScriptWorld.java | 11 +- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 4 + 9 files changed, 339 insertions(+), 4 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/INbt.java create mode 100644 src/main/java/noppes/npcs/scripted/ScriptNbt.java diff --git a/src/main/java/noppes/npcs/scripted/INbt.java b/src/main/java/noppes/npcs/scripted/INbt.java new file mode 100644 index 000000000..5ac4ddc95 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/INbt.java @@ -0,0 +1,76 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import net.minecraft.nbt.NBTTagCompound; + +public interface INbt { + void remove(String var1); + + boolean has(String var1); + + boolean getBoolean(String var1); + + void setBoolean(String var1, boolean var2); + + short getShort(String var1); + + void setShort(String var1, short var2); + + int getInteger(String var1); + + void setInteger(String var1, int var2); + + byte getByte(String var1); + + void setByte(String var1, byte var2); + + long getLong(String var1); + + void setLong(String var1, long var2); + + double getDouble(String var1); + + void setDouble(String var1, double var2); + + float getFloat(String var1); + + void setFloat(String var1, float var2); + + String getString(String var1); + + void setString(String var1, String var2); + + byte[] getByteArray(String var1); + + void setByteArray(String var1, byte[] var2); + + int[] getIntegerArray(String var1); + + void setIntegerArray(String var1, int[] var2); + + Object[] getList(String var1, int var2); + + int getListType(String var1); + + void setList(String var1, Object[] var2); + + INbt getCompound(String var1); + + void setCompound(String var1, INbt var2); + + String[] getKeys(); + + int getType(String var1); + + NBTTagCompound getMCNBT(); + + String toJsonString(); + + boolean isEqual(INbt var1); + + void clear(); +} diff --git a/src/main/java/noppes/npcs/scripted/IWorld.java b/src/main/java/noppes/npcs/scripted/IWorld.java index 291624518..1be45c61e 100644 --- a/src/main/java/noppes/npcs/scripted/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/IWorld.java @@ -13,6 +13,7 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; @@ -41,7 +42,7 @@ public interface IWorld { * @param z World position z * @return The block at the given position. Returns null if there isn't a block */ - public ScriptItemStack getBlock(int x, int y, int z); + public IBlock getBlock(int x, int y, int z); /** * @param x World position x @@ -219,6 +220,8 @@ public interface IWorld { public ScriptScoreboard getScoreboard(); + BlockPos getMCBlockPos(int x, int y, int z); + /** * @since 1.7.10c * Expert use only diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 327e155ba..e43f1bed9 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -77,4 +77,6 @@ public abstract class NpcAPI { public abstract String executeCommand(IWorld var1, String var2); public abstract String getRandomName(int var1, int var2); + + public abstract INbt getINbt(NBTTagCompound entityData); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index e74850582..86893eb5d 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -9,6 +9,7 @@ import java.util.Map; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -109,4 +110,10 @@ public class ScriptBlock implements IBlock { public TileEntity getMCTileEntity() { return this.tile; } + + public INbt getTileEntityNBT() { + NBTTagCompound compound = new NBTTagCompound(); + this.tile.writeToNBT(compound); + return NpcAPI.Instance().getINbt(compound); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index c95abd0e8..bba2fa4af 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -19,6 +19,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; import noppes.npcs.Server; @@ -486,4 +487,12 @@ public class ScriptEntity implements IEntity{ public T getMCEntity(){ return entity; } + + public INbt getNbt() { + return NpcAPI.Instance().getINbt(this.entity.getEntityData()); + } + + public void setNbt(INbt nbt) { + this.entity.readFromNBT(nbt.getMCNBT()); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 477346d08..ba0d1030e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -199,6 +199,21 @@ public class ScriptItemStack implements IItemStack { return true; } + public INbt getNbt() { + NBTTagCompound compound = this.item.getTagCompound(); + if(compound == null) { + this.item.setTagCompound(compound = new NBTTagCompound()); + } + + return NpcAPI.Instance().getINbt(compound); + } + + public INbt getItemNbt() { + NBTTagCompound compound = new NBTTagCompound(); + this.item.writeToNBT(compound); + return NpcAPI.Instance().getINbt(compound); + } + /** * No support is given for this method. Dont use if you dont know what you are doing. * @return Minecraft ItemStack diff --git a/src/main/java/noppes/npcs/scripted/ScriptNbt.java b/src/main/java/noppes/npcs/scripted/ScriptNbt.java new file mode 100644 index 000000000..25816f90f --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptNbt.java @@ -0,0 +1,214 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.scripted; + +import java.util.Iterator; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagInt; +import net.minecraft.nbt.NBTTagIntArray; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.util.NBTJsonUtil; + +public class ScriptNbt implements INbt { + private NBTTagCompound compound; + + public ScriptNbt(NBTTagCompound compound) { + this.compound = compound; + } + + public void remove(String key) { + this.compound.removeTag(key); + } + + public boolean has(String key) { + return this.compound.hasKey(key); + } + + public boolean getBoolean(String key) { + return this.compound.getBoolean(key); + } + + public void setBoolean(String key, boolean value) { + this.compound.setBoolean(key, value); + } + + public short getShort(String key) { + return this.compound.getShort(key); + } + + public void setShort(String key, short value) { + this.compound.setShort(key, value); + } + + public int getInteger(String key) { + return this.compound.getInteger(key); + } + + public void setInteger(String key, int value) { + this.compound.setInteger(key, value); + } + + public byte getByte(String key) { + return this.compound.getByte(key); + } + + public void setByte(String key, byte value) { + this.compound.setByte(key, value); + } + + public long getLong(String key) { + return this.compound.getLong(key); + } + + public void setLong(String key, long value) { + this.compound.setLong(key, value); + } + + public double getDouble(String key) { + return this.compound.getDouble(key); + } + + public void setDouble(String key, double value) { + this.compound.setDouble(key, value); + } + + public float getFloat(String key) { + return this.compound.getFloat(key); + } + + public void setFloat(String key, float value) { + this.compound.setFloat(key, value); + } + + public String getString(String key) { + return this.compound.getString(key); + } + + public void setString(String key, String value) { + this.compound.setString(key, value); + } + + public byte[] getByteArray(String key) { + return this.compound.getByteArray(key); + } + + public void setByteArray(String key, byte[] value) { + this.compound.setByteArray(key, value); + } + + public int[] getIntegerArray(String key) { + return this.compound.getIntArray(key); + } + + public void setIntegerArray(String key, int[] value) { + this.compound.setIntArray(key, value); + } + + public Object[] getList(String key, int type) { + NBTTagList list = this.compound.getTagList(key, type); + Object[] nbts = new Object[list.tagCount()]; + + for(int i = 0; i < list.tagCount(); ++i) { + if(list.func_150303_d() == 10) { + nbts[i] = new ScriptNbt(list.getCompoundTagAt(i)); + } else if(list.func_150303_d() == 8) { + nbts[i] = list.getStringTagAt(i); + } else if(list.func_150303_d() == 6) { + nbts[i] = Double.valueOf(list.func_150309_d(i)); + } else if(list.func_150303_d() == 5) { + nbts[i] = Float.valueOf(list.func_150308_e(i)); + } else if(list.func_150303_d() == 3) { + nbts[i] = Integer.valueOf(list.getStringTagAt(i)); + } else if(list.func_150303_d() == 11) { + nbts[i] = list.func_150306_c(i); + } + } + + return nbts; + } + + public int getListType(String key) { + NBTBase b = this.compound.getTag(key); + if(b == null) { + return 0; + } else if(b.getId() != 9) { + throw new CustomNPCsException("NBT tag " + key + " isn\'t a list", new Object[0]); + } else { + return ((NBTTagList)b).func_150303_d(); + } + } + + public void setList(String key, Object[] value) { + NBTTagList list = new NBTTagList(); + Object[] var4 = value; + int var5 = value.length; + + for(int var6 = 0; var6 < var5; ++var6) { + Object nbt = var4[var6]; + if(nbt instanceof INbt) { + list.appendTag(((INbt) nbt).getMCNBT()); + } else if(nbt instanceof String) { + list.appendTag(new NBTTagString((String) nbt)); + } else if(nbt instanceof Double) { + list.appendTag(new NBTTagDouble(((Double) nbt).doubleValue())); + } else if(nbt instanceof Float) { + list.appendTag(new NBTTagFloat(((Float) nbt).floatValue())); + } else if(nbt instanceof Integer) { + list.appendTag(new NBTTagInt(((Integer) nbt).intValue())); + } else if(nbt instanceof int[]) { + list.appendTag(new NBTTagIntArray((int[]) ((int[]) nbt))); + } + } + + this.compound.setTag(key, list); + } + + public INbt getCompound(String key) { + return new ScriptNbt(this.compound.getCompoundTag(key)); + } + + public void setCompound(String key, INbt value) { + if(value == null) { + throw new CustomNPCsException("Value cant be null", new Object[0]); + } else { + this.compound.setTag(key, value.getMCNBT()); + } + } + + public String[] getKeys() { + return (String[])this.compound.func_150296_c().toArray(new String[this.compound.func_150296_c().size()]); + } + + public int getType(String key) { + return this.compound.func_150299_b(key); + } + + public NBTTagCompound getMCNBT() { + return this.compound; + } + + public String toJsonString() { + return NBTJsonUtil.Convert(this.compound); + } + + public boolean isEqual(INbt nbt) { + return nbt == null?false:this.compound.equals(nbt.getMCNBT()); + } + + public void clear() { + Iterator var1 = this.compound.func_150296_c().iterator(); + + while(var1.hasNext()) { + String name = (String)var1.next(); + this.compound.removeTag(name); + } + + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index b47dc19b4..82f354fce 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; @@ -57,11 +58,11 @@ public class ScriptWorld implements IWorld{ * @param z World position z * @return The block at the given position. Returns null if there isn't a block */ - public ScriptItemStack getBlock(int x, int y, int z){ + public IBlock getBlock(int x, int y, int z){ Block block = world.getBlock(x, y, z); if(block == null || block.isAir(world, x, y, z)) return null; - return new ScriptItemStack(new ItemStack(block, 1, world.getBlockMetadata(x, y, z))); + return new ScriptBlock(world, block, new BlockPos(x,y,z)); } /** @@ -345,7 +346,11 @@ public class ScriptWorld implements IWorld{ public ScriptScoreboard getScoreboard(){ return new ScriptScoreboard(); } - + + public BlockPos getMCBlockPos(int x, int y, int z){ + return new BlockPos(x,y,z); + } + /** * @since 1.7.10c * Expert use only diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 455e53a87..7af89455a 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -63,6 +63,10 @@ public class WrapperNpcAPI extends NpcAPI { return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); } + public INbt getINbt(NBTTagCompound compound) { + return compound == null?new ScriptNbt(new NBTTagCompound()):new ScriptNbt(compound); + } + public ICustomNpc createNPC(World world) { if (world.isRemote) { return null; From 047552d9e57f62e3348824f5f83242fb339c2ede Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 12 Oct 2021 04:20:33 -0500 Subject: [PATCH 25/58] Made constant BlockPos calculateLogBaseTwo calculation explicit, enabled player events by default. --- .../net/minecraft/util/math/BlockPos.java | 3 +-- src/main/java/noppes/npcs/DataScript.java | 25 ++----------------- .../java/noppes/npcs/PacketHandlerServer.java | 4 +-- .../client/gui/script/GuiScriptInterface.java | 1 + .../client/gui/script/GuiScriptPlayers.java | 6 +++-- .../controllers/data/PlayerDataScript.java | 2 +- .../assets/customnpcs/lang/en_US.lang | 1 + 7 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/minecraft/util/math/BlockPos.java b/src/main/java/net/minecraft/util/math/BlockPos.java index 87db5faf0..b9aa29c1b 100644 --- a/src/main/java/net/minecraft/util/math/BlockPos.java +++ b/src/main/java/net/minecraft/util/math/BlockPos.java @@ -4,7 +4,6 @@ import com.google.common.collect.AbstractIterator; import java.util.Iterator; import net.minecraft.entity.Entity; import net.minecraft.util.EnumFacing; -import net.minecraft.util.MathHelper; import net.minecraft.util.Vec3; import net.minecraft.util.Vec3i; @@ -13,7 +12,7 @@ import net.minecraft.util.Vec3i; public class BlockPos extends Vec3i{ /** The BlockPos with all coordinates 0 */ public static final BlockPos ORIGIN = new BlockPos(0, 0, 0); - private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); + private static final int NUM_X_BITS = 1 + 25;//MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); private static final int NUM_Z_BITS = NUM_X_BITS; private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS; private static final int Y_SHIFT = 0 + NUM_Z_BITS; diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/DataScript.java index bea4219bb..2516817ad 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/DataScript.java @@ -111,29 +111,9 @@ public class DataScript { script.engine.put(obs[i].toString(), ob); } - //return callScript(script); - ScriptEngine engine = script.engine; - engine.put("npc", dummyNpc); - engine.put("world", dummyWorld); - ScriptEvent result = (ScriptEvent) engine.get("event"); - if(result == null) - engine.put("event", result = new ScriptEvent()); - engine.put("EntityType", entities); - engine.put("RoleType", roles); - engine.put("JobType", jobs); - script.run(engine); - - if(clientNeedsUpdate){ - npc.updateClient = true; - clientNeedsUpdate = false; - } - if(aiNeedsUpdate){ - npc.updateAI = true; - aiNeedsUpdate = false; - } - return result.isCancelled(); + return callScript(script); } - /* + private boolean callScript(ScriptContainer script){ ScriptEngine engine = script.engine; engine.put("npc", dummyNpc); @@ -156,7 +136,6 @@ public class DataScript { } return result.isCancelled(); } - */ public boolean isEnabled(){ return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty(); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 8a12e60d0..ac90681a9 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -107,7 +107,7 @@ public class PacketHandlerServer{ else if(item.getItem() == CustomItems.teleporter) featherPackets(type, buffer, player); else if(type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) - playerScriptPackets(type, buffer, player, npc); + playerScriptPackets(type, buffer, player); else if(item.getItem() == CustomItems.scripter) scriptPackets(type, buffer, player, npc); else if(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) @@ -130,7 +130,7 @@ public class PacketHandlerServer{ } } - private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { + private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception { NBTTagCompound compound; if(type == EnumPacketServer.ScriptPlayerGet) { compound = ScriptController.Instance.playerScripts.writeToNBT(new NBTTagCompound()); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index d8ac18fad..dc1a90541 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -70,6 +70,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } List list = new ArrayList(); + list.add("playerscript.disabled"); list.add("playerscript.init"); list.add("playerscript.tick"); list.add("playerscript.interact"); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java index 9e3256f27..332f1828b 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -16,7 +16,8 @@ public class GuiScriptPlayers extends GuiScriptInterface { public GuiScriptPlayers() { this.handler = this.script; - Client.sendData(EnumPacketServer.ScriptPlayerGet, new Object[0]); + //Client.sendData(EnumPacketServer.ScriptPlayerGet, new Object[0]); + Client.sendData(EnumPacketServer.ScriptPlayerGet); } public void setGuiData(NBTTagCompound compound) { @@ -26,6 +27,7 @@ public class GuiScriptPlayers extends GuiScriptInterface { public void save() { super.save(); - Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); + //Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); + Client.sendData(EnumPacketServer.ScriptPlayerSave, script.writeToNBT(new NBTTagCompound())); } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index e648f8b15..2bccaec7b 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -41,7 +41,7 @@ public class PlayerDataScript implements IScriptHandler { private long lastPlayerUpdate = 0L; public long lastInited = -1L; public boolean hadInteract = true; - private boolean enabled = false; + public boolean enabled = true; private static Map console = new TreeMap(); private static List errored = new ArrayList(); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index bb3254e55..dad4b5dab 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -463,6 +463,7 @@ script.dialog_closed=Dialog Closed eventscript.playerevent=Player Events +playerscript.disabled=Disabled playerscript.attack=Attack playerscript.break=Break playerscript.chat=Chat From a9bce4a3e3328b8b9b87317daa21820e7615f0ff Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 15 Oct 2021 09:17:31 -0500 Subject: [PATCH 26/58] Fixed player script enabled button not working right on servers. Added more player events and a getDimension() method to ScriptPlayer. Set player scripts to be off by default. --- src/main/java/noppes/npcs/EventHooks.java | 27 +++++- .../noppes/npcs/ScriptPlayerEventHandler.java | 40 ++++++++ .../client/gui/script/GuiScriptInterface.java | 93 +++++++++++-------- .../noppes/npcs/constants/EnumScriptType.java | 4 + .../controllers/data/PlayerDataScript.java | 3 +- .../java/noppes/npcs/scripted/IItemStack.java | 8 +- .../noppes/npcs/scripted/ScriptPlayer.java | 5 + .../npcs/scripted/event/PlayerEvent.java | 38 ++++++++ .../assets/customnpcs/lang/en_US.lang | 4 + 9 files changed, 178 insertions(+), 44 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 47a1c7078..f8863cf79 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -110,7 +110,7 @@ public class EventHooks { } public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) { - PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); + PickUpEvent event = new PickUpEvent(handler.getPlayer(), new ScriptItemStack(entityItem.getEntityItem()));//NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); handler.callScript(EnumScriptType.PICKUP, event, "item", event.item); return WrapperNpcAPI.EVENT_BUS.post(event); } @@ -138,6 +138,18 @@ public class EventHooks { return WrapperNpcAPI.EVENT_BUS.post(event); } + public static boolean onPlayerLightning(PlayerDataScript handler) { + PlayerEvent.LightningEvent event = new PlayerEvent.LightningEvent(handler.getPlayer()); + handler.callScript(EnumScriptType.LIGHTNING, event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static boolean onPlayerSound(PlayerDataScript handler, String name, float pitch, float volume) { + PlayerEvent.SoundEvent event = new PlayerEvent.SoundEvent(handler.getPlayer(), name, pitch, volume); + handler.callScript(EnumScriptType.PLAYSOUND, event, "name", name, "pitch", pitch, "volume", volume); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerFall(PlayerDataScript handler, float distance) { PlayerEvent.FallEvent event = new PlayerEvent.FallEvent(handler.getPlayer(),distance); handler.callScript(EnumScriptType.FALL, event, "distance", event.distance); @@ -150,6 +162,13 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } + + public static void onPlayerRespawn(PlayerDataScript handler) { + PlayerEvent.RespawnEvent event = new PlayerEvent.RespawnEvent(handler.getPlayer()); + handler.callScript(EnumScriptType.RESPAWN, event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerLogout(PlayerDataScript handler) { LogoutEvent event = new LogoutEvent(handler.getPlayer()); handler.callScript(EnumScriptType.LOGOUT, event); @@ -171,6 +190,12 @@ public class EventHooks { return WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onPlayerChangeDim(PlayerDataScript handler, int fromDim, int toDim) { + PlayerEvent.ChangedDimension event = new PlayerEvent.ChangedDimension(handler.getPlayer(), fromDim, toDim); + handler.callScript(EnumScriptType.CHANGED_DIM, event, "fromDim", event.fromDim, "toDim", event.toDim); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel) { PlayerDataScript handler = PlayerData.get(player).scriptData; PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent(handler.getPlayer(), button, mouseWheel); diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 9f73fdaab..d4ac78f1b 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -34,6 +34,8 @@ import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; +import net.minecraftforge.event.entity.EntityStruckByLightningEvent; +import net.minecraftforge.event.entity.PlaySoundAtEntityEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; @@ -139,6 +141,14 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(PlayerEvent.PlayerChangedDimensionEvent event) { + if(event.player.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + EventHooks.onPlayerChangeDim(handler, event.fromDim, event.toDim); + } + } + @SubscribeEvent public void invoke(PlayerEvent.ItemPickupEvent event) { if(event.player.worldObj instanceof WorldServer) { @@ -166,6 +176,28 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(EntityStruckByLightningEvent event) { + if(event.entity.worldObj instanceof WorldServer) { + PlayerDataScript handler; + if (event.entity instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.entity).scriptData; + EventHooks.onPlayerLightning(handler); + } + } + } + + @SubscribeEvent + public void invoke(PlaySoundAtEntityEvent event) { + if(event.entity.worldObj instanceof WorldServer) { + PlayerDataScript handler; + if (event.entity instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.entity).scriptData; + EventHooks.onPlayerSound(handler,event.name,event.pitch,event.volume); + } + } + } + @SubscribeEvent public void invoke(LivingDeathEvent event) { if(event.entityLiving.worldObj instanceof WorldServer) { @@ -206,6 +238,14 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(PlayerEvent.PlayerRespawnEvent event) { + if(event.player.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + EventHooks.onPlayerRespawn(handler); + } + } + @SubscribeEvent public void invoke(PlayerEvent.PlayerLoggedInEvent event) { if(event.player.worldObj instanceof WorldServer) { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index dc1a90541..6e9c7a397 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -26,11 +26,13 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.PlayerDataScript; public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener { private int activeTab = 0; - public IScriptHandler handler; + public PlayerDataScript handler; public Map> languages = new HashMap(); + private int scriptLimit = 1; public GuiScriptInterface() { this.drawDefaultBackground = true; @@ -54,14 +56,53 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb GuiMenuTopButton top; this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings")); + List hookList = new ArrayList(); + hookList.add("playerscript.disabled"); + hookList.add("playerscript.init"); + hookList.add("playerscript.tick"); + hookList.add("playerscript.interact"); + hookList.add("playerscript.damaged"); + hookList.add("playerscript.killed"); + hookList.add("playerscript.kills"); + hookList.add("playerscript.chat"); + hookList.add("playerscript.drop"); + hookList.add("playerscript.containerOpen"); + hookList.add("playerscript.login"); + hookList.add("playerscript.logout"); + hookList.add("playerscript.chat"); + hookList.add("playerscript.damagedentity"); + hookList.add("playerscript.keyPressed"); + hookList.add("playerscript.mouseClicked"); + hookList.add("playerscript.pickUp"); + hookList.add("playerscript.rangedLaunched"); + hookList.add("playerscript.pickupXP"); + hookList.add("playerscript.timer"); + hookList.add("playerscript.startItem"); + hookList.add("playerscript.usingItem"); + hookList.add("playerscript.stopItem"); + hookList.add("playerscript.finishItem"); + hookList.add("playerscript.fall"); + hookList.add("playerscript.playSound"); + hookList.add("playerscript.lightning"); + hookList.add("playerscript.break"); + hookList.add("playerscript.changedDim"); + hookList.add("playerscript.respawn"); + + int topXoffset = 0; + int topYoffset = 0; for(int ta = 0; ta < this.handler.getScripts().size(); ++ta) { - PlayerScriptContainer var10000 = (PlayerScriptContainer)this.handler.getScripts().get(ta); - this.addTopButton(top = new GuiMenuTopButton(ta + 1, top, ta + 1 + "")); + if(ta%15 == 0 && ta > 0) { + topYoffset -= 20; + topXoffset -= top.width+260; + } + this.addTopButton(top = new GuiMenuTopButton(ta + 1, top.xPosition+top.width + topXoffset, top.yPosition + topYoffset, ta + 1 + "")); + topXoffset = 0; + topYoffset = 0; + scriptLimit = ta + 2; } - if(this.handler.getScripts().size() < 16) { - this.addTopButton(new GuiMenuTopButton(12, top, "+")); - } + if(this.handler.getScripts().size() < 75) + this.addTopButton(new GuiMenuTopButton(scriptLimit, top.xPosition+top.width, top.yPosition, "+")); top = this.getTopButton(this.activeTab); if(top == null) { @@ -69,34 +110,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb top = this.getTopButton(0); } - List list = new ArrayList(); - list.add("playerscript.disabled"); - list.add("playerscript.init"); - list.add("playerscript.tick"); - list.add("playerscript.interact"); - list.add("playerscript.damaged"); - list.add("playerscript.killed"); - list.add("playerscript.kills"); - list.add("playerscript.chat"); - list.add("playerscript.drop"); - list.add("playerscript.containerOpen"); - list.add("playerscript.login"); - list.add("playerscript.logout"); - list.add("playerscript.chat"); - list.add("playerscript.damagedentity"); - list.add("playerscript.keyPressed"); - list.add("playerscript.mouseClicked"); - list.add("playerscript.pickUp"); - list.add("playerscript.rangedLaunched"); - list.add("playerscript.pickupXP"); - list.add("playerscript.timer"); - list.add("playerscript.startItem"); - list.add("playerscript.usingItem"); - list.add("playerscript.stopItem"); - list.add("playerscript.finishItem"); - list.add("playerscript.fall"); - list.add("playerscript.break"); - top.active = true; if(this.activeTab > 0) { addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); @@ -104,8 +117,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hooks.setSize(68, 198); hooks.guiLeft = guiLeft + 4; hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(list); - hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),list); + hooks.setUnsortedList(hookList); + hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),hookList); addScroll(hooks); PlayerScriptContainer var7 = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); @@ -219,14 +232,15 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb this.displayGuiScreen(this); } + @Override protected void actionPerformed(GuiButton guibutton) { - if(guibutton.id >= 0 && guibutton.id < 12) { + if(guibutton.id >= 0 && guibutton.id < scriptLimit) { this.setScript(); this.activeTab = guibutton.id; this.initGui(); } - if(guibutton.id == 12) { + if(guibutton.id == scriptLimit) { this.handler.getScripts().add(new PlayerScriptContainer(this.handler)); this.activeTab = this.handler.getScripts().size(); this.initGui(); @@ -273,7 +287,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } if(guibutton.id == 104) { - this.handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); + //ScriptController.Instance.playerScripts.enabled = (((GuiNpcButton)guibutton).getValue() == 1); + this.handler.setEnabled((((GuiNpcButton)guibutton).getValue() == 1)); } if(guibutton.id == 105) { diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index 6fb48d2bd..e7cc70457 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -60,6 +60,10 @@ public enum EnumScriptType { STOP_USING_ITEM("stopItem"), FINISH_USING_ITEM("finishItem"), FALL("fall"), + LIGHTNING("lightning"), + PLAYSOUND("playSound"), + RESPAWN("respawn"), + CHANGED_DIM("changedDim"), BREAK("break"); public String function; diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 2bccaec7b..e5a913adf 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -41,7 +41,7 @@ public class PlayerDataScript implements IScriptHandler { private long lastPlayerUpdate = 0L; public long lastInited = -1L; public boolean hadInteract = true; - public boolean enabled = true; + public boolean enabled = false; private static Map console = new TreeMap(); private static List errored = new ArrayList(); @@ -155,6 +155,7 @@ public class PlayerDataScript implements IScriptHandler { } public void setEnabled(boolean bo) { + ScriptController.Instance.playerScripts.enabled = bo; this.enabled = bo; } diff --git a/src/main/java/noppes/npcs/scripted/IItemStack.java b/src/main/java/noppes/npcs/scripted/IItemStack.java index 51617cb81..57daa5e0f 100644 --- a/src/main/java/noppes/npcs/scripted/IItemStack.java +++ b/src/main/java/noppes/npcs/scripted/IItemStack.java @@ -14,9 +14,6 @@ import java.util.ArrayList; import java.util.List; public interface IItemStack { - /** - * @return The minecraft name for this item - */ public String getName(); /** @@ -114,6 +111,11 @@ public interface IItemStack { * @return Returns whether or not this item is a block */ public boolean isBlock(); + + public INbt getNbt(); + + public INbt getItemNbt(); + /** * No support is given for this method. Dont use if you dont know what you are doing. * @return Minecraft ItemStack diff --git a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java index b34f0b1cc..21084924b 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPlayer.java @@ -50,6 +50,11 @@ public class ScriptPlayer extends ScriptLivingBase public void setPosition(double x, double y, double z){ NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension); } + + public int getDimension(){ + return player.dimension; + } + public boolean hasFinishedQuest(int id){ PlayerQuestData data = PlayerDataController.instance.getPlayerData(player).questData; diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index cb0247ac9..898738bef 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -89,6 +89,23 @@ public class PlayerEvent extends CustomNPCsEvent { } } + public static class RespawnEvent extends PlayerEvent { + public RespawnEvent(IPlayer player) { + super(player); + } + } + + public static class ChangedDimension extends PlayerEvent { + public final int fromDim; + public final int toDim; + + public ChangedDimension(IPlayer player, int fromDim, int toDim){ + super(player); + this.fromDim = fromDim; + this.toDim = toDim; + } + } + public static class TimerEvent extends PlayerEvent { public final int id; @@ -113,6 +130,27 @@ public class PlayerEvent extends CustomNPCsEvent { } } + @Cancelable + public static class LightningEvent extends PlayerEvent { + public LightningEvent(IPlayer player) { + super(player); + } + } + + @Cancelable + public static class SoundEvent extends PlayerEvent { + public final String name; + public final float pitch; + public final float volume; + + public SoundEvent(ScriptPlayer player, String name, float pitch, float volume) { + super(player); + this.name = name; + this.pitch = pitch; + this.volume = volume; + } + } + public static class FallEvent extends PlayerEvent { public final float distance; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index dad4b5dab..34ff82e6a 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -491,7 +491,11 @@ playerscript.startItem=Item Start playerscript.usingItem=Using Item playerscript.stopItem=Item Stop playerscript.finishItem=Item Finish +playerscript.playSound=Play Sound +playerscript.lightning=Lightning Struck playerscript.fall=Fall +playerscript.respawn=Respawn +playerscript.changedDim=Dimension Change item.npcWand.name=Npc Wand item.npcMobCloner.name=Mob Cloner From c5ed7497c8cb96f6812b569a6f513c00a0646fab Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 17 Oct 2021 16:11:29 -0500 Subject: [PATCH 27/58] Added console output and correct script halting to scripted player events. Renamed PlayerScriptContainer to EventScriptContainer. --- ...ntainer.java => EventScriptContainer.java} | 25 ++--- src/main/java/noppes/npcs/NBTTags.java | 8 +- .../java/noppes/npcs/PacketHandlerServer.java | 19 +++- .../noppes/npcs/ScriptPlayerEventHandler.java | 4 - .../client/gui/script/GuiScriptInterface.java | 106 +++++++++--------- .../client/gui/script/GuiScriptPlayers.java | 2 - .../npcs/controllers/IScriptHandler.java | 4 +- .../controllers/data/ForgeDataScript.java | 17 ++- .../controllers/data/PlayerDataScript.java | 94 +++++++++------- 9 files changed, 149 insertions(+), 130 deletions(-) rename src/main/java/noppes/npcs/{PlayerScriptContainer.java => EventScriptContainer.java} (83%) diff --git a/src/main/java/noppes/npcs/PlayerScriptContainer.java b/src/main/java/noppes/npcs/EventScriptContainer.java similarity index 83% rename from src/main/java/noppes/npcs/PlayerScriptContainer.java rename to src/main/java/noppes/npcs/EventScriptContainer.java index 8d3938ca0..cdb11a70f 100644 --- a/src/main/java/noppes/npcs/PlayerScriptContainer.java +++ b/src/main/java/noppes/npcs/EventScriptContainer.java @@ -7,30 +7,20 @@ package noppes.npcs; import java.io.PrintWriter; import java.io.StringWriter; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.TreeMap; import javax.script.Compilable; import javax.script.CompiledScript; -import javax.script.Invocable; import javax.script.ScriptEngine; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; -import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.scripted.constants.*; -public class PlayerScriptContainer { - public static PlayerScriptContainer Current; +public class EventScriptContainer { + public static EventScriptContainer Current; public String type = "init"; public String fullscript = ""; public String script = ""; @@ -44,7 +34,7 @@ public class PlayerScriptContainer { private CompiledScript compScript = null; private boolean init = false; - public PlayerScriptContainer(IScriptHandler handler) { + public EventScriptContainer(IScriptHandler handler) { this.handler = handler; } @@ -111,18 +101,17 @@ public class PlayerScriptContainer { } public void appandConsole(String message) { - if(message != null && !message.isEmpty()) { + if (message != null && !message.isEmpty()) { long time = System.currentTimeMillis(); - if(this.console.containsKey(Long.valueOf(time))) { - message = (String)this.console.get(Long.valueOf(time)) + "\n" + message; + if (this.console.containsKey(time)) { + message = (String)this.console.get(time) + "\n" + message; } - this.console.put(Long.valueOf(time), message); + this.console.put(time, message); while(this.console.size() > 40) { this.console.remove(this.console.firstKey()); } - } } diff --git a/src/main/java/noppes/npcs/NBTTags.java b/src/main/java/noppes/npcs/NBTTags.java index fbf2fedf4..23cc9b8e4 100644 --- a/src/main/java/noppes/npcs/NBTTags.java +++ b/src/main/java/noppes/npcs/NBTTags.java @@ -408,12 +408,12 @@ public class NBTTags { } } - public static List GetScript(NBTTagList list, IScriptHandler handler) { + public static List GetScript(NBTTagList list, IScriptHandler handler) { ArrayList scripts = new ArrayList(); for(int i = 0; i < list.tagCount(); ++i) { NBTTagCompound compoundd = list.getCompoundTagAt(i); - PlayerScriptContainer script = new PlayerScriptContainer(handler); + EventScriptContainer script = new EventScriptContainer(handler); script.readFromNBT(compoundd); scripts.add(script); } @@ -421,12 +421,12 @@ public class NBTTags { return scripts; } - public static NBTTagList NBTScript(List scripts) { + public static NBTTagList NBTScript(List scripts) { NBTTagList list = new NBTTagList(); Iterator var2 = scripts.iterator(); while(var2.hasNext()) { - PlayerScriptContainer script = (PlayerScriptContainer)var2.next(); + EventScriptContainer script = (EventScriptContainer)var2.next(); NBTTagCompound compound = new NBTTagCompound(); script.writeToNBT(compound); list.appendTag(compound); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index ac90681a9..45ee43028 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -62,6 +62,8 @@ import noppes.npcs.controllers.SpawnController; import noppes.npcs.controllers.SpawnData; import noppes.npcs.controllers.TransportController; import noppes.npcs.controllers.TransportLocation; +import noppes.npcs.controllers.data.ForgeDataScript; +import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobSpawner; @@ -108,6 +110,8 @@ public class PacketHandlerServer{ featherPackets(type, buffer, player); else if(type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) playerScriptPackets(type, buffer, player); + else if(type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave) + forgeScriptPackets(type, buffer, player); else if(item.getItem() == CustomItems.scripter) scriptPackets(type, buffer, player, npc); else if(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) @@ -133,7 +137,8 @@ public class PacketHandlerServer{ private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception { NBTTagCompound compound; if(type == EnumPacketServer.ScriptPlayerGet) { - compound = ScriptController.Instance.playerScripts.writeToNBT(new NBTTagCompound()); + PlayerDataScript data = ScriptController.Instance.playerScripts; + compound = data.writeToNBT(new NBTTagCompound()); compound.setTag("Languages", ScriptController.Instance.nbtLanguages()); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else if(type == EnumPacketServer.ScriptPlayerSave) { @@ -141,6 +146,18 @@ public class PacketHandlerServer{ } } + private void forgeScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception { + NBTTagCompound compound; + if (type == EnumPacketServer.ScriptForgeGet) { + ForgeDataScript data = ScriptController.Instance.forgeScripts; + compound = data.writeToNBT(new NBTTagCompound()); + compound.setTag("Languages", ScriptController.Instance.nbtLanguages()); + Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound}); + } else if (type == EnumPacketServer.ScriptForgeSave) { + ScriptController.Instance.setForgeScripts(Server.readNBT(buffer)); + } + } + private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException { if(type == EnumPacketServer.DimensionsGet){ HashMap map = new HashMap(); diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index d4ac78f1b..a65adefad 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -322,10 +322,6 @@ public class ScriptPlayerEventHandler { classes = classLoader.getName(); } while(classes.startsWith("net.minecraftforge.event.terraingen")); - if(classes.startsWith("cpw.mods.fml.common.gameevent")){ - ; - } - Class infoClass = classLoader.load(); ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses())); if(c.isEmpty()) { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 6e9c7a397..b99f56c2d 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -18,19 +18,19 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.EventScriptContainer; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.swing.GuiJTextArea; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener { private int activeTab = 0; - public PlayerDataScript handler; + public IScriptHandler handler; public Map> languages = new HashMap(); private int scriptLimit = 1; @@ -57,36 +57,41 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings")); List hookList = new ArrayList(); - hookList.add("playerscript.disabled"); - hookList.add("playerscript.init"); - hookList.add("playerscript.tick"); - hookList.add("playerscript.interact"); - hookList.add("playerscript.damaged"); - hookList.add("playerscript.killed"); - hookList.add("playerscript.kills"); - hookList.add("playerscript.chat"); - hookList.add("playerscript.drop"); - hookList.add("playerscript.containerOpen"); - hookList.add("playerscript.login"); - hookList.add("playerscript.logout"); - hookList.add("playerscript.chat"); - hookList.add("playerscript.damagedentity"); - hookList.add("playerscript.keyPressed"); - hookList.add("playerscript.mouseClicked"); - hookList.add("playerscript.pickUp"); - hookList.add("playerscript.rangedLaunched"); - hookList.add("playerscript.pickupXP"); - hookList.add("playerscript.timer"); - hookList.add("playerscript.startItem"); - hookList.add("playerscript.usingItem"); - hookList.add("playerscript.stopItem"); - hookList.add("playerscript.finishItem"); - hookList.add("playerscript.fall"); - hookList.add("playerscript.playSound"); - hookList.add("playerscript.lightning"); - hookList.add("playerscript.break"); - hookList.add("playerscript.changedDim"); - hookList.add("playerscript.respawn"); + if(handler instanceof PlayerDataScript) { + hookList.add("playerscript.disabled"); + hookList.add("playerscript.init"); + hookList.add("playerscript.tick"); + hookList.add("playerscript.interact"); + hookList.add("playerscript.damaged"); + hookList.add("playerscript.killed"); + hookList.add("playerscript.kills"); + hookList.add("playerscript.chat"); + hookList.add("playerscript.drop"); + hookList.add("playerscript.containerOpen"); + hookList.add("playerscript.login"); + hookList.add("playerscript.logout"); + hookList.add("playerscript.chat"); + hookList.add("playerscript.damagedentity"); + hookList.add("playerscript.keyPressed"); + hookList.add("playerscript.mouseClicked"); + hookList.add("playerscript.pickUp"); + hookList.add("playerscript.rangedLaunched"); + hookList.add("playerscript.pickupXP"); + hookList.add("playerscript.timer"); + hookList.add("playerscript.startItem"); + hookList.add("playerscript.usingItem"); + hookList.add("playerscript.stopItem"); + hookList.add("playerscript.finishItem"); + hookList.add("playerscript.fall"); + hookList.add("playerscript.playSound"); + hookList.add("playerscript.lightning"); + hookList.add("playerscript.break"); + hookList.add("playerscript.changedDim"); + hookList.add("playerscript.respawn"); + } + else if(handler instanceof ForgeDataScript){ + hookList.add("forgescript.forgeInit"); + } int topXoffset = 0; int topYoffset = 0; @@ -121,7 +126,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),hookList); addScroll(hooks); - PlayerScriptContainer var7 = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + 72 + yoffset, this.guiTop + yoffset, this.xSize - 180 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); this.addTextField(left); int left1 = this.guiLeft + this.xSize - 104; @@ -170,9 +175,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb this.handler.getScripts().get(this.activeTab - 1).setType(scroll.getSelected().replace("playerscript.","")); } - private int getScriptHook(PlayerScriptContainer playerScriptContainer, List list) { + private int getScriptHook(EventScriptContainer eventScriptContainer, List list) { for(String s : list) { - if (s.replace("playerscript.", "").equals(playerScriptContainer.type)) { + if (s.replace("playerscript.", "").equals(eventScriptContainer.type)) { return list.indexOf(s); } } @@ -180,13 +185,13 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } private String getConsoleText() { - Map map = this.handler.getConsoleText(); + Map map = this.handler.getConsoleText(); StringBuilder builder = new StringBuilder(); Iterator var3 = map.entrySet().iterator(); while(var3.hasNext()) { - Entry entry = (Entry)var3.next(); - builder.insert(0, new Date(((Long)entry.getKey()).longValue()) + (String)entry.getValue() + "\n"); + Entry entry = (Entry)var3.next(); + builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n"); } return builder.toString(); @@ -241,7 +246,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } if(guibutton.id == scriptLimit) { - this.handler.getScripts().add(new PlayerScriptContainer(this.handler)); + this.handler.getScripts().add(new EventScriptContainer(this.handler)); this.activeTab = this.handler.getScripts().size(); this.initGui(); } @@ -270,10 +275,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb (this.getTextField(2)).setText(NoppesStringUtils.getClipboardContents()); } - PlayerScriptContainer container; + EventScriptContainer container; if(guibutton.id == 102) { if(this.activeTab > 0) { - container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); container.script = ""; } else { this.handler.clearConsole(); @@ -287,7 +292,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } if(guibutton.id == 104) { - //ScriptController.Instance.playerScripts.enabled = (((GuiNpcButton)guibutton).getValue() == 1); this.handler.setEnabled((((GuiNpcButton)guibutton).getValue() == 1)); } @@ -301,16 +305,16 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } if(guibutton.id == 107) { - container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container == null) { - this.handler.getScripts().add(container = new PlayerScriptContainer(this.handler)); + this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); } this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.handler.getLanguage()), container)); } if(guibutton.id == 108) { - container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container != null) { this.setScript(); this.AWTWindow = new GuiJTextArea(container.script).setListener(this); @@ -321,15 +325,17 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb private void setScript() { if(this.activeTab > 0) { - PlayerScriptContainer container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container == null) { - this.handler.getScripts().add(container = new PlayerScriptContainer(this.handler)); + this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); } String text = (this.getTextField(2)).getText(); text = text.replace("\r\n", "\n"); text = text.replace("\r", "\n"); container.script = text; + + ScriptController.Instance.playerScripts.errored.clear(); } } @@ -359,7 +365,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb } public void textUpdate(String text) { - PlayerScriptContainer container = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); if(container != null) { container.script = text; } @@ -368,7 +374,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb @Override public void saveText(String text) { - PlayerScriptContainer container = handler.getScripts().get(activeTab); + EventScriptContainer container = handler.getScripts().get(activeTab); if(container != null) container.script = text; initGui(); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java index 332f1828b..20838f2dd 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -16,7 +16,6 @@ public class GuiScriptPlayers extends GuiScriptInterface { public GuiScriptPlayers() { this.handler = this.script; - //Client.sendData(EnumPacketServer.ScriptPlayerGet, new Object[0]); Client.sendData(EnumPacketServer.ScriptPlayerGet); } @@ -27,7 +26,6 @@ public class GuiScriptPlayers extends GuiScriptInterface { public void save() { super.save(); - //Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); Client.sendData(EnumPacketServer.ScriptPlayerSave, script.writeToNBT(new NBTTagCompound())); } } diff --git a/src/main/java/noppes/npcs/controllers/IScriptHandler.java b/src/main/java/noppes/npcs/controllers/IScriptHandler.java index 72d9cb003..b4f8f9625 100644 --- a/src/main/java/noppes/npcs/controllers/IScriptHandler.java +++ b/src/main/java/noppes/npcs/controllers/IScriptHandler.java @@ -8,7 +8,7 @@ package noppes.npcs.controllers; import java.util.List; import java.util.Map; import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.EventScriptContainer; import noppes.npcs.constants.EnumScriptType; public interface IScriptHandler { @@ -24,7 +24,7 @@ public interface IScriptHandler { void setLanguage(String var1); - List getScripts(); + List getScripts(); String noticeString(); diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index effccff93..aafa32fa8 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -17,7 +17,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.EventHooks; -import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.EventScriptContainer; import noppes.npcs.NBTTags; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; @@ -26,10 +26,9 @@ import noppes.npcs.controllers.ScriptController; import javax.script.ScriptEngine; public class ForgeDataScript implements IScriptHandler { - private List scripts = new ArrayList(); + private List scripts = new ArrayList(); private String scriptLanguage = "ECMAScript"; public long lastInited = -1L; - public boolean hadInteract = true; private boolean enabled = false; public ForgeDataScript() { @@ -58,7 +57,7 @@ public class ForgeDataScript implements IScriptHandler { Minecraft.getMinecraft().func_152344_a(() -> { if (ScriptController.Instance.lastLoaded > this.lastInited) { this.lastInited = ScriptController.Instance.lastLoaded; - if (!type.equals("init")) { + if (!type.equals(EnumScriptType.FORGE_INIT)) { EventHooks.onForgeInit(this); } } @@ -66,7 +65,7 @@ public class ForgeDataScript implements IScriptHandler { Iterator var3 = this.scripts.iterator(); while (var3.hasNext()) { - PlayerScriptContainer script = (PlayerScriptContainer) var3.next(); + EventScriptContainer script = (EventScriptContainer) var3.next(); if(script.type != type.function) continue; @@ -102,7 +101,7 @@ public class ForgeDataScript implements IScriptHandler { Iterator var3 = this.scripts.iterator(); while (var3.hasNext()) { - PlayerScriptContainer script = (PlayerScriptContainer) var3.next(); + EventScriptContainer script = (EventScriptContainer) var3.next(); //script.run(EnumScriptType.valueOf(type), event); script.setEngine(scriptLanguage); @@ -140,7 +139,7 @@ public class ForgeDataScript implements IScriptHandler { this.scriptLanguage = lang; } - public List getScripts() { + public List getScripts() { return this.scripts; } @@ -154,7 +153,7 @@ public class ForgeDataScript implements IScriptHandler { Iterator var3 = this.getScripts().iterator(); while(var3.hasNext()) { - PlayerScriptContainer script = (PlayerScriptContainer)var3.next(); + EventScriptContainer script = (EventScriptContainer)var3.next(); ++tab; Iterator var5 = script.console.entrySet().iterator(); @@ -171,7 +170,7 @@ public class ForgeDataScript implements IScriptHandler { Iterator var1 = this.getScripts().iterator(); while(var1.hasNext()) { - PlayerScriptContainer script = (PlayerScriptContainer)var1.next(); + EventScriptContainer script = (EventScriptContainer)var1.next(); script.console.clear(); } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index e5a913adf..31573661c 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -18,7 +18,7 @@ import net.minecraft.util.math.BlockPos; import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.world.WorldServer; import noppes.npcs.EventHooks; -import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.EventScriptContainer; import noppes.npcs.NBTTags; import noppes.npcs.scripted.ScriptPlayer; import noppes.npcs.constants.EnumScriptType; @@ -34,7 +34,7 @@ import javax.annotation.CheckForNull; import javax.script.ScriptEngine; public class PlayerDataScript implements IScriptHandler { - public List scripts = new ArrayList(); + public List scripts = new ArrayList(); public String scriptLanguage = "ECMAScript"; private EntityPlayer player; private ScriptPlayer playerAPI; @@ -42,8 +42,8 @@ public class PlayerDataScript implements IScriptHandler { public long lastInited = -1L; public boolean hadInteract = true; public boolean enabled = false; - private static Map console = new TreeMap(); - private static List errored = new ArrayList(); + private Map console = new TreeMap(); + public List errored = new ArrayList(); public ScriptPlayer dummyPlayer; public ScriptWorld dummyWorld; @@ -62,8 +62,8 @@ public class PlayerDataScript implements IScriptHandler { } public void clear() { - console = new TreeMap(); - errored = new ArrayList(); + this.console = new TreeMap(); + this.errored = new ArrayList(); this.scripts = new ArrayList(); } @@ -71,30 +71,30 @@ public class PlayerDataScript implements IScriptHandler { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); this.enabled = compound.getBoolean("ScriptEnabled"); - console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); + this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("Scripts", NBTTags.NBTScript(this.scripts)); compound.setString("ScriptLanguage", this.scriptLanguage); compound.setBoolean("ScriptEnabled", this.enabled); - compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(console)); + compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.console)); return compound; } public void callScript(EnumScriptType type, Event event, Object... obs) { if(this.isEnabled()) { - PlayerScriptContainer script; + EventScriptContainer script; if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) { this.lastInited = ScriptController.Instance.lastLoaded; - errored.clear(); + //ScriptController.Instance.playerScripts.errored.clear(); if(this.player != null) { this.scripts.clear(); Iterator i = ScriptController.Instance.playerScripts.scripts.iterator(); while(i.hasNext()) { - script = (PlayerScriptContainer)i.next(); - PlayerScriptContainer s = new PlayerScriptContainer(this); + script = (EventScriptContainer)i.next(); + EventScriptContainer s = new EventScriptContainer(this); s.readFromNBT(script.writeToNBT(new NBTTagCompound())); this.scripts.add(s); @@ -108,12 +108,12 @@ public class PlayerDataScript implements IScriptHandler { } for(int var7 = 0; var7 < this.scripts.size(); ++var7) { - script = (PlayerScriptContainer)this.scripts.get(var7); + script = (EventScriptContainer)this.scripts.get(var7); if(!script.type.equals(type.function)) continue; - if(!errored.contains(Integer.valueOf(var7))) { + if(!ScriptController.Instance.playerScripts.errored.contains(Integer.valueOf(var7))) { if(script == null || script.errored || !script.hasCode()) return; script.setEngine(scriptLanguage); @@ -136,9 +136,23 @@ public class PlayerDataScript implements IScriptHandler { engine.put("RoleType", roles); engine.put("JobType", jobs); script.run(engine); + + if (script.errored) { + ScriptController.Instance.playerScripts.errored.add(var7); + } + + Iterator var8 = script.console.entrySet().iterator(); + + while(var8.hasNext()) { + Entry entry = (Entry)var8.next(); + if (!ScriptController.Instance.playerScripts.console.containsKey(entry.getKey())) { + ScriptController.Instance.playerScripts.console.put(entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue()); + } + } + + script.console.clear(); } } - } } @@ -167,10 +181,34 @@ public class PlayerDataScript implements IScriptHandler { this.scriptLanguage = lang; } - public List getScripts() { + public List getScripts() { return this.scripts; } + public String noticeString() { + if(this.player == null) { + return "Global script"; + } else { + BlockPos pos = new BlockPos(this.player); + return PlayerDataScript.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); + } + } + + public ScriptPlayer getPlayer() { + if(this.playerAPI == null) { + this.playerAPI = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(this.player); + } + return this.playerAPI; + } + + public Map getConsoleText() { + return this.console; + } + + public void clearConsole() { + this.console.clear(); + } + public static final class ToStringHelper { private final String className; private final PlayerDataScript.ToStringHelper.ValueHolder holderHead; @@ -367,28 +405,4 @@ public class PlayerDataScript implements IScriptHandler { public static PlayerDataScript.ToStringHelper toStringHelper(Object self) { return new PlayerDataScript.ToStringHelper(self.getClass().getSimpleName()); } - - public String noticeString() { - if(this.player == null) { - return "Global script"; - } else { - BlockPos pos = new BlockPos(this.player); - return PlayerDataScript.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); - } - } - - public ScriptPlayer getPlayer() { - if(this.playerAPI == null) { - this.playerAPI = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(this.player); - } - return this.playerAPI; - } - - public Map getConsoleText() { - return console; - } - - public void clearConsole() { - console.clear(); - } } From 72f2c3c60afbf937e0b09403c498ab2fd4c6e202 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 18 Oct 2021 06:33:39 -0500 Subject: [PATCH 28/58] Implemented global Forge events. Reorganized NPC API files. --- src/main/java/noppes/npcs/DataScript.java | 4 +- src/main/java/noppes/npcs/EventHooks.java | 96 ++++++++------- .../java/noppes/npcs/NoppesUtilServer.java | 5 +- .../npcs/client/gui/EventGuiScriptList.java | 6 +- .../client/gui/script/EventGuiScriptList.java | 6 +- .../client/gui/script/GuiScriptForge.java | 30 +++++ .../client/gui/script/GuiScriptGlobal.java | 4 +- .../client/gui/script/GuiScriptInterface.java | 110 ++++++++++-------- .../client/gui/script/GuiScriptPlayers.java | 6 + .../npcs/constants/EnumPacketServer.java | 3 + .../noppes/npcs/constants/EnumScriptType.java | 5 +- .../containers/ContainerNpcInterface.java | 3 +- .../npcs/controllers/ScriptController.java | 14 +-- .../npcs/controllers/ScriptEntityData.java | 2 +- .../controllers/data/ForgeDataScript.java | 49 +++----- .../controllers/data/PlayerDataScript.java | 13 +-- .../npcs/entity/EntityNPCInterface.java | 7 +- .../noppes/npcs/entity/data/DataTimers.java | 3 +- .../java/noppes/npcs/scripted/NpcAPI.java | 6 + .../noppes/npcs/scripted/ScriptBlock.java | 2 +- .../noppes/npcs/scripted/ScriptBlockPos.java | 1 + .../noppes/npcs/scripted/ScriptContainer.java | 7 +- .../npcs/scripted/ScriptEntityParticle.java | 2 +- .../npcs/scripted/ScriptEventDialog.java | 15 --- .../noppes/npcs/scripted/ScriptFaction.java | 2 + .../noppes/npcs/scripted/ScriptItemStack.java | 4 +- .../java/noppes/npcs/scripted/ScriptNbt.java | 1 + .../scripted/ScriptPixelmonPlayerData.java | 1 + .../noppes/npcs/scripted/ScriptWorld.java | 7 +- .../scripted/{ => entity}/ScriptAnimal.java | 3 +- .../scripted/{ => entity}/ScriptEntity.java | 14 +-- .../scripted/{ => entity}/ScriptLiving.java | 8 +- .../{ => entity}/ScriptLivingBase.java | 20 +--- .../scripted/{ => entity}/ScriptMonster.java | 4 +- .../npcs/scripted/{ => entity}/ScriptNpc.java | 9 +- .../scripted/{ => entity}/ScriptPixelmon.java | 4 +- .../scripted/{ => entity}/ScriptPlayer.java | 5 +- .../npcs/scripted/event/ForgeEvent.java | 4 +- .../npcs/scripted/event/PlayerEvent.java | 4 +- .../scripted/{ => event}/ScriptEvent.java | 2 +- .../{ => event}/ScriptEventAttack.java | 4 +- .../{ => event}/ScriptEventDamaged.java | 3 +- .../scripted/event/ScriptEventDialog.java | 11 ++ .../{ => event}/ScriptEventKilled.java | 3 +- .../{ => event}/ScriptEventTarget.java | 4 +- .../scripted/{ => interfaces}/IAnimal.java | 2 +- .../scripted/{ => interfaces}/IBlock.java | 2 +- .../scripted/{ => interfaces}/IContainer.java | 2 +- .../scripted/{ => interfaces}/ICustomNpc.java | 16 +-- .../{ => interfaces}/IDamageSource.java | 2 +- .../scripted/{ => interfaces}/IEntity.java | 27 +---- .../{ => interfaces}/IEntityLiving.java | 2 +- .../{ => interfaces}/IEntityLivingBase.java | 10 +- .../scripted/{ => interfaces}/IItemStack.java | 13 +-- .../scripted/{ => interfaces}/IMonster.java | 2 +- .../npcs/scripted/{ => interfaces}/INbt.java | 2 +- .../scripted/{ => interfaces}/IPixelmon.java | 2 +- .../scripted/{ => interfaces}/IPlayer.java | 20 +--- .../npcs/scripted/{ => interfaces}/IPos.java | 2 +- .../scripted/{ => interfaces}/ITimers.java | 2 +- .../scripted/{ => interfaces}/IWorld.java | 27 +---- .../scripted/roles/ScriptJobConversation.java | 4 - .../scripted/roles/ScriptJobFollower.java | 3 +- .../npcs/scripted/roles/ScriptJobHealer.java | 2 +- .../scripted/roles/ScriptJobItemGiver.java | 3 - .../npcs/scripted/roles/ScriptJobPuppet.java | 4 - .../npcs/scripted/roles/ScriptJobSpawner.java | 8 +- .../scripted/roles/ScriptRoleFollower.java | 2 +- .../scripted/wrapper/ScriptDamageSource.java | 4 +- .../scripted/wrapper/WrapperEntityData.java | 10 +- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 25 ++-- .../assets/customnpcs/lang/en_US.lang | 2 + 72 files changed, 321 insertions(+), 395 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java delete mode 100644 src/main/java/noppes/npcs/scripted/ScriptEventDialog.java rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptAnimal.java (83%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptEntity.java (97%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptLiving.java (87%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptLivingBase.java (88%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptMonster.java (83%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptNpc.java (98%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptPixelmon.java (98%) rename src/main/java/noppes/npcs/scripted/{ => entity}/ScriptPlayer.java (98%) rename src/main/java/noppes/npcs/scripted/{ => event}/ScriptEvent.java (84%) rename src/main/java/noppes/npcs/scripted/{ => event}/ScriptEventAttack.java (90%) rename src/main/java/noppes/npcs/scripted/{ => event}/ScriptEventDamaged.java (92%) create mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java rename src/main/java/noppes/npcs/scripted/{ => event}/ScriptEventKilled.java (88%) rename src/main/java/noppes/npcs/scripted/{ => event}/ScriptEventTarget.java (85%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IAnimal.java (85%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IBlock.java (93%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IContainer.java (92%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/ICustomNpc.java (95%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IDamageSource.java (89%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IEntity.java (89%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IEntityLiving.java (90%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IEntityLivingBase.java (92%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IItemStack.java (88%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IMonster.java (84%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/INbt.java (97%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IPixelmon.java (85%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IPlayer.java (87%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IPos.java (95%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/ITimers.java (89%) rename src/main/java/noppes/npcs/scripted/{ => interfaces}/IWorld.java (87%) diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/DataScript.java index 2516817ad..b40cd88f2 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/DataScript.java @@ -15,8 +15,8 @@ import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.ScriptEvent; -import noppes.npcs.scripted.ScriptNpc; +import noppes.npcs.scripted.event.ScriptEvent; +import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.constants.JobType; diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index f8863cf79..d9d5a7d5e 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -16,26 +16,24 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityEvent; -import net.minecraftforge.event.entity.player.PlayerUseItemEvent; import net.minecraftforge.event.world.WorldEvent; -import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.scripted.*; import noppes.npcs.scripted.event.ForgeEvent; import noppes.npcs.scripted.event.PlayerEvent; -import noppes.npcs.scripted.event.PlayerEvent.AttackEvent; import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; -import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed; import noppes.npcs.scripted.event.PlayerEvent.ContainerOpen; import noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent; import noppes.npcs.scripted.event.PlayerEvent.KeyPressedEvent; -import noppes.npcs.scripted.event.PlayerEvent.LevelUpEvent; import noppes.npcs.scripted.event.PlayerEvent.LoginEvent; import noppes.npcs.scripted.event.PlayerEvent.LogoutEvent; import noppes.npcs.scripted.event.PlayerEvent.PickUpEvent; import noppes.npcs.scripted.event.PlayerEvent.TossEvent; +import noppes.npcs.scripted.interfaces.IEntity; +import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.PlayerData; @@ -47,50 +45,44 @@ public class EventHooks { public EventHooks() { } - public static void onForgeInit(IScriptHandler handler) { - noppes.npcs.scripted.event.ForgeEvent.InitEvent event = new noppes.npcs.scripted.event.ForgeEvent.InitEvent(); - handler.callScript(EnumScriptType.INIT, event); - WrapperNpcAPI.EVENT_BUS.post(event); - } - public static void onPlayerInit(PlayerDataScript handler) { noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(handler.getPlayer()); - handler.callScript(EnumScriptType.INIT, event); + handler.callScript(EnumScriptType.INIT, event, "event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerTick(PlayerDataScript handler) { noppes.npcs.scripted.event.PlayerEvent.UpdateEvent event = new noppes.npcs.scripted.event.PlayerEvent.UpdateEvent(handler.getPlayer()); - handler.callScript(EnumScriptType.TICK, event); + handler.callScript(EnumScriptType.TICK, event, "event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerInteract(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) { - handler.callScript(EnumScriptType.INTERACT, event, "target", event.target, "type", event.type); + handler.callScript(EnumScriptType.INTERACT, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onStartUsingItem(PlayerDataScript handler, int duration, ItemStack item){ PlayerEvent.StartUsingItem event = new PlayerEvent.StartUsingItem(handler.getPlayer(), item, duration); - handler.callScript(EnumScriptType.START_USING_ITEM, event, "duration", event.duration, "item", event.item); + handler.callScript(EnumScriptType.START_USING_ITEM, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onUsingItem(PlayerDataScript handler, int duration, ItemStack item){ PlayerEvent.UsingItem event = new PlayerEvent.UsingItem(handler.getPlayer(), item, duration); - handler.callScript(EnumScriptType.USING_ITEM, event, "duration", event.duration, "item", event.item); + handler.callScript(EnumScriptType.USING_ITEM, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onStopUsingItem(PlayerDataScript handler, int duration, ItemStack item){ PlayerEvent.StopUsingItem event = new PlayerEvent.StopUsingItem(handler.getPlayer(), item, duration); - handler.callScript(EnumScriptType.STOP_USING_ITEM, event, "duration", event.duration, "item", event.item); + handler.callScript(EnumScriptType.STOP_USING_ITEM, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onFinishUsingItem(PlayerDataScript handler, int duration, ItemStack item){ PlayerEvent.FinishUsingItem event = new PlayerEvent.FinishUsingItem(handler.getPlayer(), item, duration); - handler.callScript(EnumScriptType.FINISH_USING_ITEM, event, "duration", event.duration, "item", event.item); + handler.callScript(EnumScriptType.FINISH_USING_ITEM, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } @@ -99,126 +91,126 @@ public class EventHooks { for(int i = 0; i < entityItems.size(); i++){ items[i] = NpcAPI.Instance().getIItemStack(entityItems.get(i).getEntityItem()); } TossEvent event = new TossEvent(handler.getPlayer(), items); - handler.callScript(EnumScriptType.DROP, event, "items", event.items); + handler.callScript(EnumScriptType.DROP, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerPickupXP(PlayerDataScript handler, EntityXPOrb orb) { PlayerEvent.PickupXPEvent event = new PlayerEvent.PickupXPEvent(handler.getPlayer(), orb); - handler.callScript(EnumScriptType.PICKUP_XP, event, "amount", event.amount); + handler.callScript(EnumScriptType.PICKUP_XP, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) { PickUpEvent event = new PickUpEvent(handler.getPlayer(), new ScriptItemStack(entityItem.getEntityItem()));//NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); - handler.callScript(EnumScriptType.PICKUP, event, "item", event.item); + handler.callScript(EnumScriptType.PICKUP, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerContainerOpen(PlayerDataScript handler, Container container) { ContainerOpen event = new ContainerOpen(handler.getPlayer(), NpcAPI.Instance().getIContainer(container)); - handler.callScript(EnumScriptType.CONTAINER_OPEN, event, "container", event.container); + handler.callScript(EnumScriptType.CONTAINER_OPEN, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerDeath(PlayerDataScript handler, DamageSource source, Entity entity) { noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(handler.getPlayer(), source, entity); - handler.callScript(EnumScriptType.KILLED, event, "source", event.source, "damageSource", event.damageSource, "type", event.type); + handler.callScript(EnumScriptType.KILLED, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerKills(PlayerDataScript handler, EntityLivingBase entityLiving) { noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent event = new noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent(handler.getPlayer(), entityLiving); - handler.callScript(EnumScriptType.KILLS, event, "entity", event.entity); + handler.callScript(EnumScriptType.KILLS, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerDamaged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) { - handler.callScript(EnumScriptType.DAMAGED, event, "damage", event.damage, "source", event.source, "damageSource", event.damageSource); + handler.callScript(EnumScriptType.DAMAGED, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerLightning(PlayerDataScript handler) { PlayerEvent.LightningEvent event = new PlayerEvent.LightningEvent(handler.getPlayer()); - handler.callScript(EnumScriptType.LIGHTNING, event); + handler.callScript(EnumScriptType.LIGHTNING, event, "event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerSound(PlayerDataScript handler, String name, float pitch, float volume) { PlayerEvent.SoundEvent event = new PlayerEvent.SoundEvent(handler.getPlayer(), name, pitch, volume); - handler.callScript(EnumScriptType.PLAYSOUND, event, "name", name, "pitch", pitch, "volume", volume); + handler.callScript(EnumScriptType.PLAYSOUND, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerFall(PlayerDataScript handler, float distance) { PlayerEvent.FallEvent event = new PlayerEvent.FallEvent(handler.getPlayer(),distance); - handler.callScript(EnumScriptType.FALL, event, "distance", event.distance); + handler.callScript(EnumScriptType.FALL, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerLogin(PlayerDataScript handler) { LoginEvent event = new LoginEvent(handler.getPlayer()); - handler.callScript(EnumScriptType.LOGIN, event); + handler.callScript(EnumScriptType.LOGIN, event, "event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerRespawn(PlayerDataScript handler) { PlayerEvent.RespawnEvent event = new PlayerEvent.RespawnEvent(handler.getPlayer()); - handler.callScript(EnumScriptType.RESPAWN, event); + handler.callScript(EnumScriptType.RESPAWN, event, "event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerLogout(PlayerDataScript handler) { LogoutEvent event = new LogoutEvent(handler.getPlayer()); - handler.callScript(EnumScriptType.LOGOUT, event); + handler.callScript(EnumScriptType.LOGOUT, event, "event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerChat(PlayerDataScript handler, ChatEvent event) { - handler.callScript(EnumScriptType.CHAT, event, "message", event.message); + handler.callScript(EnumScriptType.CHAT, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerRanged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) { - handler.callScript(EnumScriptType.RANGED_LAUNCHED, event, "bow", event.bow, "charge", event.charge); + handler.callScript(EnumScriptType.RANGED_LAUNCHED, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerDamagedEntity(PlayerDataScript handler, DamagedEntityEvent event) { - handler.callScript(EnumScriptType.DAMAGED_ENTITY, event, "target", event.target, "damage", event.damage, "damageSource", event.damageSource, ""); + handler.callScript(EnumScriptType.DAMAGED_ENTITY, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerChangeDim(PlayerDataScript handler, int fromDim, int toDim) { PlayerEvent.ChangedDimension event = new PlayerEvent.ChangedDimension(handler.getPlayer(), fromDim, toDim); - handler.callScript(EnumScriptType.CHANGED_DIM, event, "fromDim", event.fromDim, "toDim", event.toDim); + handler.callScript(EnumScriptType.CHANGED_DIM, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel) { PlayerDataScript handler = PlayerData.get(player).scriptData; PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent(handler.getPlayer(), button, mouseWheel); - handler.callScript(EnumScriptType.MOUSE_CLICKED, event, "button", event.button, "mouseWheel", event.mouseWheel); + handler.callScript(EnumScriptType.MOUSE_CLICKED, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { PlayerDataScript handler = PlayerData.get(player).scriptData; KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); - handler.callScript(EnumScriptType.KEY_PRESSED, event, "key", button, "isCtrlPressed", isCtrlPressed, "isAltPressed", isAltPressed, "isShiftPressed", isShiftPressed, "isMetaPressed", isMetaPressed); + handler.callScript(EnumScriptType.KEY_PRESSED, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static void onPlayerTimer(PlayerData data, int id) { PlayerDataScript handler = data.scriptData; noppes.npcs.scripted.event.PlayerEvent.TimerEvent event = new noppes.npcs.scripted.event.PlayerEvent.TimerEvent(handler.getPlayer(), id); - handler.callScript(EnumScriptType.TIMER, event); + handler.callScript(EnumScriptType.TIMER, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } public static boolean onPlayerBreak(PlayerDataScript handler, PlayerEvent.BreakEvent event) { - handler.callScript(EnumScriptType.BREAK, event, "block", event.block, "xp", event.exp); + handler.callScript(EnumScriptType.BREAK, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } @@ -227,9 +219,22 @@ public class EventHooks { onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.EntityEvent(event, e), event); } + public static void onForgeWorldEvent(WorldEvent event) { + if(ScriptController.Instance.forgeScripts.isEnabled()) { + IWorld e = NpcAPI.Instance().getIWorld((WorldServer)event.world); + onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.WorldEvent(event, e), event); + } + } + + public static void onForgeInit(ForgeDataScript handler) { + noppes.npcs.scripted.event.ForgeEvent.InitEvent event = new noppes.npcs.scripted.event.ForgeEvent.InitEvent(); + handler.callScript("init", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onForgeEvent(ForgeEvent ev, Event event) { - ForgeDataScript data = ScriptController.Instance.forgeScripts; - if(data.isEnabled()) { + ForgeDataScript handler = ScriptController.Instance.forgeScripts; + if(handler.isEnabled()) { String eventName = event.getClass().getName(); int i = eventName.lastIndexOf("."); eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); @@ -237,7 +242,7 @@ public class EventHooks { ev.setCanceled(event.isCanceled()); } - data.callScript(eventName, event); + handler.callScript(eventName, event); WrapperNpcAPI.EVENT_BUS.post(ev); if(event.isCancelable()) { event.setCanceled(ev.isCanceled()); @@ -245,11 +250,4 @@ public class EventHooks { } } - - public static void onForgeWorldEvent(WorldEvent event) { - if(ScriptController.Instance.forgeScripts.isEnabled()) { - IWorld e = NpcAPI.Instance().getIWorld((WorldServer)event.world); - onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.WorldEvent(event, e), event); - } - } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 4f46d54bb..1cbd5fa70 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -14,7 +14,6 @@ import java.util.Map; import java.util.UUID; import java.util.zip.GZIPOutputStream; -import net.minecraft.command.ICommandManager; import net.minecraft.command.ICommandSender; import net.minecraft.command.server.CommandBlockLogic; import net.minecraft.entity.Entity; @@ -29,7 +28,6 @@ import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.rcon.RConConsoleSource; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraft.tileentity.TileEntity; @@ -38,7 +36,6 @@ import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import noppes.npcs.constants.EnumGuiType; @@ -76,7 +73,7 @@ import noppes.npcs.controllers.TransportLocation; import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTransporter; -import noppes.npcs.scripted.ScriptEventDialog; +import noppes.npcs.scripted.event.ScriptEventDialog; public class NoppesUtilServer { private static HashMap editingQuests = new HashMap(); diff --git a/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java index 0dbc6b2d1..7cbdc488a 100644 --- a/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java +++ b/src/main/java/noppes/npcs/client/gui/EventGuiScriptList.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.client.gui.GuiButton; -import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.EventScriptContainer; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; @@ -13,10 +13,10 @@ import noppes.npcs.client.gui.util.SubGuiInterface; public class EventGuiScriptList extends SubGuiInterface{ private GuiCustomScroll scroll1; private GuiCustomScroll scroll2; - private PlayerScriptContainer container; + private EventScriptContainer container; private List scripts; - public EventGuiScriptList(List scripts, PlayerScriptContainer container){ + public EventGuiScriptList(List scripts, EventScriptContainer container){ this.container = container; setBackground("menubg.png"); xSize = 346; diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java index af60efd49..533a7654f 100644 --- a/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.minecraft.client.gui.GuiButton; -import noppes.npcs.PlayerScriptContainer; +import noppes.npcs.EventScriptContainer; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; @@ -18,10 +18,10 @@ import noppes.npcs.client.gui.util.SubGuiInterface; public class EventGuiScriptList extends SubGuiInterface { private GuiCustomScroll scroll1; private GuiCustomScroll scroll2; - private PlayerScriptContainer container; + private EventScriptContainer container; private List scripts; - public EventGuiScriptList(List scripts, PlayerScriptContainer container) { + public EventGuiScriptList(List scripts, EventScriptContainer container) { this.container = container; this.setBackground("menubg.png"); this.xSize = 346; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java new file mode 100644 index 000000000..e9a29fe6a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java @@ -0,0 +1,30 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.script; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.client.Client; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.ForgeDataScript; + +public class GuiScriptForge extends GuiScriptInterface { + private ForgeDataScript script = new ForgeDataScript(); + + public GuiScriptForge() { + this.handler = this.script; + Client.sendData(EnumPacketServer.ScriptForgeGet); + } + + public void setGuiData(NBTTagCompound compound) { + this.script.readFromNBT(compound); + super.setGuiData(compound); + } + + public void save() { + super.save(); + Client.sendData(EnumPacketServer.ScriptForgeSave, script.writeToNBT(new NBTTagCompound())); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java index 84ade08f8..26bfb2834 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -39,9 +39,9 @@ public class GuiScriptGlobal extends GuiNPCInterface { if (guibutton.id == 0) { this.displayGuiScreen(new GuiScriptPlayers()); } - /*if (guibutton.id == 1) { + if (guibutton.id == 1) { this.displayGuiScreen(new GuiScriptForge()); - }*/ + } } public void keyTyped(char c, int i) { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index b99f56c2d..9330a8f7c 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -28,7 +28,7 @@ import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; -public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener { +public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener, ITextfieldListener { private int activeTab = 0; public IScriptHandler handler; public Map> languages = new HashMap(); @@ -56,49 +56,12 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb GuiMenuTopButton top; this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings")); - List hookList = new ArrayList(); - if(handler instanceof PlayerDataScript) { - hookList.add("playerscript.disabled"); - hookList.add("playerscript.init"); - hookList.add("playerscript.tick"); - hookList.add("playerscript.interact"); - hookList.add("playerscript.damaged"); - hookList.add("playerscript.killed"); - hookList.add("playerscript.kills"); - hookList.add("playerscript.chat"); - hookList.add("playerscript.drop"); - hookList.add("playerscript.containerOpen"); - hookList.add("playerscript.login"); - hookList.add("playerscript.logout"); - hookList.add("playerscript.chat"); - hookList.add("playerscript.damagedentity"); - hookList.add("playerscript.keyPressed"); - hookList.add("playerscript.mouseClicked"); - hookList.add("playerscript.pickUp"); - hookList.add("playerscript.rangedLaunched"); - hookList.add("playerscript.pickupXP"); - hookList.add("playerscript.timer"); - hookList.add("playerscript.startItem"); - hookList.add("playerscript.usingItem"); - hookList.add("playerscript.stopItem"); - hookList.add("playerscript.finishItem"); - hookList.add("playerscript.fall"); - hookList.add("playerscript.playSound"); - hookList.add("playerscript.lightning"); - hookList.add("playerscript.break"); - hookList.add("playerscript.changedDim"); - hookList.add("playerscript.respawn"); - } - else if(handler instanceof ForgeDataScript){ - hookList.add("forgescript.forgeInit"); - } - int topXoffset = 0; int topYoffset = 0; for(int ta = 0; ta < this.handler.getScripts().size(); ++ta) { - if(ta%15 == 0 && ta > 0) { + if(ta%20 == 0 && ta > 0) { topYoffset -= 20; - topXoffset -= top.width+260; + topXoffset -= top.width+20*22; } this.addTopButton(top = new GuiMenuTopButton(ta + 1, top.xPosition+top.width + topXoffset, top.yPosition + topYoffset, ta + 1 + "")); topXoffset = 0; @@ -106,7 +69,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb scriptLimit = ta + 2; } - if(this.handler.getScripts().size() < 75) + if(this.handler.getScripts().size() < 100) this.addTopButton(new GuiMenuTopButton(scriptLimit, top.xPosition+top.width, top.yPosition, "+")); top = this.getTopButton(this.activeTab); @@ -117,14 +80,54 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb top.active = true; if(this.activeTab > 0) { - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(hookList); - hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),hookList); - addScroll(hooks); + if(handler instanceof PlayerDataScript) { + List hookList = new ArrayList(); + hookList.add("playerscript.disabled"); + hookList.add("playerscript.init"); + hookList.add("playerscript.tick"); + hookList.add("playerscript.interact"); + hookList.add("playerscript.damaged"); + hookList.add("playerscript.killed"); + hookList.add("playerscript.kills"); + hookList.add("playerscript.chat"); + hookList.add("playerscript.drop"); + hookList.add("playerscript.containerOpen"); + hookList.add("playerscript.login"); + hookList.add("playerscript.logout"); + hookList.add("playerscript.chat"); + hookList.add("playerscript.damagedentity"); + hookList.add("playerscript.keyPressed"); + hookList.add("playerscript.mouseClicked"); + hookList.add("playerscript.pickUp"); + hookList.add("playerscript.rangedLaunched"); + hookList.add("playerscript.pickupXP"); + hookList.add("playerscript.timer"); + hookList.add("playerscript.startItem"); + hookList.add("playerscript.usingItem"); + hookList.add("playerscript.stopItem"); + hookList.add("playerscript.finishItem"); + hookList.add("playerscript.fall"); + hookList.add("playerscript.playSound"); + hookList.add("playerscript.lightning"); + hookList.add("playerscript.break"); + hookList.add("playerscript.changedDim"); + hookList.add("playerscript.respawn"); + + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.setSize(68, 198); + hooks.guiLeft = guiLeft + 4; + hooks.guiTop = guiTop + 14; + hooks.setUnsortedList(hookList); + hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),hookList); + addScroll(hooks); + } + else if(handler instanceof ForgeDataScript){ + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); + GuiNpcTextField hookField = new GuiNpcTextField(1,this,this.fontRendererObj,guiLeft + 4,guiTop + 14,68,20,""); + hookField.setText(this.handler.getScripts().get(this.activeTab - 1).type); + addTextField(hookField); + } EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + 72 + yoffset, this.guiTop + yoffset, this.xSize - 180 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); @@ -175,6 +178,13 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb this.handler.getScripts().get(this.activeTab - 1).setType(scroll.getSelected().replace("playerscript.","")); } + @Override + public void unFocused(GuiNpcTextField textfield) { + if(textfield.id == 1){ + this.handler.getScripts().get(this.activeTab - 1).setType(textfield.getText()); + } + } + private int getScriptHook(EventScriptContainer eventScriptContainer, List list) { for(String s : list) { if (s.replace("playerscript.", "").equals(eventScriptContainer.type)) { @@ -334,8 +344,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb text = text.replace("\r\n", "\n"); text = text.replace("\r", "\n"); container.script = text; - - ScriptController.Instance.playerScripts.errored.clear(); } } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java index 20838f2dd..79dd8753c 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.PlayerDataScript; public class GuiScriptPlayers extends GuiScriptInterface { @@ -28,4 +29,9 @@ public class GuiScriptPlayers extends GuiScriptInterface { super.save(); Client.sendData(EnumPacketServer.ScriptPlayerSave, script.writeToNBT(new NBTTagCompound())); } + + public void close() { + super.close(); + ScriptController.Instance.playerScripts.errored.clear(); + } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index ea1d395c1..474094a0e 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -37,6 +37,9 @@ public enum EnumPacketServer { ScriptPlayerSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), ScriptPlayerGet(false), + ScriptForgeSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptForgeGet(false), + LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED), ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true), PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA), diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index e7cc70457..10c242b09 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -64,7 +64,10 @@ public enum EnumScriptType { PLAYSOUND("playSound"), RESPAWN("respawn"), CHANGED_DIM("changedDim"), - BREAK("break"); + BREAK("break"), + FORGE_INIT("forgeInit"), + FORGE_ENTITY("forgeEntity"), + FORGE_WORLD("forgeWorld"); public String function; diff --git a/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java b/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java index 3ddf2d0d1..9996ec51f 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java +++ b/src/main/java/noppes/npcs/containers/ContainerNpcInterface.java @@ -2,9 +2,8 @@ package noppes.npcs.containers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; import net.minecraft.util.MathHelper; -import noppes.npcs.scripted.IContainer; +import noppes.npcs.scripted.interfaces.IContainer; import noppes.npcs.scripted.ScriptContainer; public class ContainerNpcInterface extends Container{ diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index b426ac053..2d6a501db 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -31,13 +31,13 @@ import noppes.npcs.LogWriter; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.ScriptAnimal; -import noppes.npcs.scripted.ScriptEntity; -import noppes.npcs.scripted.ScriptLiving; -import noppes.npcs.scripted.ScriptLivingBase; -import noppes.npcs.scripted.ScriptMonster; -import noppes.npcs.scripted.ScriptPixelmon; -import noppes.npcs.scripted.ScriptPlayer; +import noppes.npcs.scripted.entity.ScriptAnimal; +import noppes.npcs.scripted.entity.ScriptEntity; +import noppes.npcs.scripted.entity.ScriptLiving; +import noppes.npcs.scripted.entity.ScriptLivingBase; +import noppes.npcs.scripted.entity.ScriptMonster; +import noppes.npcs.scripted.entity.ScriptPixelmon; +import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.util.JsonException; import noppes.npcs.util.NBTJsonUtil; diff --git a/src/main/java/noppes/npcs/controllers/ScriptEntityData.java b/src/main/java/noppes/npcs/controllers/ScriptEntityData.java index 3f283f1f7..08c4e152d 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptEntityData.java +++ b/src/main/java/noppes/npcs/controllers/ScriptEntityData.java @@ -4,7 +4,7 @@ import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; -import noppes.npcs.scripted.ScriptEntity; +import noppes.npcs.scripted.entity.ScriptEntity; public class ScriptEntityData implements IExtendedEntityProperties{ public ScriptEntity base; diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index aafa32fa8..ddfc54063 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -14,7 +14,6 @@ import java.util.Map.Entry; import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.client.Minecraft; -import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.EventHooks; import noppes.npcs.EventScriptContainer; @@ -22,6 +21,7 @@ import noppes.npcs.NBTTags; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import javax.script.ScriptEngine; @@ -51,40 +51,9 @@ public class ForgeDataScript implements IScriptHandler { return compound; } - public void callScript(EnumScriptType type, Event event, Object... obs) { - if(this.isEnabled()) { -// CustomNpcs.getServer().func_152344_a(() -> { - Minecraft.getMinecraft().func_152344_a(() -> { - if (ScriptController.Instance.lastLoaded > this.lastInited) { - this.lastInited = ScriptController.Instance.lastLoaded; - if (!type.equals(EnumScriptType.FORGE_INIT)) { - EventHooks.onForgeInit(this); - } - } - - Iterator var3 = this.scripts.iterator(); - - while (var3.hasNext()) { - EventScriptContainer script = (EventScriptContainer) var3.next(); - if(script.type != type.function) - continue; - - script.setEngine(scriptLanguage); - if(script.engine == null) - return; - for(int i = 0; i + 1 < obs.length; i += 2){ - Object ob = obs[i + 1]; - if(ob instanceof Entity) - ob = ScriptController.Instance.getScriptForEntity((Entity)ob); - script.engine.put(obs[i].toString(), ob); - } - ScriptEngine engine = script.engine; - - //script.run(EnumScriptType.valueOf(type), event); - script.run(engine); - } - }); - } + @Override + public void callScript(EnumScriptType var1, Event var2, Object... obs) { + callScript(var1.function, var2); } public void callScript(String type, Event event) { @@ -102,11 +71,19 @@ public class ForgeDataScript implements IScriptHandler { while (var3.hasNext()) { EventScriptContainer script = (EventScriptContainer) var3.next(); - //script.run(EnumScriptType.valueOf(type), event); + + if(!script.type.equals(type)) + continue; script.setEngine(scriptLanguage); if(script.engine == null) return; + + Event result = (Event) script.engine.get("event"); + if(result == null) + script.engine.put("event", event); + script.engine.put("API", new WrapperNpcAPI()); + ScriptEngine engine = script.engine; script.run(engine); diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 31573661c..fb93ce3d2 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -20,15 +20,13 @@ import net.minecraft.world.WorldServer; import noppes.npcs.EventHooks; import noppes.npcs.EventScriptContainer; import noppes.npcs.NBTTags; -import noppes.npcs.scripted.ScriptPlayer; +import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.ScriptWorld; -import noppes.npcs.scripted.constants.EntityType; -import noppes.npcs.scripted.constants.JobType; -import noppes.npcs.scripted.constants.RoleType; import noppes.npcs.scripted.event.PlayerEvent; +import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import javax.annotation.CheckForNull; import javax.script.ScriptEngine; @@ -47,9 +45,6 @@ public class PlayerDataScript implements IScriptHandler { public ScriptPlayer dummyPlayer; public ScriptWorld dummyWorld; - private final static EntityType entities = new EntityType(); - private final static JobType jobs = new JobType(); - private final static RoleType roles = new RoleType(); public PlayerDataScript(EntityPlayer player) { if(player != null) { @@ -132,9 +127,7 @@ public class PlayerDataScript implements IScriptHandler { PlayerEvent result = (PlayerEvent) engine.get("event"); if(result == null) engine.put("event", result = new PlayerEvent(this.getPlayer())); - engine.put("EntityType", entities); - engine.put("RoleType", roles); - engine.put("JobType", jobs); + script.engine.put("API", new WrapperNpcAPI()); script.run(engine); if (script.errored) { diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 7d69e39e5..825c31877 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -93,7 +93,12 @@ import noppes.npcs.roles.JobInterface; import noppes.npcs.roles.RoleCompanion; import noppes.npcs.roles.RoleFollower; import noppes.npcs.roles.RoleInterface; -import noppes.npcs.scripted.*; +import noppes.npcs.scripted.entity.ScriptNpc; +import noppes.npcs.scripted.event.ScriptEventAttack; +import noppes.npcs.scripted.event.ScriptEventDamaged; +import noppes.npcs.scripted.event.ScriptEventKilled; +import noppes.npcs.scripted.event.ScriptEventTarget; +import noppes.npcs.scripted.interfaces.ICustomNpc; import noppes.npcs.util.GameProfileAlt; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index bdad6f419..843d38849 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -12,9 +12,8 @@ import java.util.Map; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.EventHooks; -import noppes.npcs.scripted.ITimers; +import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.controllers.PlayerData; -import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.CustomNPCsException; public class DataTimers implements ITimers { diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index e43f1bed9..774ac105c 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -10,6 +10,7 @@ import java.io.File; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.EventBus; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -18,6 +19,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import noppes.npcs.scripted.interfaces.*; public abstract class NpcAPI { private static NpcAPI instance = null; @@ -31,8 +33,12 @@ public abstract class NpcAPI { public abstract IEntity getIEntity(Entity var1); + public abstract IPlayer getIPlayer(EntityPlayerMP var1); + public abstract IBlock getIBlock(World var1, BlockPos var2); + public abstract IBlock getIBlock(World world, int x, int y, int z); + public abstract IContainer getIContainer(IInventory var1); public abstract IContainer getIContainer(Container var1); diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index 86893eb5d..69dd6d984 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -7,7 +7,6 @@ package noppes.npcs.scripted; import java.util.Map; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -15,6 +14,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import noppes.npcs.scripted.interfaces.*; import noppes.npcs.util.LRUHashMap; public class ScriptBlock implements IBlock { diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java b/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java index 3dcb87c1a..d8214e1c9 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlockPos.java @@ -7,6 +7,7 @@ package noppes.npcs.scripted; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import noppes.npcs.scripted.interfaces.IPos; public class ScriptBlockPos implements IPos { private BlockPos blockPos; diff --git a/src/main/java/noppes/npcs/scripted/ScriptContainer.java b/src/main/java/noppes/npcs/scripted/ScriptContainer.java index 722eeafea..34c733a87 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptContainer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptContainer.java @@ -6,15 +6,12 @@ package noppes.npcs.scripted; import net.minecraft.block.Block; -import net.minecraft.block.BlockAir; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.scripted.CustomNPCsException; -import noppes.npcs.scripted.IContainer; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.IItemStack; +import noppes.npcs.scripted.interfaces.IContainer; +import noppes.npcs.scripted.interfaces.IItemStack; public class ScriptContainer implements IContainer { private IInventory inventory; diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java index 849faafce..19ab0e360 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntityParticle.java @@ -1,7 +1,7 @@ package noppes.npcs.scripted; -import net.minecraft.entity.Entity; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.scripted.entity.ScriptEntity; /** * Created by luisc on 9/8/2021. diff --git a/src/main/java/noppes/npcs/scripted/ScriptEventDialog.java b/src/main/java/noppes/npcs/scripted/ScriptEventDialog.java deleted file mode 100644 index 861faa27e..000000000 --- a/src/main/java/noppes/npcs/scripted/ScriptEventDialog.java +++ /dev/null @@ -1,15 +0,0 @@ -package noppes.npcs.scripted; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; -import noppes.npcs.controllers.ScriptController; - -public class ScriptEventDialog extends ScriptEvent{ - - /** - * @deprecated - */ - public boolean isClosing(){ - return true; - } -} diff --git a/src/main/java/noppes/npcs/scripted/ScriptFaction.java b/src/main/java/noppes/npcs/scripted/ScriptFaction.java index 003c08dba..972ecaf2b 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptFaction.java +++ b/src/main/java/noppes/npcs/scripted/ScriptFaction.java @@ -1,6 +1,8 @@ package noppes.npcs.scripted; import noppes.npcs.controllers.Faction; +import noppes.npcs.scripted.entity.ScriptNpc; +import noppes.npcs.scripted.entity.ScriptPlayer; public class ScriptFaction { private Faction faction; diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index ba0d1030e..97567e857 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -13,9 +13,11 @@ import net.minecraft.nbt.NBTBase.NBTPrimitive; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; +import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.interfaces.INbt; public class ScriptItemStack implements IItemStack { - protected ItemStack item; + public ItemStack item; public ScriptItemStack(ItemStack item){ this.item = item; diff --git a/src/main/java/noppes/npcs/scripted/ScriptNbt.java b/src/main/java/noppes/npcs/scripted/ScriptNbt.java index 25816f90f..968ea698d 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptNbt.java +++ b/src/main/java/noppes/npcs/scripted/ScriptNbt.java @@ -14,6 +14,7 @@ import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; +import noppes.npcs.scripted.interfaces.INbt; import noppes.npcs.util.NBTJsonUtil; public class ScriptNbt implements INbt { diff --git a/src/main/java/noppes/npcs/scripted/ScriptPixelmonPlayerData.java b/src/main/java/noppes/npcs/scripted/ScriptPixelmonPlayerData.java index e44476362..1efd16256 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPixelmonPlayerData.java +++ b/src/main/java/noppes/npcs/scripted/ScriptPixelmonPlayerData.java @@ -4,6 +4,7 @@ import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.scripted.entity.ScriptPixelmon; public class ScriptPixelmonPlayerData { private EntityPlayerMP player; diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 82f354fce..60d1390a0 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -23,11 +23,14 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; -import noppes.npcs.blocks.tiles.TileSign; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; +import noppes.npcs.scripted.entity.ScriptEntity; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.interfaces.IBlock; +import noppes.npcs.scripted.interfaces.IWorld; -public class ScriptWorld implements IWorld{ +public class ScriptWorld implements IWorld { private static Map tempData = new HashMap(); public WorldServer world; public ScriptWorld(WorldServer world){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptAnimal.java b/src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java similarity index 83% rename from src/main/java/noppes/npcs/scripted/ScriptAnimal.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java index 585fd777a..e1217aedb 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptAnimal.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptAnimal.java @@ -1,7 +1,8 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; import net.minecraft.entity.passive.EntityAnimal; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.IAnimal; public class ScriptAnimal extends ScriptLiving implements IAnimal { diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java similarity index 97% rename from src/main/java/noppes/npcs/scripted/ScriptEntity.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index bba2fa4af..ac8fd300e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -1,4 +1,4 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; import java.util.ArrayList; import java.util.HashMap; @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; @@ -19,16 +18,17 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.Server; -import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptEntityParticle; +import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.IEntity; +import noppes.npcs.scripted.interfaces.INbt; -public class ScriptEntity implements IEntity{ +public class ScriptEntity implements IEntity { protected T entity; private Map tempData = new HashMap(); diff --git a/src/main/java/noppes/npcs/scripted/ScriptLiving.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java similarity index 87% rename from src/main/java/noppes/npcs/scripted/ScriptLiving.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java index 8abbfd8ee..9b06e5625 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptLiving.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java @@ -1,12 +1,8 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; -import net.minecraft.entity.NPCEntityHelper; import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.IEntityLiving; public class ScriptLiving extends ScriptLivingBase implements IEntityLiving { diff --git a/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java similarity index 88% rename from src/main/java/noppes/npcs/scripted/ScriptLivingBase.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index ace51679e..9a1a23cb2 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -1,27 +1,15 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import net.minecraft.block.material.Material; -import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTBase.NBTPrimitive; -import net.minecraft.nbt.NBTTagString; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.MathHelper; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.IEntityLivingBase; -public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase{ +public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase { protected T entity; public ScriptLivingBase(T entity){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptMonster.java b/src/main/java/noppes/npcs/scripted/entity/ScriptMonster.java similarity index 83% rename from src/main/java/noppes/npcs/scripted/ScriptMonster.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptMonster.java index 60cccd200..8e7afdd8e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptMonster.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptMonster.java @@ -1,8 +1,8 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.monster.EntityMob; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.IMonster; public class ScriptMonster extends ScriptLiving implements IMonster { diff --git a/src/main/java/noppes/npcs/scripted/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java similarity index 98% rename from src/main/java/noppes/npcs/scripted/ScriptNpc.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 073c1af98..01b96a2b3 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -1,9 +1,6 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; -import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumAnimation; import noppes.npcs.constants.EnumJobType; @@ -11,9 +8,11 @@ import noppes.npcs.constants.EnumRoleType; import noppes.npcs.controllers.Line; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.roles.JobBard; +import noppes.npcs.scripted.ScriptFaction; +import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.AnimationType; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.ICustomNpc; import noppes.npcs.scripted.roles.ScriptJobBard; import noppes.npcs.scripted.roles.ScriptJobConversation; import noppes.npcs.scripted.roles.ScriptJobFollower; diff --git a/src/main/java/noppes/npcs/scripted/ScriptPixelmon.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java similarity index 98% rename from src/main/java/noppes/npcs/scripted/ScriptPixelmon.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java index 57400dfcb..727ca20e8 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java @@ -1,9 +1,9 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; -import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.scripted.interfaces.IPixelmon; import noppes.npcs.util.ValueUtil; public class ScriptPixelmon extends ScriptAnimal implements IPixelmon { diff --git a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java similarity index 98% rename from src/main/java/noppes/npcs/scripted/ScriptPlayer.java rename to src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 21084924b..47e8925ce 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -1,4 +1,4 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; @@ -22,7 +22,10 @@ import noppes.npcs.controllers.PlayerQuestData; import noppes.npcs.controllers.Quest; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.QuestData; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.ScriptPixelmonPlayerData; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.IPlayer; import noppes.npcs.util.ValueUtil; public class ScriptPlayer extends ScriptLivingBase implements IPlayer { diff --git a/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java b/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java index d858a7b56..29c03b5a8 100644 --- a/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/ForgeEvent.java @@ -7,8 +7,8 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Cancelable; import cpw.mods.fml.common.eventhandler.Event; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.IEntity; +import noppes.npcs.scripted.interfaces.IWorld; +import noppes.npcs.scripted.interfaces.IEntity; @Cancelable public class ForgeEvent extends CustomNPCsEvent { diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 898738bef..4c14e8bf2 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -6,13 +6,15 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Cancelable; -import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import noppes.npcs.scripted.*; +import noppes.npcs.scripted.entity.ScriptLivingBase; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.interfaces.*; public class PlayerEvent extends CustomNPCsEvent { public final IPlayer player; diff --git a/src/main/java/noppes/npcs/scripted/ScriptEvent.java b/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java similarity index 84% rename from src/main/java/noppes/npcs/scripted/ScriptEvent.java rename to src/main/java/noppes/npcs/scripted/event/ScriptEvent.java index fc5ccc9a1..5a5a8cbfd 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java @@ -1,4 +1,4 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.event; public class ScriptEvent{ diff --git a/src/main/java/noppes/npcs/scripted/ScriptEventAttack.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java similarity index 90% rename from src/main/java/noppes/npcs/scripted/ScriptEventAttack.java rename to src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java index 218b6e681..5b37517a4 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEventAttack.java +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java @@ -1,8 +1,8 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.event; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.entity.ScriptLivingBase; public class ScriptEventAttack extends ScriptEvent{ diff --git a/src/main/java/noppes/npcs/scripted/ScriptEventDamaged.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java similarity index 92% rename from src/main/java/noppes/npcs/scripted/ScriptEventDamaged.java rename to src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java index 27cf4a26f..8a21666e5 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEventDamaged.java +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java @@ -1,8 +1,9 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.event; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.entity.ScriptLivingBase; public class ScriptEventDamaged extends ScriptEvent{ diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java new file mode 100644 index 000000000..af4e300ad --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java @@ -0,0 +1,11 @@ +package noppes.npcs.scripted.event; + +public class ScriptEventDialog extends ScriptEvent{ + + /** + * @deprecated + */ + public boolean isClosing(){ + return true; + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptEventKilled.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java similarity index 88% rename from src/main/java/noppes/npcs/scripted/ScriptEventKilled.java rename to src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java index 37c7e202f..606002a34 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEventKilled.java +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java @@ -1,8 +1,9 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.event; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.DamageSource; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.entity.ScriptLivingBase; public class ScriptEventKilled extends ScriptEvent{ diff --git a/src/main/java/noppes/npcs/scripted/ScriptEventTarget.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java similarity index 85% rename from src/main/java/noppes/npcs/scripted/ScriptEventTarget.java rename to src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java index 9fa1f28d3..c5aef813c 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEventTarget.java +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java @@ -1,8 +1,8 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.event; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.scripted.entity.ScriptLivingBase; public class ScriptEventTarget extends ScriptEvent{ diff --git a/src/main/java/noppes/npcs/scripted/IAnimal.java b/src/main/java/noppes/npcs/scripted/interfaces/IAnimal.java similarity index 85% rename from src/main/java/noppes/npcs/scripted/IAnimal.java rename to src/main/java/noppes/npcs/scripted/interfaces/IAnimal.java index c5f8ade49..4bf435547 100644 --- a/src/main/java/noppes/npcs/scripted/IAnimal.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IAnimal.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.passive.EntityAnimal; diff --git a/src/main/java/noppes/npcs/scripted/IBlock.java b/src/main/java/noppes/npcs/scripted/interfaces/IBlock.java similarity index 93% rename from src/main/java/noppes/npcs/scripted/IBlock.java rename to src/main/java/noppes/npcs/scripted/interfaces/IBlock.java index 9b1ce2f8a..bb84849df 100644 --- a/src/main/java/noppes/npcs/scripted/IBlock.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IBlock.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/noppes/npcs/scripted/IContainer.java b/src/main/java/noppes/npcs/scripted/interfaces/IContainer.java similarity index 92% rename from src/main/java/noppes/npcs/scripted/IContainer.java rename to src/main/java/noppes/npcs/scripted/interfaces/IContainer.java index 1d0862d7a..915980288 100644 --- a/src/main/java/noppes/npcs/scripted/IContainer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IContainer.java @@ -3,7 +3,7 @@ // (powered by FernFlower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; diff --git a/src/main/java/noppes/npcs/scripted/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java similarity index 95% rename from src/main/java/noppes/npcs/scripted/ICustomNpc.java rename to src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java index 43f3b15d4..a384a6379 100644 --- a/src/main/java/noppes/npcs/scripted/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java @@ -3,20 +3,14 @@ // (powered by FernFlower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.EntityCreature; -import net.minecraft.item.ItemStack; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.constants.EnumAnimation; -import noppes.npcs.constants.EnumJobType; -import noppes.npcs.constants.EnumRoleType; -import noppes.npcs.controllers.Line; -import noppes.npcs.scripted.IItemStack; -import noppes.npcs.scripted.constants.AnimationType; -import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.ScriptFaction; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.entity.ScriptLivingBase; +import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.roles.*; -import noppes.npcs.util.ValueUtil; public interface ICustomNpc extends IEntityLiving { /** diff --git a/src/main/java/noppes/npcs/scripted/IDamageSource.java b/src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java similarity index 89% rename from src/main/java/noppes/npcs/scripted/IDamageSource.java rename to src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java index 2d7ab3e4a..8d7dd5caa 100644 --- a/src/main/java/noppes/npcs/scripted/IDamageSource.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java @@ -3,7 +3,7 @@ // (powered by FernFlower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.util.DamageSource; diff --git a/src/main/java/noppes/npcs/scripted/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java similarity index 89% rename from src/main/java/noppes/npcs/scripted/IEntity.java rename to src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index 39926aac2..4478e69bc 100644 --- a/src/main/java/noppes/npcs/scripted/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -3,34 +3,11 @@ // (powered by FernFlower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; -import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.monster.EntityMob; -import net.minecraft.entity.passive.EntityAnimal; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.DamageSource; -import net.minecraft.util.MathHelper; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.scripted.IWorld; -import noppes.npcs.scripted.IItemStack; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.ScriptEntity; -import noppes.npcs.scripted.ScriptEntityParticle; +import noppes.npcs.scripted.entity.ScriptEntity; import noppes.npcs.scripted.ScriptItemStack; -import noppes.npcs.scripted.constants.EntityType; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; public interface IEntity { /** diff --git a/src/main/java/noppes/npcs/scripted/IEntityLiving.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntityLiving.java similarity index 90% rename from src/main/java/noppes/npcs/scripted/IEntityLiving.java rename to src/main/java/noppes/npcs/scripted/interfaces/IEntityLiving.java index cc321c196..4fda07e84 100644 --- a/src/main/java/noppes/npcs/scripted/IEntityLiving.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntityLiving.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.EntityLiving; diff --git a/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntityLivingBase.java similarity index 92% rename from src/main/java/noppes/npcs/scripted/IEntityLivingBase.java rename to src/main/java/noppes/npcs/scripted/interfaces/IEntityLivingBase.java index 14a4dec97..1fc2b472d 100644 --- a/src/main/java/noppes/npcs/scripted/IEntityLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntityLivingBase.java @@ -1,11 +1,9 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.entity.ScriptEntity; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.entity.ScriptLivingBase; public interface IEntityLivingBase extends IEntity { /** diff --git a/src/main/java/noppes/npcs/scripted/IItemStack.java b/src/main/java/noppes/npcs/scripted/interfaces/IItemStack.java similarity index 88% rename from src/main/java/noppes/npcs/scripted/IItemStack.java rename to src/main/java/noppes/npcs/scripted/interfaces/IItemStack.java index 57daa5e0f..afd04e263 100644 --- a/src/main/java/noppes/npcs/scripted/IItemStack.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IItemStack.java @@ -1,17 +1,6 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; - -import java.util.ArrayList; -import java.util.List; public interface IItemStack { public String getName(); diff --git a/src/main/java/noppes/npcs/scripted/IMonster.java b/src/main/java/noppes/npcs/scripted/interfaces/IMonster.java similarity index 84% rename from src/main/java/noppes/npcs/scripted/IMonster.java rename to src/main/java/noppes/npcs/scripted/interfaces/IMonster.java index 2da043c5c..99baf9350 100644 --- a/src/main/java/noppes/npcs/scripted/IMonster.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IMonster.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.monster.EntityMob; diff --git a/src/main/java/noppes/npcs/scripted/INbt.java b/src/main/java/noppes/npcs/scripted/interfaces/INbt.java similarity index 97% rename from src/main/java/noppes/npcs/scripted/INbt.java rename to src/main/java/noppes/npcs/scripted/interfaces/INbt.java index 5ac4ddc95..0ff2b9f77 100644 --- a/src/main/java/noppes/npcs/scripted/INbt.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/INbt.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/java/noppes/npcs/scripted/IPixelmon.java b/src/main/java/noppes/npcs/scripted/interfaces/IPixelmon.java similarity index 85% rename from src/main/java/noppes/npcs/scripted/IPixelmon.java rename to src/main/java/noppes/npcs/scripted/interfaces/IPixelmon.java index 7458347b3..b744ac4cc 100644 --- a/src/main/java/noppes/npcs/scripted/IPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPixelmon.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.passive.EntityTameable; diff --git a/src/main/java/noppes/npcs/scripted/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java similarity index 87% rename from src/main/java/noppes/npcs/scripted/IPlayer.java rename to src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index 60e454082..495ecbb1a 100644 --- a/src/main/java/noppes/npcs/scripted/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -1,22 +1,8 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.stats.Achievement; -import net.minecraft.stats.StatBase; -import net.minecraft.stats.StatList; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.world.WorldSettings; -import noppes.npcs.CustomNpcsPermissions; -import noppes.npcs.NoppesStringUtils; -import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.Server; -import noppes.npcs.constants.EnumPacketClient; -import noppes.npcs.controllers.*; -import noppes.npcs.scripted.constants.EntityType; -import noppes.npcs.util.ValueUtil; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.ScriptPixelmonPlayerData; public interface IPlayer extends IEntityLivingBase { /** diff --git a/src/main/java/noppes/npcs/scripted/IPos.java b/src/main/java/noppes/npcs/scripted/interfaces/IPos.java similarity index 95% rename from src/main/java/noppes/npcs/scripted/IPos.java rename to src/main/java/noppes/npcs/scripted/interfaces/IPos.java index 581a62d8d..3743f60aa 100644 --- a/src/main/java/noppes/npcs/scripted/IPos.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPos.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/noppes/npcs/scripted/ITimers.java b/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java similarity index 89% rename from src/main/java/noppes/npcs/scripted/ITimers.java rename to src/main/java/noppes/npcs/scripted/interfaces/ITimers.java index 24d1de2fe..c01509e34 100644 --- a/src/main/java/noppes/npcs/scripted/ITimers.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java @@ -3,7 +3,7 @@ // (powered by Fernflower decompiler) // -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; public interface ITimers { void start(int var1, int var2, boolean var3); diff --git a/src/main/java/noppes/npcs/scripted/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java similarity index 87% rename from src/main/java/noppes/npcs/scripted/IWorld.java rename to src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 1be45c61e..1f9e1c0c9 100644 --- a/src/main/java/noppes/npcs/scripted/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -1,29 +1,10 @@ -package noppes.npcs.scripted; +package noppes.npcs.scripted.interfaces; -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.EntityLightningBolt; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.blocks.tiles.TileBigSign; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.ServerCloneController; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import noppes.npcs.scripted.*; +import noppes.npcs.scripted.entity.ScriptEntity; +import noppes.npcs.scripted.entity.ScriptPlayer; public interface IWorld { /** diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java index 45d403e34..5f92c6d92 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java @@ -2,10 +2,6 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobConversation; -import noppes.npcs.roles.JobGuard; -import noppes.npcs.roles.JobItemGiver; -import noppes.npcs.scripted.ScriptItemStack; -import noppes.npcs.scripted.ScriptPlayer; import noppes.npcs.scripted.constants.JobType; public class ScriptJobConversation extends ScriptJobInterface{ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java index f12e9cb88..c2ddd5d82 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java @@ -2,8 +2,7 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobFollower; -import noppes.npcs.roles.JobGuard; -import noppes.npcs.scripted.ScriptNpc; +import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.constants.JobType; public class ScriptJobFollower extends ScriptJobInterface{ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java index 13bceb0f5..52bcaefc9 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java @@ -2,7 +2,7 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobHealer; -import noppes.npcs.scripted.ScriptLivingBase; +import noppes.npcs.scripted.entity.ScriptLivingBase; import noppes.npcs.scripted.constants.JobType; public class ScriptJobHealer extends ScriptJobInterface{ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java index e2d81c5c2..046f89dac 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java @@ -1,10 +1,7 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.roles.JobGuard; import noppes.npcs.roles.JobItemGiver; -import noppes.npcs.scripted.ScriptItemStack; -import noppes.npcs.scripted.ScriptPlayer; import noppes.npcs.scripted.constants.JobType; public class ScriptJobItemGiver extends ScriptJobInterface{ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java index 7177de312..20b12965f 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java @@ -1,11 +1,7 @@ package noppes.npcs.scripted.roles; -import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.roles.JobGuard; -import noppes.npcs.roles.JobHealer; import noppes.npcs.roles.JobPuppet; -import noppes.npcs.scripted.ScriptLivingBase; import noppes.npcs.scripted.constants.JobType; public class ScriptJobPuppet extends ScriptJobInterface{ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java index 178afc911..cf9529be8 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java @@ -1,18 +1,12 @@ package noppes.npcs.scripted.roles; import java.util.ArrayList; -import java.util.Iterator; import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.roles.JobGuard; -import noppes.npcs.roles.JobItemGiver; import noppes.npcs.roles.JobSpawner; -import noppes.npcs.scripted.ScriptItemStack; -import noppes.npcs.scripted.ScriptLivingBase; -import noppes.npcs.scripted.ScriptPlayer; +import noppes.npcs.scripted.entity.ScriptLivingBase; import noppes.npcs.scripted.constants.JobType; public class ScriptJobSpawner extends ScriptJobInterface{ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java index fa105d022..d10bd8dad 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java @@ -4,7 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleFollower; -import noppes.npcs.scripted.ScriptPlayer; +import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.constants.RoleType; public class ScriptRoleFollower extends ScriptRoleInterface{ diff --git a/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java b/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java index 94b5aef7a..32aecda6c 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/ScriptDamageSource.java @@ -6,9 +6,9 @@ package noppes.npcs.scripted.wrapper; import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.IDamageSource; +import noppes.npcs.scripted.interfaces.IDamageSource; import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.IEntity; +import noppes.npcs.scripted.interfaces.IEntity; public class ScriptDamageSource implements IDamageSource { private DamageSource source; diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java index 201867d80..641e211e2 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperEntityData.java @@ -8,20 +8,14 @@ package noppes.npcs.scripted.wrapper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; -import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.entity.projectile.EntityThrowable; -import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; -import noppes.npcs.LogWriter; -import noppes.npcs.scripted.*; import noppes.npcs.controllers.PixelmonHelper; -import noppes.npcs.entity.EntityProjectile; +import noppes.npcs.scripted.entity.*; +import noppes.npcs.scripted.interfaces.IEntity; public class WrapperEntityData{ public IEntity base; diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 7af89455a..95501992b 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -9,17 +9,15 @@ import java.io.File; import java.util.Map; import cpw.mods.fml.common.eventhandler.EventBus; -import net.minecraft.block.Block; -import net.minecraft.block.BlockAir; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; -import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -28,16 +26,11 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.scripted.*; import noppes.npcs.containers.ContainerNpcInterface; -import noppes.npcs.controllers.DialogController; -import noppes.npcs.controllers.FactionController; -import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.RecipeController; -import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.interfaces.*; import noppes.npcs.util.LRUHashMap; -import noppes.npcs.util.NBTJsonUtil; -import noppes.npcs.util.JsonException; public class WrapperNpcAPI extends NpcAPI { private static final Map worldCache = new LRUHashMap(10); @@ -59,10 +52,22 @@ public class WrapperNpcAPI extends NpcAPI { } } + public IPlayer getIPlayer(EntityPlayerMP player) { + if (player != null && !player.worldObj.isRemote) { + return new ScriptPlayer(player); + } else { + return null; + } + } + public IBlock getIBlock(World world, BlockPos pos) { return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); } + public IBlock getIBlock(World world, int x, int y, int z) { + return new ScriptBlock(world, world.getBlock(x, y, z), new BlockPos(x,y,z)); + } + public INbt getINbt(NBTTagCompound compound) { return compound == null?new ScriptNbt(new NBTTagCompound()):new ScriptNbt(compound); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 34ff82e6a..cd66b129d 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -497,6 +497,8 @@ playerscript.fall=Fall playerscript.respawn=Respawn playerscript.changedDim=Dimension Change +forgescript.forgeInit=Init + item.npcWand.name=Npc Wand item.npcMobCloner.name=Mob Cloner item.npcMovingPath.name=Npc Pather From 15bfbcdbd109da5be5878139a067ee42efbf54ac Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 18 Oct 2021 07:02:19 -0500 Subject: [PATCH 29/58] Added storeAsClone function. Made some fields in Script Entity, NPC, and Player public because of the refactoring. --- .../noppes/npcs/scripted/entity/ScriptEntity.java | 11 +++++++++++ .../java/noppes/npcs/scripted/entity/ScriptNpc.java | 2 +- .../noppes/npcs/scripted/entity/ScriptPlayer.java | 2 +- .../java/noppes/npcs/scripted/interfaces/IEntity.java | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index ac8fd300e..c50b7be1a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -20,7 +20,9 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptEntityParticle; import noppes.npcs.scripted.ScriptItemStack; @@ -495,4 +497,13 @@ public class ScriptEntity implements IEntity { public void setNbt(INbt nbt) { this.entity.readFromNBT(nbt.getMCNBT()); } + + public void storeAsClone(int tab, String name) { + NBTTagCompound compound = new NBTTagCompound(); + if (!this.entity.writeToNBTOptional(compound)) { + throw new CustomNPCsException("Cannot store dead entities", new Object[0]); + } else { + ServerCloneController.Instance.addClone(compound, name, tab); + } + } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 01b96a2b3..2b1b9473c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -31,7 +31,7 @@ import noppes.npcs.scripted.roles.ScriptRoleTransporter; import noppes.npcs.util.ValueUtil; public class ScriptNpc extends ScriptLiving implements ICustomNpc { - protected EntityCustomNpc npc; + public EntityCustomNpc npc; public ScriptNpc(T npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 47e8925ce..0d967cfee 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -29,7 +29,7 @@ import noppes.npcs.scripted.interfaces.IPlayer; import noppes.npcs.util.ValueUtil; public class ScriptPlayer extends ScriptLivingBase implements IPlayer { - protected T player; + public T player; public ScriptPlayer(T player){ super(player); this.player = player; diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index 4478e69bc..331557a46 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -300,4 +300,6 @@ public interface IEntity { * @return Returns minecrafts entity */ public T getMCEntity(); + + void storeAsClone(int tab, String name); } From feeef71b5ae99a1fcb4855b40d7be4e1b7eceeb3 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 18 Oct 2021 20:50:54 -0500 Subject: [PATCH 30/58] Added more player events. --- src/main/java/noppes/npcs/EventHooks.java | 48 ++++++++++ .../noppes/npcs/ScriptPlayerEventHandler.java | 69 +++++++++++++++ .../client/gui/script/GuiScriptInterface.java | 23 +++-- .../noppes/npcs/constants/EnumScriptType.java | 8 ++ .../npcs/scripted/event/PlayerEvent.java | 87 +++++++++++++++++++ .../assets/customnpcs/lang/en_US.lang | 13 ++- 6 files changed, 238 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index d9d5a7d5e..7e6975e9b 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -6,6 +6,7 @@ package noppes.npcs; import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; @@ -14,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; +import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.world.WorldEvent; @@ -113,6 +115,24 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onPlayerUseHoe(PlayerDataScript handler, ItemStack hoe, int x, int y, int z) { + noppes.npcs.scripted.event.PlayerEvent.UseHoe event = new noppes.npcs.scripted.event.PlayerEvent.UseHoe(handler.getPlayer(), hoe, x, y, z); + handler.callScript(EnumScriptType.USE_HOE, event,"event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerSleep(PlayerDataScript handler, int x, int y, int z) { + noppes.npcs.scripted.event.PlayerEvent.Sleep event = new noppes.npcs.scripted.event.PlayerEvent.Sleep(handler.getPlayer(), x, y, z); + handler.callScript(EnumScriptType.SLEEP, event,"event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerWakeUp(PlayerDataScript handler, boolean setSpawn) { + noppes.npcs.scripted.event.PlayerEvent.WakeUp event = new noppes.npcs.scripted.event.PlayerEvent.WakeUp(handler.getPlayer(), setSpawn); + handler.callScript(EnumScriptType.WAKE_UP, event,"event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerDeath(PlayerDataScript handler, DamageSource source, Entity entity) { noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(handler.getPlayer(), source, entity); handler.callScript(EnumScriptType.KILLED, event,"event", event); @@ -148,12 +168,35 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onPlayerJump(PlayerDataScript handler) { + PlayerEvent.JumpEvent event = new PlayerEvent.JumpEvent(handler.getPlayer()); + handler.callScript(EnumScriptType.JUMP, event,"event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerLogin(PlayerDataScript handler) { LoginEvent event = new LoginEvent(handler.getPlayer()); handler.callScript(EnumScriptType.LOGIN, event, "event", event); WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onPlayerAchievement(PlayerDataScript handler, String description) { + PlayerEvent.Achievement event = new PlayerEvent.Achievement(handler.getPlayer(), description); + handler.callScript(EnumScriptType.ACHIEVEMENT, event, "event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerFillBucket(PlayerDataScript handler, ItemStack current, ItemStack result) { + PlayerEvent.FillBucket event = new PlayerEvent.FillBucket(handler.getPlayer(), current, result); + handler.callScript(EnumScriptType.FILL_BUCKET, event, "event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onPlayerBonemeal(PlayerDataScript handler, int x, int y, int z, World world) { + PlayerEvent.Bonemeal event = new PlayerEvent.Bonemeal(handler.getPlayer(), x, y, z, world); + handler.callScript(EnumScriptType.BONEMEAL, event, "event", event); + WrapperNpcAPI.EVENT_BUS.post(event); + } public static void onPlayerRespawn(PlayerDataScript handler) { PlayerEvent.RespawnEvent event = new PlayerEvent.RespawnEvent(handler.getPlayer()); @@ -172,6 +215,11 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } + public static boolean onPlayerBowCharge(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedChargeEvent event) { + handler.callScript(EnumScriptType.RANGED_CHARGE, event,"event", event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + public static boolean onPlayerRanged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) { handler.callScript(EnumScriptType.RANGED_LAUNCHED, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index a65adefad..30c74504a 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -37,6 +37,7 @@ import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.entity.EntityStruckByLightningEvent; import net.minecraftforge.event.entity.PlaySoundAtEntityEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; @@ -77,6 +78,15 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(ArrowNockEvent event) { + if(!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + noppes.npcs.scripted.event.PlayerEvent.RangedChargeEvent ev = new noppes.npcs.scripted.event.PlayerEvent.RangedChargeEvent(handler.getPlayer()); + EventHooks.onPlayerBowCharge(handler, ev); + } + } + @SubscribeEvent public void invoke(ArrowLooseEvent event) { if(!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) { @@ -165,6 +175,54 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(UseHoeEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerUseHoe(handler, event.current, event.x, event.y, event.z); + } + } + + @SubscribeEvent + public void invoke(PlayerSleepInBedEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerSleep(handler, event.x, event.y, event.z); + } + } + + @SubscribeEvent + public void invoke(PlayerWakeUpEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerWakeUp(handler, event.setSpawn); + } + } + + @SubscribeEvent + public void invoke(FillBucketEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerFillBucket(handler, event.current, event.result); + } + } + + @SubscribeEvent + public void invoke(BonemealEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerBonemeal(handler, event.x, event.y, event.z, event.world); + } + } + + @SubscribeEvent + public void invoke(AchievementEvent event) { + if(event.entityPlayer.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; + EventHooks.onPlayerAchievement(handler, event.achievement.getDescription()); + } + } + @SubscribeEvent public void invoke(LivingFallEvent event) { if(event.entityLiving.worldObj instanceof WorldServer) { @@ -176,6 +234,17 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(LivingEvent.LivingJumpEvent event) { + if(event.entityLiving.worldObj instanceof WorldServer) { + PlayerDataScript handler; + if (event.entityLiving instanceof EntityPlayer) { + handler = PlayerData.get((EntityPlayer)event.entityLiving).scriptData; + EventHooks.onPlayerJump(handler); + } + } + } + @SubscribeEvent public void invoke(EntityStruckByLightningEvent event) { if(event.entity.worldObj instanceof WorldServer) { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 9330a8f7c..d731c2685 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -86,32 +86,39 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hookList.add("playerscript.init"); hookList.add("playerscript.tick"); hookList.add("playerscript.interact"); + hookList.add("playerscript.damagedEntity"); hookList.add("playerscript.damaged"); - hookList.add("playerscript.killed"); hookList.add("playerscript.kills"); - hookList.add("playerscript.chat"); + hookList.add("playerscript.killed"); hookList.add("playerscript.drop"); - hookList.add("playerscript.containerOpen"); + hookList.add("playerscript.respawn"); + hookList.add("playerscript.break"); + hookList.add("playerscript.chat"); hookList.add("playerscript.login"); hookList.add("playerscript.logout"); - hookList.add("playerscript.chat"); - hookList.add("playerscript.damagedentity"); hookList.add("playerscript.keyPressed"); hookList.add("playerscript.mouseClicked"); hookList.add("playerscript.pickUp"); - hookList.add("playerscript.rangedLaunched"); hookList.add("playerscript.pickupXP"); + hookList.add("playerscript.rangedCharge"); + hookList.add("playerscript.rangedLaunched"); hookList.add("playerscript.timer"); hookList.add("playerscript.startItem"); hookList.add("playerscript.usingItem"); hookList.add("playerscript.stopItem"); hookList.add("playerscript.finishItem"); + hookList.add("playerscript.containerOpen"); + hookList.add("playerscript.useHoe"); + hookList.add("playerscript.bonemeal"); + hookList.add("playerscript.fillBucket"); + hookList.add("playerscript.jump"); hookList.add("playerscript.fall"); + hookList.add("playerscript.wakeUp"); + hookList.add("playerscript.sleep"); hookList.add("playerscript.playSound"); hookList.add("playerscript.lightning"); - hookList.add("playerscript.break"); hookList.add("playerscript.changedDim"); - hookList.add("playerscript.respawn"); + hookList.add("playerscript.achievement"); addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); GuiCustomScroll hooks = new GuiCustomScroll(this, 1); diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index 10c242b09..a45721633 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -14,6 +14,7 @@ public enum EnumScriptType { DIALOG_OPTION("dialogOption"), TARGET_LOST("targetLost"), ROLE("role"), + RANGED_CHARGE("rangedCharge"), RANGED_LAUNCHED("rangedLaunched"), CLICKED("clicked"), FALLEN_UPON("fallenUpon"), @@ -59,7 +60,14 @@ public enum EnumScriptType { USING_ITEM("usingItem"), STOP_USING_ITEM("stopItem"), FINISH_USING_ITEM("finishItem"), + USE_HOE("useHoe"), + SLEEP("sleep"), + WAKE_UP("wakeUp"), + FILL_BUCKET("fillBucket"), + BONEMEAL("bonemeal"), + ACHIEVEMENT("achievement"), FALL("fall"), + JUMP("jump"), LIGHTNING("lightning"), PLAYSOUND("playSound"), RESPAWN("respawn"), diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 4c14e8bf2..2b4db24dd 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -6,11 +6,14 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import noppes.npcs.scripted.*; import noppes.npcs.scripted.entity.ScriptLivingBase; import noppes.npcs.scripted.entity.ScriptPlayer; @@ -162,6 +165,12 @@ public class PlayerEvent extends CustomNPCsEvent { } } + public static class JumpEvent extends PlayerEvent { + public JumpEvent(IPlayer player){ + super(player); + } + } + public static class KilledEntityEvent extends PlayerEvent { public final IEntityLivingBase entity; @@ -341,4 +350,82 @@ public class PlayerEvent extends CustomNPCsEvent { this.exp = exp; } } + + public static class UseHoe extends PlayerEvent { + public final IItemStack hoe; + public final int x; + public final int y; + public final int z; + + public UseHoe(IPlayer player, ItemStack item, int x, int y, int z) { + super(player); + this.hoe = new ScriptItemStack(item); + this.x = x; + this.y = y; + this.z = z; + } + } + + public static class WakeUp extends PlayerEvent{ + public final boolean setSpawn; + + public WakeUp(IPlayer player, boolean setSpawn) { + super(player); + this.setSpawn = setSpawn; + } + } + + public static class Sleep extends PlayerEvent { + public final int x; + public final int y; + public final int z; + + public Sleep(ScriptPlayer player, int x, int y, int z) { + super(player); + this.x = x; + this.y = y; + this.z = z; + } + } + + public static class Achievement extends PlayerEvent { + public final String description; + + public Achievement(IPlayer player, String description) { + super(player); + this.description = description; + } + } + + public static class FillBucket extends PlayerEvent { + public final IItemStack current; + public final IItemStack result; + + public FillBucket(IPlayer player, ItemStack current, ItemStack result) { + super(player); + this.current = new ScriptItemStack(current); + this.result = new ScriptItemStack(result); + } + } + + public static class Bonemeal extends PlayerEvent { + public final IBlock block; + public final int x; + public final int y; + public final int z; + + public Bonemeal(IPlayer player, int x, int y, int z, World world) { + super(player); + this.block = API.getIBlock(world, x, y, z); + this.x = x; + this.y = y; + this.z = z; + } + } + + public static class RangedChargeEvent extends PlayerEvent { + public RangedChargeEvent(ScriptPlayer player) { + super(player); + } + } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index cd66b129d..8be11f8ff 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -469,7 +469,7 @@ playerscript.break=Break playerscript.chat=Chat playerscript.containerclosed=Closed Container playerscript.containerOpen=Open Container -playerscript.damagedentity=Damaged Entity +playerscript.damagedEntity=Damaged Entity playerscript.damaged=Hurt playerscript.killed=Killed playerscript.factionupdate=Faction Updated @@ -481,7 +481,8 @@ playerscript.levelUp=Level Up playerscript.login=Login playerscript.logout=Logout playerscript.pickUp=Pickup -playerscript.rangedLaunched=Range Launched +playerscript.rangedCharge=Arrow Charge +playerscript.rangedLaunched=Arrow Launched playerscript.drop=Drop Items playerscript.tick=Update playerscript.pickupXP=Pickup XP @@ -494,8 +495,16 @@ playerscript.finishItem=Item Finish playerscript.playSound=Play Sound playerscript.lightning=Lightning Struck playerscript.fall=Fall +playerscript.jump=Jump playerscript.respawn=Respawn playerscript.changedDim=Dimension Change +playerscript.useHoe=Use Hoe +playerscript.sleep=Sleep +playerscript.wakeUp=Wake Up +playerscript.fillBucket=Fill Bucket +playerscript.bonemeal=Bonemeal +playerscript.achievement=Achievement + forgescript.forgeInit=Init From bb1da8376d8823caf966a91bb376288f9ed8c6de Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 18 Oct 2021 22:01:15 -0500 Subject: [PATCH 31/58] Implemented 1.12 event scripting API. --- src/main/java/noppes/npcs/EventHooks.java | 11 +- .../noppes/npcs/EventScriptContainer.java | 64 ++++++-- .../noppes/npcs/ScriptPlayerEventHandler.java | 9 ++ .../client/gui/script/GuiScriptInterface.java | 152 ++++++++++-------- .../controllers/data/ForgeDataScript.java | 5 +- .../controllers/data/PlayerDataScript.java | 5 +- .../npcs/scripted/event/PlayerEvent.java | 14 +- .../assets/customnpcs/lang/en_US.lang | 1 + 8 files changed, 174 insertions(+), 87 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 7e6975e9b..a4739700e 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -6,7 +6,6 @@ package noppes.npcs; import cpw.mods.fml.common.eventhandler.Event; -import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; @@ -32,7 +31,7 @@ import noppes.npcs.scripted.event.PlayerEvent.KeyPressedEvent; import noppes.npcs.scripted.event.PlayerEvent.LoginEvent; import noppes.npcs.scripted.event.PlayerEvent.LogoutEvent; import noppes.npcs.scripted.event.PlayerEvent.PickUpEvent; -import noppes.npcs.scripted.event.PlayerEvent.TossEvent; +import noppes.npcs.scripted.event.PlayerEvent.DropEvent; import noppes.npcs.scripted.interfaces.IEntity; import noppes.npcs.scripted.interfaces.IItemStack; import noppes.npcs.scripted.interfaces.IWorld; @@ -92,7 +91,7 @@ public class EventHooks { IItemStack[] items = new IItemStack[entityItems.size()]; for(int i = 0; i < entityItems.size(); i++){ items[i] = NpcAPI.Instance().getIItemStack(entityItems.get(i).getEntityItem()); } - TossEvent event = new TossEvent(handler.getPlayer(), items); + DropEvent event = new DropEvent(handler.getPlayer(), items); handler.callScript(EnumScriptType.DROP, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } @@ -103,6 +102,12 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } + public static boolean onPlayerToss(PlayerDataScript handler, EntityItem entityItem) { + PlayerEvent.TossEvent event = new PlayerEvent.TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); + handler.callScript(EnumScriptType.TOSS, event,"event", event); + return WrapperNpcAPI.EVENT_BUS.post(event); + } + public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) { PickUpEvent event = new PickUpEvent(handler.getPlayer(), new ScriptItemStack(entityItem.getEntityItem()));//NpcAPI.Instance().getIItemStack(entityItem.getEntityItem())); handler.callScript(EnumScriptType.PICKUP, event,"event", event); diff --git a/src/main/java/noppes/npcs/EventScriptContainer.java b/src/main/java/noppes/npcs/EventScriptContainer.java index cdb11a70f..a66d930b3 100644 --- a/src/main/java/noppes/npcs/EventScriptContainer.java +++ b/src/main/java/noppes/npcs/EventScriptContainer.java @@ -7,24 +7,26 @@ package noppes.npcs; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.TreeMap; +import java.util.*; import javax.script.Compilable; import javax.script.CompiledScript; +import javax.script.Invocable; import javax.script.ScriptEngine; +import cpw.mods.fml.common.eventhandler.Event; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; public class EventScriptContainer { public static EventScriptContainer Current; - public String type = "init"; + //public String type = "init"; + private static String CurrentType; public String fullscript = ""; public String script = ""; public TreeMap console = new TreeMap(); + private HashSet unknownFunctions = new HashSet(); public boolean errored = false; public List scripts = new ArrayList(); public long lastCreated = 0L; @@ -40,7 +42,7 @@ public class EventScriptContainer { public void readFromNBT(NBTTagCompound compound) { this.script = compound.getString("Script"); - this.type = compound.getString("Type"); + //this.type = compound.getString("Type"); this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10)); this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10)); this.lastCreated = 0L; @@ -48,7 +50,7 @@ public class EventScriptContainer { public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setString("Script", this.script); - compound.setString("Type", this.type); + //compound.setString("Type", this.type); compound.setTag("Console", NBTTags.NBTLongStringMap(this.console)); compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts)); return compound; @@ -74,7 +76,8 @@ public class EventScriptContainer { return this.fullscript; } - public void run(ScriptEngine engine){ + + /*public void run(ScriptEngine engine){ StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); engine.getContext().setWriter(pw); @@ -94,10 +97,51 @@ public class EventScriptContainer { appandConsole(e.getMessage()); } appandConsole(sw.getBuffer().toString().trim()); + }*/ + + public void run(EnumScriptType type, Event event) { + this.run((String)type.function, (Object)event); } - public void setType(String type) { - this.type = type; + public void run(String type, Object event) { + if (!this.errored && this.hasCode() && !this.unknownFunctions.contains(type)) { + this.setEngine(this.handler.getLanguage()); + if (this.engine != null) { + if (ScriptController.Instance.lastLoaded > this.lastCreated) { + this.lastCreated = ScriptController.Instance.lastLoaded; + this.init = false; + } + + String var3 = "lock"; + synchronized("lock") { + Current = this; + CurrentType = type; + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + this.engine.getContext().setWriter(pw); + this.engine.getContext().setErrorWriter(pw); + + try { + if (!this.init) { + this.engine.eval(this.getFullCode()); + this.init = true; + } + + ((Invocable)this.engine).invokeFunction(type, new Object[]{event}); + } catch (NoSuchMethodException var13) { + this.unknownFunctions.add(type); + } catch (Throwable var14) { + this.errored = true; + var14.printStackTrace(pw); + } finally { + this.appandConsole(sw.getBuffer().toString().trim()); + pw.close(); + Current = null; + } + + } + } + } } public void appandConsole(String message) { diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 30c74504a..53f6b0efd 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -36,6 +36,7 @@ import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.entity.EntityStruckByLightningEvent; import net.minecraftforge.event.entity.PlaySoundAtEntityEvent; +import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; @@ -223,6 +224,14 @@ public class ScriptPlayerEventHandler { } } + @SubscribeEvent + public void invoke(ItemTossEvent event) { + if(event.player.worldObj instanceof WorldServer) { + PlayerDataScript handler = PlayerData.get(event.player).scriptData; + EventHooks.onPlayerToss(handler, event.entityItem); + } + } + @SubscribeEvent public void invoke(LivingFallEvent event) { if(event.entityLiving.worldObj instanceof WorldServer) { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index d731c2685..416715b58 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -5,28 +5,40 @@ package noppes.npcs.client.gui.script; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.*; import java.util.Map.Entry; + +import com.google.common.reflect.ClassPath; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.network.FMLNetworkEvent; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiConfirmOpenLink; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.EntityEvent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.EventScriptContainer; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.swing.GuiJTextArea; import noppes.npcs.client.gui.util.*; import noppes.npcs.controllers.IScriptHandler; +import noppes.npcs.controllers.PixelmonHelper; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; +import org.apache.commons.lang3.StringUtils; public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener, ITextfieldListener { private int activeTab = 0; @@ -80,64 +92,76 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb top.active = true; if(this.activeTab > 0) { + List hookList = new ArrayList(); if(handler instanceof PlayerDataScript) { - List hookList = new ArrayList(); - hookList.add("playerscript.disabled"); - hookList.add("playerscript.init"); - hookList.add("playerscript.tick"); - hookList.add("playerscript.interact"); - hookList.add("playerscript.damagedEntity"); - hookList.add("playerscript.damaged"); - hookList.add("playerscript.kills"); - hookList.add("playerscript.killed"); - hookList.add("playerscript.drop"); - hookList.add("playerscript.respawn"); - hookList.add("playerscript.break"); - hookList.add("playerscript.chat"); - hookList.add("playerscript.login"); - hookList.add("playerscript.logout"); - hookList.add("playerscript.keyPressed"); - hookList.add("playerscript.mouseClicked"); - hookList.add("playerscript.pickUp"); - hookList.add("playerscript.pickupXP"); - hookList.add("playerscript.rangedCharge"); - hookList.add("playerscript.rangedLaunched"); - hookList.add("playerscript.timer"); - hookList.add("playerscript.startItem"); - hookList.add("playerscript.usingItem"); - hookList.add("playerscript.stopItem"); - hookList.add("playerscript.finishItem"); - hookList.add("playerscript.containerOpen"); - hookList.add("playerscript.useHoe"); - hookList.add("playerscript.bonemeal"); - hookList.add("playerscript.fillBucket"); - hookList.add("playerscript.jump"); - hookList.add("playerscript.fall"); - hookList.add("playerscript.wakeUp"); - hookList.add("playerscript.sleep"); - hookList.add("playerscript.playSound"); - hookList.add("playerscript.lightning"); - hookList.add("playerscript.changedDim"); - hookList.add("playerscript.achievement"); + hookList.add("init"); + hookList.add("tick"); + hookList.add("interact"); + hookList.add("damagedEntity"); + hookList.add("damaged"); + hookList.add("kills"); + hookList.add("killed"); + hookList.add("drop"); + hookList.add("respawn"); + hookList.add("break"); + hookList.add("chat"); + hookList.add("login"); + hookList.add("logout"); + hookList.add("keyPressed"); + hookList.add("mouseClicked"); + hookList.add("toss"); + hookList.add("pickUp"); + hookList.add("pickupXP"); + hookList.add("rangedCharge"); + hookList.add("rangedLaunched"); + hookList.add("timer"); + hookList.add("startItem"); + hookList.add("usingItem"); + hookList.add("stopItem"); + hookList.add("finishItem"); + hookList.add("containerOpen"); + hookList.add("useHoe"); + hookList.add("bonemeal"); + hookList.add("fillBucket"); + hookList.add("jump"); + hookList.add("fall"); + hookList.add("wakeUp"); + hookList.add("sleep"); + hookList.add("playSound"); + hookList.add("lightning"); + hookList.add("changedDim"); + hookList.add("achievement"); + } + else if(handler instanceof ForgeDataScript) { + hookList.add("init"); - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(hookList); - hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),hookList); - addScroll(hooks); - } - else if(handler instanceof ForgeDataScript){ - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiNpcTextField hookField = new GuiNpcTextField(1,this,this.fontRendererObj,guiLeft + 4,guiTop + 14,68,20,""); - hookField.setText(this.handler.getScripts().get(this.activeTab - 1).type); - addTextField(hookField); + ArrayList list = new ArrayList(); + try { + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); + } catch (IOException e) { + e.printStackTrace(); + } + + for(ClassPath.ClassInfo classInfo : list){ + String eventName = classInfo.getName(); + int i = eventName.lastIndexOf("."); + eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); + + hookList.add(eventName); + } } + addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft - 160, guiTop + 5)); + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.allowUserInput = false; + hooks.setSize(158, 198); + hooks.guiLeft = guiLeft - 160; + hooks.guiTop = guiTop + 14; + hooks.setUnsortedList(hookList); + addScroll(hooks); + EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + 72 + yoffset, this.guiTop + yoffset, this.xSize - 180 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); + GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + yoffset, this.guiTop + yoffset, this.xSize - 110 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); this.addTextField(left); int left1 = this.guiLeft + this.xSize - 104; this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear")); @@ -182,24 +206,24 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { - this.handler.getScripts().get(this.activeTab - 1).setType(scroll.getSelected().replace("playerscript.","")); + //this.handler.getScripts().get(this.activeTab - 1).setType(scroll.getSelected().replace("playerscript.","")); } @Override public void unFocused(GuiNpcTextField textfield) { - if(textfield.id == 1){ + /*if(textfield.id == 1){ this.handler.getScripts().get(this.activeTab - 1).setType(textfield.getText()); - } + }*/ } - private int getScriptHook(EventScriptContainer eventScriptContainer, List list) { + /*private int getScriptHook(EventScriptContainer eventScriptContainer, List list) { for(String s : list) { if (s.replace("playerscript.", "").equals(eventScriptContainer.type)) { return list.indexOf(s); } } return 0; - } + }*/ private String getConsoleText() { Map map = this.handler.getConsoleText(); diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index ddfc54063..21cf1f1e7 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -72,9 +72,6 @@ public class ForgeDataScript implements IScriptHandler { while (var3.hasNext()) { EventScriptContainer script = (EventScriptContainer) var3.next(); - if(!script.type.equals(type)) - continue; - script.setEngine(scriptLanguage); if(script.engine == null) return; @@ -86,7 +83,7 @@ public class ForgeDataScript implements IScriptHandler { ScriptEngine engine = script.engine; - script.run(engine); + script.run(type, event); } }); } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index fb93ce3d2..3919b178e 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -105,9 +105,6 @@ public class PlayerDataScript implements IScriptHandler { for(int var7 = 0; var7 < this.scripts.size(); ++var7) { script = (EventScriptContainer)this.scripts.get(var7); - if(!script.type.equals(type.function)) - continue; - if(!ScriptController.Instance.playerScripts.errored.contains(Integer.valueOf(var7))) { if(script == null || script.errored || !script.hasCode()) return; @@ -128,7 +125,7 @@ public class PlayerDataScript implements IScriptHandler { if(result == null) engine.put("event", result = new PlayerEvent(this.getPlayer())); script.engine.put("API", new WrapperNpcAPI()); - script.run(engine); + script.run(type, event); if (script.errored) { ScriptController.Instance.playerScripts.errored.add(var7); diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 2b4db24dd..b09e61128 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -249,15 +249,25 @@ public class PlayerEvent extends CustomNPCsEvent { } @Cancelable - public static class TossEvent extends PlayerEvent { + public static class DropEvent extends PlayerEvent { public final IItemStack[] items; - public TossEvent(IPlayer player, IItemStack[] items) { + public DropEvent(IPlayer player, IItemStack[] items) { super(player); this.items = items; } } + @Cancelable + public static class TossEvent extends PlayerEvent { + public final IItemStack item; + + public TossEvent(IPlayer player, IItemStack item) { + super(player); + this.item = item; + } + } + @Cancelable public static class AttackEvent extends PlayerEvent { public final int type; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 8be11f8ff..a42be9058 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -483,6 +483,7 @@ playerscript.logout=Logout playerscript.pickUp=Pickup playerscript.rangedCharge=Arrow Charge playerscript.rangedLaunched=Arrow Launched +playerscript.toss=Toss Item playerscript.drop=Drop Items playerscript.tick=Update playerscript.pickupXP=Pickup XP From f88cbb8b51ad5f386c2053eb9fd6bc7ebd150872 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 19 Oct 2021 02:49:46 -0500 Subject: [PATCH 32/58] Server-side compatibility changes --- src/main/java/noppes/npcs/CommonProxy.java | 40 ++-- src/main/java/noppes/npcs/EventHooks.java | 4 +- .../noppes/npcs/ScriptPlayerEventHandler.java | 4 +- .../java/noppes/npcs/client/ClientProxy.java | 205 +++++++++--------- .../client/gui/script/GuiScriptInterface.java | 5 +- .../noppes/npcs/constants/EnumScriptType.java | 4 +- .../npcs/controllers/ScriptController.java | 69 +++--- .../npcs/scripted/entity/ScriptEntity.java | 98 +++++---- .../assets/customnpcs/lang/en_US.lang | 13 +- 9 files changed, 230 insertions(+), 212 deletions(-) diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index c722656df..75a06e5d3 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -5,6 +5,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.Item; +import net.minecraft.stats.Achievement; import net.minecraft.world.World; import noppes.npcs.blocks.tiles.TileNpcContainer; import noppes.npcs.constants.EnumGuiType; @@ -60,31 +61,31 @@ public class CommonProxy implements IGuiHandler { if(gui == EnumGuiType.PlayerBankSmall) return new ContainerNPCBankSmall(player, x , y); - + if(gui == EnumGuiType.PlayerBankUnlock) return new ContainerNPCBankUnlock(player, x , y); if(gui == EnumGuiType.PlayerBankUprade) return new ContainerNPCBankUpgrade(player, x , y); - + if(gui == EnumGuiType.PlayerBankLarge) return new ContainerNPCBankLarge(player, x , y); if(gui == EnumGuiType.PlayerFollowerHire) return new ContainerNPCFollowerHire(npc, player); - + if(gui == EnumGuiType.PlayerFollower) return new ContainerNPCFollower(npc, player); - + if(gui == EnumGuiType.PlayerTrader) return new ContainerNPCTrader(npc, player); if(gui == EnumGuiType.PlayerAnvil) return new ContainerCarpentryBench(player.inventory, player.worldObj, x, y, z); - + if(gui == EnumGuiType.SetupItemGiver) return new ContainerNpcItemGiver(npc, player); - + if(gui == EnumGuiType.SetupTrader) return new ContainerNPCTraderSetup(npc, player); @@ -93,10 +94,10 @@ public class CommonProxy implements IGuiHandler { if(gui == EnumGuiType.QuestReward) return new ContainerNpcQuestReward(player); - + if(gui == EnumGuiType.QuestItem) return new ContainerNpcQuestTypeItem(player); - + if(gui == EnumGuiType.ManageRecipes) return new ContainerManageRecipes(player,x); @@ -108,13 +109,13 @@ public class CommonProxy implements IGuiHandler { if(gui == EnumGuiType.Crate) return new ContainerCrate(player.inventory, (TileNpcContainer)player.worldObj.getTileEntity(x, y, z)); - + if(gui == EnumGuiType.PlayerMailman) return new ContainerMail(player, x == 1, y == 1); - + if(gui == EnumGuiType.CompanionInv) return new ContainerNPCCompanion(npc, player); - + return null; } @@ -134,17 +135,17 @@ public class CommonProxy implements IGuiHandler { public void openGui(int i, int j, int k, EnumGuiType gui, EntityPlayer player) { - + } public void openGui(EntityPlayer player, Object guiscreen) { // TODO Auto-generated method stub - + } public void spawnParticle(EntityLivingBase player, String string, Object... ob) { // TODO Auto-generated method stub - + } public boolean hasClient() { @@ -157,7 +158,7 @@ public class CommonProxy implements IGuiHandler { public void registerItem(Item item) { // TODO Auto-generated method stub - + } public ModelBiped getSkirtModel() { @@ -165,8 +166,11 @@ public class CommonProxy implements IGuiHandler { } public void spawnParticle(String particle, double x, double y, double z, - double motionX, double motionY, double motionZ, float scale) { - + double motionX, double motionY, double motionZ, float scale) { + } -} + public String getAchievementDesc(Achievement achievement) { + return ""; + } +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index a4739700e..d3a5368a8 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -263,7 +263,7 @@ public class EventHooks { } public static boolean onPlayerBreak(PlayerDataScript handler, PlayerEvent.BreakEvent event) { - handler.callScript(EnumScriptType.BREAK, event,"event", event); + handler.callScript(EnumScriptType.BREAK_BLOCK, event,"event", event); return WrapperNpcAPI.EVENT_BUS.post(event); } @@ -303,4 +303,4 @@ public class EventHooks { } } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 53f6b0efd..2841cf20a 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -220,7 +220,7 @@ public class ScriptPlayerEventHandler { public void invoke(AchievementEvent event) { if(event.entityPlayer.worldObj instanceof WorldServer) { PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData; - EventHooks.onPlayerAchievement(handler, event.achievement.getDescription()); + EventHooks.onPlayerAchievement(handler, CustomNpcs.proxy.getAchievementDesc(event.achievement)); } } @@ -450,4 +450,4 @@ public class ScriptPlayerEventHandler { } } } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index f07d3541e..59601e3f3 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -21,6 +21,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.Item; +import net.minecraft.stats.Achievement; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; @@ -158,9 +159,9 @@ import cpw.mods.fml.common.ObfuscationReflectionHelper; public class ClientProxy extends CommonProxy { public static KeyBinding QuestLog; - + public static FontContainer Font; - + public void load() { Font = new FontContainer(CustomNpcs.FontType, CustomNpcs.FontSize); createFolders(); @@ -210,43 +211,43 @@ public class ClientProxy extends CommonProxy { RenderingRegistry.registerBlockHandler(new BlockBloodRenderer()); } Minecraft mc = Minecraft.getMinecraft(); - + QuestLog = new KeyBinding("Quest Log", Keyboard.KEY_L, "key.categories.gameplay"); - + ClientRegistry.registerKeyBinding(QuestLog); mc.gameSettings.loadOptions(); - + new PresetController(CustomNpcs.Dir); - + if(CustomNpcs.EnableUpdateChecker){ VersionChecker checker = new VersionChecker(); checker.start(); } - + ClientCloneController.Instance = new ClientCloneController(); - MinecraftForge.EVENT_BUS.register(new ClientEventHandler()); - - if(CustomNpcs.InventoryGuiEnabled){ - MinecraftForge.EVENT_BUS.register(new TabRegistry()); - - if (TabRegistry.getTabList().size() < 2){ - TabRegistry.registerTab(new InventoryTabVanilla()); - } - TabRegistry.registerTab(new InventoryTabFactions()); - TabRegistry.registerTab(new InventoryTabQuests()); - } + MinecraftForge.EVENT_BUS.register(new ClientEventHandler()); + + if(CustomNpcs.InventoryGuiEnabled){ + MinecraftForge.EVENT_BUS.register(new TabRegistry()); + + if (TabRegistry.getTabList().size() < 2){ + TabRegistry.registerTab(new InventoryTabVanilla()); + } + TabRegistry.registerTab(new InventoryTabFactions()); + TabRegistry.registerTab(new InventoryTabQuests()); + } } private void createFolders() { File file = new File(CustomNpcs.Dir,"assets/customnpcs"); if(!file.exists()) file.mkdirs(); - + File check = new File(file,"sounds"); if(!check.exists()) check.mkdir(); - + File json = new File(file, "sounds.json"); if(!json.exists()){ try { @@ -261,7 +262,7 @@ public class ClientProxy extends CommonProxy { check = new File(file,"textures"); if(!check.exists()) check.mkdir(); - + File cache = new File(check,"cache"); if(!cache.exists()) cache.mkdir(); @@ -284,7 +285,7 @@ public class ClientProxy extends CommonProxy { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - + if (ID > EnumGuiType.values().length) return null; EnumGuiType gui = EnumGuiType.values()[ID]; @@ -293,6 +294,8 @@ public class ClientProxy extends CommonProxy { return getGui(npc, gui, container, x, y, z); } + + private GuiScreen getGui(EntityNPCInterface npc, EnumGuiType gui, Container container, int x, int y, int z) { if (gui == EnumGuiType.MainMenuDisplay){ if(npc != null) @@ -311,16 +314,16 @@ public class ClientProxy extends CommonProxy { else if(gui == EnumGuiType.QuestReward) return new GuiNpcQuestReward(npc, (ContainerNpcQuestReward) container); - + else if(gui == EnumGuiType.QuestItem) return new GuiNpcQuestTypeItem(npc, (ContainerNpcQuestTypeItem) container); - + else if (gui == EnumGuiType.MovingPath) return new GuiNpcPather(npc); else if (gui == EnumGuiType.ManageFactions) return new GuiNPCManageFactions(npc); - + else if (gui == EnumGuiType.ManageLinked) return new GuiNPCManageLinkedNpc(npc); @@ -329,15 +332,15 @@ public class ClientProxy extends CommonProxy { else if (gui == EnumGuiType.ManageRecipes) return new GuiNpcManageRecipes(npc,(ContainerManageRecipes) container); - + else if (gui == EnumGuiType.ManageDialogs) return new GuiNPCManageDialogs(npc); - + else if (gui == EnumGuiType.ManageQuests) return new GuiNPCManageQuest(npc); - + else if(gui == EnumGuiType.ManageBanks) - return new GuiNPCManageBanks(npc,(ContainerManageBanks) container); + return new GuiNPCManageBanks(npc,(ContainerManageBanks) container); else if (gui == EnumGuiType.MainMenuGlobal) return new GuiNPCGlobalMainMenu(npc); @@ -350,37 +353,37 @@ public class ClientProxy extends CommonProxy { else if (gui == EnumGuiType.PlayerFollower) return new GuiNpcFollower(npc, (ContainerNPCFollower) container); - + else if(gui == EnumGuiType.PlayerTrader) return new GuiNPCTrader(npc, (ContainerNPCTrader) container); - + else if(gui == EnumGuiType.PlayerBankSmall || gui == EnumGuiType.PlayerBankUnlock || gui == EnumGuiType.PlayerBankUprade || gui == EnumGuiType.PlayerBankLarge) return new GuiNPCBankChest(npc, (ContainerNPCBankInterface) container); else if(gui == EnumGuiType.PlayerTransporter) return new GuiTransportSelection(npc); - + else if(gui == EnumGuiType.Script) return new GuiScript(npc); - + else if(gui == EnumGuiType.PlayerAnvil) return new GuiNpcCarpentryBench((ContainerCarpentryBench) container); - + else if (gui == EnumGuiType.SetupFollower) return new GuiNpcFollowerSetup(npc, (ContainerNPCFollowerSetup) container); - + else if (gui == EnumGuiType.SetupItemGiver) return new GuiNpcItemGiver(npc, (ContainerNpcItemGiver) container); - + else if(gui == EnumGuiType.SetupTrader) return new GuiNpcTraderSetup(npc, (ContainerNPCTraderSetup) container); else if(gui == EnumGuiType.SetupTransporter) return new GuiNpcTransporter(npc); - + else if(gui == EnumGuiType.SetupBank) return new GuiNpcBankSetup(npc); - + else if(gui == EnumGuiType.NpcRemote && Minecraft.getMinecraft().currentScreen == null) return new GuiNpcRemoteEditor(); @@ -389,48 +392,48 @@ public class ClientProxy extends CommonProxy { else if(gui == EnumGuiType.PlayerMailman) return new GuiMailmanWrite((ContainerMail) container, x == 1, y == 1); - + else if(gui == EnumGuiType.PlayerMailbox) return new GuiMailbox(); - + else if(gui == EnumGuiType.MerchantAdd) return new GuiMerchantAdd(); - + else if(gui == EnumGuiType.Crate) return new GuiCrate((ContainerCrate)container); else if(gui == EnumGuiType.NpcDimensions) return new GuiNpcDimension(); - + else if(gui == EnumGuiType.Border) return new GuiBorderBlock(x, y, z); else if(gui == EnumGuiType.BigSign) return new GuiBigSign(x, y, z); - + else if (gui == EnumGuiType.RedstoneBlock) return new GuiNpcRedstoneBlock(x, y, z); - + else if(gui == EnumGuiType.MobSpawner) return new GuiNpcMobSpawner(x, y, z); - + else if(gui == EnumGuiType.MobSpawnerMounter) return new GuiNpcMobSpawnerMounter(x, y, z); else if (gui == EnumGuiType.Waypoint) return new GuiNpcWaypoint(x, y, z); - + else if (gui == EnumGuiType.Companion) return new GuiNpcCompanionStats(npc); - + else if (gui == EnumGuiType.CompanionTalent) return new GuiNpcCompanionTalents(npc); - + else if (gui == EnumGuiType.CompanionInv) return new GuiNpcCompanionInv(npc, (ContainerNPCCompanion) container); return null; } - + @Override public void openGui(int i, int j, int k, EnumGuiType gui, EntityPlayer player) { Minecraft minecraft = Minecraft.getMinecraft(); @@ -438,7 +441,7 @@ public class ClientProxy extends CommonProxy { return; GuiScreen guiscreen = getGui(null, gui, null, i, j, k); - + if (guiscreen != null) { minecraft.displayGuiScreen(guiscreen); @@ -469,7 +472,7 @@ public class ClientProxy extends CommonProxy { if (guiscreen != null) { minecraft.displayGuiScreen((GuiScreen)guiscreen); } - + } @Override @@ -477,18 +480,18 @@ public class ClientProxy extends CommonProxy { if(string.equals("Spell")){ int color = (Integer) ob[0]; int number = (Integer) ob[1]; - for(int i = 0; i < number; i++){ - Random rand = player.worldObj.rand; + for(int i = 0; i < number; i++){ + Random rand = player.worldObj.rand; double x = (rand.nextDouble() - 0.5D) * (double)player.width; double y = player.getEyeHeight(); double z = (rand.nextDouble() - 0.5D) * (double)player.width; - - double f = (rand.nextDouble() - 0.5D) * 2D; - double f1 = -rand.nextDouble(); - double f2 = (rand.nextDouble() - 0.5D) * 2D; - - Minecraft.getMinecraft().effectRenderer.addEffect(new EntityElementalStaffFX(player, x, y, z, f, f1, f2, color)); - } + + double f = (rand.nextDouble() - 0.5D) * 2D; + double f1 = -rand.nextDouble(); + double f2 = (rand.nextDouble() - 0.5D) * 2D; + + Minecraft.getMinecraft().effectRenderer.addEffect(new EntityElementalStaffFX(player, x, y, z, f, f1, f2, color)); + } } else if(string.equals("ModelData")){ ModelData data = (ModelData) ob[0]; @@ -502,21 +505,21 @@ public class ClientProxy extends CommonProxy { EntityEnderFX fx = new EntityEnderFX(npc, (rand.nextDouble() - 0.5D) * (double)player.width, (rand.nextDouble() * (double)player.height) - height - 0.25D, (rand.nextDouble() - 0.5D) * (double)player.width, (rand.nextDouble() - 0.5D) * 2D, -rand.nextDouble(), (rand.nextDouble() - 0.5D) * 2D, particles); minecraft.effectRenderer.addEffect(fx); } - + } else if(particles.type == 1){ - for(int i = 0; i < 2; i++){ - double x = player.posX + (rand.nextDouble() - 0.5D) * 0.9; - double y = (player.posY + rand.nextDouble() * 1.9) - 0.25D - height; - double z = player.posZ + (rand.nextDouble() - 0.5D) * 0.9; - - - double f = (rand.nextDouble() - 0.5D) * 2D; - double f1 = -rand.nextDouble(); - double f2 = (rand.nextDouble() - 0.5D) * 2D; - - minecraft.effectRenderer.addEffect(new EntityRainbowFX(player.worldObj, x, y, z, f, f1, f2)); - } + for(int i = 0; i < 2; i++){ + double x = player.posX + (rand.nextDouble() - 0.5D) * 0.9; + double y = (player.posY + rand.nextDouble() * 1.9) - 0.25D - height; + double z = player.posZ + (rand.nextDouble() - 0.5D) * 0.9; + + + double f = (rand.nextDouble() - 0.5D) * 2D; + double f1 = -rand.nextDouble(); + double f2 = (rand.nextDouble() - 0.5D) * 2D; + + minecraft.effectRenderer.addEffect(new EntityRainbowFX(player.worldObj, x, y, z, f, f1, f2)); + } } } } @@ -529,7 +532,7 @@ public class ClientProxy extends CommonProxy { public boolean hasClient() { return true; } - + public EntityPlayer getPlayer() { return Minecraft.getMinecraft().thePlayer; } @@ -544,54 +547,58 @@ public class ClientProxy extends CommonProxy { try{ if(location == null) return; - TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); - if(location != null) - texturemanager.bindTexture((ResourceLocation) location); + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + if(location != null) + texturemanager.bindTexture((ResourceLocation) location); } catch(NullPointerException ex){ - + } catch(ReportedException ex){ - + } } @Override public void spawnParticle(String particle, double x, double y, double z, - double motionX, double motionY, double motionZ, float scale) { - + double motionX, double motionY, double motionZ, float scale) { + RenderGlobal render = Minecraft.getMinecraft().renderGlobal; - + EntityFX fx = render.doSpawnParticle(particle, x, y, z, motionX, motionY, motionZ); if(fx == null) return; - if (particle.equals("flame")){ - ObfuscationReflectionHelper.setPrivateValue(EntityFlameFX.class, (EntityFlameFX)fx, scale, 0); - } - else if (particle.equals("smoke")){ - ObfuscationReflectionHelper.setPrivateValue(EntitySmokeFX.class, (EntitySmokeFX)fx, scale, 0); - } + if (particle.equals("flame")){ + ObfuscationReflectionHelper.setPrivateValue(EntityFlameFX.class, (EntityFlameFX)fx, scale, 0); + } + else if (particle.equals("smoke")){ + ObfuscationReflectionHelper.setPrivateValue(EntitySmokeFX.class, (EntitySmokeFX)fx, scale, 0); + } + } + + @Override + public String getAchievementDesc(Achievement achievement) { + return achievement.getDescription(); } - public static class FontContainer { private StringCache textFont = null; public boolean useCustomFont = true; - + private FontContainer(){ - + } - + public FontContainer(String fontType, int fontSize) { textFont = new StringCache(); textFont.setDefaultFont("Arial", fontSize, true); useCustomFont = !fontType.equalsIgnoreCase("minecraft"); - try { - if(!useCustomFont || fontType.isEmpty() || fontType.equalsIgnoreCase("default")) - textFont.setCustomFont(new ResourceLocation("customnpcs","OpenSans.ttf"), fontSize, true); - else - textFont.setDefaultFont(fontType, fontSize, true); + try { + if(!useCustomFont || fontType.isEmpty() || fontType.equalsIgnoreCase("default")) + textFont.setCustomFont(new ResourceLocation("customnpcs","OpenSans.ttf"), fontSize, true); + else + textFont.setDefaultFont(fontType, fontSize, true); } catch (Exception e) { LogWriter.info("Failed loading font so using Arial"); } @@ -602,7 +609,7 @@ public class ClientProxy extends CommonProxy { return textFont.fontHeight; return Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT; } - + public int width(String text){ if(useCustomFont) return textFont.getStringWidth(text); @@ -632,4 +639,4 @@ public class ClientProxy extends CommonProxy { return textFont.usedFont().getFontName(); } } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 416715b58..4b7df1106 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -103,7 +103,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hookList.add("killed"); hookList.add("drop"); hookList.add("respawn"); - hookList.add("break"); + hookList.add("breakBlock"); hookList.add("chat"); hookList.add("login"); hookList.add("logout"); @@ -130,7 +130,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hookList.add("playSound"); hookList.add("lightning"); hookList.add("changedDim"); - hookList.add("achievement"); } else if(handler instanceof ForgeDataScript) { hookList.add("init"); @@ -418,4 +417,4 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb container.script = text; initGui(); } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index a45721633..dc545d999 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -72,7 +72,7 @@ public enum EnumScriptType { PLAYSOUND("playSound"), RESPAWN("respawn"), CHANGED_DIM("changedDim"), - BREAK("break"), + BREAK_BLOCK("breakBlock"), FORGE_INIT("forgeInit"), FORGE_ENTITY("forgeEntity"), FORGE_WORLD("forgeWorld"); @@ -82,4 +82,4 @@ public enum EnumScriptType { private EnumScriptType(String function) { this.function = function; } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 2d6a501db..83415bd1a 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -44,7 +44,7 @@ import noppes.npcs.util.NBTJsonUtil; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class ScriptController { - + public static ScriptController Instance; public static boolean HasStart = false; private ScriptEngineManager manager; @@ -184,39 +184,40 @@ public class ScriptController { } } public boolean loadStoredData(){ - loadCategories(); - File file = getSavedFile(); - try { - if(!file.exists()) - return false; - this.compound = NBTJsonUtil.LoadFile(file); - shouldSave = false; - } - catch (Exception e) { + loadCategories(); + File file = getSavedFile(); + try { + if(!file.exists()) + return false; + this.compound = NBTJsonUtil.LoadFile(file); + shouldSave = false; + } + catch (Exception e) { LogWriter.error("Error loading: " + file.getAbsolutePath(), e); - return false; - } - return true; + return false; + } + return true; } - + private File getSavedFile(){ return new File(dir, "world_data.json"); } - private String readFile(File file) throws IOException { - BufferedReader br = new BufferedReader(new FileReader(file)); - try { - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null) { - sb.append(line); - sb.append("\n"); - line = br.readLine(); - } - return sb.toString(); - } finally { - br.close(); - } + private String readFile(File file) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(file)); + try { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } finally { + br.close(); + } } public ScriptEngine getEngineByName(String language) { @@ -237,7 +238,7 @@ public class ScriptController { } return list; } - + private List getScripts(String language){ List list = new ArrayList(); String ext = languages.get(language); @@ -283,14 +284,14 @@ public class ScriptController { public void saveWorld(WorldEvent.Save event){ if(!shouldSave || event.world.isRemote || event.world != MinecraftServer.getServer().worldServers[0]) return; - + try { NBTJsonUtil.SaveFile(getSavedFile(), compound); - } + } catch (Exception e) { LogWriter.except(e); - } - + } + shouldSave = false; } -} +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index c50b7be1a..641fb837c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -98,35 +98,35 @@ public class ScriptEntity implements IEntity { public double getX(){ return entity.posX; } - + /** * @param x The entities x position */ public void setX(double x){ entity.posX = x; } - + /** * @return The entities y position */ public double getY(){ return entity.posY; } - + /** * @param y The entities y position */ public void setY(double y){ entity.posY = y; } - + /** * @return The entities x position */ public double getZ(){ return entity.posZ; } - + /** * @param z The entities x position */ @@ -154,7 +154,7 @@ public class ScriptEntity implements IEntity { public int getBlockZ(){ return MathHelper.floor_double(entity.posZ); } - + /** * @param x The x position * @param y The y position @@ -164,7 +164,7 @@ public class ScriptEntity implements IEntity { entity.setPosition(x, y, z); } - + /** * @param range The search range for entities around this entity * @return Array of entities within range @@ -178,7 +178,7 @@ public class ScriptEntity implements IEntity { } return list.toArray(new ScriptEntity[list.size()]); } - + /** * @param range The search range for entities around this entity * @param type The EntityType you want to find @@ -196,7 +196,7 @@ public class ScriptEntity implements IEntity { cls = EntityMob.class; else if(type == EntityType.NPC) cls = EntityNPCInterface.class; - + List entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range)); List list = new ArrayList(); for(Entity living : entities){ @@ -204,16 +204,16 @@ public class ScriptEntity implements IEntity { list.add(ScriptController.Instance.getScriptForEntity(living)); } return list.toArray(new ScriptEntity[list.size()]); - } + } + - /** * @return Whether the entity is alive or not */ public boolean isAlive(){ return entity.isEntityAlive(); } - + /** * @param key Get temp data for this key * @return Returns the stored temp data @@ -221,7 +221,7 @@ public class ScriptEntity implements IEntity { public Object getTempData(String key){ return tempData.get(key); } - + /** * Tempdata gets cleared when the entity gets unloaded or the world restarts * @param key The key for the data stored @@ -230,7 +230,7 @@ public class ScriptEntity implements IEntity { public void setTempData(String key, Object value){ tempData.put(key, value); } - + /** * @param key The key thats going to be tested against the temp data * @return Whether or not temp data containes the key @@ -238,21 +238,21 @@ public class ScriptEntity implements IEntity { public boolean hasTempData(String key){ return tempData.containsKey(key); } - + /** * @param key The key for the temp data to be removed */ public void removeTempData(String key){ tempData.remove(key); } - + /** * Remove all tempdata */ public void clearTempData(){ tempData.clear(); } - + /** * @param key The key of the data to be returned * @return Returns the stored data @@ -266,7 +266,7 @@ public class ScriptEntity implements IEntity { return ((NBTPrimitive)base).func_150286_g(); return ((NBTTagString)base).func_150285_a_(); } - + /** * Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved * @param key The key for the data stored @@ -281,7 +281,7 @@ public class ScriptEntity implements IEntity { compound.setString(key, (String)value); saveStoredCompound(compound); } - + /** * @param key The key of the data to be checked * @return Returns whether or not the stored data contains the key @@ -289,7 +289,7 @@ public class ScriptEntity implements IEntity { public boolean hasStoredData(String key){ return getStoredCompound().hasKey(key); } - + /** * @param key The key of the data to be removed */ @@ -298,74 +298,74 @@ public class ScriptEntity implements IEntity { compound.removeTag(key); saveStoredCompound(compound); } - + /** * Remove all stored data */ public void clearStoredData(){ entity.getEntityData().removeTag("CNPCStoredData"); } - + private NBTTagCompound getStoredCompound(){ NBTTagCompound compound = entity.getEntityData().getCompoundTag("CNPCStoredData"); if(compound == null) entity.getEntityData().setTag("CNPCStoredData", compound = new NBTTagCompound()); return compound; } - + private void saveStoredCompound(NBTTagCompound compound){ entity.getEntityData().setTag("CNPCStoredData", compound); } - + /** * @return The age of this entity in ticks */ public long getAge(){ return entity.ticksExisted; } - + /** * Despawns this entity. Removes it permanently */ public void despawn(){ entity.isDead = true; } - + /** * @return Return whether or not this entity is standing in water */ public boolean inWater(){ return entity.isInsideOfMaterial(Material.water); } - + /** * @return Return whether or not this entity is standing in lava */ public boolean inLava(){ return entity.isInsideOfMaterial(Material.lava); } - + /** * @return Return whether or not this entity is standing in fire */ public boolean inFire(){ return entity.isInsideOfMaterial(Material.fire); } - + /** * @return Return whether or not this entity is on fire */ public boolean isBurning(){ return entity.isBurning(); } - + /** * @param ticks Amount of world ticks this entity will burn. 20 ticks equals 1 second */ public void setBurning(int ticks){ entity.setFire(ticks); } - + /** * Removes fire from this entity */ @@ -379,7 +379,7 @@ public class ScriptEntity implements IEntity { public String getTypeName(){ return EntityList.getEntityString(entity); } - + /** * @param item Item to be dropped */ @@ -393,7 +393,7 @@ public class ScriptEntity implements IEntity { public ScriptEntity getRider(){ return ScriptController.Instance.getScriptForEntity(entity.riddenByEntity); } - + /** * @param entity The entity to ride this entity */ @@ -411,7 +411,7 @@ public class ScriptEntity implements IEntity { public ScriptEntity getMount(){ return ScriptController.Instance.getScriptForEntity(entity.ridingEntity); } - + /** * @param entity The entity this entity will mount */ @@ -429,7 +429,7 @@ public class ScriptEntity implements IEntity { public int getType(){ return EntityType.UNKNOWN; } - + /** * @since 1.7.10c * @param type @EntityType to check @@ -438,33 +438,39 @@ public class ScriptEntity implements IEntity { public boolean typeOf(int type){ return type == EntityType.UNKNOWN; } - + /** * @param rotation The rotation to be set (0-360) */ public void setRotation(float rotation){ entity.rotationYaw = rotation; } - + /** * @return Current rotation of the npc */ public float getRotation(){ return entity.rotationYaw; } - + /** * @param power How strong the knockback is * @param direction The direction in which he flies back (0-360). Usually based on getRotation() */ public void knockback(int power, float direction){ float v = direction * (float)Math.PI / 180.0F; - entity.addVelocity(-MathHelper.sin(v) * (float)power, 0.1D + power * 0.04f, MathHelper.cos(v) * (float)power); - entity.motionX *= 0.6D; - entity.motionZ *= 0.6D; - entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); + entity.addVelocity(-MathHelper.sin(v) * (float)power, 0.1D + power * 0.04f, MathHelper.cos(v) * (float)power); + entity.motionX *= 0.6D; + entity.motionZ *= 0.6D; + entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); } - + + public void knockback(int xpower, int ypower, int zpower, float direction){ + float v = direction * (float)Math.PI / 180.0F; + entity.addVelocity(-MathHelper.sin(v) * (float)xpower, 0.1D + ypower * 0.04f, MathHelper.cos(v) * (float)zpower); + entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); + } + /** * @since 1.7.10c * @return Returns whether or not this entity is sneaking @@ -472,7 +478,7 @@ public class ScriptEntity implements IEntity { public boolean isSneaking(){ return entity.isSneaking(); } - + /** * @since 1.7.10c * @return Returns whether or not this entity is sprinting @@ -480,7 +486,7 @@ public class ScriptEntity implements IEntity { public boolean isSprinting(){ return entity.isSprinting(); } - + /** * @since 1.7.10c * Expert users only @@ -506,4 +512,4 @@ public class ScriptEntity implements IEntity { ServerCloneController.Instance.addClone(compound, name, tab); } } -} +} \ No newline at end of file diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index a42be9058..ba4b81182 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -117,6 +117,7 @@ gui.update=Update gui.disabled=Disabled gui.editor=Editor gui.playernearby=Player nearby +gui.forum=Forum remote.title=Nearby NPCs remote.reset=Reset @@ -145,7 +146,7 @@ mailbox.name=Mailbox mailbox.sender=Sender mailbox.read=Read mailbox.timesend=%s ago -mailbox.day=day +mailbox.day=day mailbox.days=days mailbox.hour=hour mailbox.hours=hours @@ -376,7 +377,7 @@ follower.lastday=Last day follower.day=Day follower.days=Days follower.hireText=Thank you for hiring me for -follower.farewellText=My days with you are over. Farewell +follower.farewellText=My days with you are over. Farewell follower.infiniteDays=Infinite Days follower.guiDisabled=GuiDisabled follower.allowSoulstone=AllowSoulstone @@ -442,6 +443,9 @@ quest.exp=Exp quest.takeitems=Take Items quest.objectives=Objectives +script.apidoc=API Docs +script.apisrc=API Source + script.scripts=Scripts script.hooks=Hooks script.loadscript=Load Scripts @@ -465,7 +469,7 @@ eventscript.playerevent=Player Events playerscript.disabled=Disabled playerscript.attack=Attack -playerscript.break=Break +playerscript.breakBlock=Break playerscript.chat=Chat playerscript.containerclosed=Closed Container playerscript.containerOpen=Open Container @@ -506,9 +510,6 @@ playerscript.fillBucket=Fill Bucket playerscript.bonemeal=Bonemeal playerscript.achievement=Achievement - -forgescript.forgeInit=Init - item.npcWand.name=Npc Wand item.npcMobCloner.name=Mob Cloner item.npcMovingPath.name=Npc Pather From 40e738384fde8bc42595f140ceb46feacc0fb19f Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 19 Oct 2021 03:44:41 -0500 Subject: [PATCH 33/58] Disabled invulnerability during knockback() for ScriptEntity. --- src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 641fb837c..f52538367 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -463,12 +463,14 @@ public class ScriptEntity implements IEntity { entity.motionX *= 0.6D; entity.motionZ *= 0.6D; entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); + entity.hurtResistantTime = 0; } public void knockback(int xpower, int ypower, int zpower, float direction){ float v = direction * (float)Math.PI / 180.0F; entity.addVelocity(-MathHelper.sin(v) * (float)xpower, 0.1D + ypower * 0.04f, MathHelper.cos(v) * (float)zpower); entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); + entity.hurtResistantTime = 0; } /** From b15f5221fda27e54f9346c8e05c7822be5f22382 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 19 Oct 2021 14:48:59 -0500 Subject: [PATCH 34/58] Added getAllNbt function to ScriptEntity. --- src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index f52538367..41d438434 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -502,6 +502,12 @@ public class ScriptEntity implements IEntity { return NpcAPI.Instance().getINbt(this.entity.getEntityData()); } + public INbt getAllNbt() { + NBTTagCompound compound = new NBTTagCompound(); + this.entity.writeToNBT(compound); + return NpcAPI.Instance().getINbt(compound); + } + public void setNbt(INbt nbt) { this.entity.readFromNBT(nbt.getMCNBT()); } From 8b710ed5207d7e20ff0fb64944ea836e7b975d8a Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 19 Oct 2021 16:59:09 -0500 Subject: [PATCH 35/58] Fixed executeCommand() function for scripting API. --- src/main/java/noppes/npcs/scripted/ScriptWorld.java | 4 ++-- src/main/java/noppes/npcs/scripted/interfaces/IWorld.java | 3 ++- src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 60d1390a0..7ee5ba757 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -359,7 +359,7 @@ public class ScriptWorld implements IWorld { * Expert use only * @return Returns minecraft world object */ - public World getMCWorld(){ - return world; + public WorldServer getMCWorld(){ + return this.world; } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 1f9e1c0c9..ef12df261 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -2,6 +2,7 @@ package noppes.npcs.scripted.interfaces; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import noppes.npcs.scripted.*; import noppes.npcs.scripted.entity.ScriptEntity; import noppes.npcs.scripted.entity.ScriptPlayer; @@ -208,5 +209,5 @@ public interface IWorld { * Expert use only * @return Returns minecraft world object */ - public World getMCWorld(); + public WorldServer getMCWorld(); } diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 95501992b..220a2989f 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -7,7 +7,9 @@ package noppes.npcs.scripted.wrapper; import java.io.File; import java.util.Map; +import java.util.UUID; +import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.eventhandler.EventBus; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -173,7 +175,7 @@ public class WrapperNpcAPI extends NpcAPI { } public String executeCommand(IWorld world, String command) { - FakePlayer player = EntityNPCInterface.CommandPlayer; + FakePlayer player = new FakePlayer(world.getMCWorld(), new GameProfile(new UUID(0L,0L), "CommandPlayer")); player.setWorld(world.getMCWorld()); player.setPosition(0.0D, 0.0D, 0.0D); return NoppesUtilServer.runCommand(world.getMCWorld(), BlockPos.ORIGIN, "API", command, (EntityPlayer)null, player); From 5515f5ef8325c6cfe48006791abec3c57962a7d5 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 19 Oct 2021 19:49:43 -0500 Subject: [PATCH 36/58] Fixed executeCommand() function for scripting API on the server-side. --- src/main/java/noppes/npcs/CommonProxy.java | 5 +++++ src/main/java/noppes/npcs/NoppesUtilServer.java | 16 +++++----------- .../java/noppes/npcs/client/ClientProxy.java | 6 ++++++ .../noppes/npcs/entity/EntityNPCInterface.java | 5 ++--- src/main/java/noppes/npcs/scripted/NpcAPI.java | 4 +++- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 9 ++++----- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index 75a06e5d3..1964503da 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -7,6 +7,7 @@ import net.minecraft.inventory.Container; import net.minecraft.item.Item; import net.minecraft.stats.Achievement; import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.blocks.tiles.TileNpcContainer; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.containers.ContainerCarpentryBench; @@ -30,8 +31,10 @@ import noppes.npcs.containers.ContainerNpcItemGiver; import noppes.npcs.containers.ContainerNpcQuestReward; import noppes.npcs.containers.ContainerNpcQuestTypeItem; import noppes.npcs.controllers.PlayerData; +import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import cpw.mods.fml.common.network.IGuiHandler; +import noppes.npcs.scripted.interfaces.IWorld; public class CommonProxy implements IGuiHandler { @@ -148,6 +151,8 @@ public class CommonProxy implements IGuiHandler { } + public FakePlayer getCommandPlayer(IWorld world) { return null; } + public boolean hasClient() { return false; } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 1cbd5fa70..e2b7e0621 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -221,23 +221,17 @@ public class NoppesUtilServer { logic.func_145755_a(executer.worldObj); } - public static String runCommand(final World world, final BlockPos pos, final String name, String command, EntityPlayer player, final ICommandSender executer) { - if (player != null) { - command = command.replace("@dp", player.getDisplayName()); - } - + public static void runCommand(World world, String name, String command) { TileEntityCommandBlock tile = new TileEntityCommandBlock(); - tile.setWorldObj(world); - tile.xCoord = MathHelper.floor_double(pos.getX()); - tile.yCoord = MathHelper.floor_double(pos.getY()); - tile.zCoord = MathHelper.floor_double(pos.getZ()); + tile.setWorldObj(world.provider.worldObj); + tile.xCoord = 0; + tile.yCoord = 0; + tile.zCoord = 0; CommandBlockLogic logic = tile.func_145993_a(); logic.func_145752_a(command); logic.func_145754_b("@"+name); logic.func_145755_a(world); - - return logic.func_145749_h().getUnformattedText(); } public static void consumeItemStack(int i, EntityPlayer player){ diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 59601e3f3..58ab042df 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -28,6 +28,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.CommonProxy; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; @@ -146,6 +147,7 @@ import noppes.npcs.containers.ContainerNpcQuestTypeItem; import noppes.npcs.controllers.PlayerData; import noppes.npcs.entity.*; +import noppes.npcs.scripted.interfaces.IWorld; import org.lwjgl.input.Keyboard; import tconstruct.client.tabs.InventoryTabFactions; @@ -239,6 +241,10 @@ public class ClientProxy extends CommonProxy { } } + public FakePlayer getCommandPlayer(IWorld world) { + return (FakePlayer)(new EntityCustomNpc(world.getMCWorld())).getFakePlayer(); + } + private void createFolders() { File file = new File(CustomNpcs.Dir,"assets/customnpcs"); if(!file.exists()) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 825c31877..ea030ce2c 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -105,8 +105,9 @@ import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; public abstract class EntityNPCInterface extends EntityCreature implements IEntityAdditionalSpawnData, ICommandSender, IRangedAttackMob, IBossDisplayData{ public ICustomNpc wrappedNPC; - private static final GameProfileAlt chateventProfile = new GameProfileAlt(); + public static final GameProfileAlt chateventProfile = new GameProfileAlt(); public static FakePlayer chateventPlayer; + public static FakePlayer CommandPlayer; public DataDisplay display; public DataStats stats; public DataAI ai; @@ -131,8 +132,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti private int taskCount = 1; public int lastInteract = 0; - public static FakePlayer CommandPlayer; - public Faction faction; //should only be used server side private EntityAIRangedAttack aiRange; diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 774ac105c..bc8e46f7e 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -10,6 +10,7 @@ import java.io.File; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.EventBus; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; @@ -19,6 +20,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.interfaces.*; public abstract class NpcAPI { @@ -80,7 +82,7 @@ public abstract class NpcAPI { } } - public abstract String executeCommand(IWorld var1, String var2); + public abstract void executeCommand(IWorld var1, String var2); public abstract String getRandomName(int var1, int var2); diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 220a2989f..ab4bba363 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -26,6 +26,7 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.client.EntityUtil; import noppes.npcs.scripted.*; import noppes.npcs.containers.ContainerNpcInterface; import noppes.npcs.entity.EntityCustomNpc; @@ -174,11 +175,9 @@ public class WrapperNpcAPI extends NpcAPI { return new ScriptDamageSource(damagesource); } - public String executeCommand(IWorld world, String command) { - FakePlayer player = new FakePlayer(world.getMCWorld(), new GameProfile(new UUID(0L,0L), "CommandPlayer")); - player.setWorld(world.getMCWorld()); - player.setPosition(0.0D, 0.0D, 0.0D); - return NoppesUtilServer.runCommand(world.getMCWorld(), BlockPos.ORIGIN, "API", command, (EntityPlayer)null, player); + public void executeCommand(IWorld world, String command) { + //if(!world.getMCWorld().isRemote) + NoppesUtilServer.runCommand(world.getMCWorld(), "API", command); } public String getRandomName(int dictionary, int gender) { return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender); From a993c8feff4282014d1bcba1fa3421d9a8f8c138 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 20 Oct 2021 20:27:42 -0500 Subject: [PATCH 37/58] Fixed forge scripts on the server side. getIEntity() now correctly returns an IPlayer when given a player as a parameter. --- .../java/noppes/npcs/controllers/data/ForgeDataScript.java | 5 ++--- .../java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index 21cf1f1e7..8514f9b00 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -58,8 +58,7 @@ public class ForgeDataScript implements IScriptHandler { public void callScript(String type, Event event) { if(this.isEnabled()) { - //CustomNpcs.getServer().func_152344_a(() -> { - Minecraft.getMinecraft().func_152344_a(() -> { + //Minecraft.getMinecraft().func_152344_a(() -> { if (ScriptController.Instance.lastLoaded > this.lastInited) { this.lastInited = ScriptController.Instance.lastLoaded; if (!type.equals("init")) { @@ -85,7 +84,7 @@ public class ForgeDataScript implements IScriptHandler { script.run(type, event); } - }); + //}); } } diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index ab4bba363..bd857e54c 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -49,7 +49,7 @@ public class WrapperNpcAPI extends NpcAPI { public IEntity getIEntity(Entity entity) { if (entity != null && !entity.worldObj.isRemote) { - return (IEntity)(entity instanceof EntityNPCInterface ? ((EntityNPCInterface)entity).wrappedNPC : WrapperEntityData.get(entity)); + return (entity instanceof EntityNPCInterface ? ((EntityNPCInterface)entity).wrappedNPC : entity instanceof EntityPlayerMP ? getIPlayer((EntityPlayerMP) entity) : WrapperEntityData.get(entity)); } else { return null; } From 4de969f6c9b5ef6cb7a56eba4040f6fa85a604ac Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 20 Oct 2021 23:04:52 -0500 Subject: [PATCH 38/58] Implemented scripted timers for players and NPCs. --- src/main/java/noppes/npcs/CustomNpcs.java | 26 ++++ src/main/java/noppes/npcs/EventHooks.java | 11 +- .../noppes/npcs/ScriptPlayerEventHandler.java | 1 + .../noppes/npcs/client/gui/GuiScript.java | 1 + .../noppes/npcs/constants/EnumScriptType.java | 7 +- .../noppes/npcs/controllers/PlayerData.java | 74 ++++++++- .../npcs/entity/EntityNPCInterface.java | 9 +- .../noppes/npcs/entity/data/DataTimers.java | 31 +++- .../npcs/scripted/entity/ScriptNpc.java | 5 + .../npcs/scripted/entity/ScriptPlayer.java | 15 ++ .../noppes/npcs/scripted/event/NpcEvent.java | 145 ++++++++++++++++++ .../scripted/event/ScriptEventTarget.java | 2 +- .../npcs/scripted/event/ScriptEventTimer.java | 13 ++ .../npcs/scripted/interfaces/IPlayer.java | 2 + .../assets/customnpcs/lang/en_US.lang | 1 + 15 files changed, 327 insertions(+), 16 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/event/NpcEvent.java create mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 5d27c249a..c4ceaa46d 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -315,6 +315,32 @@ public class CustomNpcs { return null; } + public static File getWorldSaveDirectory(String s) { + try { + File dir = new File("."); + if (getServer() != null) { + if (!getServer().isDedicatedServer()) { + dir = new File(Minecraft.getMinecraft().mcDataDir, "saves"); + } + + dir = new File(new File(dir, getServer().getFolderName()), "customnpcs"); + } + + if (s != null) { + dir = new File(dir, s); + } + + if (!dir.exists()) { + dir.mkdirs(); + } + + return dir; + } catch (Exception var2) { + LogWriter.error("Error getting worldsave", var2); + return null; + } + } + public static MinecraftServer getServer(){ return MinecraftServer.getServer(); } diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index d3a5368a8..ea2b619bc 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -21,9 +21,9 @@ import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.*; -import noppes.npcs.scripted.event.ForgeEvent; -import noppes.npcs.scripted.event.PlayerEvent; +import noppes.npcs.scripted.event.*; import noppes.npcs.scripted.event.PlayerEvent.ChatEvent; import noppes.npcs.scripted.event.PlayerEvent.ContainerOpen; import noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent; @@ -46,6 +46,13 @@ public class EventHooks { public EventHooks() { } + public static void onNPCTimer(EntityNPCInterface npc, int id) { + NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); + ScriptEventTimer scriptEvent = new ScriptEventTimer(id); + npc.script.callScript(EnumScriptType.TIMER, "event", scriptEvent); + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerInit(PlayerDataScript handler) { noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(handler.getPlayer()); handler.callScript(EnumScriptType.INIT, event, "event", event); diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 2841cf20a..50789cf1c 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -46,6 +46,7 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent.PotentialSpawns; import noppes.npcs.controllers.PlayerData; +import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.NpcAPI; diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index 4d84a3fc6..bbdec81d3 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -71,6 +71,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall list.add("script.collide"); list.add("script.kills"); list.add("script.dialog_closed"); + list.add("script.timer"); if(showScript){ addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index dc545d999..a3980a94a 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -7,11 +7,14 @@ public enum EnumScriptType { DIALOG("dialog"), DAMAGED("damaged"), KILLED("killed"), - ATTACK_MELEE("meleeAttack"), + ATTACK("attack"), TARGET("target"), COLLIDE("collide"), KILLS("kills"), DIALOG_OPTION("dialogOption"), + TIMER("timer"), + + ATTACK_MELEE("meleeAttack"), TARGET_LOST("targetLost"), ROLE("role"), RANGED_CHARGE("rangedCharge"), @@ -25,7 +28,6 @@ public enum EnumScriptType { NEIGHBOR_CHANGED("neighborChanged"), REDSTONE("redstone"), DOOR_TOGGLE("doorToggle"), - TIMER("timer"), TOSS("toss"), DROP("drop"), CONTAINER_OPEN("containerOpen"), @@ -39,7 +41,6 @@ public enum EnumScriptType { TOSSED("tossed"), PICKEDUP("pickedUp"), PICKUP("pickUp"), - ATTACK("attack"), PROJECTILE_TICK("projectileTick"), PROJECTILE_IMPACT("projectileImpact"), LEVEL_UP("levelUp"), diff --git a/src/main/java/noppes/npcs/controllers/PlayerData.java b/src/main/java/noppes/npcs/controllers/PlayerData.java index 69634c971..3139a28c6 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/PlayerData.java @@ -2,16 +2,23 @@ package noppes.npcs.controllers; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.RoleCompanion; +import noppes.npcs.util.NBTJsonUtil; + +import java.io.File; +import java.io.FileInputStream; public class PlayerData implements IExtendedEntityProperties{ public PlayerDialogData dialogData = new PlayerDialogData(); @@ -145,16 +152,79 @@ public class PlayerData implements IExtendedEntityProperties{ world.spawnEntityInWorld(npc); } + public static NBTTagCompound loadPlayerDataOld(String player) { + File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata"); + String filename = player; + if (player.isEmpty()) { + filename = "noplayername"; + } + + filename = filename + ".dat"; + + File file; + try { + file = new File(saveDir, filename); + if (file.exists()) { + NBTTagCompound comp = CompressedStreamTools.readCompressed(new FileInputStream(file)); + file.delete(); + file = new File(saveDir, filename + "_old"); + if (file.exists()) { + file.delete(); + } + + return comp; + } + } catch (Exception var6) { + LogWriter.except(var6); + } + + try { + file = new File(saveDir, filename + "_old"); + if (file.exists()) { + return CompressedStreamTools.readCompressed(new FileInputStream(file)); + } + } catch (Exception var5) { + LogWriter.except(var5); + } + + return new NBTTagCompound(); + } + + public static NBTTagCompound loadPlayerData(String player) { + File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata"); + String filename = player; + if (player.isEmpty()) { + filename = "noplayername"; + } + + filename = filename + ".json"; + File file = null; + + try { + file = new File(saveDir, filename); + if (file.exists()) { + return NBTJsonUtil.LoadFile(file); + } + } catch (Exception var5) { + LogWriter.error("Error loading: " + file.getAbsolutePath(), var5); + } + + return new NBTTagCompound(); + } + public static PlayerData get(EntityPlayer player) { if(player.worldObj.isRemote) { return CustomNpcs.proxy.getPlayerData(player); } else { PlayerData data = new PlayerData(); - if(data.player == null) { + if (data.player == null) { data.player = player; data.playerLevel = player.experienceLevel; data.scriptData = new PlayerDataScript(player); - NBTTagCompound compound = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName()); + NBTTagCompound compound = loadPlayerData(player.getPersistentID().toString()); + if (compound.hasNoTags()) { + compound = loadPlayerDataOld(player.getCommandSenderName()); + } data.setNBT(compound); } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index ea030ce2c..790c8204b 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -87,6 +87,7 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.PlayerQuestData; import noppes.npcs.controllers.QuestData; import noppes.npcs.controllers.TransformData; +import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.JobBard; import noppes.npcs.roles.JobFollower; import noppes.npcs.roles.JobInterface; @@ -115,6 +116,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public DataInventory inventory; public DataScript script; public TransformData transform; + public DataTimers timers; public String linkedName = ""; public long linkedLast = 0; @@ -190,7 +192,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti inventory = new DataInventory(this); transform = new TransformData(this); script = new DataScript(this); - + timers = new DataTimers(this); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(stats.maxHealth); @@ -226,6 +228,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti super.onUpdate(); if(this.ticksExisted % 10 == 0) script.callScript(EnumScriptType.TICK); + this.timers.update(); } public void setWorld(World world){ @@ -920,7 +923,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti stats.readToNBT(compound); ai.readToNBT(compound); script.readFromNBT(compound); - + timers.readFromNBT(compound); advanced.readToNBT(compound); if (advanced.role != EnumRoleType.None && roleInterface != null) roleInterface.readFromNBT(compound); @@ -951,7 +954,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti stats.writeToNBT(compound); ai.writeToNBT(compound); script.writeToNBT(compound); - + timers.writeToNBT(compound); advanced.writeToNBT(compound); if (advanced.role != EnumRoleType.None && roleInterface != null) roleInterface.writeToNBT(compound); diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index 843d38849..d51012961 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -12,6 +12,7 @@ import java.util.Map; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.EventHooks; +import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.controllers.PlayerData; import noppes.npcs.scripted.CustomNPCsException; @@ -24,16 +25,29 @@ public class DataTimers implements ITimers { this.parent = parent; } + private void saveNbt() { + if(parent instanceof PlayerData) { + PlayerData playerData = (PlayerData) parent; + playerData.saveNBTData(null); + } + else if(parent instanceof PlayerData) { + PlayerData playerData = (PlayerData) parent; + playerData.saveNBTData(null); + } + } + public void start(int id, int ticks, boolean repeat) { if(this.timers.containsKey(Integer.valueOf(id))) { throw new CustomNPCsException("There is already a timer with id: " + id, new Object[0]); } else { this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat)); + saveNbt(); } } public void forceStart(int id, int ticks, boolean repeat) { this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat)); + saveNbt(); } public boolean has(int id) { @@ -41,7 +55,9 @@ public class DataTimers implements ITimers { } public boolean stop(int id) { - return this.timers.remove(Integer.valueOf(id)) != null; + boolean remove = this.timers.remove(Integer.valueOf(id)) != null; + saveNbt(); + return remove; } public void reset(int id) { @@ -50,6 +66,7 @@ public class DataTimers implements ITimers { throw new CustomNPCsException("There is no timer with id: " + id, new Object[0]); } else { timer.ticks = 0; + saveNbt(); } } @@ -71,14 +88,14 @@ public class DataTimers implements ITimers { } public void readFromNBT(NBTTagCompound compound) { - HashMap timers = new HashMap(); + Map timers = new HashMap(); NBTTagList list = compound.getTagList("NpcsTimers", 10); for(int i = 0; i < list.tagCount(); ++i) { NBTTagCompound c = list.getCompoundTagAt(i); DataTimers.Timer t = new DataTimers.Timer(c.getInteger("ID"), c.getInteger("TimerTicks"), c.getBoolean("Repeat")); t.ticks = c.getInteger("Ticks"); - timers.put(Integer.valueOf(t.id), t); + timers.put(t.id, t); } this.timers = timers; @@ -91,11 +108,12 @@ public class DataTimers implements ITimers { DataTimers.Timer timer = (DataTimers.Timer)var1.next(); timer.update(); } - + saveNbt(); } public void clear() { this.timers = new HashMap(); + saveNbt(); } class Timer { @@ -120,7 +138,10 @@ public class DataTimers implements ITimers { } Object ob = DataTimers.this.parent; - if(ob instanceof PlayerData) { + if (ob instanceof EntityNPCInterface) { + EventHooks.onNPCTimer((EntityNPCInterface)ob, this.id); + } + else if(ob instanceof PlayerData) { EventHooks.onPlayerTimer((PlayerData)ob, this.id); } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 2b1b9473c..65a136a2b 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -13,6 +13,7 @@ import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.AnimationType; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.ICustomNpc; +import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.scripted.roles.ScriptJobBard; import noppes.npcs.scripted.roles.ScriptJobConversation; import noppes.npcs.scripted.roles.ScriptJobFollower; @@ -678,4 +679,8 @@ public class ScriptNpc extends ScriptLiving imp public long getAge(){ return npc.totalTicksAlive; } + + public ITimers getTimers() { + return ((EntityNPCInterface)this.npc).timers; + } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 0d967cfee..08934d55d 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -1,5 +1,6 @@ package noppes.npcs.scripted.entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -26,10 +27,12 @@ import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IPlayer; +import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.util.ValueUtil; public class ScriptPlayer extends ScriptLivingBase implements IPlayer { public T player; + private PlayerData data; public ScriptPlayer(T player){ super(player); this.player = player; @@ -350,4 +353,16 @@ public class ScriptPlayer extends ScriptLivingBase return null; return new ScriptPixelmonPlayerData(player); } + + private PlayerData getData() { + if (this.data == null) { + this.data = PlayerData.get(player); + } + + return this.data; + } + + public ITimers getTimers() { + return this.getData().timers; + } } diff --git a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java new file mode 100644 index 000000000..58994c14d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java @@ -0,0 +1,145 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.event; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.DamageSource; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.*; + +public class NpcEvent extends CustomNPCsEvent { + public final ICustomNpc npc; + + public NpcEvent(ICustomNpc npc) { + this.npc = npc; + } + + public static class TimerEvent extends NpcEvent { + public final int id; + + public TimerEvent(ICustomNpc npc, int id) { + super(npc); + this.id = id; + } + } + + public static class CollideEvent extends NpcEvent { + public final IEntity entity; + + public CollideEvent(ICustomNpc npc, Entity entity) { + super(npc); + this.entity = NpcAPI.Instance().getIEntity(entity); + } + } + + @Cancelable + public static class DamagedEvent extends NpcEvent { + public final IDamageSource damageSource; + public final IEntity source; + public float damage; + public boolean clearTarget = false; + + public DamagedEvent(ICustomNpc npc, Entity source, float damage, DamageSource damagesource) { + super(npc); + this.source = NpcAPI.Instance().getIEntity(source); + this.damage = damage; + this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + } + } + + public static class RangedLaunchedEvent extends NpcEvent { + public final IEntityLivingBase target; + public float damage; + //public List projectiles = new ArrayList(); + + public RangedLaunchedEvent(ICustomNpc npc, EntityLivingBase target, float damage) { + super(npc); + this.target = (IEntityLivingBase)NpcAPI.Instance().getIEntity(target); + this.damage = damage; + } + } + + @Cancelable + public static class MeleeAttackEvent extends NpcEvent { + public final IEntityLivingBase target; + public float damage; + + public MeleeAttackEvent(ICustomNpc npc, EntityLivingBase target, float damage) { + super(npc); + this.target = (IEntityLivingBase)NpcAPI.Instance().getIEntity(target); + this.damage = damage; + } + } + + public static class KilledEntityEvent extends NpcEvent { + public final IEntityLivingBase entity; + + public KilledEntityEvent(ICustomNpc npc, EntityLivingBase entity) { + super(npc); + this.entity = (IEntityLivingBase)NpcAPI.Instance().getIEntity(entity); + } + } + + public static class DiedEvent extends NpcEvent { + public final IDamageSource damageSource; + public final String type; + public final IEntity source; + public IItemStack[] droppedItems; + public int expDropped; + + public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity) { + super(npc); + this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + this.type = damagesource.damageType; + this.source = NpcAPI.Instance().getIEntity(entity); + } + } + + @Cancelable + public static class InteractEvent extends NpcEvent { + public final IPlayer player; + + public InteractEvent(ICustomNpc npc, EntityPlayer player) { + super(npc); + this.player = (IPlayer)NpcAPI.Instance().getIEntity(player); + } + } + + @Cancelable + public static class TargetLostEvent extends NpcEvent { + public final IEntityLivingBase entity; + + public TargetLostEvent(ICustomNpc npc, EntityLivingBase entity) { + super(npc); + this.entity = (IEntityLivingBase)NpcAPI.Instance().getIEntity(entity); + } + } + + @Cancelable + public static class TargetEvent extends NpcEvent { + public IEntityLivingBase entity; + + public TargetEvent(ICustomNpc npc, EntityLivingBase entity) { + super(npc); + this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity); + } + } + + public static class UpdateEvent extends NpcEvent { + public UpdateEvent(ICustomNpc npc) { + super(npc); + } + } + + public static class InitEvent extends NpcEvent { + public InitEvent(ICustomNpc npc) { + super(npc); + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java index c5aef813c..1bb9832c2 100644 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java @@ -4,7 +4,7 @@ import net.minecraft.entity.EntityLivingBase; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.entity.ScriptLivingBase; -public class ScriptEventTarget extends ScriptEvent{ +public class ScriptEventTarget extends ScriptEvent { private ScriptLivingBase target; diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java new file mode 100644 index 000000000..0fdc3584b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java @@ -0,0 +1,13 @@ +package noppes.npcs.scripted.event; + +public class ScriptEventTimer extends ScriptEvent { + private int id; + + public ScriptEventTimer(int id){ + this.id = id; + } + + public int getId(){ + return id; + } +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index 495ecbb1a..a4254fcb9 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -166,4 +166,6 @@ public interface IPlayer extends IEntityLivingBase * @since 1.7.10d */ public ScriptPixelmonPlayerData getPixelmonData(); + + public ITimers getTimers(); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index ba4b81182..7a022e197 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -459,6 +459,7 @@ script.damaged=Damaged script.killed=Killed script.attack=Attack script.target=Target +script.timer=Timer script.availableScripts=Available Scripts script.loadedScripts=Loaded Scripts script.collide=Collide From d1c4adf371e913246d3c5bae424744c8154f082e Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 21 Oct 2021 22:14:12 -0500 Subject: [PATCH 39/58] ScriptEntity instances are now properly retrieved in event scripts --- .../controllers/data/PlayerDataScript.java | 23 ++++++----- .../java/noppes/npcs/scripted/NpcAPI.java | 2 - .../npcs/scripted/event/PlayerEvent.java | 7 ++-- .../npcs/scripted/wrapper/WrapperNpcAPI.java | 40 +++++++++++++++---- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 3919b178e..b051d1ea5 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -20,12 +20,16 @@ import net.minecraft.world.WorldServer; import noppes.npcs.EventHooks; import noppes.npcs.EventScriptContainer; import noppes.npcs.NBTTags; +import noppes.npcs.controllers.PlayerData; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.event.PlayerEvent; +import noppes.npcs.scripted.interfaces.IPlayer; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import javax.annotation.CheckForNull; @@ -35,7 +39,7 @@ public class PlayerDataScript implements IScriptHandler { public List scripts = new ArrayList(); public String scriptLanguage = "ECMAScript"; private EntityPlayer player; - private ScriptPlayer playerAPI; + private IPlayer playerAPI; private long lastPlayerUpdate = 0L; public long lastInited = -1L; public boolean hadInteract = true; @@ -43,16 +47,16 @@ public class PlayerDataScript implements IScriptHandler { private Map console = new TreeMap(); public List errored = new ArrayList(); - public ScriptPlayer dummyPlayer; - public ScriptWorld dummyWorld; + public IPlayer dummyPlayer; + public IWorld dummyWorld; public PlayerDataScript(EntityPlayer player) { if(player != null) { this.player = player; if (player instanceof EntityPlayer) - dummyPlayer = new ScriptPlayer((EntityPlayerMP) player); + dummyPlayer = (IPlayer) ScriptController.Instance.getScriptForEntity(this.player); if (player.worldObj instanceof WorldServer) - dummyWorld = new ScriptWorld((WorldServer) player.worldObj); + dummyWorld = (IWorld) NpcAPI.Instance().getIWorld((WorldServer) this.player.worldObj); } } @@ -119,8 +123,8 @@ public class PlayerDataScript implements IScriptHandler { } ScriptEngine engine = script.engine; - engine.put("player", dummyPlayer); engine.put("world", dummyWorld); + engine.put("player", dummyPlayer); PlayerEvent result = (PlayerEvent) engine.get("event"); if(result == null) engine.put("event", result = new PlayerEvent(this.getPlayer())); @@ -184,10 +188,11 @@ public class PlayerDataScript implements IScriptHandler { } } - public ScriptPlayer getPlayer() { - if(this.playerAPI == null) { - this.playerAPI = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(this.player); + public IPlayer getPlayer() { + if (this.playerAPI == null) { + this.playerAPI = (IPlayer) NpcAPI.Instance().getIEntity(this.player); } + return this.playerAPI; } diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index bc8e46f7e..b9f646977 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -35,8 +35,6 @@ public abstract class NpcAPI { public abstract IEntity getIEntity(Entity var1); - public abstract IPlayer getIPlayer(EntityPlayerMP var1); - public abstract IBlock getIBlock(World var1, BlockPos var2); public abstract IBlock getIBlock(World world, int x, int y, int z); diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index b09e61128..9010656bc 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -16,7 +16,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import noppes.npcs.scripted.*; import noppes.npcs.scripted.entity.ScriptLivingBase; -import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.interfaces.*; public class PlayerEvent extends CustomNPCsEvent { @@ -148,7 +147,7 @@ public class PlayerEvent extends CustomNPCsEvent { public final float pitch; public final float volume; - public SoundEvent(ScriptPlayer player, String name, float pitch, float volume) { + public SoundEvent(IPlayer player, String name, float pitch, float volume) { super(player); this.name = name; this.pitch = pitch; @@ -390,7 +389,7 @@ public class PlayerEvent extends CustomNPCsEvent { public final int y; public final int z; - public Sleep(ScriptPlayer player, int x, int y, int z) { + public Sleep(IPlayer player, int x, int y, int z) { super(player); this.x = x; this.y = y; @@ -434,7 +433,7 @@ public class PlayerEvent extends CustomNPCsEvent { } public static class RangedChargeEvent extends PlayerEvent { - public RangedChargeEvent(ScriptPlayer player) { + public RangedChargeEvent(IPlayer player) { super(player); } } diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index bd857e54c..a07a134a0 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -12,6 +12,11 @@ import java.util.UUID; import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.eventhandler.EventBus; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; @@ -27,11 +32,13 @@ import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.client.EntityUtil; +import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.controllers.ScriptEntityData; import noppes.npcs.scripted.*; import noppes.npcs.containers.ContainerNpcInterface; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.entity.*; import noppes.npcs.scripted.interfaces.*; import noppes.npcs.util.LRUHashMap; @@ -48,18 +55,37 @@ public class WrapperNpcAPI extends NpcAPI { } public IEntity getIEntity(Entity entity) { + /* if (entity != null && !entity.worldObj.isRemote) { return (entity instanceof EntityNPCInterface ? ((EntityNPCInterface)entity).wrappedNPC : entity instanceof EntityPlayerMP ? getIPlayer((EntityPlayerMP) entity) : WrapperEntityData.get(entity)); } else { return null; } - } - - public IPlayer getIPlayer(EntityPlayerMP player) { - if (player != null && !player.worldObj.isRemote) { - return new ScriptPlayer(player); - } else { + */ + if(entity == null) return null; + if(entity instanceof EntityNPCInterface) + return ((EntityNPCInterface) entity).script.dummyNpc; + else{ + ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject"); + if(data != null) + return data.base; + if(entity instanceof EntityPlayerMP) + data = new ScriptEntityData(new ScriptPlayer((EntityPlayerMP) entity)); + else if(PixelmonHelper.isPixelmon(entity)) + return new ScriptPixelmon((EntityTameable) entity); + else if(entity instanceof EntityAnimal) + data = new ScriptEntityData(new ScriptAnimal((EntityAnimal) entity)); + else if(entity instanceof EntityMob) + data = new ScriptEntityData(new ScriptMonster((EntityMob) entity)); + else if(entity instanceof EntityLiving) + data = new ScriptEntityData(new ScriptLiving((EntityLiving) entity)); + else if(entity instanceof EntityLivingBase) + data = new ScriptEntityData(new ScriptLivingBase((EntityLivingBase)entity)); + else + data = new ScriptEntityData(new ScriptEntity(entity)); + entity.registerExtendedProperties("ScriptedObject", data); + return data.base; } } From a29058d696c610945dbbc4dc3b86330a32e9e0d0 Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 22 Oct 2021 02:22:45 -0500 Subject: [PATCH 40/58] Fixed timers on the server-side. --- .../noppes/npcs/ScriptPlayerEventHandler.java | 7 ++++--- .../noppes/npcs/entity/data/DataTimers.java | 17 ----------------- .../npcs/scripted/entity/ScriptPlayer.java | 10 +--------- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 50789cf1c..ce0e59c35 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -63,11 +63,12 @@ public class ScriptPlayerEventHandler { if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; PlayerData data = PlayerData.get(player); - //if(player.ticksExisted % 10 == 0) { EventHooks.onPlayerTick(data.scriptData); - //} - data.timers.update(); + if(PlayerDataController.instance != null) { + PlayerDataController.instance.getPlayerData(player).scriptData = data.scriptData; + PlayerDataController.instance.getPlayerData(player).timers.update(); + } } } diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index d51012961..42b05f298 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -25,29 +25,16 @@ public class DataTimers implements ITimers { this.parent = parent; } - private void saveNbt() { - if(parent instanceof PlayerData) { - PlayerData playerData = (PlayerData) parent; - playerData.saveNBTData(null); - } - else if(parent instanceof PlayerData) { - PlayerData playerData = (PlayerData) parent; - playerData.saveNBTData(null); - } - } - public void start(int id, int ticks, boolean repeat) { if(this.timers.containsKey(Integer.valueOf(id))) { throw new CustomNPCsException("There is already a timer with id: " + id, new Object[0]); } else { this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat)); - saveNbt(); } } public void forceStart(int id, int ticks, boolean repeat) { this.timers.put(Integer.valueOf(id), new DataTimers.Timer(id, ticks, repeat)); - saveNbt(); } public boolean has(int id) { @@ -56,7 +43,6 @@ public class DataTimers implements ITimers { public boolean stop(int id) { boolean remove = this.timers.remove(Integer.valueOf(id)) != null; - saveNbt(); return remove; } @@ -66,7 +52,6 @@ public class DataTimers implements ITimers { throw new CustomNPCsException("There is no timer with id: " + id, new Object[0]); } else { timer.ticks = 0; - saveNbt(); } } @@ -108,12 +93,10 @@ public class DataTimers implements ITimers { DataTimers.Timer timer = (DataTimers.Timer)var1.next(); timer.update(); } - saveNbt(); } public void clear() { this.timers = new HashMap(); - saveNbt(); } class Timer { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 08934d55d..7c73b9c55 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -354,15 +354,7 @@ public class ScriptPlayer extends ScriptLivingBase return new ScriptPixelmonPlayerData(player); } - private PlayerData getData() { - if (this.data == null) { - this.data = PlayerData.get(player); - } - - return this.data; - } - public ITimers getTimers() { - return this.getData().timers; + return PlayerDataController.instance.getPlayerData(player).timers; } } From b068c76fc86bd7b15dee07b98a3c5c8552202e98 Mon Sep 17 00:00:00 2001 From: luisc Date: Sat, 23 Oct 2021 02:43:28 -0500 Subject: [PATCH 41/58] Fixed some forge events not working from being registered on the wrong event bus. --- .../noppes/npcs/ScriptPlayerEventHandler.java | 28 ++++++++++-- .../client/gui/script/GuiScriptInterface.java | 45 ++++++++++++++----- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index ce0e59c35..c1ebd7f06 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.Vector; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.eventhandler.Event; @@ -365,10 +366,10 @@ public class ScriptPlayerEventHandler { try { Method e = handler.getClass().getMethod("forgeEntity", new Class[]{Event.class}); - Method register = MinecraftForge.EVENT_BUS.getClass().getDeclaredMethod("register", new Class[]{Class.class, Object.class, Method.class, ModContainer.class}); + Method register = FMLCommonHandler.instance().bus().getClass().getDeclaredMethod("register", new Class[]{Class.class, Object.class, Method.class, ModContainer.class}); register.setAccessible(true); ArrayList list = new ArrayList(); - list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common")); + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.gameevent")); list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); Iterator e1 = list.iterator(); @@ -412,7 +413,7 @@ public class ScriptPlayerEventHandler { while(var10.hasNext()) { Class c1 = (Class)var10.next(); if(!EntityConstructing.class.isAssignableFrom(c1) && !PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers())) { - register.invoke(MinecraftForge.EVENT_BUS, new Object[]{c1, handler, e, Loader.instance().activeModContainer()}); + register.invoke(FMLCommonHandler.instance().bus(), new Object[]{c1, handler, e, Loader.instance().activeModContainer()}); } } } @@ -452,4 +453,25 @@ public class ScriptPlayerEventHandler { } } } + + /*@SubscribeEvent + public void forgeTick(TickEvent.ServerTickEvent event){ + if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { + EventHooks.onForgeEvent(new ForgeEvent(event), event); + } + } + + @SubscribeEvent + public void forgeTick(TickEvent.WorldTickEvent event){ + if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { + EventHooks.onForgeEvent(new ForgeEvent(event), event); + } + } + + @SubscribeEvent + public void forgeTick(TickEvent.PlayerTickEvent event){ + if(event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { + EventHooks.onForgeEvent(new ForgeEvent(event), event); + } + }*/ } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 4b7df1106..735689a0d 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -93,6 +93,13 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb top.active = true; if(this.activeTab > 0) { List hookList = new ArrayList(); + + GuiCustomScroll hooks = new GuiCustomScroll(this, 1); + hooks.allowUserInput = false; + hooks.setSize(108, 198); + hooks.guiLeft = guiLeft - 110; + hooks.guiTop = guiTop + 14; + if(handler instanceof PlayerDataScript) { hookList.add("init"); hookList.add("tick"); @@ -132,33 +139,47 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hookList.add("changedDim"); } else if(handler instanceof ForgeDataScript) { + hooks.setSize(238, 198); + hooks.guiLeft = guiLeft - 240; + hookList.add("init"); ArrayList list = new ArrayList(); try { + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.event")); + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.gameevent")); list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); } catch (IOException e) { e.printStackTrace(); } - for(ClassPath.ClassInfo classInfo : list){ - String eventName = classInfo.getName(); - int i = eventName.lastIndexOf("."); - eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); + for(ClassPath.ClassInfo e1 : list){ + ClassPath.ClassInfo classLoader = e1; + Class infoClass = classLoader.load(); + ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses())); + if(c.isEmpty()) { + c.add(infoClass); + } + Iterator var10 = c.iterator(); + while(var10.hasNext()) { + Class c1 = (Class) var10.next(); + if (!EntityEvent.EntityConstructing.class.isAssignableFrom(c1) && !WorldEvent.PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers())) { + String eventName = c1.getName(); + int i = eventName.lastIndexOf("."); + eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); - hookList.add(eventName); + hookList.add(eventName); + } + } } } - - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft - 160, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.allowUserInput = false; - hooks.setSize(158, 198); - hooks.guiLeft = guiLeft - 160; - hooks.guiTop = guiTop + 14; hooks.setUnsortedList(hookList); addScroll(hooks); + GuiNpcLabel hookLabel = new GuiNpcLabel(0, "script.hooks", hooks.guiLeft, guiTop + 5); + hookLabel.color = 0xaaaaaa; + addLabel(hookLabel); + EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); GuiNpcTextArea left = new GuiNpcTextArea(2, this, this.guiLeft + yoffset, this.guiTop + yoffset, this.xSize - 110 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); this.addTextField(left); From 18aa2d099fcc46a2a64f6985b259100fc5494ce2 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 24 Oct 2021 01:53:20 -0500 Subject: [PATCH 42/58] Added updatePlayerInventory to ScriptPlayer --- .../noppes/npcs/scripted/entity/ScriptPlayer.java | 12 +++++++++++- .../noppes/npcs/scripted/interfaces/IPlayer.java | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 7c73b9c55..70a2c3473 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -15,6 +15,7 @@ import noppes.npcs.NoppesStringUtils; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.Server; import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.PixelmonHelper; import noppes.npcs.controllers.PlayerData; import noppes.npcs.controllers.PlayerDataController; @@ -232,6 +233,7 @@ public class ScriptPlayer extends ScriptLivingBase } } } + this.updatePlayerInventory(); return true; } @@ -258,7 +260,9 @@ public class ScriptPlayer extends ScriptLivingBase public boolean giveItem(ScriptItemStack item, int amount){ if(item != null && item.getMCItemStack() != null) { item.setStackSize(amount); - return this.player.inventory.addItemStackToInventory(item.getMCItemStack()); + boolean bool = this.player.inventory.addItemStackToInventory(item.getMCItemStack()); + this.updatePlayerInventory(); + return bool; } else { return false; } @@ -357,4 +361,10 @@ public class ScriptPlayer extends ScriptLivingBase public ITimers getTimers() { return PlayerDataController.instance.getPlayerData(player).timers; } + + public void updatePlayerInventory() { + ((EntityPlayerMP)this.entity).inventoryContainer.detectAndSendChanges(); + PlayerQuestData playerdata = PlayerDataController.instance.getPlayerData(player).questData; + playerdata.checkQuestCompletion((EntityPlayer)this.entity, EnumQuestType.Item); + } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index a4254fcb9..36d074625 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -168,4 +168,6 @@ public interface IPlayer extends IEntityLivingBase public ScriptPixelmonPlayerData getPixelmonData(); public ITimers getTimers(); + + public void updatePlayerInventory(); } From 6fcf566ef7cb126f23fd4386a64e767951b97a85 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 24 Oct 2021 23:33:22 -0500 Subject: [PATCH 43/58] Made setRotation work for players, with yaw and pitch parameters. --- .../java/noppes/npcs/NoppesUtilPlayer.java | 22 +++++++++++++++++++ .../npcs/scripted/entity/ScriptPlayer.java | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index 984bd717e..42d2c00b8 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -110,6 +110,28 @@ public class NoppesUtilPlayer { } player.worldObj.updateEntityWithOptionalForce(player, false); } + + public static void teleportPlayer(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension){ + if(player.dimension != dimension){ + int dim = player.dimension; + MinecraftServer server = MinecraftServer.getServer(); + WorldServer wor = server.worldServerForDimension(dimension); + if(wor == null){ + player.addChatMessage(new ChatComponentText("Broken transporter. Dimenion does not exist")); + return; + } + player.setLocationAndAngles(posX, posY, posZ, yaw, pitch); + server.getConfigurationManager().transferPlayerToDimension(player, dimension, new CustomTeleporter(wor)); + player.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, yaw, pitch); + + if(!wor.playerEntities.contains(player)) + wor.spawnEntityInWorld(player); + } + else{ + player.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, yaw, pitch); + } + player.worldObj.updateEntityWithOptionalForce(player, false); + } private static void followerBuy(RoleFollower role,IInventory currencyInv,EntityPlayerMP player, EntityNPCInterface npc){ ItemStack currency = currencyInv.getStackInSlot(0); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 70a2c3473..9a5502357 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -309,7 +309,10 @@ public class ScriptPlayer extends ScriptLivingBase player.inventory.mainInventory[i] = null; } } - + + public void setRotation(float rotationYaw, float rotationPitch){ + NoppesUtilPlayer.teleportPlayer(player, player.posX, player.posY, player.posZ, rotationYaw, rotationPitch, player.dimension); + } /** * @param achievement The achievement id. For a complete list see http://minecraft.gamepedia.com/Achievements From 1478841098f6394097b0b21fef04d8e7d5019289 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 25 Oct 2021 00:58:03 -0500 Subject: [PATCH 44/58] Added hurt functions to ScriptLivingBase --- .../npcs/scripted/entity/ScriptLivingBase.java | 15 +++++++++++++++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 9a1a23cb2..252b04ff3 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -4,10 +4,13 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSource; import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IEntityLivingBase; +import noppes.npcs.scripted.wrapper.ScriptDamageSource; public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase { protected T entity; @@ -30,6 +33,18 @@ public class ScriptLivingBase extends ScriptEntity Date: Mon, 25 Oct 2021 01:07:31 -0500 Subject: [PATCH 45/58] Small parameter adjustment to ScriptLivingBase.hurt() --- .../java/noppes/npcs/scripted/entity/ScriptLivingBase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 252b04ff3..108295123 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -38,11 +38,11 @@ public class ScriptLivingBase extends ScriptEntity Date: Thu, 28 Oct 2021 16:46:09 -0500 Subject: [PATCH 46/58] Added setImmune() function to ScriptEntity. --- src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java | 4 ++++ .../java/noppes/npcs/scripted/entity/ScriptLivingBase.java | 4 ++-- src/main/java/noppes/npcs/scripted/interfaces/IEntity.java | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 41d438434..00747b07a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -473,6 +473,10 @@ public class ScriptEntity implements IEntity { entity.hurtResistantTime = 0; } + public void setImmune(int ticks) { + entity.hurtResistantTime = ticks; + }; + /** * @since 1.7.10c * @return Returns whether or not this entity is sneaking diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 108295123..705de1b55 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -38,11 +38,11 @@ public class ScriptLivingBase extends ScriptEntity { */ public void knockback(int power, float direction); + public void knockback(int xpower, int ypower, int zpower, float direction); + + public void setImmune(int ticks); + /** * @since 1.7.10c * @return Returns whether or not this entity is sneaking From 6b2a9d92b134046a3f3f56e3f248e9aa7490d3a5 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 28 Oct 2021 16:54:41 -0500 Subject: [PATCH 47/58] Added hasCollided() function to ScriptEntity. --- src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java | 4 ++++ src/main/java/noppes/npcs/scripted/interfaces/IEntity.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 00747b07a..541ff0778 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -477,6 +477,10 @@ public class ScriptEntity implements IEntity { entity.hurtResistantTime = ticks; }; + public boolean hasCollided() { + return entity.isCollided; + } + /** * @since 1.7.10c * @return Returns whether or not this entity is sneaking diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index 32c51c312..27cdbc218 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -286,6 +286,8 @@ public interface IEntity { public void setImmune(int ticks); + public boolean hasCollided(); + /** * @since 1.7.10c * @return Returns whether or not this entity is sneaking From 70f1ff261332f4616a0c8c5d1182b0735fa10e19 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 10 Nov 2021 02:21:03 -0600 Subject: [PATCH 48/58] Added API to NPC script engine. --- src/main/java/noppes/npcs/DataScript.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/DataScript.java index b40cd88f2..9494e0811 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/DataScript.java @@ -21,6 +21,8 @@ import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.IWorld; +import noppes.npcs.scripted.wrapper.WrapperNpcAPI; public class DataScript { public Map scripts = new HashMap(); @@ -33,7 +35,7 @@ public class DataScript { public boolean enabled = false; public ScriptNpc dummyNpc; - public ScriptWorld dummyWorld; + public IWorld dummyWorld; public boolean clientNeedsUpdate = false; public boolean aiNeedsUpdate = false; public boolean hasInited = false; @@ -121,6 +123,7 @@ public class DataScript { ScriptEvent result = (ScriptEvent) engine.get("event"); if(result == null) engine.put("event", result = new ScriptEvent()); + engine.put("API", new WrapperNpcAPI()); engine.put("EntityType", entities); engine.put("RoleType", roles); engine.put("JobType", jobs); From 40b39d3b206a93565c1f4163eaa5faf8681c8c3e Mon Sep 17 00:00:00 2001 From: luisc Date: Sat, 13 Nov 2021 12:52:21 -0600 Subject: [PATCH 49/58] Player key and mouse scripts now execute even when the player has a GUI open. --- src/main/java/noppes/npcs/client/ClientTickHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index f12b44967..fe050dde1 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -48,7 +48,7 @@ public class ClientTickHandler{ @SubscribeEvent public void onMouse(InputEvent.MouseInputEvent event){ Minecraft mc = Minecraft.getMinecraft(); - if(mc.currentScreen != null || (Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0)) + if(Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0) return; NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, new Object[]{Mouse.getEventButton(),Mouse.getEventDWheel()}); @@ -73,7 +73,7 @@ public class ClientTickHandler{ } } else { Minecraft mc = Minecraft.getMinecraft(); - if(key == this.buttonPressed && time - this.buttonTime < 500000000L && mc.currentScreen == null) { + if(key == this.buttonPressed && time - this.buttonTime < 500000000L) { boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42); boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56); From 27b88c1fce8fb77026f529d5789bf3e1380ce8b8 Mon Sep 17 00:00:00 2001 From: luisc Date: Sat, 13 Nov 2021 13:32:33 -0600 Subject: [PATCH 50/58] Player key events now detect key presses as well, not just releases. --- src/main/java/noppes/npcs/EventHooks.java | 8 +++---- .../java/noppes/npcs/PacketHandlerPlayer.java | 4 ++-- .../noppes/npcs/client/ClientTickHandler.java | 23 ++++++++----------- .../npcs/scripted/event/PlayerEvent.java | 8 +++++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index ea2b619bc..7833cb110 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -248,16 +248,16 @@ public class EventHooks { WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel) { + public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel, boolean buttonDown) { PlayerDataScript handler = PlayerData.get(player).scriptData; - PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent(handler.getPlayer(), button, mouseWheel); + PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent(handler.getPlayer(), button, mouseWheel, buttonDown); handler.callScript(EnumScriptType.MOUSE_CLICKED, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } - public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) { + public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed, boolean buttonDown) { PlayerDataScript handler = PlayerData.get(player).scriptData; - KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed); + KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed, buttonDown); handler.callScript(EnumScriptType.KEY_PRESSED, event,"event", event); WrapperNpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 36709bdb6..55f3faabb 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -66,14 +66,14 @@ public class PacketHandlerPlayer{ return; } - EventHooks.onPlayerKeyPressed(player, buffer.readInt(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean()); + EventHooks.onPlayerKeyPressed(player, buffer.readInt(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean(), buffer.readBoolean()); } else if(type == EnumPlayerPacket.MouseClicked) { if(ScriptController.Instance.languages.isEmpty()) { return; } - EventHooks.onPlayerMouseClicked(player, buffer.readInt(), buffer.readInt()); + EventHooks.onPlayerMouseClicked(player, buffer.readInt(), buffer.readInt(), buffer.readBoolean()); } else if(type == EnumPlayerPacket.FollowerHire){ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index fe050dde1..255a92908 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -51,7 +51,7 @@ public class ClientTickHandler{ if(Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0) return; - NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, new Object[]{Mouse.getEventButton(),Mouse.getEventDWheel()}); + NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, new Object[]{Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton())}); } @SubscribeEvent @@ -66,23 +66,20 @@ public class ClientTickHandler{ int key = Keyboard.getEventKey(); long time = Keyboard.getEventNanoseconds(); + if(Keyboard.getEventKeyState()) { if(!this.isIgnoredKey(key)) { this.buttonTime = time; - this.buttonPressed = key; - } - } else { - Minecraft mc = Minecraft.getMinecraft(); - if(key == this.buttonPressed && time - this.buttonTime < 500000000L) { - boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); - boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42); - boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56); - boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219); - NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, new Object[]{Integer.valueOf(key), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed)}); } + } - this.buttonPressed = -1; - this.buttonTime = 0L; + if((Keyboard.getEventKeyState() && time-this.buttonTime == 0) || !Keyboard.getEventKeyState()) { + boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); + boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42); + boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56); + boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219); + boolean keyDown = Keyboard.isKeyDown(key); + NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, new Object[]{Integer.valueOf(key), Boolean.valueOf(isCtrlPressed), Boolean.valueOf(isShiftPressed), Boolean.valueOf(isAltPressed), Boolean.valueOf(isMetaPressed), Boolean.valueOf(keyDown)}); } } diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index 9010656bc..cc07fdb11 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -41,25 +41,29 @@ public class PlayerEvent extends CustomNPCsEvent { public final boolean isAltPressed; public final boolean isShiftPressed; public final boolean isMetaPressed; + public final boolean keyDown; - public KeyPressedEvent(IPlayer player, int key, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed) { + public KeyPressedEvent(IPlayer player, int key, boolean isCtrlPressed, boolean isAltPressed, boolean isShiftPressed, boolean isMetaPressed, boolean keyDown) { super(player); this.key = key; this.isCtrlPressed = isCtrlPressed; this.isAltPressed = isAltPressed; this.isShiftPressed = isShiftPressed; this.isMetaPressed = isMetaPressed; + this.keyDown = keyDown; } } public static class MouseClickedEvent extends PlayerEvent { public final int button; public final int mouseWheel; + public final boolean buttonDown; - public MouseClickedEvent(IPlayer player, int button, int mouseWheel){ + public MouseClickedEvent(IPlayer player, int button, int mouseWheel, boolean buttonDown){ super(player); this.button = button; this.mouseWheel = mouseWheel; + this.buttonDown = buttonDown; } } From 0d807b36d9314b272f1bc5ec726578c70931d614 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 16 Nov 2021 10:41:04 -0600 Subject: [PATCH 51/58] Added isGUIOpen() function, and setPosition function with a dimensionId parameter to ScriptPlayer. --- src/main/java/noppes/npcs/CommonProxy.java | 4 ++++ .../java/noppes/npcs/NoppesUtilPlayer.java | 4 +++- .../java/noppes/npcs/NoppesUtilServer.java | 15 ++++++++++++++- .../java/noppes/npcs/PacketHandlerServer.java | 17 +++++++++++++---- .../java/noppes/npcs/client/ClientProxy.java | 5 +++++ .../noppes/npcs/client/ClientTickHandler.java | 3 +-- .../java/noppes/npcs/client/NoppesUtil.java | 4 +++- .../npcs/client/PacketHandlerClient.java | 8 +++++--- .../npcs/constants/EnumPacketClient.java | 2 +- .../npcs/constants/EnumPacketServer.java | 2 +- .../noppes/npcs/controllers/PlayerData.java | 18 ++++++++++++++++-- .../npcs/scripted/entity/ScriptPlayer.java | 15 ++++++++++++++- .../npcs/scripted/interfaces/IPlayer.java | 4 ++++ 13 files changed, 84 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index 1964503da..b5075fec4 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -178,4 +178,8 @@ public class CommonProxy implements IGuiHandler { public String getAchievementDesc(Achievement achievement) { return ""; } + + public boolean isGUIOpen(){ + return false; + } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index 42d2c00b8..30e07e2e4 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -397,5 +397,7 @@ public class NoppesUtilPlayer { } } } - + public static void isGUIOpen(EntityPlayerMP player){ + Server.sendData(player, EnumPacketClient.ISGUIOPEN); + } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index e2b7e0621..db38b3a9a 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -36,7 +36,6 @@ import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; @@ -706,4 +705,18 @@ public class NoppesUtilServer { return (Entity)entity; } + + public static void isGUIOpen(ByteBuf buffer, EntityPlayer player) throws IOException { + EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(player.getDisplayName()); + PlayerData playerdata; + if(pl == null) + playerdata = PlayerDataController.instance.getDataFromUsername(player.getDisplayName()); + else + playerdata = PlayerDataController.instance.getPlayerData(pl); + + boolean isGUIOpen = buffer.readBoolean(); + playerdata.setGUIOpen(isGUIOpen); + + sendPlayerData(EnumPlayerData.Players, (EntityPlayerMP)player, player.getDisplayName()); + } } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 45ee43028..6e4f42fbb 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.List; import java.util.Set; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.passive.EntityVillager; @@ -90,13 +89,19 @@ public class PacketHandlerServer{ ItemStack item = player.inventory.getCurrentItem(); EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); + + if(type == EnumPacketServer.IsGuiOpen) { + isGuiOpenPacket(buffer, player); + return; + } + if(type.needsNpc && npc == null){ } else if(type.hasPermission() && !CustomNpcsPermissions.Instance.hasPermission(player, type.permission)){ - //player doesnt have permission todo this + //player doesnt have permission to do this } - else if(item == null ) + else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)) warn(player, "tried to use custom npcs without a tool in hand, probably a hacker"); else if(item.getItem() == CustomItems.wand) wandPackets(type, buffer, player, npc); @@ -120,7 +125,11 @@ public class PacketHandlerServer{ LogWriter.error("Error with EnumPacketServer." + type, e); } } - + + private void isGuiOpenPacket(ByteBuf buffer, EntityPlayerMP player) throws IOException { + NoppesUtilServer.isGUIOpen(buffer, player); + } + private void scriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { if(type == EnumPacketServer.ScriptDataSave){ npc.script.readFromNBT(Server.readNBT(buffer)); diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 58ab042df..b96e82b61 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -588,6 +588,11 @@ public class ClientProxy extends CommonProxy { return achievement.getDescription(); } + @Override + public boolean isGUIOpen(){ + return Minecraft.getMinecraft().currentScreen != null; + } + public static class FontContainer { private StringCache textFont = null; public boolean useCustomFont = true; diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 255a92908..30ef21cae 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -47,7 +47,6 @@ public class ClientTickHandler{ @SubscribeEvent public void onMouse(InputEvent.MouseInputEvent event){ - Minecraft mc = Minecraft.getMinecraft(); if(Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0) return; @@ -73,7 +72,7 @@ public class ClientTickHandler{ } } - if((Keyboard.getEventKeyState() && time-this.buttonTime == 0) || !Keyboard.getEventKeyState()) { + if(time-this.buttonTime == 0 || !Keyboard.getEventKeyState()) { boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29); boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42); boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56); diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index 7c1ae2c9b..d933ec479 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -21,7 +21,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.Util; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; -import noppes.npcs.ModelPartData; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.Server; import noppes.npcs.client.fx.EntityCustomFX; @@ -289,4 +288,7 @@ public class NoppesUtil { CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.Waypoint, player); } + public static void isGUIOpen(boolean isGUIOpen) { + Client.sendData(EnumPacketServer.IsGuiOpen, isGUIOpen); + } } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 2689b498b..138958ed4 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -254,8 +254,10 @@ public class PacketHandlerClient extends PacketHandlerServer{ player.addChatMessage(new ChatComponentTranslation("Current font is %s", ClientProxy.Font.getName())); } } + else if(type == EnumPacketClient.ISGUIOPEN){ + boolean isGUIOpen = Minecraft.getMinecraft().currentScreen != null; + + NoppesUtil.isGUIOpen(isGUIOpen); + } } - - - } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 8c53c6b57..c11a36d6e 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -1,6 +1,6 @@ package noppes.npcs.constants; public enum EnumPacketClient { - CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG + CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 474094a0e..54b7bbcbf 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -76,7 +76,7 @@ public enum EnumPacketServer { RemoteTpToNpc,QuestGet, QuestCategoryGet, SaveTileEntity, NaturalSpawnGetAll, MailOpenSetup, - DimensionsGet, DimensionTeleport, GetTileEntity, Gui, ; + DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen; public CustomNpcsPermissions.Permission permission = null; public boolean needsNpc = false; diff --git a/src/main/java/noppes/npcs/controllers/PlayerData.java b/src/main/java/noppes/npcs/controllers/PlayerData.java index 3139a28c6..994dd25d2 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/PlayerData.java @@ -39,10 +39,12 @@ public class PlayerData implements IExtendedEntityProperties{ public String playername = ""; public String uuid = ""; - + private EntityNPCInterface activeCompanion = null; public int companionID = 0; + public boolean isGUIOpen = false; + @Override public void saveNBTData(NBTTagCompound compound) { PlayerDataController.instance.savePlayerData(this); @@ -86,6 +88,7 @@ public class PlayerData implements IExtendedEntityProperties{ player.worldObj.spawnEntityInWorld(npc); } } + isGUIOpen = data.getBoolean("isGUIOpen"); } public NBTTagCompound getNBT() { if(player != null){ @@ -105,6 +108,7 @@ public class PlayerData implements IExtendedEntityProperties{ compound.setString("PlayerName", playername); compound.setString("UUID", uuid); compound.setInteger("PlayerCompanionId", companionID); + compound.setBoolean("isGUIOpen",isGUIOpen); if(hasCompanion()){ NBTTagCompound nbt = new NBTTagCompound(); @@ -118,7 +122,17 @@ public class PlayerData implements IExtendedEntityProperties{ public void init(Entity entity, World world) { } - + + public void setGUIOpen(boolean bool) { + isGUIOpen = bool; + saveNBTData(null); + } + + public boolean getGUIOpen() { + loadNBTData(null); + return isGUIOpen; + } + public boolean hasCompanion(){ return activeCompanion != null && !activeCompanion.isDead; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 9a5502357..55cfb4aed 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -24,6 +24,7 @@ import noppes.npcs.controllers.PlayerQuestData; import noppes.npcs.controllers.Quest; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.QuestData; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; import noppes.npcs.scripted.constants.EntityType; @@ -33,7 +34,6 @@ import noppes.npcs.util.ValueUtil; public class ScriptPlayer extends ScriptLivingBase implements IPlayer { public T player; - private PlayerData data; public ScriptPlayer(T player){ super(player); this.player = player; @@ -58,6 +58,13 @@ public class ScriptPlayer extends ScriptLivingBase NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension); } + public void setPosition(double x, double y, double z, int dimensionId){ + if (NpcAPI.Instance().getIWorld(dimensionId) == null) + return; + + NoppesUtilPlayer.teleportPlayer(player, x, y, z, dimensionId); + } + public int getDimension(){ return player.dimension; } @@ -370,4 +377,10 @@ public class ScriptPlayer extends ScriptLivingBase PlayerQuestData playerdata = PlayerDataController.instance.getPlayerData(player).questData; playerdata.checkQuestCompletion((EntityPlayer)this.entity, EnumQuestType.Item); } + + public boolean checkGUIOpen() { + NoppesUtilPlayer.isGUIOpen(player); + PlayerData data = PlayerDataController.instance.getPlayerData(player); + return data.getGUIOpen(); + } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index 36d074625..c83d258a8 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -17,6 +17,8 @@ public interface IPlayer extends IEntityLivingBase public void setPosition(double x, double y, double z); + public void setPosition(double x, double y, double z, int dimensionId); + public boolean hasFinishedQuest(int id); public boolean hasActiveQuest(int id); @@ -170,4 +172,6 @@ public interface IPlayer extends IEntityLivingBase public ITimers getTimers(); public void updatePlayerInventory(); + + public boolean checkGUIOpen(); } From 03e4400b2edf0198533a0cea4deede88854a6454 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 18 Nov 2021 01:13:42 -0600 Subject: [PATCH 52/58] Small custom particle null pointer error fix --- src/main/java/noppes/npcs/client/NoppesUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index d933ec479..cfe3ce72e 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -103,6 +103,9 @@ public class NoppesUtil { World worldObj = Minecraft.getMinecraft().theWorld; Entity entity = worldObj.getEntityByID(entityID); + if(entity == null) + return; + EntityCustomFX fx = new EntityCustomFX( entity, directory, HEXcolor, From d2fe832508c5c3da8430725eae35707484a2ccca Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 18 Nov 2021 01:16:11 -0600 Subject: [PATCH 53/58] Removed playerLevel parameter from PlayerData --- src/main/java/noppes/npcs/controllers/PlayerData.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/PlayerData.java b/src/main/java/noppes/npcs/controllers/PlayerData.java index 994dd25d2..ec37e4cb4 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/PlayerData.java @@ -29,7 +29,6 @@ public class PlayerData implements IExtendedEntityProperties{ public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); public PlayerMailData mailData = new PlayerMailData(); public PlayerDataScript scriptData; - public int playerLevel = 0; public DataTimers timers = new DataTimers(this); public EntityNPCInterface editingNpc; @@ -233,7 +232,6 @@ public class PlayerData implements IExtendedEntityProperties{ PlayerData data = new PlayerData(); if (data.player == null) { data.player = player; - data.playerLevel = player.experienceLevel; data.scriptData = new PlayerDataScript(player); NBTTagCompound compound = loadPlayerData(player.getPersistentID().toString()); if (compound.hasNoTags()) { From d5c13ae65ffdef98ce71a06f582ee7fa3b81d761 Mon Sep 17 00:00:00 2001 From: luisc Date: Sat, 20 Nov 2021 13:12:21 -0600 Subject: [PATCH 54/58] Fixed scripted particle texture replacing in-world vanilla particle effects while alive. --- .../noppes/npcs/client/fx/EntityCustomFX.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java index e3c968232..318cf8152 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityCustomFX.java @@ -1,15 +1,19 @@ package noppes.npcs.client.fx; +import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ClientProxy; +import org.lwjgl.Sys; import org.lwjgl.opengl.GL11; public class EntityCustomFX extends EntityFX { private Entity entity; private final ResourceLocation location; + private static final ResourceLocation resource = new ResourceLocation("textures/particle/particles.png"); private boolean move = true; private float startX = 0, startY = 0, startZ = 0; @@ -92,8 +96,8 @@ public class EntityCustomFX extends EntityFX { particleAlpha = this.alpha2; else if(particleAge >= this.alphaRateStart) particleAlpha += alpha; - - ClientProxy.bindTexture(location); + + ClientProxy.bindTexture(location); float f = 0.0f; float f1 = 1.0f; @@ -104,7 +108,6 @@ public class EntityCustomFX extends EntityFX { float f6 = (float)(((prevPosY + (posY - prevPosY) * (double)par2) - interpPosY) + startY); float f7 = (float)(((prevPosZ + (posZ - prevPosZ) * (double)par2) - interpPosZ) + startZ); - GL11.glColor4f(1, 1, 1, 1.0F); tessellator.startDrawingQuads(); tessellator.setBrightness(240); par1Tessellator.setColorOpaque_F(1, 1, 1); @@ -114,8 +117,43 @@ public class EntityCustomFX extends EntityFX { par1Tessellator.addVertexWithUV(f5 + par3 * f4 + par6 * f4, f6 + par4 * f4, f7 + par5 * f4 + par7 * f4, f, f2); par1Tessellator.addVertexWithUV((f5 + par3 * f4) - par6 * f4, f6 - par4 * f4, (f7 + par5 * f4) - par7 * f4, f, f3); - tessellator.draw(); - tessellator.startDrawingQuads(); + /* + Minecraft minecraft = Minecraft.getMinecraft(); + EntityPlayer player = minecraft.thePlayer; + + double yaw = (player.rotationYaw/180)*Math.PI; + double pitch = (player.rotationPitch/180)*Math.PI; + + double angle = Minecraft.getMinecraft().theWorld.getWorldTime()%360; + double angleRad = (angle/180)*Math.PI; + + double angleX = Math.sin(yaw)*Math.cos(pitch); + if(Math.abs(angleX) < 0.0001){ + angleX = 0.0D; + } + double angleY = Math.sin(pitch); + if(Math.abs(angleY) < 0.0001){ + angleY = 0.0D; + } + double angleZ = -Math.cos(yaw)*Math.cos(pitch); + if(Math.abs(angleZ) < 0.0001){ + angleZ = 0.0D; + } + + double translateX = 0; + double translateY = 0; + double translateZ = 0; + */ + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1.0F); + //GL11.glTranslated(translateX,translateY,translateZ); + //GL11.glRotated(angle, angleX, angleY, angleZ); + + tessellator.draw(); + ClientProxy.bindTexture(resource); + tessellator.startDrawingQuads(); + GL11.glPopMatrix(); } public int getFXLayer(){ From 77c2897109f3abf479603d916c46b86ce2d87870 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 22 Nov 2021 01:10:27 -0600 Subject: [PATCH 55/58] Added getAllServerPlayers, createItem & createEntityParticle to NPC API. Added getDimensionID() to ScriptWorld. --- .../java/noppes/npcs/scripted/NpcAPI.java | 7 ++++ .../noppes/npcs/scripted/ScriptWorld.java | 4 +++ .../npcs/scripted/interfaces/IWorld.java | 2 ++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 34 +++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index b9f646977..b2948c564 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; @@ -85,4 +86,10 @@ public abstract class NpcAPI { public abstract String getRandomName(int var1, int var2); public abstract INbt getINbt(NBTTagCompound entityData); + + public abstract ScriptPlayer[] getAllServerPlayers(); + + public abstract ScriptItemStack createItem(String id, int damage, int size); + + public abstract ScriptEntityParticle createEntityParticle(String directory); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 7ee5ba757..cbcc43f48 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -362,4 +362,8 @@ public class ScriptWorld implements IWorld { public WorldServer getMCWorld(){ return this.world; } + + public int getDimensionID(){ + return world.provider.dimensionId; + } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index ef12df261..9c7b14534 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -210,4 +210,6 @@ public interface IWorld { * @return Returns minecraft world object */ public WorldServer getMCWorld(); + + public int getDimensionID(); } diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index d396e14eb..23576e5f5 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -6,6 +6,7 @@ package noppes.npcs.scripted.wrapper; import java.io.File; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -24,6 +25,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.DamageSource; import net.minecraft.util.EntityDamageSource; import net.minecraft.util.math.BlockPos; @@ -34,6 +36,7 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.client.EntityUtil; import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ScriptEntityData; import noppes.npcs.scripted.*; import noppes.npcs.containers.ContainerNpcInterface; @@ -213,4 +216,35 @@ public class WrapperNpcAPI extends NpcAPI { public String getRandomName(int dictionary, int gender) { return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender); } + + public ScriptPlayer[] getAllServerPlayers(){ + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + ScriptPlayer[] arr = new ScriptPlayer[list.size()]; + for(int i = 0; i < list.size(); i++){ + arr[i] = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(list.get(i)); + } + + return arr; + } + + /** + * @param id The items name + * @param damage The damage value + * @param size The number of items in the item + * @return Returns the item + */ + public ScriptItemStack createItem(String id, int damage, int size){ + Item item = (Item)Item.itemRegistry.getObject(id); + if(item == null) + return null; + return new ScriptItemStack(new ItemStack(item, size, damage)); + } + + /** + * @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" + * @return Returns ScriptEntityParticle object + */ + public ScriptEntityParticle createEntityParticle(String directory){ + return new ScriptEntityParticle(directory); + } } From 8a7f40189ec2a4db0ea71dc2f5298e203aaed500 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 22 Nov 2021 02:33:28 -0600 Subject: [PATCH 56/58] Fixed redundant function calls for saving player data in NoppesUtilServer when using isGUIOpen(). Added getServerTime() to NpcAPI. --- src/main/java/noppes/npcs/NoppesUtilServer.java | 10 +--------- src/main/java/noppes/npcs/scripted/NpcAPI.java | 2 ++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 14 ++++---------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index db38b3a9a..13b82c061 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -707,16 +707,8 @@ public class NoppesUtilServer { } public static void isGUIOpen(ByteBuf buffer, EntityPlayer player) throws IOException { - EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(player.getDisplayName()); - PlayerData playerdata; - if(pl == null) - playerdata = PlayerDataController.instance.getDataFromUsername(player.getDisplayName()); - else - playerdata = PlayerDataController.instance.getPlayerData(pl); - + PlayerData playerdata = PlayerDataController.instance.getPlayerData(player); boolean isGUIOpen = buffer.readBoolean(); playerdata.setGUIOpen(isGUIOpen); - - sendPlayerData(EnumPlayerData.Players, (EntityPlayerMP)player, player.getDisplayName()); } } diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index b2948c564..3d49dc260 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -92,4 +92,6 @@ public abstract class NpcAPI { public abstract ScriptItemStack createItem(String id, int damage, int size); public abstract ScriptEntityParticle createEntityParticle(String directory); + + public abstract int getServerTime(); } diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 23576e5f5..9bdfe6d21 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -227,12 +227,6 @@ public class WrapperNpcAPI extends NpcAPI { return arr; } - /** - * @param id The items name - * @param damage The damage value - * @param size The number of items in the item - * @return Returns the item - */ public ScriptItemStack createItem(String id, int damage, int size){ Item item = (Item)Item.itemRegistry.getObject(id); if(item == null) @@ -240,11 +234,11 @@ public class WrapperNpcAPI extends NpcAPI { return new ScriptItemStack(new ItemStack(item, size, damage)); } - /** - * @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" - * @return Returns ScriptEntityParticle object - */ public ScriptEntityParticle createEntityParticle(String directory){ return new ScriptEntityParticle(directory); } + + public int getServerTime() { + return MinecraftServer.getServer().getTickCounter(); + } } From d24422c3a10262bf4f0c3786bbf18ee14e2dd0d4 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 22 Nov 2021 23:34:02 -0600 Subject: [PATCH 57/58] Added setVisibleTo(player,visible) and isVisibleTo(player) to ScriptNpc --- src/main/java/noppes/npcs/DataDisplay.java | 23 +++++++++++++++++++ .../noppes/npcs/client/model/ModelMPM.java | 8 ++++++- .../npcs/entity/EntityNPCInterface.java | 13 +++++++---- .../npcs/scripted/entity/ScriptNpc.java | 23 +++++++++++++++++++ .../npcs/scripted/interfaces/ICustomNpc.java | 16 +++++++++++++ 5 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index 0bac810dd..942afc39c 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -1,8 +1,15 @@ package noppes.npcs; +import java.util.ArrayList; +import java.util.List; import java.util.Random; +import java.util.UUID; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import net.minecraft.nbt.NBTUtil; import net.minecraft.server.MinecraftServer; import net.minecraft.util.StringUtils; @@ -43,6 +50,8 @@ public class DataDisplay { public byte showBossBar = 0; + public ArrayList invisibleToList = new ArrayList<>(); + public DataDisplay(EntityNPCInterface npc){ this.npc = npc; @@ -112,6 +121,13 @@ public class DataDisplay { nbttagcompound.setBoolean("NoLivingAnimation", disableLivingAnimation); nbttagcompound.setByte("BossBar", showBossBar); + NBTTagList list = new NBTTagList(); + for(UUID uuid : invisibleToList){ + list.appendTag(new NBTTagString(uuid.toString())); + } + + nbttagcompound.setTag("InvisibleToList", list); + return nbttagcompound; } public void readToNBT(NBTTagCompound nbttagcompound) { @@ -152,6 +168,13 @@ public class DataDisplay { disableLivingAnimation = nbttagcompound.getBoolean("NoLivingAnimation"); showBossBar = nbttagcompound.getByte("BossBar"); + invisibleToList.clear(); + NBTTagList tagList = (NBTTagList)nbttagcompound.getTag("InvisibleToList"); + for(int i = 0; i < tagList.tagCount(); i++){ + String nbtTagString = tagList.getStringTagAt(i); + invisibleToList.add(UUID.fromString(nbtTagString)); + } + if(prevSkinType != skinType || !texture.equals(prevTexture)) npc.textureLocation = null; npc.textureGlowLocation = null; diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index 5e7a4ece2..f24822fa7 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -9,6 +9,7 @@ import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.MathHelper; +import noppes.npcs.CustomItems; import noppes.npcs.ModelPartConfig; import noppes.npcs.ModelPartData; import noppes.npcs.client.ClientProxy; @@ -294,6 +295,8 @@ public class ModelMPM extends ModelNPCMale{ @Override public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7){ EntityCustomNpc npc = (EntityCustomNpc) par1Entity; + if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() != CustomItems.wand) + return; if(entityModel != null){ if(!isArmor){ @@ -311,7 +314,10 @@ public class ModelMPM extends ModelNPCMale{ } } else{ - alpha = npc.isInvisible() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer)?0.15f:1; + alpha = npc.isInvisible() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) ? 0.15f : 1; + if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() == CustomItems.wand) + alpha = 0.15f; + setPlayerData(npc); currentlyPlayerTexture = true; setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity); diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 790c8204b..9077b722a 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -3,10 +3,7 @@ package noppes.npcs.entity; import io.netty.buffer.ByteBuf; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; +import java.util.*; import net.minecraft.block.Block; import net.minecraft.command.ICommandSender; @@ -95,6 +92,7 @@ import noppes.npcs.roles.RoleCompanion; import noppes.npcs.roles.RoleFollower; import noppes.npcs.roles.RoleInterface; import noppes.npcs.scripted.entity.ScriptNpc; +import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.event.ScriptEventAttack; import noppes.npcs.scripted.event.ScriptEventDamaged; import noppes.npcs.scripted.event.ScriptEventKilled; @@ -1599,9 +1597,16 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public boolean isInvisibleToPlayer(EntityPlayer player){ + if(display.invisibleToList != null && display.invisibleToList.contains(player.getPersistentID())) + return true; + return display.visible == 1 && (player.getHeldItem() == null || player.getHeldItem().getItem() != CustomItems.wand); } + public boolean scriptInvisibleToPlayer(EntityPlayer player){ + return display.invisibleToList != null && display.invisibleToList.contains(player.getPersistentID()); + } + @Override public boolean isInvisible(){ return display.visible != 0; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 65a136a2b..14240d037 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -1,5 +1,6 @@ package noppes.npcs.scripted.entity; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumAnimation; @@ -31,6 +32,10 @@ import noppes.npcs.scripted.roles.ScriptRoleTrader; import noppes.npcs.scripted.roles.ScriptRoleTransporter; import noppes.npcs.util.ValueUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + public class ScriptNpc extends ScriptLiving implements ICustomNpc { public EntityCustomNpc npc; @@ -431,6 +436,24 @@ public class ScriptNpc extends ScriptLiving imp public int getVisibleType(){ return npc.display.visible; } + + public void setVisibleTo(ScriptPlayer player, boolean visible) { + UUID uuid = player.player.getPersistentID(); + ArrayList uuidList = npc.display.invisibleToList; + if(uuidList != null) { + if (!uuidList.contains(uuid)) { + if (!visible) + npc.display.invisibleToList.add(uuid); + } else if (visible) { + npc.display.invisibleToList.remove(uuid); + } + } + npc.script.clientNeedsUpdate = true; + } + + public boolean isVisibleTo(ScriptPlayer player) { + return !npc.scriptInvisibleToPlayer(player.player); + } /** * @param type The visibility type of the name, 0:visible, 1:invisible, 2:when-attacking diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java index a384a6379..69c78d02d 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java @@ -225,6 +225,22 @@ public interface ICustomNpc extends IEntityLiving { */ public int getVisibleType(); + /** + * + * @param player The player this NPC becomes visible/invisible to + * @param visible True if you want the NPC to be invisible to the player, false otherwise + */ + public void setVisibleTo(ScriptPlayer player, boolean visible); + + /** + * + * @param player The player this NPC is visible/invisible to + * @return False if the NPC has been toggled to be invisible to this player, true otherwise. + * If setVisibleTo(player,visible) was not called to make this NPC invisible to the player at any point + * in the NPC's life, this function will return true regardless of the value of isVisible(). + */ + public boolean isVisibleTo(ScriptPlayer player); + /** * @param type The visibility type of the name, 0:visible, 1:invisible, 2:when-attacking */ From ecbfd7dab0eb18f0a4d9e01bafc63a248aa487dc Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 23 Nov 2021 15:08:35 -0600 Subject: [PATCH 58/58] Fixed some console spam caused by a NullPointerException when checking scriptVisibleToPlayer(player) in ModelMPM --- src/main/java/noppes/npcs/client/model/ModelMPM.java | 8 ++++---- src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index f24822fa7..58f35c2bb 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -8,6 +8,7 @@ import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; import noppes.npcs.CustomItems; import noppes.npcs.ModelPartConfig; @@ -295,7 +296,8 @@ public class ModelMPM extends ModelNPCMale{ @Override public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7){ EntityCustomNpc npc = (EntityCustomNpc) par1Entity; - if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() != CustomItems.wand) + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && (player.getHeldItem() == null || player.getHeldItem().getItem() != CustomItems.wand)) return; if(entityModel != null){ @@ -314,9 +316,7 @@ public class ModelMPM extends ModelNPCMale{ } } else{ - alpha = npc.isInvisible() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) ? 0.15f : 1; - if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() == CustomItems.wand) - alpha = 0.15f; + alpha = npc.isInvisible() && !npc.isInvisibleToPlayer(player) ? 0.15f : 1; setPlayerData(npc); currentlyPlayerTexture = true; diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 9077b722a..4f674cbe5 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -1597,10 +1597,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public boolean isInvisibleToPlayer(EntityPlayer player){ - if(display.invisibleToList != null && display.invisibleToList.contains(player.getPersistentID())) - return true; - - return display.visible == 1 && (player.getHeldItem() == null || player.getHeldItem().getItem() != CustomItems.wand); + return (scriptInvisibleToPlayer(player) || display.visible == 1) && (player.getHeldItem() == null || player.getHeldItem().getItem() != CustomItems.wand); } public boolean scriptInvisibleToPlayer(EntityPlayer player){