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; + } +}