diff --git a/build.gradle b/build.gradle index 16d8b0e56..a1879f7de 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ configurations { apply plugin: 'forge' -version = "1.9-beta3" +version = "1.9-beta3.2" group= "com.kamkeel.customnpc-plus" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/noppes/npcs/DataAdvanced.java b/src/main/java/noppes/npcs/DataAdvanced.java index 2db06c527..406889b8d 100644 --- a/src/main/java/noppes/npcs/DataAdvanced.java +++ b/src/main/java/noppes/npcs/DataAdvanced.java @@ -161,23 +161,23 @@ public class DataAdvanced { } public Line getInteractLine() { - return interactLines.getLine(!orderedLines); + return (Line) interactLines.getLine(!orderedLines); } public Line getAttackLine() { - return attackLines.getLine(!orderedLines); + return (Line) attackLines.getLine(!orderedLines); } public Line getKilledLine() { - return killedLines.getLine(!orderedLines); + return (Line) killedLines.getLine(!orderedLines); } public Line getKillLine() { - return killLines.getLine(!orderedLines); + return (Line) killLines.getLine(!orderedLines); } public Line getWorldLine() { - return worldLines.getLine(!orderedLines); + return (Line) worldLines.getLine(!orderedLines); } public void setRole(int i) { diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 0f590bb3a..ea784ccd4 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -262,6 +262,14 @@ public class EventHooks { script.run(EnumScriptType.PROJECTILE_TICK, event); } } + + EntityLivingBase thrower = projectile.getThrower(); + if(thrower != null){ + if(thrower instanceof EntityNPCInterface){ + ((EntityNPCInterface) thrower).script.callScript(EnumScriptType.PROJECTILE_TICK, event); + } + } + NpcAPI.EVENT_BUS.post(event); } @@ -272,6 +280,14 @@ public class EventHooks { script.run(EnumScriptType.PROJECTILE_IMPACT, event); } } + + EntityLivingBase thrower = projectile.getThrower(); + if(thrower != null){ + if(thrower instanceof EntityNPCInterface){ + ((EntityNPCInterface) thrower).script.callScript(EnumScriptType.PROJECTILE_IMPACT, event); + } + } + NpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 70751237b..f790873ed 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -672,17 +672,20 @@ public class NoppesUtilServer { } public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException { - EntityNPCInterface npc = getEditingNpc(player); + return setNpcDialog(slot, dialogId, getEditingNpc(player)); + } + + public static DialogOption setNpcDialog(int slot, int dialogId, EntityNPCInterface npc) { if(npc == null) return null; if(!npc.dialogs.containsKey(slot)) npc.dialogs.put(slot, new DialogOption()); - + DialogOption option = npc.dialogs.get(slot); option.dialogId = dialogId; if(option.hasDialog()) option.title = option.getDialog().title; - + return option; } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 14c3eb8a3..5c40b481a 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -12,7 +12,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.chunk.Chunk; import noppes.npcs.blocks.tiles.TileBigSign; import noppes.npcs.blocks.tiles.TileBook; import noppes.npcs.constants.*; diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 64b8b9c36..d163b7a7a 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -108,6 +108,38 @@ public class PacketHandlerServer{ } compound.setTag("TagNames",tagList); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } else if (type == EnumPacketServer.CacheAnimation) { + PlayerDataController.Instance.getPlayerData(player).animationData.cacheAnimation(buffer.readInt()); + return; + } else if (type == EnumPacketServer.GetPartyData || type == EnumPacketServer.CreateParty) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (type == EnumPacketServer.CreateParty) { + Party party = PartyController.Instance().createParty(); + party.addPlayer(player); + party.setLeader(player); + } + + NBTTagCompound compound = new NBTTagCompound(); + if (playerData.partyUUID != null) { + Party party = PartyController.Instance().getParty(playerData.partyUUID); + compound = party.writeToNBT(); + + Quest quest = (Quest) QuestController.Instance.get(party.getCurrentQuestID()); + if (quest != null) { + compound.setString("QuestName", quest.getName()); + compound.setString("QuestCategory", quest.getCategory().getName()); + } + } + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } else if (type == EnumPacketServer.DisbandParty) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (playerData.partyUUID != null) { + PartyController.Instance().disbandParty(playerData.partyUUID); + } + + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("Disband", true); + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } if(type.needsNpc && npc == null){ diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 05e5b9aca..faf91da84 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -1,11 +1,13 @@ package noppes.npcs.client; import net.minecraft.util.ResourceLocation; +import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.client.gui.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.renderer.ImageData; import noppes.npcs.config.ConfigClient; +import noppes.npcs.controllers.data.Party; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.util.CacheHashMap; @@ -14,11 +16,15 @@ import java.util.UUID; public class ClientCacheHandler { private static final CacheHashMap> imageDataCache = new CacheHashMap<>((long) ConfigClient.CacheLife * 60 * 1000); + public static final HashMap animationCache = new HashMap<>(); + public static OverlayQuestTracking questTrackingOverlay = null; public static HashMap customOverlays = new HashMap<>(); public static HashMap> skinOverlays = new HashMap<>(); public static HashMap playerAnimations = new HashMap<>(); + public static Party party; + public static ImageData getImageData(String directory) { synchronized (imageDataCache) { if (!imageDataCache.containsKey(directory)) { @@ -39,9 +45,11 @@ public class ClientCacheHandler { public static void clearCache() { ClientCacheHandler.imageDataCache.clear(); + ClientCacheHandler.animationCache.clear(); ClientCacheHandler.questTrackingOverlay = null; ClientCacheHandler.customOverlays.clear(); ClientCacheHandler.skinOverlays.clear(); ClientCacheHandler.playerAnimations.clear(); + party = null; } } diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 0307b5236..06e24ee67 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -108,7 +108,7 @@ public class ClientEventHandler { ClientEventHandler.playerModel = null; } - if (data != null && data.isActive()) { + if (data != null && data.isActive() && !Minecraft.getMinecraft().isGamePaused()) { Animation animation = data.animation; if (data.isActive() && animation.currentFrame().useRenderTicks()) { animation.increaseTime(); diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index bbf4782dd..16df44bf9 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -62,8 +62,7 @@ import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.items.ItemScripted; import org.lwjgl.input.Keyboard; -import tconstruct.client.tabs.InventoryTabFactions; -import tconstruct.client.tabs.InventoryTabQuests; +import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.InventoryTabVanilla; import tconstruct.client.tabs.TabRegistry; @@ -152,8 +151,7 @@ public class ClientProxy extends CommonProxy { if (TabRegistry.getTabList().size() < 2){ TabRegistry.registerTab(new InventoryTabVanilla()); } - TabRegistry.registerTab(new InventoryTabFactions()); - TabRegistry.registerTab(new InventoryTabQuests()); + TabRegistry.registerTab(new InventoryTabCustomNpc()); } } diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 9a1ec9a75..940cdbf6c 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -3,18 +3,16 @@ package noppes.npcs.client; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; -import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.controllers.ScriptSoundController; -import noppes.npcs.client.gui.player.GuiQuestLog; +import noppes.npcs.client.gui.player.inventory.GuiQuestLog; import noppes.npcs.client.renderer.RenderNPCInterface; import noppes.npcs.constants.EnumPlayerPacket; import org.lwjgl.input.Keyboard; diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 647941ff7..276fde16d 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -28,17 +28,18 @@ import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.player.GuiBook; import noppes.npcs.client.gui.util.*; import noppes.npcs.config.ConfigClient; +import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.RecipeController; -import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.AnimationData; -import noppes.npcs.controllers.data.RecipeCarpentry; +import noppes.npcs.controllers.data.*; import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.entity.EntityNPCInterface; import java.io.IOException; import java.util.HashMap; +import java.util.Map; public class PacketHandlerClient extends PacketHandlerServer{ @@ -299,22 +300,56 @@ public class PacketHandlerClient extends PacketHandlerServer{ } else if(type == EnumPacketClient.UPDATE_ANIMATIONS) { NBTTagCompound compound = Server.readNBT(buffer); + AnimationData animationData = null; if (compound.hasKey("EntityId")) { Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId")); if (entity instanceof EntityNPCInterface) { - AnimationData data = ((EntityNPCInterface) entity).display.animationData; - data.readFromNBT(compound); - data.animation = new Animation(); - data.animation.readFromNBT(compound.getCompoundTag("Animation")); + animationData = ((EntityNPCInterface) entity).display.animationData; } } else { EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(Server.readString(buffer)); if (sendingPlayer != null) { - AnimationData data = new AnimationData(sendingPlayer); - data.readFromNBT(compound); - data.animation = new Animation(); - data.animation.readFromNBT(compound.getCompoundTag("Animation")); - ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), data); + if (!ClientCacheHandler.playerAnimations.containsKey(sendingPlayer.getUniqueID())) { + ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), new AnimationData(sendingPlayer)); + } + animationData = ClientCacheHandler.playerAnimations.get(sendingPlayer.getUniqueID()); + } + } + + if (animationData != null) { + animationData.readFromNBT(compound); + int animationId; + if (compound.hasKey("AnimationID")) { + animationId = compound.getInteger("AnimationID"); + } else { + Animation animation = new Animation(); + animation.readFromNBT(compound.getCompoundTag("Animation")); + ClientCacheHandler.animationCache.put(animation.getID(), animation); + animationId = animation.getID(); + } + + if (animationData.allowAnimation) { + Animation animation = new Animation(); + animation.readFromNBT(ClientCacheHandler.animationCache.get(animationId).writeToNBT()); + if (animationData.animation != null && animation.frames.size() > 0) { + Frame frame = (Frame) animationData.animation.currentFrame(); + if (frame != null) { + Frame firstFrame = animation.frames.get(0); + for (Map.Entry entry : frame.frameParts.entrySet()) { + if (firstFrame.frameParts.containsKey(entry.getKey())) { + FramePart prevFramePart = entry.getValue(); + FramePart newFramePart = firstFrame.frameParts.get(entry.getKey()); + for (int i = 0; i < 3; i++) { + newFramePart.prevPivots[i] = prevFramePart.prevPivots[i]; + newFramePart.prevRotations[i] = prevFramePart.prevRotations[i]; + } + } + } + } + } + animationData.animation = animation; + animation.parent = animationData; + Client.sendData(EnumPacketServer.CacheAnimation, animationId); } } } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java index c0cc81241..a44cca5f5 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java @@ -46,36 +46,43 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS scroll.guiLeft = guiLeft + 172; scroll.guiTop = guiTop + 8; addScroll(scroll); - addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 172, guiTop + 8 + 3 + 180, 130, 20, search)); - - this.addButton(new GuiNpcButton(0,guiLeft + 306, guiTop + 10, 94, 30, "menu.global")); - this.addButton(new GuiNpcButton(1,guiLeft + 306, guiTop + 32, 94, 20, "tile.npcCarpentyBench.name")); - this.getButton(0).setEnabled(container.width == 4); - this.getButton(1).setEnabled(container.width == 3); - this.addButton(new GuiNpcButton(3,guiLeft + 306, guiTop + 60, 94, 20, "gui.add")); - this.addButton(new GuiNpcButton(4,guiLeft + 306, guiTop + 82, 94, 20, "gui.remove")); + this.addButton(new GuiNpcButton(0,guiLeft + 306, guiTop + 10, 84, 20, "menu.global")); + this.addButton(new GuiNpcButton(1,guiLeft + 306, guiTop + 32, 84, 20, "tile.npcCarpentyBench.name")); + this.getButton(0).setEnabled(container.width == 4); + this.getButton(1).setEnabled(container.width == 3); + + this.addButton(new GuiNpcButton(3,guiLeft + 306, guiTop + 60, 84, 20, "gui.add")); + this.addButton(new GuiNpcButton(4,guiLeft + 306, guiTop + 82, 84, 20, "gui.remove")); this.addLabel(new GuiNpcLabel(0, "gui.ignoreDamage", guiLeft + 86, guiTop + 32)); this.addButton(new GuiNpcButtonYesNo(5,guiLeft + 114, guiTop + 40, 50, 20, container.recipe.ignoreDamage)); this.addLabel(new GuiNpcLabel(1, "gui.ignoreNBT", guiLeft + 86, guiTop + 82)); this.addButton(new GuiNpcButtonYesNo(6,guiLeft + 114, guiTop + 90, 50, 20, container.recipe.ignoreNBT)); - - this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name)); - this.getTextField(0).enabled = false; - this.getButton(5).setEnabled(false); - this.getButton(6).setEnabled(false); - } + + this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name)); + this.getTextField(0).enabled = false; + this.getButton(5).setEnabled(false); + this.getButton(6).setEnabled(false); + + this.addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 172, guiTop + 8 + 3 + 180, 130, 20, search)); + } @Override protected void actionPerformed(GuiButton guibutton){ GuiNpcButton button = (GuiNpcButton) guibutton; if(button.id == 0){ + getTextField(55).setText(""); + search = ""; + scroll.clear(); save(); NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,3,0,0); } if(button.id == 1){ + getTextField(55).setText(""); + search = ""; + scroll.clear(); save(); NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,4,0,0); } @@ -192,14 +199,16 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS @Override public void unFocused(GuiNpcTextField guiNpcTextField) { - String name = guiNpcTextField.getText(); - if(!name.isEmpty() && !data.containsKey(name)){ - String old = container.recipe.name; - data.remove(container.recipe.name); - container.recipe.name = name; - data.put(container.recipe.name, container.recipe.id); - selected = name; - scroll.replace(old,container.recipe.name); + if(guiNpcTextField.id == 0){ + String name = guiNpcTextField.getText(); + if(!name.isEmpty() && !data.containsKey(name)){ + String old = container.recipe.name; + data.remove(container.recipe.name); + container.recipe.name = name; + data.put(container.recipe.name, container.recipe.id); + selected = name; + scroll.replace(old,container.recipe.name); + } } } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiFaction.java b/src/main/java/noppes/npcs/client/gui/player/GuiFaction.java deleted file mode 100644 index a26e43ec2..000000000 --- a/src/main/java/noppes/npcs/client/gui/player/GuiFaction.java +++ /dev/null @@ -1,186 +0,0 @@ -package noppes.npcs.client.gui.player; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.gui.util.GuiButtonNextPage; -import noppes.npcs.client.gui.util.GuiNPCInterface; -import noppes.npcs.client.gui.util.IGuiData; -import noppes.npcs.constants.EnumPlayerPacket; -import noppes.npcs.controllers.data.Faction; -import noppes.npcs.controllers.data.PlayerFactionData; -import org.lwjgl.opengl.GL11; -import tconstruct.client.tabs.InventoryTabFactions; -import tconstruct.client.tabs.TabRegistry; - -import java.util.ArrayList; - -public class GuiFaction extends GuiNPCInterface implements IGuiData{ - - private int xSize; - private int ySize; - private int guiLeft; - private int guiTop; - - private ArrayList playerFactions = new ArrayList(); - - private int page = 0; - private int pages = 1; - - private GuiButtonNextPage buttonNextPage; - private GuiButtonNextPage buttonPreviousPage; - private ResourceLocation indicator; - - public GuiFaction() { - super(); - xSize = 200; - ySize = 195; - this.drawDefaultBackground = false; - title = ""; - NoppesUtilPlayer.sendData(EnumPlayerPacket.FactionsGet); - indicator = getResource("standardbg.png"); - } - - @Override - public void initGui() - { - super.initGui(); - guiLeft = (width - xSize) / 2; - guiTop = (height - ySize) / 2 + 12; - - - TabRegistry.updateTabValues(guiLeft, guiTop + 8, InventoryTabFactions.class); - TabRegistry.addTabsToList(buttonList); - - this.buttonList.add(buttonNextPage = new GuiButtonNextPage(1, guiLeft + xSize - 43, guiTop + 180, true)); - this.buttonList.add(buttonPreviousPage = new GuiButtonNextPage(2, guiLeft + 20, guiTop + 180, false)); - updateButtons(); - } - - @Override - public void drawScreen(int i, int j, float f) - { - drawDefaultBackground(); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(indicator); - drawTexturedModalRect(guiLeft, guiTop + 8, 0, 0, xSize, ySize); - drawTexturedModalRect(guiLeft + 4, guiTop + 8, 56, 0, 200, ySize); - - if(playerFactions.isEmpty()){ - String noFaction = StatCollector.translateToLocal("faction.nostanding"); - fontRendererObj.drawString(noFaction,guiLeft + (xSize - fontRendererObj.getStringWidth(noFaction)) / 2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); - } - else - renderScreen(); - - super.drawScreen(i, j, f); - - } - - private void renderScreen(){ - int size = 5; - if(playerFactions.size() % 5 != 0 && page == pages) - size = playerFactions.size() % 5; - - for(int id = 0 ; id < size; id++){ - drawHorizontalLine(guiLeft + 2, guiLeft + xSize, guiTop + 14 + id * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - - Faction faction = playerFactions.get((page - 1) * 5 + id); - String name = faction.name; - String points = " : " + faction.defaultPoints; - - String standing = StatCollector.translateToLocal("faction.friendly"); - int color = 0x00FF00; - if(faction.defaultPoints < faction.neutralPoints){ - standing = StatCollector.translateToLocal("faction.unfriendly"); - color = 0xFF0000; - points += "/" + faction.neutralPoints; - } - else if(faction.defaultPoints < faction.friendlyPoints){ - standing = StatCollector.translateToLocal("faction.neutral"); - color = 0xF2FF00; - points += "/" + faction.friendlyPoints; - } - else{ - points += "/-"; - } - - fontRendererObj.drawString(name, guiLeft + (xSize - fontRendererObj.getStringWidth(name)) / 2, guiTop + 19 + id * 30, faction.color); - - fontRendererObj.drawString(standing, width / 2 - fontRendererObj.getStringWidth(standing) - 1, guiTop + 33 + id * 30, color); - fontRendererObj.drawString(points, width / 2, guiTop + 33 + id * 30, CustomNpcResourceListener.DefaultTextColor); - } - drawHorizontalLine(guiLeft + 2, guiLeft + xSize, guiTop + 14 + size * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - - if(pages > 1){ - String s = page +"/" + pages; - fontRendererObj.drawString(s, guiLeft + (xSize - fontRendererObj.getStringWidth(s)) / 2, guiTop + 203, CustomNpcResourceListener.DefaultTextColor); - } - } - - @Override - protected void actionPerformed(GuiButton guibutton){ - if(!(guibutton instanceof GuiButtonNextPage)) - return; - int id = guibutton.id; - if(id == 1){ - page++; - } - if(id == 2){ - page--; - } - updateButtons(); - } - private void updateButtons(){ - buttonNextPage.setVisible(page < pages); - buttonPreviousPage.setVisible(page > 1); - } - protected void drawGuiContainerBackgroundLayer(float f, int i, int j) - { - - } - - @Override - public void keyTyped(char c, int i) - { - if (i == 1 || isInventoryKey(i)) - { - close(); - } - } - @Override - public void save() { - } - @Override - public void setGuiData(NBTTagCompound compound) { - playerFactions = new ArrayList(); - - NBTTagList list = compound.getTagList("FactionList", 10); - for(int i = 0; i < list.tagCount(); i++){ - Faction faction = new Faction(); - faction.readNBT(list.getCompoundTagAt(i)); - playerFactions.add(faction); - } - PlayerFactionData data = new PlayerFactionData(); - data.loadNBTData(compound); - for(int id : data.factionData.keySet()){ - int points = data.factionData.get(id); - for(Faction faction : playerFactions){ - if(faction.id == id) - faction.defaultPoints = points; - } - } - - pages = (playerFactions.size() - 1) / 5 ; - pages++; - - page = 1; - - updateButtons(); - } - -} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java new file mode 100644 index 000000000..b39eb51e5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java @@ -0,0 +1,52 @@ +package noppes.npcs.client.gui.player.inventory; + +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.CustomItems; +import noppes.npcs.client.gui.util.GuiMenuSideButton; +import noppes.npcs.client.gui.util.GuiNPCInterface; +import tconstruct.client.tabs.InventoryTabCustomNpc; +import tconstruct.client.tabs.TabRegistry; + +public class GuiCNPCInventory extends GuiNPCInterface { + private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); + protected static int activeTab = 0; + private Minecraft mc = Minecraft.getMinecraft(); + + public GuiCNPCInventory() { + super(); + xSize = 280; + ySize = 180; + drawDefaultBackground = false; + } + + public void initGui(){ + super.initGui(); + guiTop +=10; + + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + + GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); + questsButton.rightSided = true; + questsButton.active = activeTab == 0; + questsButton.renderStack = new ItemStack(CustomItems.letter); + addButton(questsButton); + + GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); + partyButton.rightSided = true; + partyButton.active = activeTab == 1; + partyButton.renderStack = new ItemStack(CustomItems.bag); + addButton(partyButton); + + GuiMenuSideButton factionButton = new GuiMenuSideButton(102, guiLeft + xSize + 37, this.guiTop + 3 + 21*2, 22, 22, ""); + factionButton.rightSided = true; + factionButton.active = activeTab == 2; + factionButton.renderStack = new ItemStack(CustomItems.wallBanner); + addButton(factionButton); + } + + @Override + public void save() {} +} diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java new file mode 100644 index 000000000..9fe7bf8a3 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java @@ -0,0 +1,211 @@ +package noppes.npcs.client.gui.player.inventory; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.gui.util.GuiButtonNextPage; +import noppes.npcs.client.gui.util.IGuiData; +import noppes.npcs.constants.EnumPlayerPacket; +import noppes.npcs.controllers.data.Faction; +import noppes.npcs.controllers.data.PlayerFactionData; +import org.lwjgl.opengl.GL11; +import tconstruct.client.tabs.InventoryTabCustomNpc; +import tconstruct.client.tabs.TabRegistry; + +import java.util.ArrayList; + +public class GuiFaction extends GuiCNPCInventory implements IGuiData{ + + private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); + + private ArrayList playerFactions = new ArrayList(); + private Minecraft mc = Minecraft.getMinecraft(); + + private int page = 0; + private int pages = 1; + + private GuiButtonNextPage buttonNextPage; + private GuiButtonNextPage buttonPreviousPage; + + public GuiFaction() { + super(); + xSize = 280; + ySize = 180; + this.drawDefaultBackground = false; + title = ""; + activeTab = 2; + NoppesUtilPlayer.sendData(EnumPlayerPacket.FactionsGet); + } + + @Override + public void initGui() + { + super.initGui(); + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + + this.buttonList.add(buttonNextPage = new GuiButtonNextPage(1, (guiLeft + (xSize + 35) / 2) + 25, guiTop + 170, true)); + this.buttonList.add(buttonPreviousPage = new GuiButtonNextPage(2, (guiLeft + (xSize + 35) / 2) - 40, guiTop + 170, false)); + updateButtons(); + } + + @Override + public void drawScreen(int i, int j, float f) + { + drawDefaultBackground(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(resource); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); + drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); + + if(playerFactions.isEmpty()){ + String noFaction = StatCollector.translateToLocal("faction.nostanding"); + fontRendererObj.drawString(noFaction,guiLeft + (xSize - fontRendererObj.getStringWidth(noFaction)) / 2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); + } + else + renderScreen(); + + super.drawScreen(i, j, f); + + } + + private void renderScreen(){ + int size = 10; + if(playerFactions.size() % 10 != 0 && page == pages) + size = playerFactions.size() % 10; + + int hLine = 5; + if(size < 5){ + hLine = size; + } + + int count = -1; + for(int id = 0 ; id < size; id++){ + count++; + + Faction faction = playerFactions.get((page - 1) * 10 + id); + String name = faction.name; + String points = " : " + faction.defaultPoints; + + String standing = StatCollector.translateToLocal("faction.friendly"); + int color = 0x00FF00; + if(faction.defaultPoints < faction.neutralPoints){ + standing = StatCollector.translateToLocal("faction.unfriendly"); + color = 0xFF0000; + points += "/" + faction.neutralPoints; + } + else if(faction.defaultPoints < faction.friendlyPoints){ + standing = StatCollector.translateToLocal("faction.neutral"); + color = 0xF2FF00; + points += "/" + faction.friendlyPoints; + } + else{ + points += "/-"; + } + + drawVerticalLine(guiLeft + (xSize + 45) / 2, (guiTop + ySize - 15), guiTop + 13, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + if(count < 5){ + drawHorizontalLine(guiLeft + 2, guiLeft + xSize + 35, guiTop + 14 + count * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + fontRendererObj.drawString(name, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(name)) / 4, guiTop + 19 + count * 30, faction.color); + + fontRendererObj.drawString(standing, (guiLeft + (xSize + 45) / 4) - fontRendererObj.getStringWidth(standing), guiTop + 33 + count * 30, color); + fontRendererObj.drawString(points, (guiLeft + (xSize + 45) / 4), guiTop + 33 + count * 30, CustomNpcResourceListener.DefaultTextColor); + } + else { + fontRendererObj.drawString(name, guiLeft + 3*(xSize + 45 - fontRendererObj.getStringWidth(name)) / 4, guiTop + 19 + (count - 5) * 30, faction.color); + + fontRendererObj.drawString(standing, (guiLeft + 3*(xSize + 45) / 4) - fontRendererObj.getStringWidth(standing) - 10, guiTop + 33 + (count - 5) * 30, color); + fontRendererObj.drawString(points, (guiLeft + 3*(xSize + 45) / 4) - 10, guiTop + 33 + (count - 5) * 30, CustomNpcResourceListener.DefaultTextColor); + } + + drawHorizontalLine(guiLeft + 2, guiLeft + xSize + 35, guiTop + 14 + hLine * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + } + + if(pages > 1){ + String s = page +"/" + pages; + fontRendererObj.drawString(s, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(s)) / 2, guiTop + 175, CustomNpcResourceListener.DefaultTextColor); + } + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + if (guibutton.id >= 100) { + if (guibutton.id == 100 && activeTab != 0) { + activeTab = 0; + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + } + if (guibutton.id == 101 && activeTab != 1) { + activeTab = 1; + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + } + if (guibutton.id == 102 && activeTab != 2) { + activeTab = 2; + mc.displayGuiScreen(new GuiFaction()); + } + } + + if(!(guibutton instanceof GuiButtonNextPage)) + return; + int id = guibutton.id; + if(id == 1){ + page++; + } + if(id == 2){ + page--; + } + updateButtons(); + } + private void updateButtons(){ + buttonNextPage.setVisible(page < pages); + buttonPreviousPage.setVisible(page > 1); + } + protected void drawGuiContainerBackgroundLayer(float f, int i, int j) + { + + } + + @Override + public void keyTyped(char c, int i) + { + if (i == 1 || isInventoryKey(i)) + { + close(); + } + } + @Override + public void save() { + } + @Override + public void setGuiData(NBTTagCompound compound) { + playerFactions = new ArrayList(); + + NBTTagList list = compound.getTagList("FactionList", 10); + for(int i = 0; i < list.tagCount(); i++){ + Faction faction = new Faction(); + faction.readNBT(list.getCompoundTagAt(i)); + playerFactions.add(faction); + } + PlayerFactionData data = new PlayerFactionData(); + data.loadNBTData(compound); + for(int id : data.factionData.keySet()){ + int points = data.factionData.get(id); + for(Faction faction : playerFactions){ + if(faction.id == id) + faction.defaultPoints = points; + } + } + + pages = (playerFactions.size() - 1) / 10 ; + pages++; + + page = 1; + + updateButtons(); + } + +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java new file mode 100644 index 000000000..ce7dcfd30 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -0,0 +1,229 @@ +package noppes.npcs.client.gui.player.inventory; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.Client; +import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Party; +import org.lwjgl.opengl.GL11; +import tconstruct.client.tabs.InventoryTabCustomNpc; +import tconstruct.client.tabs.TabRegistry; + +import java.util.ArrayList; +import java.util.UUID; + +public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData { + private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); + private final EntityPlayer player; + private Minecraft mc = Minecraft.getMinecraft(); + + private boolean receivedData; + private long renderTicks; + + public GuiParty(EntityPlayer player) { + super(); + this.player = player; + xSize = 280; + ySize = 180; + drawDefaultBackground = false; + activeTab = 1; + Client.sendData(EnumPacketServer.GetPartyData); + } + + public void initGui(){ + super.initGui(); + Party party = ClientCacheHandler.party; + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + + if (receivedData) { + if (party == null) { + // + //create party button + // + GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "Create Party"); + createPartyButton.width = 100; + this.addButton(createPartyButton); + + this.addLabel(new GuiNpcLabel(201, "You're not in a party!", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30)); + this.addLabel(new GuiNpcLabel(202, "Either wait for an invite", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20)); + this.addLabel(new GuiNpcLabel(203, "or create one.", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10)); + + //party invites list + // + GuiCustomScroll inviteScroll = new GuiCustomScroll(this, 210, false); + inviteScroll.setSize(150, 160); + inviteScroll.guiLeft = guiLeft + 5; + inviteScroll.guiTop = guiTop + 5; + this.addScroll(inviteScroll); + + GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "Accept"); + acceptButton.width = 60; + this.addButton(acceptButton); + + GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "Ignore"); + ignoreButton.width = 60; + this.addButton(ignoreButton); + } else { + // + //party player list + // + GuiCustomScroll playerScroll = new GuiCustomScroll(this, 300, false); + playerScroll.setSize(150, 160); + playerScroll.guiLeft = guiLeft + 5; + playerScroll.guiTop = guiTop + 5; + playerScroll.setList(new ArrayList<>(party.getPlayerNames())); + this.addScroll(playerScroll); + + //set leader button + // + GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "Make Leader"); + leaderButton.width = 70; + this.addButton(leaderButton); + + //kick player button + // + GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "Kick"); + kickButton.width = 70; + this.addButton(kickButton); + + //toggle friendly fire + // + GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"On", "Off"}, 0); //party.friendlyFire() ? 0 : 1 + friendlyFireButton.width = 40; + this.addButton(friendlyFireButton); + + GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, "Friendly Fire:", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5); + this.addLabel(friendlyFireLabel); + + //send invite button (opens subgui) + // + GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize/2 + 20, guiTop + ySize/2 + 40,100, 20, ""); + this.addTextField(playerTextField); + + GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "Invite"); + inviteButton.width = 50; + this.addButton(inviteButton); + + //disband party + // + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "Disband Party"); + disbandButton.width = 100; + this.addButton(disbandButton); + } + } + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + switch (guibutton.id) { + case 200: + Client.sendData(EnumPacketServer.CreateParty); + receivedData = false; + break; + case 335: + Client.sendData(EnumPacketServer.DisbandParty); + receivedData = false; + break; + } + initGui(); + if (guibutton.id == 100 && activeTab != 0) { + activeTab = 0; + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + } + if (guibutton.id == 101 && activeTab != 1) { + activeTab = 1; + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + } + if (guibutton.id == 102 && activeTab != 2) { + activeTab = 2; + mc.displayGuiScreen(new GuiFaction()); + } + } + + @Override + public void drawScreen(int i, int j, float f){ + renderTicks++; + + drawDefaultBackground(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(resource); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); + drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); + super.drawScreen(i, j, f); + + if(!receivedData){ + String periods = ""; + for (int k = 0; k < (renderTicks/10)%4; k++) { + periods += "."; + } + fontRendererObj.drawString(StatCollector.translateToLocal("gui.loading") + periods,guiLeft + xSize/2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); + } + } + + @Override + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if (!GuiNpcTextField.isFieldActive()) { + if (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode()) // inventory key + { + mc.displayGuiScreen(null); + mc.setIngameFocus(); + } + } + } + + @Override + public boolean doesGuiPauseGame() + { + return false; + } + + @Override + public void setGuiData(NBTTagCompound compound) { + this.receivedData = true; + + if (compound.hasKey("PartyUUID")) { + Party party = ClientCacheHandler.party; + UUID uuid = UUID.fromString(compound.getString("PartyUUID")); + if (party == null || !party.getPartyUUID().equals(uuid)) { + ClientCacheHandler.party = new Party(uuid); + party = ClientCacheHandler.party; + } + party.readFromNBT(compound); + } else if (compound.hasKey("Disband")) { + ClientCacheHandler.party = null; + } + + initGui(); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + this.save(); + } + + @Override + public void save() { + + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + + } + + @Override + public void unFocused(GuiNpcTextField textfield) { + + } +} diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java similarity index 93% rename from src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java rename to src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java index f95aec81e..02be187b6 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java @@ -1,4 +1,4 @@ -package noppes.npcs.client.gui.player; +package noppes.npcs.client.gui.player.inventory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; @@ -17,14 +17,13 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.util.ValueUtil; -import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import tconstruct.client.tabs.InventoryTabQuests; +import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; import java.util.*; -public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,ICustomScrollListener, IGuiData{ +public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,ICustomScrollListener, IGuiData{ private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); @@ -51,14 +50,13 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I ySize = 180; NoppesUtilPlayer.sendData(EnumPlayerPacket.QuestLog); drawDefaultBackground = false; + activeTab = 0; } public void initGui(){ super.initGui(); sideButtons.clear(); - guiTop +=10; - TabRegistry.addTabsToList(buttonList); - TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabQuests.class); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); noQuests = false; @@ -124,6 +122,18 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I data.toggleQuestAlerts(); } initGui(); + if (guibutton.id == 100 && activeTab != 0) { + activeTab = 0; + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + } + if (guibutton.id == 101 && activeTab != 1) { + activeTab = 1; + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + } + if (guibutton.id == 102 && activeTab != 2) { + activeTab = 2; + mc.displayGuiScreen(new GuiFaction()); + } } @Override public void drawScreen(int i, int j, float f){ diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java index 506e30075..99fdb45c8 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java @@ -2,20 +2,27 @@ package noppes.npcs.client.gui.util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; public class GuiMenuSideButton extends GuiNpcButton{ public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/menusidebutton.png"); + public static final ResourceLocation resource2 = new ResourceLocation("customnpcs","textures/gui/menusidebutton2.png"); public boolean active; + public boolean rightSided; + public ItemStack renderStack; - public GuiMenuSideButton(int i, int j, int k, String s){ - this(i, j, k, 200, 20, s); + public GuiMenuSideButton(int id, int x, int y, String s){ + this(id, x, y, 200, 20, s); } - public GuiMenuSideButton(int i, int j, int k, int l, int i1, String s){ - super(i, j, k, l, i1, s); + public GuiMenuSideButton(int id, int x, int y, int width, int height, String s){ + super(id, x, y, width, height, s); active = false; } @@ -23,7 +30,7 @@ public class GuiMenuSideButton extends GuiNpcButton{ public int getHoverState(boolean flag){ if (active) return 0; - return 1; + return super.getHoverState(flag); } @Override @@ -32,13 +39,38 @@ public class GuiMenuSideButton extends GuiNpcButton{ return; } FontRenderer fontrenderer = minecraft.fontRenderer; - minecraft.renderEngine.bindTexture(resource); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int width = this.width + (active?2:0); field_146123_n = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height; int k = getHoverState(field_146123_n); - drawTexturedModalRect(xPosition, yPosition, 0, k * 22, width, height); + + if (this.rightSided) { + minecraft.renderEngine.bindTexture(resource2); + drawTexturedModalRect(xPosition, yPosition, 197 - width, k * 22, width, height); + } else { + minecraft.renderEngine.bindTexture(resource); + drawTexturedModalRect(xPosition, yPosition, 0, k * 22, width, height); + } mouseDragged(minecraft, i, j); + + if (this.renderStack != null) { + RenderHelper.enableGUIStandardItemLighting(); + this.zLevel = 100.0F; + RenderItem itemRenderer = RenderItem.getInstance(); + itemRenderer.zLevel = 100.0F; + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + itemRenderer.renderItemAndEffectIntoGUI(minecraft.fontRenderer, + minecraft.renderEngine, this.renderStack, xPosition + 2, yPosition + height/2 - 8); + itemRenderer.renderItemOverlayIntoGUI(minecraft.fontRenderer, + minecraft.renderEngine, this.renderStack, xPosition + 2, yPosition + height/2 - 8); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_BLEND); + itemRenderer.zLevel = 0.0F; + this.zLevel = 0.0F; + RenderHelper.disableStandardItemLighting(); + } String text = ""; float maxWidth = width * 0.75f; diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index f3569c1d2..fb776be91 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -91,10 +91,12 @@ public enum EnumPacketServer { RemoteTpToNpc,QuestGet, QuestCategoryGet, SaveTileEntity, NaturalSpawnGetAll, MailOpenSetup, - DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, + DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, CacheAnimation, CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, + CreateParty, GetPartyData, DisbandParty, + ServerUpdateSkinOverlays; public CustomNpcsPermissions.Permission permission = null; diff --git a/src/main/java/noppes/npcs/controllers/AnimationController.java b/src/main/java/noppes/npcs/controllers/AnimationController.java index 685c94ec6..3b28eb35e 100644 --- a/src/main/java/noppes/npcs/controllers/AnimationController.java +++ b/src/main/java/noppes/npcs/controllers/AnimationController.java @@ -3,15 +3,12 @@ package noppes.npcs.controllers; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.api.handler.IAnimationHandler; import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.api.handler.data.IFaction; import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.Faction; -import noppes.npcs.controllers.data.TagMap; +import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.util.NBTJsonUtil; import java.io.*; @@ -120,6 +117,10 @@ public class AnimationController implements IAnimationHandler { animations.remove(animation.getID()); animations.put(animation.getID(), (Animation) animation); + for (PlayerData playerData : PlayerDataController.Instance.getAllPlayerData()) { + playerData.animationData.uncacheAnimation(animation.getID()); + } + saveAnimationMap(); // Save Animation File diff --git a/src/main/java/noppes/npcs/controllers/PartyController.java b/src/main/java/noppes/npcs/controllers/PartyController.java new file mode 100644 index 000000000..78540c4dd --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/PartyController.java @@ -0,0 +1,47 @@ +package noppes.npcs.controllers; + +import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.controllers.data.Party; +import noppes.npcs.controllers.data.PlayerData; + +import java.util.HashMap; +import java.util.UUID; + +public class PartyController { + private static PartyController Instance; + + private HashMap parties = new HashMap<>(); + + private PartyController() { + } + + public static PartyController Instance() { + if (Instance == null) { + Instance = new PartyController(); + } + return Instance; + } + + public Party createParty() { + Party party = new Party(); + this.parties.put(party.getPartyUUID(), party); + return party; + } + + public Party getParty(UUID partyUUID) { + return this.parties.get(partyUUID); + } + + public void disbandParty(UUID partyUUID) { + Party party = this.parties.get(partyUUID); + if (party != null) { + for (UUID uuid: party.getPlayerUUIDs()) { + EntityPlayer player = NoppesUtilServer.getPlayer(uuid); + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + playerData.partyUUID = null; + } + this.parties.remove(partyUUID); + } + } +} diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index b43a33e91..fcdd7e2e7 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -281,6 +281,17 @@ public class PlayerDataController { return data; } + public ArrayList getAllPlayerData() { + ArrayList playerDataList = new ArrayList<>(); + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (Object o : list) { + if (o instanceof EntityPlayer) { + playerDataList.add(this.getPlayerData((EntityPlayer)o)); + } + } + return playerDataList; + } + public PlayerData getPlayerData(EntityPlayer player){ PlayerData data = getPlayerDataCache(player.getUniqueID().toString()); if(data != null){ diff --git a/src/main/java/noppes/npcs/controllers/data/Animation.java b/src/main/java/noppes/npcs/controllers/data/Animation.java index 0950ee42d..be4e6262c 100644 --- a/src/main/java/noppes/npcs/controllers/data/Animation.java +++ b/src/main/java/noppes/npcs/controllers/data/Animation.java @@ -2,6 +2,7 @@ package noppes.npcs.controllers.data; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.api.handler.data.IAnimation; @@ -13,7 +14,7 @@ import java.util.ArrayList; public class Animation implements IAnimation { - + public AnimationData parent; //Client-sided only public int id = -1; // Only for internal usage public ArrayList frames = new ArrayList<>(); @@ -229,6 +230,10 @@ public class Animation implements IAnimation { if (paused) return; + if (this.parent != null && this.currentFrame < this.frames.size()) { + this.parent.finishedFrame = this.currentFrame; + } + this.currentFrameTime++; if (this.currentFrameTime == this.currentFrame().getDuration()) { Frame prevFrame = (Frame) this.currentFrame(); @@ -247,6 +252,8 @@ public class Animation implements IAnimation { nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots; } } + } else if (this.parent != null && this.currentFrame > this.loop) { + this.parent.finishedTime = this.parent.animationEntity.getAge(); } } } diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index ec0f32753..72d08ff16 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -1,17 +1,23 @@ package noppes.npcs.controllers.data; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; import noppes.npcs.DataDisplay; import noppes.npcs.Server; import noppes.npcs.api.handler.data.IAnimationData; import noppes.npcs.api.handler.data.IAnimation; import noppes.npcs.constants.EnumPacketClient; -import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityNPCInterface; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + public class AnimationData implements IAnimationData { //Server-side: DataDisplay, PlayerData //Client-side: DataDisplay, EntityPlayer @@ -20,19 +26,45 @@ public class AnimationData implements IAnimationData { public Animation animation; public boolean allowAnimation = false; + private final HashSet cachedAnimationIDs = new HashSet<>(); + + //Client-side values + public EntityLivingBase animationEntity; + public int finishedTime = -1; + public int finishedFrame = -1; + public AnimationData(Object parent){ this.parent = parent; + if (parent instanceof DataDisplay) { + this.animationEntity = ((DataDisplay) parent).npc; + } else if (parent instanceof EntityPlayer) { + this.animationEntity = (EntityLivingBase) parent; + } } public void updateClient() { - NBTTagCompound compound = new NBTTagCompound(); - compound = this.writeToNBT(compound); - compound.setTag("Animation",this.animation == null ? new NBTTagCompound() : this.animation.writeToNBT()); - if (parent instanceof PlayerData) { - Server.sendToAll(EnumPacketClient.UPDATE_ANIMATIONS, compound, ((PlayerData) parent).player.getCommandSenderName()); - } else if (parent instanceof DataDisplay) { - compound.setInteger("EntityId",((DataDisplay) parent).npc.getEntityId()); - Server.sendAssociatedData(((DataDisplay) parent).npc, EnumPacketClient.UPDATE_ANIMATIONS, compound); + this.updateClient(new EntityPlayer[0]); + } + + public void updateClient(EntityPlayer... excludedPlayers) { + EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null; + float range = parent instanceof PlayerData ? 160 : 60; + if (sendingEntity != null) { + + List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox( + sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, + sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); + + entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp)); + + NBTTagCompound animationNBT = null; + for (EntityPlayer player : entities) { + AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData; + if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) { + animationNBT = this.animation.writeToNBT(); + } + animationData.viewAnimation(this.animation, sendingEntity, this, animationNBT); + } } } @@ -62,17 +94,49 @@ public class AnimationData implements IAnimationData { } } + public boolean isCached(int id) { + return this.cachedAnimationIDs.contains(id); + } + + public void cacheAnimation(int id) { + this.cachedAnimationIDs.add(id); + } + + public void uncacheAnimation(int id) { + this.cachedAnimationIDs.remove(id); + } + + public void viewAnimation(Animation animation, EntityLivingBase entity, AnimationData animationData, NBTTagCompound animationNBT) { + NBTTagCompound data = animationData.writeToNBT(new NBTTagCompound()); + if (animation != null) { + if (this.cachedAnimationIDs.contains(animation.getID())) { + data.setInteger("AnimationID", animation.getID()); + } else { + data.setTag("Animation", animationNBT); + } + } + if (!(entity instanceof EntityPlayer)) { + data.setInteger("EntityId", entity.getEntityId()); + } + Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName()); + } + public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setBoolean("AllowAnimation", allowAnimation); return compound; } public void readFromNBT(NBTTagCompound compound) { - this.allowAnimation = compound.getBoolean("AllowAnimation"); + this.setEnabled(compound.getBoolean("AllowAnimation")); } public void setEnabled(boolean enabled) { - this.allowAnimation = enabled; + if (this.allowAnimation != enabled) { + this.allowAnimation = enabled; + if (this.parent instanceof EntityPlayer) { + this.finishedTime = enabled ? -1 : ((EntityPlayer) this.parent).getAge(); + } + } } public boolean enabled() { diff --git a/src/main/java/noppes/npcs/controllers/data/Line.java b/src/main/java/noppes/npcs/controllers/data/Line.java index e9f5904fb..7385516fc 100644 --- a/src/main/java/noppes/npcs/controllers/data/Line.java +++ b/src/main/java/noppes/npcs/controllers/data/Line.java @@ -2,9 +2,11 @@ package noppes.npcs.controllers.data; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.handler.data.ILine; -public class Line { +public class Line implements ILine { public Line(){ @@ -17,21 +19,55 @@ public class Line { public String sound = ""; public boolean hideText = false; - public Line copy() { + public ILine copy() { Line line = new Line(text); line.sound = sound; line.hideText = hideText; return line; } - public Line formatTarget(EntityLivingBase entity) { + public ILine formatTarget(EntityLivingBase entity) { if(entity == null) return this; - Line line = copy(); + Line line = (Line) copy(); if(entity instanceof EntityPlayer) line.text = line.text.replace("@target", ((EntityPlayer) entity).getDisplayName()); else line.text = line.text.replace("@target", entity.getCommandSenderName()); return line; } + + public ILine formatTarget(IEntityLivingBase entityLivingBase) { + return this.formatTarget(entityLivingBase.getMCEntity()); + } + + @Override + public String getText() { + return this.text; + } + + @Override + public void setText(String text) { + this.text = text; + } + + @Override + public String getSound() { + return this.sound; + } + + @Override + public void setSound(String sound) { + this.sound = sound; + } + + @Override + public void hideText(boolean hide) { + this.hideText = hide; + } + + @Override + public boolean hideText() { + return this.hideText; + } } diff --git a/src/main/java/noppes/npcs/controllers/data/Lines.java b/src/main/java/noppes/npcs/controllers/data/Lines.java index b649b2cb4..c8ffeb6e0 100644 --- a/src/main/java/noppes/npcs/controllers/data/Lines.java +++ b/src/main/java/noppes/npcs/controllers/data/Lines.java @@ -2,13 +2,15 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.api.handler.data.ILine; +import noppes.npcs.api.handler.data.ILines; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; -public class Lines { +public class Lines implements ILines { private static final Random random = new Random(); private int lastLine = -1; @@ -49,7 +51,11 @@ public class Lines { lines = map; } - public Line getLine(boolean isRandom) { + public ILine createLine(String text) { + return new Line(text); + } + + public ILine getLine(boolean isRandom) { if(lines.isEmpty()) return null; if(isRandom){ @@ -66,7 +72,27 @@ public class Lines { } } + public ILine getLine(int lineIndex) { + return lines.get(lineIndex); + } + + public void setLine(int lineIndex, ILine line) { + lines.put(lineIndex, (Line) line); + } + + public void removeLine(int lineIndex) { + lines.remove(lineIndex); + } + + public void clear() { + lines.clear(); + } + public boolean isEmpty() { return lines.isEmpty(); } + + public Integer[] getKeys() { + return lines.keySet().toArray(new Integer[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index a8ab6699a..3f9c95d75 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -2,7 +2,13 @@ package noppes.npcs.controllers.data; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.handler.IPlayerQuestData; import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.controllers.PlayerDataController; @@ -14,8 +20,7 @@ import java.net.URL; import java.util.*; public class Party { - - private final UUID partyUUID = UUID.randomUUID(); + private final UUID partyUUID; private UUID partyLeader; private final HashMap partyMembers = new HashMap<>(); @@ -23,12 +28,21 @@ public class Party { private int currentQuestID = -1; - public UUID getPartyLeader() { - return partyLeader; + private boolean friendlyFire; + + //Client-sided + private String partyLeaderName; + + public Party() { + this.partyUUID = UUID.randomUUID(); } - public void setPartyLeader(UUID partyLeader) { - this.partyLeader = partyLeader; + public Party(UUID uuid) { + this.partyUUID = uuid; + } + + public UUID getPartyUUID() { + return this.partyUUID; } public int getCurrentQuestID() { @@ -44,6 +58,9 @@ public class Party { return false; } + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + playerData.partyUUID = this.partyUUID; + partyMembers.put(player.getUniqueID(), player.getCommandSenderName()); partyOrder.add(player.getUniqueID()); return true; @@ -71,12 +88,13 @@ public class Party { return false; } - public boolean removePlayer(UUID player) { - if(partyMembers.containsKey(player)){ - partyMembers.remove(player); - partyOrder.remove(player); + public boolean removePlayer(EntityPlayer player) { + UUID uuid = player.getUniqueID(); + if(partyMembers.containsKey(uuid)){ + partyMembers.remove(uuid); + partyOrder.remove(uuid); - if(player.equals(partyLeader)){ + if(uuid.equals(partyLeader)){ if(partyMembers.size() > 0){ partyLeader = partyOrder.get(0); } @@ -88,8 +106,8 @@ public class Party { return false; } - public boolean hasPlayer(UUID player) { - return partyMembers.containsKey(player); + public boolean hasPlayer(EntityPlayer player) { + return partyMembers.containsKey(player.getUniqueID()); } public boolean hasPlayer(String playerName) { @@ -100,8 +118,18 @@ public class Party { return partyMembers.containsKey(uuid); } - public boolean setLeader(UUID uuid){ - if(partyLeader.equals(uuid)){ + public EntityPlayer getPartyLeader() { + return NoppesUtilServer.getPlayer(this.partyLeader); + } + + @SideOnly(Side.CLIENT) + public String getPartyLeaderName() { + return this.partyLeaderName; + } + + public boolean setLeader(EntityPlayer player){ + UUID uuid = player.getUniqueID(); + if(partyLeader != null && partyLeader.equals(uuid)){ return false; } @@ -120,6 +148,14 @@ public class Party { return true; } + public Collection getPlayerNames() { + return this.partyMembers.values(); + } + + public Collection getPlayerUUIDs() { + return this.partyMembers.keySet(); + } + // To Be Called DURING Invite, Leave, Quest Switch, Leader Switch, etc. public static boolean validateQuest(int questID, Collection players){ IQuest quest = QuestController.Instance.get(questID); @@ -154,6 +190,14 @@ public class Party { } } + public void toggleFriendlyFire() { + this.friendlyFire = !this.friendlyFire; + } + + public boolean friendlyFire() { + return this.friendlyFire; + } + public static UUID getUUID(String name) { UUID uuid = null; try { @@ -168,4 +212,35 @@ public class Party { return uuid; } + public void readFromNBT(NBTTagCompound compound) { + this.partyLeaderName = compound.getString("PartyLeader"); + this.currentQuestID = compound.getInteger("PartyQuestID"); + + NBTTagList list = compound.getTagList("PartyMembers", 10); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound tagCompound = list.getCompoundTagAt(i); + UUID uuid = UUID.fromString(tagCompound.getString("UUID")); + String playerName = tagCompound.getString("PlayerName"); + this.partyOrder.add(uuid); + this.partyMembers.put(uuid, playerName); + } + } + + public NBTTagCompound writeToNBT() { + NBTTagCompound compound = new NBTTagCompound(); + + compound.setString("PartyUUID", this.partyUUID.toString()); + compound.setInteger("PartyQuestID", this.currentQuestID); + compound.setString("PartyLeader", getPartyLeader().getCommandSenderName()); + NBTTagList list = new NBTTagList(); + for (UUID uuid : this.partyOrder) { + NBTTagCompound uuidCompound = new NBTTagCompound(); + uuidCompound.setString("UUID", uuid.toString()); + uuidCompound.setString("PlayerName", this.partyMembers.get(uuid)); + list.appendTag(uuidCompound); + } + compound.setTag("PartyMembers", list); + + return compound; + } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 67ddcf18f..713e83569 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -48,6 +48,7 @@ import noppes.npcs.ai.target.EntityAIClosestTarget; import noppes.npcs.ai.target.EntityAIOwnerHurtByTarget; import noppes.npcs.ai.target.EntityAIOwnerHurtTarget; import noppes.npcs.api.entity.ICustomNpc; +import noppes.npcs.api.handler.data.ILine; import noppes.npcs.api.item.IItemStack; import noppes.npcs.client.EntityUtil; import noppes.npcs.config.ConfigMain; @@ -931,28 +932,28 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return chateventPlayer; } - public void saySurrounding(Line line) { - if (line == null || line.text == null || getFakePlayer() == null) + public void saySurrounding(ILine line) { + if (line == null || line.getText() == null || getFakePlayer() == null) return; - ServerChatEvent event = new ServerChatEvent(getFakePlayer(), line.text, new ChatComponentTranslation(line.text.replace("%", "%%"))); + ServerChatEvent event = new ServerChatEvent(getFakePlayer(), line.getText(), new ChatComponentTranslation(line.getText().replace("%", "%%"))); if (MinecraftForge.EVENT_BUS.post(event) || event.component == null){ return; } - line.text = event.component.getUnformattedText().replace("%%", "%"); + line.setText(event.component.getUnformattedText().replace("%%", "%")); List inRange = worldObj.getEntitiesWithinAABB( EntityPlayer.class, this.boundingBox.expand(20D, 20D, 20D)); for (EntityPlayer player : inRange) say(player, line); } - public void say(EntityPlayer player, Line line) { - if (line == null || !this.canSee(player) || line.text == null) + public void say(EntityPlayer player, ILine line) { + if (line == null || !this.canSee(player) || line.getText() == null) return; - if(!line.sound.isEmpty()){ - Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_SOUND, line.sound, (float)posX, (float)posY, (float)posZ); + if(!line.getSound().isEmpty()){ + Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_SOUND, line.getSound(), (float)posX, (float)posY, (float)posZ); } - Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHATBUBBLE, this.getEntityId(), line.text, !line.hideText); + Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHATBUBBLE, this.getEntityId(), line.getText(), !line.hideText()); } public boolean getAlwaysRenderNameTagForRender(){ return true; diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index 22daf661a..ebe761a1c 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -29,6 +29,7 @@ import noppes.npcs.DataStats; import noppes.npcs.EventHooks; import noppes.npcs.api.IPos; import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.entity.IProjectile; import noppes.npcs.constants.EnumParticleType; import noppes.npcs.constants.EnumPotionType; @@ -452,7 +453,8 @@ public class EntityProjectile extends EntityThrowable { if (!this.worldObj.isRemote) { ProjectileEvent.ImpactEvent event; if (movingobjectposition.entityHit != null) { - event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, movingobjectposition.entityHit); + IEntity target = NpcAPI.Instance().getIEntity(movingobjectposition.entityHit); + event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, target); } else { IPos pos = NpcAPI.Instance().getIPos(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ); IWorld world = NpcAPI.Instance().getIWorld(this.worldObj); diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 41accf7fa..9df021671 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelRenderer; +import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.ClientEventHandler; @@ -123,7 +124,9 @@ public abstract class MixinModelRenderer { } catch (Exception ignored){} - if (partType != null && animData != null) { + if (partType != null && animData != null && animData.animation != null) { + boolean animDataActive = animData.isActive(); + if (!ClientEventHandler.originalValues.containsKey((ModelRenderer) (Object) this)) { FramePart part = new FramePart(); part.pivot = new float[]{prevPointX, prevPointY, prevPointZ}; @@ -131,23 +134,38 @@ public abstract class MixinModelRenderer { ClientEventHandler.originalValues.put((ModelRenderer) (Object) this, part); } FramePart originalPart = ClientEventHandler.originalValues.get((ModelRenderer) (Object) this); - if (animData.isActive()) { - Frame frame = (Frame) animData.animation.currentFrame(); - if (frame.frameParts.containsKey(partType)) { - FramePart part = frame.frameParts.get(partType); - if (partType == mainPartType) { + Frame frame = (Frame) animData.animation.currentFrame(); + if (!animDataActive && animData.finishedFrame >= 0 && animData.finishedFrame < animData.animation.frames.size()) { + frame = animData.animation.frames.get(animData.finishedFrame); + } + + if (frame != null && frame.frameParts.containsKey(partType)) { + FramePart part = frame.frameParts.get(partType); + if (partType == mainPartType) { + if (animDataActive) { part.interpolateAngles(); part.interpolateOffset(); + } else { + float speed = 0.4F; + part.prevPivots[0] = part.prevPivots[0] * (1.0F - speed); + part.prevPivots[1] = part.prevPivots[1] * (1.0F - speed); + part.prevPivots[2] = part.prevPivots[2] * (1.0F - speed); + part.prevRotations[0] = part.prevRotations[0] * (1.0F - speed) + (this.rotateAngleX * speed); + part.prevRotations[1] = part.prevRotations[1] * (1.0F - speed) + (this.rotateAngleY * speed); + part.prevRotations[2] = part.prevRotations[2] * (1.0F - speed) + (this.rotateAngleZ * speed); + } + + if (animDataActive || (partType != EnumAnimationPart.HEAD && ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20)) { this.rotationPointX = originalPart.pivot[0] + part.prevPivots[0]; this.rotationPointY = originalPart.pivot[1] + part.prevPivots[1]; this.rotationPointZ = originalPart.pivot[2] + part.prevPivots[2]; this.rotateAngleX = part.prevRotations[0]; this.rotateAngleY = part.prevRotations[1]; this.rotateAngleZ = part.prevRotations[2]; - } else { - currentPart = part; - this.rotateAngleZ += part.prevRotations[2]; } + } else { + currentPart = part; + this.rotateAngleZ += part.prevRotations[2]; } } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 42cfc3985..cdaa9c29c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -915,4 +915,9 @@ public class ScriptEntity implements IEntity { public boolean equals(Object object) { return object instanceof IEntity && ((IEntity)object).getMCEntity().equals(this.entity); } + + public void updateEntity() { + IWorld world = NpcAPI.Instance().getIWorld(entity.worldObj); + entity.dimension = world.getDimensionID(); + } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 2a7ee13a9..34f6ffafc 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -10,13 +10,16 @@ import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.entity.data.IModelData; import noppes.npcs.api.handler.IOverlayHandler; import noppes.npcs.api.handler.data.IAnimationData; +import noppes.npcs.api.handler.data.IDialog; import noppes.npcs.api.handler.data.IFaction; +import noppes.npcs.api.handler.data.ILines; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.jobs.IJob; import noppes.npcs.api.roles.IRole; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.*; import noppes.npcs.controllers.FactionController; +import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.controllers.data.Line; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -326,7 +329,49 @@ public class ScriptNpc extends ScriptLiving imp return; npc.say((EntityPlayer) player.getMCEntity(), new Line(message)); } - + + public IDialog getDialog(int slot) { + return NpcAPI.Instance().getDialogs().get(this.getDialogId(slot)); + } + + public int getDialogId(int slot) { + if (npc.dialogs.containsKey(slot)) { + DialogOption option = npc.dialogs.get(slot); + if (option.hasDialog()) { + return option.dialogId; + } + } + return -1; + } + + public void setDialog(int slot, IDialog dialog) { + this.setDialog(slot, dialog.getId()); + } + + public void setDialog(int slot, int dialogId) { + NoppesUtilServer.setNpcDialog(slot,dialogId, this.npc); + } + + public ILines getInteractLines() { + return this.npc.advanced.interactLines; + } + + public ILines getWorldLines() { + return this.npc.advanced.worldLines; + } + + public ILines getAttackLines() { + return this.npc.advanced.attackLines; + } + + public ILines getKilledLines() { + return this.npc.advanced.killedLines; + } + + public ILines getKillLines() { + return this.npc.advanced.killLines; + } + /** * Kill the npc, doesnt't despawn it */ diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java b/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java index e22bdb8f4..b6b32db12 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java @@ -79,6 +79,10 @@ public class ScriptProjectile extends ScriptEntity