From daada3cb8a789042cacfa7b3299e707571667804 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 15 Mar 2023 19:17:39 -0500 Subject: [PATCH 01/27] IEntity: -Added setDimension function for all entities (not just players now). --- .../npcs/scripted/entity/ScriptEntity.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 4c6346aa1..acd8ec079 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -14,6 +14,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.MathHelper; +import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.INbt; import noppes.npcs.api.IParticle; @@ -423,6 +424,24 @@ public class ScriptEntity implements IEntity { return entity.dimension; } + public void setDimension(int dimensionId) { + IWorld world = NpcAPI.Instance().getIWorld(dimensionId); + if (world != null) { + World mcWorld = world.getMCWorld(); + if (this.entity.riddenByEntity != null) + { + this.entity.riddenByEntity.mountEntity((Entity)null); + } + if (this.entity.ridingEntity != null) + { + this.entity.mountEntity((Entity)null); + } + this.entity.worldObj = mcWorld; + this.entity.dimension = dimensionId; + mcWorld.addLoadedEntities(new ArrayList(Collections.singleton(this.entity))); + } + } + /** * @param range The search range for entities around this entity * @return Array of entities within range From c12bb6508c4d336d829250191f3ead792e5952c6 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 15 Mar 2023 22:24:47 -0500 Subject: [PATCH 02/27] Added global data menu to the NPC wand when right clicking the air --- src/api | 2 +- .../java/noppes/npcs/client/ClientProxy.java | 15 ++++++++--- .../npcs/client/gui/GuiNpcRemoteEditor.java | 7 ++++- .../gui/global/GuiNPCManageAnimations.java | 1 - .../gui/global/GuiNpcManagePlayerData.java | 2 +- .../gui/mainmenu/GuiNPCGlobalMainMenu.java | 2 +- .../npcs/client/gui/util/GuiNpcMenu.java | 26 ++++++++++--------- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/api b/src/api index f97b9b98f..3570b3af0 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit f97b9b98f0c50885012377d6da28172061dfe44c +Subproject commit 3570b3af0caeacecbf231fa8f626f569b3bd482d diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 74538011e..b3e662234 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -46,6 +46,7 @@ import noppes.npcs.client.gui.player.companion.GuiNpcCompanionInv; import noppes.npcs.client.gui.player.companion.GuiNpcCompanionStats; import noppes.npcs.client.gui.player.companion.GuiNpcCompanionTalents; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeItem; +import noppes.npcs.client.gui.GuiNpcRemoteEditor; import noppes.npcs.client.gui.roles.*; import noppes.npcs.client.gui.script.GuiScriptGlobal; import noppes.npcs.client.gui.script.GuiScriptItem; @@ -248,10 +249,16 @@ public class ClientProxy extends CommonProxy { return new GuiNPCManageTags(npc); else if (gui == EnumGuiType.ManageAnimations) { - EntityCustomNpc animNpc = new EntityCustomNpc(npc.worldObj); - animNpc.copyDataFrom(npc,true); - animNpc.display.showName = 1; - animNpc.display.showBossBar = 0; + EntityCustomNpc animNpc; + if (npc != null) { + animNpc = new EntityCustomNpc(npc.worldObj); + animNpc.copyDataFrom(npc, true); + animNpc.display.showName = 1; + animNpc.display.showBossBar = 0; + } else { + animNpc = new EntityCustomNpc(Minecraft.getMinecraft().theWorld); + animNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png"; + } return new GuiNPCManageAnimations(animNpc); } diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java b/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java index ed2cf7845..2b83cc849 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java @@ -7,6 +7,7 @@ import net.minecraft.entity.Entity; import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.mainmenu.GuiNPCGlobalMainMenu; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.entity.EntityNPCInterface; @@ -43,9 +44,10 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, this.addButton(new GuiNpcButton(0, guiLeft + 170, guiTop + 6,82,20, "selectServer.edit")); this.addButton(new GuiNpcButton(1, guiLeft + 170, guiTop + 28,82,20, "selectWorld.deleteButton")); this.addButton(new GuiNpcButton(2, guiLeft + 170, guiTop + 50,82,20, "remote.reset")); + this.addButton(new GuiNpcButton(3, guiLeft + 170, guiTop + 132,82,20, "remote.freeze")); this.addButton(new GuiNpcButton(4, guiLeft + 170, guiTop + 72,82,20, "remote.tp")); this.addButton(new GuiNpcButton(5, guiLeft + 170, guiTop + 110,82,20, "remote.resetall")); - this.addButton(new GuiNpcButton(3, guiLeft + 170, guiTop + 132,82,20, "remote.freeze")); + this.addButton(new GuiNpcButton(6, guiLeft + 170, guiTop + 165,82,20, "menu.global")); } @Override @@ -69,6 +71,9 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, ((EntityNPCInterface)entity).reset(); } } + if(id == 6){ + NoppesUtil.openGUI(player, new GuiNPCGlobalMainMenu(null)); + } if(!data.containsKey(scroll.getSelected())) return; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java index aca2ec8a4..d0aebabeb 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java @@ -35,7 +35,6 @@ public class GuiNPCManageAnimations extends GuiModelInterface implements IScroll Client.sendData(EnumPacketServer.AnimationListGet); xOffset -= 20; yOffset = -45; - npc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png"; AnimationData data = npc.display.animationData; data.setEnabled(true); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java index e9b821b4b..1be624891 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -21,7 +21,7 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements IScrollD private EnumPlayerData selection = EnumPlayerData.Players; private String search = ""; - public GuiNpcManagePlayerData(EntityNPCInterface npc,GuiNPCInterface2 parent) + public GuiNpcManagePlayerData(EntityNPCInterface npc) { super(npc); Client.sendData(EnumPacketServer.PlayerDataGet,selection); diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java index 6ed627a4c..7866e649c 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java @@ -58,7 +58,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2{ NoppesUtil.requestOpenGUI(EnumGuiType.ManageTransport); } if (id == 13) { - NoppesUtil.openGUI(player, new GuiNpcManagePlayerData(npc, this)); + NoppesUtil.openGUI(player, new GuiNpcManagePlayerData(npc)); } if (id == 14) { NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes, 4, 0, 0); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java index 9e1bb274b..dfb2bed7b 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java @@ -32,18 +32,20 @@ public class GuiNpcMenu implements GuiYesNoCallback{ { Keyboard.enableRepeatEvents(true); - GuiMenuTopButton display = new GuiMenuTopButton(1,guiLeft + 4, guiTop - 17, "menu.display"); - GuiMenuTopButton stats = new GuiMenuTopButton(2,display.xPosition + display.getWidth() , guiTop - 17, "menu.stats"); - GuiMenuTopButton ai = new GuiMenuTopButton(6,stats.xPosition + stats.getWidth() , guiTop - 17, "menu.ai"); - GuiMenuTopButton inv = new GuiMenuTopButton(3,ai.xPosition + ai.getWidth() , guiTop - 17, "menu.inventory"); - GuiMenuTopButton advanced = new GuiMenuTopButton(4,inv.xPosition + inv.getWidth() , guiTop - 17, "menu.advanced"); - GuiMenuTopButton global = new GuiMenuTopButton(5,advanced.xPosition + advanced.getWidth() , guiTop - 17, "menu.global"); - - GuiMenuTopButton close = new GuiMenuTopButton(0,guiLeft + width - 22, guiTop - 17, "X"); - GuiMenuTopButton delete = new GuiMenuTopButton(66,guiLeft + width - 72, guiTop - 17,"selectWorld.deleteButton"); - delete.xPosition = close.xPosition - delete.getWidth(); - - topButtons = new GuiMenuTopButton[]{display,stats,ai,inv,advanced,global,close,delete}; + GuiMenuTopButton close = new GuiMenuTopButton(0,guiLeft + width - 22, guiTop - 17, "X"); + if (npc != null) { + GuiMenuTopButton display = new GuiMenuTopButton(1, guiLeft + 4, guiTop - 17, "menu.display"); + GuiMenuTopButton stats = new GuiMenuTopButton(2, display.xPosition + display.getWidth(), guiTop - 17, "menu.stats"); + GuiMenuTopButton ai = new GuiMenuTopButton(6, stats.xPosition + stats.getWidth(), guiTop - 17, "menu.ai"); + GuiMenuTopButton inv = new GuiMenuTopButton(3, ai.xPosition + ai.getWidth(), guiTop - 17, "menu.inventory"); + GuiMenuTopButton advanced = new GuiMenuTopButton(4, inv.xPosition + inv.getWidth(), guiTop - 17, "menu.advanced"); + GuiMenuTopButton global = new GuiMenuTopButton(5, advanced.xPosition + advanced.getWidth(), guiTop - 17, "menu.global"); + GuiMenuTopButton delete = new GuiMenuTopButton(66,guiLeft + width - 72, guiTop - 17,"selectWorld.deleteButton"); + delete.xPosition = close.xPosition - delete.getWidth(); + topButtons = new GuiMenuTopButton[]{display,stats,ai,inv,advanced,global,close,delete}; + } else { + topButtons = new GuiMenuTopButton[]{close}; + } for(GuiMenuTopButton button : topButtons) button.active = button.id == activeMenu; From 22a4082890b2e089c94a123d76f8748d3f7dc6ee Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 15 Mar 2023 22:50:50 -0500 Subject: [PATCH 03/27] IWorld: -Added isPlaceCancelled and isBreakCancelled functions --- .../noppes/npcs/scripted/ScriptWorld.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index f27d84c33..8cd529566 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -16,7 +16,11 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Vec3; +import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.event.world.BlockEvent; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.*; @@ -28,6 +32,7 @@ import noppes.npcs.api.scoreboard.IScoreboard; import noppes.npcs.blocks.tiles.TileBigSign; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; +import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.scoreboard.ScriptScoreboard; import java.util.*; @@ -462,6 +467,49 @@ public class ScriptWorld implements IWorld { this.removeBlock(pos.getX(),pos.getY(),pos.getZ()); } + public boolean isPlaceCancelled(int posX, int posY, int posZ) { + IBlock block = this.getBlock(posX,posY,posZ); + if (block == null) { + return false; + } + + Block mcBlock = block.getMCBlock(); + int metadata = this.getBlockMetadata(posX,posY,posZ); + + final BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent( + new BlockSnapshot(this.world, (int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ), mcBlock, metadata), + Blocks.air, EntityNPCInterface.CommandPlayer); + + MinecraftForge.EVENT_BUS.post(placeEvent); + + return placeEvent.isCanceled(); + } + + public boolean isPlaceCancelled(IPos pos) { + return this.isPlaceCancelled(pos.getX(),pos.getY(),pos.getZ()); + } + + public boolean isBreakCancelled(int posX, int posY, int posZ) { + IBlock block = this.getBlock(posX,posY,posZ); + if (block == null) { + return false; + } + + Block mcBlock = block.getMCBlock(); + int metadata = this.getBlockMetadata(posX,posY,posZ); + + final BlockEvent.BreakEvent placeEvent = new BlockEvent.BreakEvent(posX, posY, posZ, world, + mcBlock, metadata, EntityNPCInterface.CommandPlayer); + + MinecraftForge.EVENT_BUS.post(placeEvent); + + return placeEvent.isCanceled(); + } + + public boolean isBreakCancelled(IPos pos) { + return this.isBreakCancelled(pos.getX(),pos.getY(),pos.getZ()); + } + public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) { if (startPos.length != 3 || lookVector.length != 3) { return null; From 19e14983aa449f7adcb41d09b314afc3c2fe978f Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 15 Mar 2023 23:10:03 -0500 Subject: [PATCH 04/27] IWorld: -Fixed isPlaceCancelled and isBreakCancelled functions --- src/api | 2 +- .../noppes/npcs/entity/EntityNPCInterface.java | 15 +++------------ .../java/noppes/npcs/scripted/ScriptWorld.java | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/api b/src/api index 3570b3af0..21b4d91fc 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 3570b3af0caeacecbf231fa8f626f569b3bd482d +Subproject commit 21b4d91fc7ac0d69026fc9ebb1185961190061db diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index a63b147cf..e00e9b159 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -57,6 +57,7 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.data.*; import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.*; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.event.NpcEvent; import noppes.npcs.util.GameProfileAlt; @@ -69,7 +70,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public static final GameProfileAlt chateventProfile = new GameProfileAlt(); public static FakePlayer chateventPlayer; - public static FakePlayer CommandPlayer; public DataDisplay display; public DataStats stats; public DataAI ai; @@ -901,6 +901,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti EntityUtil.Copy(this, chateventPlayer); chateventProfile.npc = this; chateventPlayer.refreshDisplayName(); + IItemStack stack = NpcAPI.Instance().createItem("minecraft:stone",0,1); + chateventPlayer.setCurrentItemOrArmor(0, stack.getMCItemStack()); return chateventPlayer; } @@ -1578,17 +1580,6 @@ 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/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 8cd529566..cf45ac060 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -20,6 +20,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.world.BlockEvent; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; @@ -30,6 +31,7 @@ import noppes.npcs.api.handler.data.ISound; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.scoreboard.IScoreboard; import noppes.npcs.blocks.tiles.TileBigSign; +import noppes.npcs.client.EntityUtil; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityNPCInterface; @@ -476,9 +478,13 @@ public class ScriptWorld implements IWorld { Block mcBlock = block.getMCBlock(); int metadata = this.getBlockMetadata(posX,posY,posZ); + FakePlayer fakePlayer = new FakePlayer(this.world, EntityNPCInterface.chateventProfile); + IItemStack stack = NpcAPI.Instance().createItem("minecraft:stone",0,1); + fakePlayer.setCurrentItemOrArmor(0, stack.getMCItemStack()); + final BlockEvent.PlaceEvent placeEvent = new BlockEvent.PlaceEvent( new BlockSnapshot(this.world, (int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ), mcBlock, metadata), - Blocks.air, EntityNPCInterface.CommandPlayer); + Blocks.air, fakePlayer); MinecraftForge.EVENT_BUS.post(placeEvent); @@ -498,8 +504,12 @@ public class ScriptWorld implements IWorld { Block mcBlock = block.getMCBlock(); int metadata = this.getBlockMetadata(posX,posY,posZ); + FakePlayer fakePlayer = new FakePlayer(this.world, EntityNPCInterface.chateventProfile); + IItemStack stack = NpcAPI.Instance().createItem("minecraft:stone",0,1); + fakePlayer.setCurrentItemOrArmor(0, stack.getMCItemStack()); + final BlockEvent.BreakEvent placeEvent = new BlockEvent.BreakEvent(posX, posY, posZ, world, - mcBlock, metadata, EntityNPCInterface.CommandPlayer); + mcBlock, metadata, fakePlayer); MinecraftForge.EVENT_BUS.post(placeEvent); From 46d668f44c730d165f66e49ac0381af931718fd6 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 02:51:40 -0500 Subject: [PATCH 05/27] Added IProjectile and its events. --- src/api | 2 +- src/main/java/noppes/npcs/EventHooks.java | 22 +++++ .../npcs/controllers/ScriptContainer.java | 4 + .../noppes/npcs/entity/EntityProjectile.java | 37 +++++++- .../java/noppes/npcs/scripted/NpcAPI.java | 3 + .../npcs/scripted/constants/EntityType.java | 2 + .../scripted/entity/ScriptProjectile.java | 90 +++++++++++++++++++ .../npcs/scripted/event/ProjectileEvent.java | 37 ++++++++ 8 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java create mode 100644 src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java diff --git a/src/api b/src/api index 21b4d91fc..c3a023021 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 21b4d91fc7ac0d69026fc9ebb1185961190061db +Subproject commit c3a023021d94aa86edfaf8262b25354a8acddf01 diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 94bf5af59..24c6301fc 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -22,14 +22,17 @@ import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.entity.IProjectile; import noppes.npcs.api.gui.ICustomGui; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.api.item.IItemStack; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.CustomGuiController; +import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.*; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.entity.EntityProjectile; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.*; import noppes.npcs.scripted.event.PlayerEvent.*; @@ -239,6 +242,25 @@ public class EventHooks { NpcAPI.EVENT_BUS.post(event); } + public static void onProjectileTick(EntityProjectile projectile) { + ProjectileEvent.UpdateEvent event = new ProjectileEvent.UpdateEvent((IProjectile) NpcAPI.Instance().getIEntity(projectile)); + for(ScriptContainer script : projectile.scripts) { + if(script.isValid()) { + script.run(EnumScriptType.PROJECTILE_TICK, event); + } + } + NpcAPI.EVENT_BUS.post(event); + } + + public static void onProjectileImpact(EntityProjectile projectile, ProjectileEvent.ImpactEvent event) { + for(ScriptContainer script : projectile.scripts) { + if(script.isValid()) { + script.run(EnumScriptType.PROJECTILE_IMPACT, event); + } + } + NpcAPI.EVENT_BUS.post(event); + } + public static void onPlayerInit(PlayerDataScript handler, IPlayer player) { noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(player); handler.callScript(EnumScriptType.INIT, event); diff --git a/src/main/java/noppes/npcs/controllers/ScriptContainer.java b/src/main/java/noppes/npcs/controllers/ScriptContainer.java index 254f6a739..862b03c45 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptContainer.java +++ b/src/main/java/noppes/npcs/controllers/ScriptContainer.java @@ -204,6 +204,10 @@ public class ScriptContainer { } } + public boolean isValid() { + return init && !errored; + } + public boolean hasCode() { return !this.getFullCode().isEmpty(); } diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index 05a9e32d2..ffb64ca1d 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -25,10 +25,18 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.world.Explosion; import net.minecraft.world.World; import noppes.npcs.DataStats; +import noppes.npcs.EventHooks; +import noppes.npcs.api.IPos; +import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IProjectile; import noppes.npcs.constants.EnumParticleType; import noppes.npcs.constants.EnumPotionType; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.event.ProjectileEvent; import noppes.npcs.util.IProjectileCallback; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.UUID; @@ -76,10 +84,11 @@ public class EntityProjectile extends EntityThrowable { public EnumPotionType effect = EnumPotionType.None; public int duration = 5; public int amplify = 0; + public int accuracy = 60; public IProjectileCallback callback; public ItemStack callbackItem; - + public List scripts = new ArrayList(); public EntityProjectile(World par1World) { @@ -209,6 +218,10 @@ public class EntityProjectile extends EntityThrowable { public void onUpdate() { super.onEntityUpdate(); + if(++ticksExisted % 10 == 0){ + EventHooks.onProjectileTick(this); + } + if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); @@ -432,11 +445,25 @@ public class EntityProjectile extends EntityThrowable { @Override protected void onImpact(MovingObjectPosition movingobjectposition) { + ProjectileEvent.ImpactEvent event; + if(movingobjectposition.entityHit != null) { + IPos pos = NpcAPI.Instance().getIPos(movingobjectposition.entityHit.posX,movingobjectposition.entityHit.posY,movingobjectposition.entityHit.posZ); + event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, movingobjectposition.entityHit); + } + else { + IPos pos = NpcAPI.Instance().getIPos(movingobjectposition.blockX,movingobjectposition.blockY,movingobjectposition.blockZ); + IWorld world = NpcAPI.Instance().getIWorld(this.worldObj); + event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 1, NpcAPI.Instance().getIBlock(world, pos)); + } + if (movingobjectposition.entityHit != null) { + if (callback != null && callbackItem != null && movingobjectposition.entityHit instanceof EntityLivingBase && callback.onImpact(this, (EntityLivingBase) movingobjectposition.entityHit, callbackItem)) { + return; + } + } + EventHooks.onProjectileImpact(this, event); + if (movingobjectposition.entityHit != null) { - if(callback != null && callbackItem != null && movingobjectposition.entityHit instanceof EntityLivingBase && callback.onImpact(this, (EntityLivingBase)movingobjectposition.entityHit, callbackItem)){ - return; - } float damage = this.damage; if(damage == 0) damage = 0.001f; @@ -695,6 +722,7 @@ public class EntityProjectile extends EntityThrowable { par1NBTTagCompound.setBoolean("accelerate", this.accelerate); par1NBTTagCompound.setByte("glows", this.dataWatcher.getWatchableObjectByte(24)); par1NBTTagCompound.setBoolean("explosive", explosive); + par1NBTTagCompound.setInteger("accuracy", accuracy); par1NBTTagCompound.setInteger("PotionEffect", effect.ordinal()); par1NBTTagCompound.setString("trail", this.dataWatcher.getWatchableObjectString(22)); par1NBTTagCompound.setByte("Render3D", this.dataWatcher.getWatchableObjectByte(28)); @@ -724,6 +752,7 @@ public class EntityProjectile extends EntityThrowable { this.duration = par1NBTTagCompound.getInteger("effectDuration"); this.accelerate = par1NBTTagCompound.getBoolean("accelerate"); this.explosive = par1NBTTagCompound.getBoolean("explosive"); + this.accuracy = par1NBTTagCompound.getInteger("accuracy"); this.effect = EnumPotionType.values()[par1NBTTagCompound.getInteger("PotionEffect") % EnumPotionType.values().length]; this.dataWatcher.updateObject(22, par1NBTTagCompound.getString("trail")); this.dataWatcher.updateObject(23, Integer.valueOf(par1NBTTagCompound.getInteger("size"))); diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index f90b75f47..f53337d83 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -54,6 +54,7 @@ import noppes.npcs.controllers.data.FramePart; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.entity.EntityProjectile; import noppes.npcs.items.ItemScripted; import noppes.npcs.scripted.entity.*; import noppes.npcs.scripted.gui.ScriptGui; @@ -202,6 +203,8 @@ public class NpcAPI extends AbstractNpcAPI { data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity)); else if(entity instanceof EntityLivingBase) data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase)entity)); + else if(entity instanceof EntityProjectile) + data = new ScriptEntityData(new ScriptProjectile<>((EntityProjectile)entity)); else data = new ScriptEntityData(new ScriptEntity<>(entity)); entity.registerExtendedProperties("ScriptedObject", data); diff --git a/src/main/java/noppes/npcs/scripted/constants/EntityType.java b/src/main/java/noppes/npcs/scripted/constants/EntityType.java index 3a9b1842c..4bd9cdfd5 100644 --- a/src/main/java/noppes/npcs/scripted/constants/EntityType.java +++ b/src/main/java/noppes/npcs/scripted/constants/EntityType.java @@ -7,4 +7,6 @@ public class EntityType { public static final int MONSTER = 3; public static final int ANIMAL = 4; public static final int LIVING = 5; + public static final int ITEM = 6; + public static final int PROJECTILE = 7; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java b/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java new file mode 100644 index 000000000..e22bdb8f4 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java @@ -0,0 +1,90 @@ +package noppes.npcs.scripted.entity; + +import net.minecraft.util.MathHelper; +import noppes.npcs.api.entity.IEntity; +import noppes.npcs.api.entity.IProjectile; +import noppes.npcs.api.item.IItemStack; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.entity.EntityProjectile; +import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.constants.EntityType; + +public class ScriptProjectile extends ScriptEntity implements IProjectile { + protected T entity; + + public ScriptProjectile(T entity) { + super(entity); + this.entity = entity; + } + + public IItemStack getItem() { + return NpcAPI.Instance().getIItemStack(entity.getItemDisplay()); + } + + public void setItem(IItemStack item) { + if(item == null) + entity.setThrownItem(null); + else + entity.setThrownItem(item.getMCItemStack()); + } + + public boolean getHasGravity() { + return entity.hasGravity(); + } + + public void setHasGravity(boolean bo) { + entity.setHasGravity(bo); + } + + public int getAccuracy() { + return entity.accuracy; + } + + public void setAccuracy(int accuracy) { + entity.accuracy = accuracy; + } + + public void setHeading(IEntity entity) { + setHeading(entity.getX(), entity.getMCEntity().boundingBox.minY + (double)(entity.getHeight() / 2.0F), entity.getZ()); + } + + public void setHeading(double x, double y, double z) { + x = x - entity.posX; + y = y - entity.posY; + z = z - entity.posZ; + float varF = entity.hasGravity() ? (float) Math.sqrt(x * x + z * z) : 0.0F; + float angle = entity.getAngleForXYZ(x, y, z, varF, false); + float acc = (float) (20.0F - Math.floor(entity.accuracy / 5.0F)); + entity.setThrowableHeading(x, y, z, angle, acc); + } + + public void setHeading(float yaw, float pitch) { + entity.prevRotationYaw = entity.rotationYaw = yaw; + entity.prevRotationPitch = entity.rotationPitch = pitch; + + double varX = (double)(-MathHelper.sin(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI)); + double varZ = (double)(MathHelper.cos(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI)); + double varY = (double)(-MathHelper.sin(pitch / 180.0F * (float)Math.PI)); + + float acc = (float) (20.0F - Math.floor(entity.accuracy / 5.0F)); + entity.setThrowableHeading(varX, varY, varZ, -pitch, acc); + } + + public int getType() { + return EntityType.PROJECTILE; + } + + public boolean typeOf(int type){ + return type == EntityType.PROJECTILE || super.typeOf(type); + } + + public void enableEvents() { + if(ScriptContainer.Current == null) + throw new CustomNPCsException("Can only be called during scripts"); + + if(!entity.scripts.contains(ScriptContainer.Current)) { + entity.scripts.add(ScriptContainer.Current); + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java b/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java new file mode 100644 index 000000000..21dffd0f2 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/ProjectileEvent.java @@ -0,0 +1,37 @@ +package noppes.npcs.scripted.event; + +import noppes.npcs.api.entity.IProjectile; + +public class ProjectileEvent extends CustomNPCsEvent { + public IProjectile projectile; + + public ProjectileEvent(IProjectile projectile) { + this.projectile = projectile; + } + + /** + * projectileTick + */ + public static class UpdateEvent extends ProjectileEvent { + public UpdateEvent(IProjectile projectile) { + super(projectile); + } + } + + /** + * projectileImpact + */ + public static class ImpactEvent extends ProjectileEvent { + /** + * 0:entity, 1:block + */ + public final int type; + public final Object target; + + public ImpactEvent(IProjectile projectile, int type, Object target) { + super(projectile); + this.type = type; + this.target = target; + } + } +} From 29935a1c6d2fc1164a3891f1751a04e91c6b6429 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 04:27:19 -0500 Subject: [PATCH 06/27] Implemented local NPC event scripts. --- src/main/java/noppes/npcs/CustomNpcs.java | 4 +- src/main/java/noppes/npcs/EventHooks.java | 26 ++-- .../java/noppes/npcs/PacketHandlerServer.java | 40 ++++-- .../java/noppes/npcs/client/ClientProxy.java | 2 +- .../noppes/npcs/client/gui/GuiScript.java | 6 + .../client/gui/script/GuiNPCEventScripts.java | 70 +++++++++ .../client/gui/script/GuiScriptAllNPCs.java | 24 +++- .../client/gui/script/GuiScriptForge.java | 50 ++++++- .../client/gui/script/GuiScriptInterface.java | 135 +----------------- .../npcs/client/gui/script/GuiScriptItem.java | 15 +- .../client/gui/script/GuiScriptPlayers.java | 54 ++++++- .../npcs/constants/EnumPacketServer.java | 5 +- .../npcs/controllers/ScriptController.java | 18 +-- .../npcs/controllers/data/DataScript.java | 30 +++- ...taScript.java => GlobalNPCDataScript.java} | 82 +++++------ .../npcs/entity/EntityNPCInterface.java | 2 + .../assets/customnpcs/lang/en_US.lang | 1 + 17 files changed, 339 insertions(+), 225 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java rename src/main/java/noppes/npcs/controllers/data/{NPCDataScript.java => GlobalNPCDataScript.java} (73%) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 9f26000e8..7aeace1b5 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -202,7 +202,7 @@ public class CustomNpcs { new AnimationController(); ScriptController.Instance.loadStoredData(); ScriptController.Instance.loadForgeScripts(); - ScriptController.Instance.loadNPCScripts(); + ScriptController.Instance.loadGlobalNPCScripts(); ScriptController.Instance.loadPlayerScripts(); ScriptController.HasStart = false; NpcAPI.clearCache(); @@ -239,7 +239,7 @@ public class CustomNpcs { GlobalDataController.instance.saveData(); ScriptController.Instance.saveForgeScripts(); ScriptController.Instance.savePlayerScripts(); - ScriptController.Instance.saveNpcScripts(); + ScriptController.Instance.saveGlobalNpcScripts(); } @EventHandler diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 24c6301fc..a563ac5fc 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -118,7 +118,7 @@ public class EventHooks { return; noppes.npcs.scripted.event.NpcEvent.InitEvent event = new noppes.npcs.scripted.event.NpcEvent.InitEvent(npc.wrappedNPC); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.INIT, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INIT, event); npc.script.callScript(EnumScriptType.INIT, event); NpcAPI.EVENT_BUS.post(event); npc.advanced.soulStoneInit = false; @@ -129,7 +129,7 @@ public class EventHooks { return; noppes.npcs.scripted.event.NpcEvent.UpdateEvent event = new noppes.npcs.scripted.event.NpcEvent.UpdateEvent(npc.wrappedNPC); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.TICK, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TICK, event); npc.script.callScript(EnumScriptType.TICK, event); NpcAPI.EVENT_BUS.post(event); } @@ -139,7 +139,7 @@ public class EventHooks { return false; NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG, event); npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); return NpcAPI.EVENT_BUS.post(event); @@ -150,7 +150,7 @@ public class EventHooks { return; NpcEvent.DialogClosedEvent event = new NpcEvent.DialogClosedEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event); npc.script.callScript(EnumScriptType.DIALOG_CLOSE, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); NpcAPI.EVENT_BUS.post(event); @@ -161,7 +161,7 @@ public class EventHooks { return false; NpcEvent.InteractEvent event = new NpcEvent.InteractEvent(npc.wrappedNPC,player); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.INTERACT, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.INTERACT, event); boolean result = npc.script.callScript(EnumScriptType.INTERACT, event, "player", player); NpcAPI.EVENT_BUS.post(event); return result; @@ -171,7 +171,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; - ScriptController.Instance.npcScripts.callScript(EnumScriptType.ATTACK_MELEE, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ATTACK_MELEE, event); npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); return NpcAPI.EVENT_BUS.post(event); } @@ -180,7 +180,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; - ScriptController.Instance.npcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event); npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); return NpcAPI.EVENT_BUS.post(event); } @@ -190,7 +190,7 @@ public class EventHooks { return; NpcEvent.KilledEntityEvent event = new NpcEvent.KilledEntityEvent(npc.wrappedNPC,entity); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLS, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLS, event); npc.script.callScript(EnumScriptType.KILLS, event, "target", entity); NpcAPI.EVENT_BUS.post(event); } @@ -199,7 +199,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; - ScriptController.Instance.npcScripts.callScript(EnumScriptType.TARGET, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET, event); npc.script.callScript(EnumScriptType.TARGET, event); return NpcAPI.EVENT_BUS.post(event); } @@ -209,7 +209,7 @@ public class EventHooks { return; NpcEvent.CollideEvent event = new NpcEvent.CollideEvent(npc.wrappedNPC,entity); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.COLLIDE, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.COLLIDE, event); npc.script.callScript(EnumScriptType.COLLIDE, event, "entity", entity); NpcAPI.EVENT_BUS.post(event); } @@ -218,7 +218,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; - ScriptController.Instance.npcScripts.callScript(EnumScriptType.DAMAGED, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.DAMAGED, event); npc.script.callScript(EnumScriptType.DAMAGED, event); return NpcAPI.EVENT_BUS.post(event); } @@ -227,7 +227,7 @@ public class EventHooks { if(npc == null || npc.wrappedNPC == null) return false; - ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLED, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.KILLED, event); npc.script.callScript(EnumScriptType.KILLED, event); return NpcAPI.EVENT_BUS.post(event); } @@ -238,7 +238,7 @@ public class EventHooks { NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); npc.script.callScript(EnumScriptType.TIMER, event); - ScriptController.Instance.npcScripts.callScript(EnumScriptType.TIMER, event); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TIMER, event); NpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 180e4c54a..baf0c2b61 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -103,7 +103,7 @@ public class PacketHandlerServer{ else if(type.hasPermission() && !CustomNpcsPermissions.hasPermission(player, type.permission)){ //player doesnt have permission to do this } - else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptNPCGet || type == EnumPacketServer.ScriptNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)) + else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)) warn(player, "tried to use custom npcs without a tool in hand, probably a hacker"); else { if (item != null) { @@ -120,10 +120,12 @@ public class PacketHandlerServer{ else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) blockPackets(type, buffer, player); else if (ConfigScript.isScriptDev(player)) { - if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) + if (type == EnumPacketServer.EventScriptDataGet || type == EnumPacketServer.EventScriptDataSave) + npcEventScriptPackets(type, buffer, player, npc); + else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) playerScriptPackets(type, buffer, player); - else if (type == EnumPacketServer.ScriptNPCGet || type == EnumPacketServer.ScriptNPCSave) - npcScriptPackets(type, buffer, player); + else if (type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave) + npcGlobalScriptPackets(type, buffer, player); else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave) forgeScriptPackets(type, buffer, player); else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave) @@ -225,8 +227,12 @@ public class PacketHandlerServer{ private void saveScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) throws Exception { int tab = buffer.readInt(); + int totalScripts = buffer.readInt(); + if (totalScripts == 0) { + data.getScripts().clear(); + } + if (tab >= 0) { - int totalScripts = buffer.readInt(); if (data.getScripts().size() > totalScripts) { data.setScripts(data.getScripts().subList(0,totalScripts)); } else while (data.getScripts().size() < totalScripts) { @@ -248,6 +254,20 @@ public class PacketHandlerServer{ } } + private void npcEventScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { + DataScript data = npc.script; + if(type == EnumPacketServer.EventScriptDataGet) { + this.getScripts(data,buffer,player); + } else if(type == EnumPacketServer.EventScriptDataSave) { + this.saveScripts(data,buffer,player); + npc.updateAI = true; + npc.script.hasInited = false; + if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s SAVED NPC %s (%s, %s, %s) [%s]", "SCRIPTER", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)(npc).posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName())); + } + } + } + private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception { PlayerDataScript data = ScriptController.Instance.playerScripts; if(type == EnumPacketServer.ScriptPlayerGet) { @@ -268,13 +288,13 @@ public class PacketHandlerServer{ } } - private void npcScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception { - NPCDataScript data = ScriptController.Instance.npcScripts; - if(type == EnumPacketServer.ScriptNPCGet) { + private void npcGlobalScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception { + GlobalNPCDataScript data = ScriptController.Instance.globalNpcScripts; + if(type == EnumPacketServer.ScriptGlobalNPCGet) { this.getScripts(data,buffer,player); - } else if(type == EnumPacketServer.ScriptNPCSave) { + } else if(type == EnumPacketServer.ScriptGlobalNPCSave) { this.saveScripts(data,buffer,player); - ScriptController.Instance.lastNpcUpdate = System.currentTimeMillis(); + ScriptController.Instance.lastGlobalNpcUpdate = System.currentTimeMillis(); } } diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index b3e662234..033af7f52 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -305,7 +305,7 @@ public class ClientProxy extends CommonProxy { return new GuiScript(npc); else if (gui == EnumGuiType.ScriptItem) - return new GuiScriptItem(Minecraft.getMinecraft().thePlayer); + return new GuiScriptItem(); else if(gui == EnumGuiType.PlayerAnvil) return new GuiNpcCarpentryBench((ContainerCarpentryBench) container); diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index 5298548d7..03ad2744c 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -9,6 +9,7 @@ import net.minecraft.server.MinecraftServer; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.script.GuiNPCEventScripts; import noppes.npcs.client.gui.swing.GuiJTextArea; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; @@ -43,6 +44,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall guiTop += 10; GuiMenuTopButton top; addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "script.scripts")); + addTopButton(new GuiMenuTopButton(16, guiLeft + (xSize - 100), guiTop - 17, "eventscript.eventScripts")); top.active = showScript; addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); top.active = !showScript; @@ -162,6 +164,10 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "https://kamkeel.github.io/CustomNPC-Plus/", 0, true); mc.displayGuiScreen(guiyesno); } + if(guibutton.id == 16){ + close(); + mc.displayGuiScreen(new GuiNPCEventScripts(npc)); + } if (guibutton.id == 100) { NoppesStringUtils.setClipboardContents(getTextField(2).getText()); } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java b/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java new file mode 100644 index 000000000..899c987fa --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java @@ -0,0 +1,70 @@ +package noppes.npcs.client.gui.script; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.NBTTags; +import noppes.npcs.client.Client; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.controllers.data.DataScript; +import noppes.npcs.entity.EntityNPCInterface; + +import java.util.ArrayList; +import java.util.List; + +public class GuiNPCEventScripts extends GuiScriptInterface { + private final DataScript script; + + public GuiNPCEventScripts(EntityNPCInterface npc) { + this.hookList = new ArrayList<>(); + hookList.add("init"); + hookList.add("tick"); + hookList.add("interact"); + hookList.add("dialog"); + hookList.add("damaged"); + hookList.add("killed"); + hookList.add("meleeAttack"); + hookList.add("rangedLaunched"); + hookList.add("target"); + hookList.add("collide"); + hookList.add("kills"); + hookList.add("dialogClose"); + hookList.add("timer"); + + this.script = new DataScript(npc); + this.handler = this.script; + Client.sendData(EnumPacketServer.EventScriptDataGet); + } + + public void setGuiData(NBTTagCompound compound) { + if (!compound.hasKey("Tab")) { + script.setLanguage(compound.getString("ScriptLanguage")); + script.setEnabled(compound.getBoolean("ScriptEnabled")); + super.setGuiData(compound); + } else { + int tab = compound.getInteger("Tab"); + ScriptContainer container = new ScriptContainer(script); + container.readFromNBT(compound.getCompoundTag("Script")); + if (script.getScripts().isEmpty()) { + for (int i = 0; i < compound.getInteger("TotalScripts"); i++) { + script.getScripts().add(new ScriptContainer(script)); + } + } + script.getScripts().set(tab,container); + initGui(); + } + } + + public void save() { + super.save(); + List containers = this.script.getScripts(); + for (int i = 0; i < containers.size(); i++) { + ScriptContainer container = containers.get(i); + Client.sendData(EnumPacketServer.EventScriptDataSave, i, containers.size(), container.writeToNBT(new NBTTagCompound())); + } + NBTTagCompound scriptData = new NBTTagCompound(); + scriptData.setString("ScriptLanguage", this.script.getLanguage()); + scriptData.setBoolean("ScriptEnabled", this.script.getEnabled()); + scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText())); + Client.sendData(EnumPacketServer.EventScriptDataSave, -1, containers.size(), scriptData); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java index 32324f5cb..8b52a993e 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java @@ -5,16 +5,30 @@ import noppes.npcs.NBTTags; import noppes.npcs.client.Client; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.ScriptContainer; -import noppes.npcs.controllers.data.NPCDataScript; +import noppes.npcs.controllers.data.GlobalNPCDataScript; import java.util.List; public class GuiScriptAllNPCs extends GuiScriptInterface { - private NPCDataScript script = new NPCDataScript(null); + private GlobalNPCDataScript script = new GlobalNPCDataScript(null); public GuiScriptAllNPCs() { + hookList.add("init"); + hookList.add("tick"); + hookList.add("interact"); + hookList.add("dialog"); + hookList.add("damaged"); + hookList.add("killed"); + hookList.add("meleeAttack"); + hookList.add("rangedLaunched"); + hookList.add("target"); + hookList.add("collide"); + hookList.add("kills"); + hookList.add("dialogClose"); + hookList.add("timer"); + this.handler = this.script; - Client.sendData(EnumPacketServer.ScriptNPCGet); + Client.sendData(EnumPacketServer.ScriptGlobalNPCGet); } public void setGuiData(NBTTagCompound compound) { @@ -41,12 +55,12 @@ public class GuiScriptAllNPCs extends GuiScriptInterface { List containers = this.script.getScripts(); for (int i = 0; i < containers.size(); i++) { ScriptContainer container = containers.get(i); - Client.sendData(EnumPacketServer.ScriptNPCSave, i, containers.size(), container.writeToNBT(new NBTTagCompound())); + Client.sendData(EnumPacketServer.ScriptGlobalNPCSave, i, containers.size(), container.writeToNBT(new NBTTagCompound())); } NBTTagCompound scriptData = new NBTTagCompound(); scriptData.setString("ScriptLanguage", this.script.getLanguage()); scriptData.setBoolean("ScriptEnabled", this.script.getEnabled()); scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText())); - Client.sendData(EnumPacketServer.ScriptNPCSave, -1, scriptData); + Client.sendData(EnumPacketServer.ScriptGlobalNPCSave, -1, containers.size(), scriptData); } } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java index d20e21073..27d525185 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java @@ -5,19 +5,67 @@ package noppes.npcs.client.gui.script; +import com.google.common.reflect.ClassPath; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.network.FMLNetworkEvent; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.event.entity.EntityEvent; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.event.world.ChunkDataEvent; +import net.minecraftforge.event.world.ChunkEvent; +import net.minecraftforge.event.world.ChunkWatchEvent; +import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.NBTTags; import noppes.npcs.client.Client; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.data.ForgeDataScript; +import org.apache.commons.lang3.StringUtils; +import java.io.IOException; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; public class GuiScriptForge extends GuiScriptInterface { private ForgeDataScript script = new ForgeDataScript(); public GuiScriptForge() { + hookList.add("init"); + + ArrayList list = new ArrayList(); + try { + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.gameevent")); + list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); + list.removeAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event.terraingen")); + } catch (IOException e) { + e.printStackTrace(); + } + + for(ClassPath.ClassInfo e1 : list){ + ClassPath.ClassInfo classLoader = e1; + Class infoClass = classLoader.load(); + ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses())); + if(c.isEmpty()) { + c.add(infoClass); + } + Iterator var10 = c.iterator(); + while(var10.hasNext()) { + Class c1 = (Class) var10.next(); + if(!EntityEvent.EntityConstructing.class.isAssignableFrom(c1) && !WorldEvent.PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers()) && !ChunkEvent.class.isAssignableFrom(c1) && !ChunkWatchEvent.class.isAssignableFrom(c1) && !ChunkDataEvent.class.isAssignableFrom(c1)) { + String eventName = c1.getName(); + int i = eventName.lastIndexOf("."); + eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); + + hookList.add(eventName); + } + } + } + hookList.add("onCNPCNaturalSpawn"); + this.handler = this.script; Client.sendData(EnumPacketServer.ScriptForgeGet); } @@ -52,6 +100,6 @@ public class GuiScriptForge extends GuiScriptInterface { scriptData.setString("ScriptLanguage", this.script.getLanguage()); scriptData.setBoolean("ScriptEnabled", this.script.getEnabled()); scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText())); - Client.sendData(EnumPacketServer.ScriptForgeSave, -1, scriptData); + Client.sendData(EnumPacketServer.ScriptForgeSave, -1, containers.size(), scriptData); } } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index efddeb023..936509045 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -5,22 +5,12 @@ package noppes.npcs.client.gui.script; -import com.google.common.reflect.ClassPath; -import cpw.mods.fml.common.eventhandler.Event; -import cpw.mods.fml.common.gameevent.TickEvent; -import cpw.mods.fml.common.network.FMLNetworkEvent; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiConfirmOpenLink; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.event.entity.EntityEvent; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; -import net.minecraftforge.event.world.ChunkDataEvent; -import net.minecraftforge.event.world.ChunkEvent; -import net.minecraftforge.event.world.ChunkWatchEvent; -import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.swing.GuiJTextArea; @@ -29,13 +19,8 @@ import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.IScriptHandler; -import noppes.npcs.controllers.data.NPCDataScript; -import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.scripted.item.ScriptCustomItem; -import org.apache.commons.lang3.StringUtils; -import java.io.IOException; -import java.lang.reflect.Modifier; import java.util.*; import java.util.Map.Entry; @@ -44,6 +29,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb public IScriptHandler handler; public Map> languages = new HashMap(); private int scriptLimit = 1; + public List hookList = new ArrayList(); public GuiScriptInterface() { this.drawDefaultBackground = true; @@ -91,132 +77,15 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb top.active = true; if(this.activeTab > 0) { - List hookList = new ArrayList(); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); hooks.allowUserInput = false; hooks.setSize(108, 198); hooks.guiLeft = guiLeft - 110; hooks.guiTop = guiTop + 14; - if(handler instanceof PlayerDataScript) { - hookList.add("init"); - hookList.add("tick"); - hookList.add("interact"); - hookList.add("attack"); - hookList.add("attacked"); - hookList.add("damagedEntity"); - hookList.add("damaged"); - hookList.add("kills"); - hookList.add("killed"); - hookList.add("drop"); - hookList.add("respawn"); - hookList.add("breakBlock"); - hookList.add("chat"); - hookList.add("login"); - hookList.add("logout"); - hookList.add("keyPressed"); - hookList.add("mouseClicked"); - hookList.add("toss"); - hookList.add("pickUp"); - hookList.add("pickupXP"); - hookList.add("rangedCharge"); - hookList.add("rangedLaunched"); - hookList.add("timer"); - hookList.add("startItem"); - hookList.add("usingItem"); - hookList.add("stopItem"); - hookList.add("finishItem"); - hookList.add("containerOpen"); - hookList.add("useHoe"); - hookList.add("bonemeal"); - hookList.add("fillBucket"); - hookList.add("jump"); - hookList.add("fall"); - hookList.add("wakeUp"); - hookList.add("sleep"); - hookList.add("playSound"); - hookList.add("lightning"); - hookList.add("changedDim"); - hookList.add("questStart"); - hookList.add("questCompleted"); - hookList.add("questTurnIn"); - hookList.add("factionPoints"); - hookList.add("dialogOpen"); - hookList.add("dialogOption"); - hookList.add("dialogClose"); - hookList.add("customGuiClosed"); - hookList.add("customGuiButton"); - hookList.add("customGuiSlot"); - hookList.add("customGuiSlotClicked"); - hookList.add("customGuiScroll"); - hookList.add("customGuiTextfield"); - - } - else if(handler instanceof NPCDataScript) { - hookList.add("init"); - hookList.add("tick"); - hookList.add("interact"); - hookList.add("dialog"); - hookList.add("damaged"); - hookList.add("killed"); - hookList.add("meleeAttack"); - hookList.add("rangedLaunched"); - hookList.add("target"); - hookList.add("collide"); - hookList.add("kills"); - hookList.add("dialogClose"); - hookList.add("timer"); - } - else if(handler instanceof ScriptCustomItem) { - hookList.add("init"); - hookList.add("tick"); - hookList.add("tossed"); - hookList.add("pickedUp"); - hookList.add("spawn"); - hookList.add("interact"); - hookList.add("attack"); - hookList.add("startItem"); - hookList.add("usingItem"); - hookList.add("stopItem"); - hookList.add("finishItem"); - } - else if(handler instanceof ForgeDataScript) { + if(handler instanceof ForgeDataScript) { hooks.setSize(238, 198); hooks.guiLeft = guiLeft - 240; - - hookList.add("init"); - - ArrayList list = new ArrayList(); - try { - list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("cpw.mods.fml.common.gameevent")); - list.addAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event")); - list.removeAll(ClassPath.from(this.getClass().getClassLoader()).getTopLevelClassesRecursive("net.minecraftforge.event.terraingen")); - } catch (IOException e) { - e.printStackTrace(); - } - - for(ClassPath.ClassInfo e1 : list){ - ClassPath.ClassInfo classLoader = e1; - Class infoClass = classLoader.load(); - ArrayList c = new ArrayList(Arrays.asList(infoClass.getDeclaredClasses())); - if(c.isEmpty()) { - c.add(infoClass); - } - Iterator var10 = c.iterator(); - while(var10.hasNext()) { - Class c1 = (Class) var10.next(); - if(!EntityEvent.EntityConstructing.class.isAssignableFrom(c1) && !WorldEvent.PotentialSpawns.class.isAssignableFrom(c1) && !TickEvent.RenderTickEvent.class.isAssignableFrom(c1) && !TickEvent.ClientTickEvent.class.isAssignableFrom(c1) && !FMLNetworkEvent.ClientCustomPacketEvent.class.isAssignableFrom(c1) && !ItemTooltipEvent.class.isAssignableFrom(c1) && Event.class.isAssignableFrom(c1) && !Modifier.isAbstract(c1.getModifiers()) && Modifier.isPublic(c1.getModifiers()) && !ChunkEvent.class.isAssignableFrom(c1) && !ChunkWatchEvent.class.isAssignableFrom(c1) && !ChunkDataEvent.class.isAssignableFrom(c1)) { - String eventName = c1.getName(); - int i = eventName.lastIndexOf("."); - eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", "")); - - hookList.add(eventName); - } - } - } - - hookList.add("onCNPCNaturalSpawn"); } hooks.setUnsortedList(hookList); addScroll(hooks); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java index a6e56cc85..b0b8170ad 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java @@ -1,6 +1,5 @@ package noppes.npcs.client.gui.script; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomItems; @@ -11,7 +10,19 @@ import noppes.npcs.scripted.item.ScriptCustomItem; public class GuiScriptItem extends GuiScriptInterface { private ScriptCustomItem item; - public GuiScriptItem(EntityPlayer player) { + public GuiScriptItem() { + hookList.add("init"); + hookList.add("tick"); + hookList.add("tossed"); + hookList.add("pickedUp"); + hookList.add("spawn"); + hookList.add("interact"); + hookList.add("attack"); + hookList.add("startItem"); + hookList.add("usingItem"); + hookList.add("stopItem"); + hookList.add("finishItem"); + this.handler = this.item = new ScriptCustomItem(new ItemStack(CustomItems.scripted_item)); Client.sendData(EnumPacketServer.ScriptItemDataGet, new Object[0]); } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java index b51a7c0bf..a789708e7 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -20,6 +20,58 @@ public class GuiScriptPlayers extends GuiScriptInterface { private PlayerDataScript script = new PlayerDataScript((EntityPlayer)null); public GuiScriptPlayers() { + hookList.add("init"); + hookList.add("tick"); + hookList.add("interact"); + hookList.add("attack"); + hookList.add("attacked"); + hookList.add("damagedEntity"); + hookList.add("damaged"); + hookList.add("kills"); + hookList.add("killed"); + hookList.add("drop"); + hookList.add("respawn"); + hookList.add("breakBlock"); + hookList.add("chat"); + hookList.add("login"); + hookList.add("logout"); + hookList.add("keyPressed"); + hookList.add("mouseClicked"); + hookList.add("toss"); + hookList.add("pickUp"); + hookList.add("pickupXP"); + hookList.add("rangedCharge"); + hookList.add("rangedLaunched"); + hookList.add("timer"); + hookList.add("startItem"); + hookList.add("usingItem"); + hookList.add("stopItem"); + hookList.add("finishItem"); + hookList.add("containerOpen"); + hookList.add("useHoe"); + hookList.add("bonemeal"); + hookList.add("fillBucket"); + hookList.add("jump"); + hookList.add("fall"); + hookList.add("wakeUp"); + hookList.add("sleep"); + hookList.add("playSound"); + hookList.add("lightning"); + hookList.add("changedDim"); + hookList.add("questStart"); + hookList.add("questCompleted"); + hookList.add("questTurnIn"); + hookList.add("factionPoints"); + hookList.add("dialogOpen"); + hookList.add("dialogOption"); + hookList.add("dialogClose"); + hookList.add("customGuiClosed"); + hookList.add("customGuiButton"); + hookList.add("customGuiSlot"); + hookList.add("customGuiSlotClicked"); + hookList.add("customGuiScroll"); + hookList.add("customGuiTextfield"); + this.handler = this.script; Client.sendData(EnumPacketServer.ScriptPlayerGet); } @@ -54,6 +106,6 @@ public class GuiScriptPlayers extends GuiScriptInterface { scriptData.setString("ScriptLanguage", this.script.getLanguage()); scriptData.setBoolean("ScriptEnabled", this.script.getEnabled()); scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText())); - Client.sendData(EnumPacketServer.ScriptPlayerSave, -1, scriptData); + Client.sendData(EnumPacketServer.ScriptPlayerSave, -1, containers.size(), scriptData); } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 0cd8bea01..2718504f9 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -44,14 +44,15 @@ public enum EnumPacketServer { ScriptForgeSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), ScriptForgeGet(false), - ScriptNPCSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), - ScriptNPCGet(false), + ScriptGlobalNPCSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptGlobalNPCGet(false), ScriptItemDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), ScriptItemDataGet(false), LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED), ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true), + EventScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), EventScriptDataGet(true), PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA), BankSave(CustomNpcsPermissions.GLOBAL_BANK), BanksGet, BankGet, BankRemove(CustomNpcsPermissions.GLOBAL_BANK), diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 97fd0aa1d..9ea320d4f 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -10,7 +10,7 @@ import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.controllers.data.ForgeDataScript; -import noppes.npcs.controllers.data.NPCDataScript; +import noppes.npcs.controllers.data.GlobalNPCDataScript; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.ScriptWorld; @@ -49,8 +49,8 @@ public class ScriptController { public ForgeDataScript forgeScripts = new ForgeDataScript(); public long lastForgeUpdate = 0L; - public NPCDataScript npcScripts = new NPCDataScript((EntityNPCInterface) null); - public long lastNpcUpdate = 0L; + public GlobalNPCDataScript globalNpcScripts = new GlobalNPCDataScript((EntityNPCInterface) null); + public long lastGlobalNpcUpdate = 0L; public ScriptController(){ loaded = false; @@ -137,15 +137,15 @@ public class ScriptController { } } - public boolean loadNPCScripts() { - this.npcScripts.clear(); + public boolean loadGlobalNPCScripts() { + this.globalNpcScripts.clear(); File file = this.npcScriptsFile(); try { if(!file.exists()) { return false; } else { - this.npcScripts.readFromNBT(NBTJsonUtil.LoadFile(file)); + this.globalNpcScripts.readFromNBT(NBTJsonUtil.LoadFile(file)); shouldSave = false; return true; } @@ -155,11 +155,11 @@ public class ScriptController { } } - public void saveNpcScripts() { + public void saveGlobalNpcScripts() { File file = this.npcScriptsFile(); try { - NBTJsonUtil.SaveFile(file, this.npcScripts.writeToNBT(new NBTTagCompound())); - this.npcScripts.lastInited = -1L; + NBTJsonUtil.SaveFile(file, this.globalNpcScripts.writeToNBT(new NBTTagCompound())); + this.globalNpcScripts.lastInited = -1L; } catch (IOException | JsonException var4) { var4.printStackTrace(); } diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index 0f7f8f1e7..a49529c91 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -10,6 +10,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.EventHooks; import noppes.npcs.LogWriter; +import noppes.npcs.NBTTags; import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.ICustomNpc; import noppes.npcs.config.ConfigDebug; @@ -29,6 +30,8 @@ import javax.script.ScriptEngine; import java.util.*; public class DataScript implements IScriptHandler { + public List eventScripts = new ArrayList(); + public List scripts = new ArrayList(); private final static EntityType entities = new EntityType(); private final static JobType jobs = new JobType(); @@ -72,6 +75,10 @@ public class DataScript implements IScriptHandler { enabled = compound.getBoolean("ScriptEnabled"); } + public void readEventsFromNBT(NBTTagCompound compound) { + eventScripts = NBTTags.GetScript(compound,this); + } + public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("ScriptsContainers", writeScript(scripts)); compound.setString("ScriptLanguage", scriptLanguage); @@ -79,6 +86,14 @@ public class DataScript implements IScriptHandler { return compound; } + public NBTTagCompound writeEventsToNBT(NBTTagCompound compound) { + compound.setInteger("TotalScripts",this.eventScripts.size()); + for (int i = 0; i < this.eventScripts.size(); i++) { + compound.setTag("Tab"+i,this.eventScripts.get(i).writeToNBT(new NBTTagCompound())); + } + return compound; + } + private List readScript(NBTTagList list){ List scripts = new ArrayList<>(); for (int i = 0; i < 12; i++) { @@ -118,10 +133,15 @@ public class DataScript implements IScriptHandler { } if(!isEnabled()) return false; + if(!hasInited && !npc.isRemote() && type != EnumScriptType.INIT){ hasInited = true; EventHooks.onNPCInit(this.npc); } + for (ScriptContainer script : eventScripts) { + script.run(type, event); + } + ScriptContainer script = scripts.get(type.ordinal()); if(script == null || script.errored || !script.hasCode()) return false; @@ -178,7 +198,7 @@ public class DataScript implements IScriptHandler { public Map getConsoleText() { Map map = new TreeMap(); int tab = 0; - Iterator var3 = this.getScripts().iterator(); + Iterator var3 = this.scripts.iterator(); while(var3.hasNext()) { ScriptContainer script = (ScriptContainer)var3.next(); @@ -195,7 +215,7 @@ public class DataScript implements IScriptHandler { } public void clearConsole() { - Iterator var1 = this.getScripts().iterator(); + Iterator var1 = this.scripts.iterator(); while(var1.hasNext()) { ScriptContainer script = (ScriptContainer)var1.next(); @@ -205,8 +225,8 @@ public class DataScript implements IScriptHandler { } @Override - public void callScript(EnumScriptType var1, Event var2) { - callScript(var1, var2, "$$IGNORED$$", null); + public void callScript(EnumScriptType type, Event event) { + callScript(type, event, "$$IGNORED$$", null); } public boolean isClient() { @@ -234,7 +254,7 @@ public class DataScript implements IScriptHandler { } public List getScripts() { - return this.scripts; + return this.eventScripts; } public String noticeString() { diff --git a/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java b/src/main/java/noppes/npcs/controllers/data/GlobalNPCDataScript.java similarity index 73% rename from src/main/java/noppes/npcs/controllers/data/NPCDataScript.java rename to src/main/java/noppes/npcs/controllers/data/GlobalNPCDataScript.java index 715e18e6f..8d31d650a 100644 --- a/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/GlobalNPCDataScript.java @@ -17,7 +17,7 @@ import javax.annotation.CheckForNull; import java.lang.reflect.Array; import java.util.*; -public class NPCDataScript implements IScriptHandler { +public class GlobalNPCDataScript implements IScriptHandler { public List scripts = new ArrayList(); public String scriptLanguage = "ECMAScript"; private EntityNPCInterface npc; @@ -26,7 +26,7 @@ public class NPCDataScript implements IScriptHandler { private long lastNpcUpdate = -1L; public boolean enabled = false; - public NPCDataScript(EntityNPCInterface npc) { + public GlobalNPCDataScript(EntityNPCInterface npc) { if(npc != null) { this.npc = npc; } @@ -62,9 +62,9 @@ public class NPCDataScript implements IScriptHandler { public void callScript(EnumScriptType type, Event event) { if (this.isEnabled()) { - if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastNpcUpdate > this.lastNpcUpdate) { + if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastGlobalNpcUpdate > this.lastNpcUpdate) { this.lastInited = ScriptController.Instance.lastLoaded; - this.lastNpcUpdate = ScriptController.Instance.lastNpcUpdate; + this.lastNpcUpdate = ScriptController.Instance.lastGlobalNpcUpdate; for (ScriptContainer script : this.scripts) { script.errored = false; @@ -109,7 +109,7 @@ public class NPCDataScript implements IScriptHandler { return "Global script"; } else { BlockPos pos = new BlockPos(this.npc); - return NPCDataScript.toStringHelper(this.npc).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); + return GlobalNPCDataScript.toStringHelper(this.npc).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString(); } } public ICustomNpc getNpc() { @@ -140,61 +140,61 @@ public class NPCDataScript implements IScriptHandler { public static final class ToStringHelper { private final String className; - private final NPCDataScript.ToStringHelper.ValueHolder holderHead; - private NPCDataScript.ToStringHelper.ValueHolder holderTail; + private final GlobalNPCDataScript.ToStringHelper.ValueHolder holderHead; + private GlobalNPCDataScript.ToStringHelper.ValueHolder holderTail; private boolean omitNullValues; private boolean omitEmptyValues; private ToStringHelper(String className) { - this.holderHead = new NPCDataScript.ToStringHelper.ValueHolder(); + this.holderHead = new GlobalNPCDataScript.ToStringHelper.ValueHolder(); this.holderTail = this.holderHead; this.omitNullValues = false; this.omitEmptyValues = false; this.className = (String) Preconditions.checkNotNull(className); } - public NPCDataScript.ToStringHelper omitNullValues() { + public GlobalNPCDataScript.ToStringHelper omitNullValues() { this.omitNullValues = true; return this; } - public NPCDataScript.ToStringHelper add(String name, @CheckForNull Object value) { + public GlobalNPCDataScript.ToStringHelper add(String name, @CheckForNull Object value) { return this.addHolder(name, value); } - public NPCDataScript.ToStringHelper add(String name, boolean value) { + public GlobalNPCDataScript.ToStringHelper add(String name, boolean value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public NPCDataScript.ToStringHelper add(String name, char value) { + public GlobalNPCDataScript.ToStringHelper add(String name, char value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public NPCDataScript.ToStringHelper add(String name, double value) { + public GlobalNPCDataScript.ToStringHelper add(String name, double value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public NPCDataScript.ToStringHelper add(String name, float value) { + public GlobalNPCDataScript.ToStringHelper add(String name, float value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public NPCDataScript.ToStringHelper add(String name, int value) { + public GlobalNPCDataScript.ToStringHelper add(String name, int value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public NPCDataScript.ToStringHelper add(String name, long value) { + public GlobalNPCDataScript.ToStringHelper add(String name, long value) { return this.addUnconditionalHolder(name, String.valueOf(value)); } - public NPCDataScript.ToStringHelper addValue(@CheckForNull Object value) { + public GlobalNPCDataScript.ToStringHelper addValue(@CheckForNull Object value) { return this.addHolder(value); } - public NPCDataScript.ToStringHelper addValue(boolean value) { + public GlobalNPCDataScript.ToStringHelper addValue(boolean value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public NPCDataScript.ToStringHelper addValue(char value) { + public GlobalNPCDataScript.ToStringHelper addValue(char value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public NPCDataScript.ToStringHelper addValue(double value) { + public GlobalNPCDataScript.ToStringHelper addValue(double value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public NPCDataScript.ToStringHelper addValue(float value) { + public GlobalNPCDataScript.ToStringHelper addValue(float value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public NPCDataScript.ToStringHelper addValue(int value) { + public GlobalNPCDataScript.ToStringHelper addValue(int value) { return this.addUnconditionalHolder(String.valueOf(value)); } - public NPCDataScript.ToStringHelper addValue(long value) { + public GlobalNPCDataScript.ToStringHelper addValue(long value) { return this.addUnconditionalHolder(String.valueOf(value)); } private static boolean isEmpty(Object value) { @@ -225,9 +225,9 @@ public class NPCDataScript implements IScriptHandler { boolean omitEmptyValuesSnapshot = this.omitEmptyValues; String nextSeparator = ""; StringBuilder builder = (new StringBuilder(32)).append(this.className).append('{'); - for(NPCDataScript.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { + for(GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { Object value = valueHolder.value; - if (!(valueHolder instanceof NPCDataScript.ToStringHelper.UnconditionalValueHolder)) { + if (!(valueHolder instanceof GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder)) { if (value == null) { if (omitNullValuesSnapshot) { continue; @@ -251,39 +251,39 @@ public class NPCDataScript implements IScriptHandler { } return builder.append('}').toString(); } - private NPCDataScript.ToStringHelper.ValueHolder addHolder() { - NPCDataScript.ToStringHelper.ValueHolder valueHolder = new NPCDataScript.ToStringHelper.ValueHolder(); + private GlobalNPCDataScript.ToStringHelper.ValueHolder addHolder() { + GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = new GlobalNPCDataScript.ToStringHelper.ValueHolder(); this.holderTail = this.holderTail.next = valueHolder; return valueHolder; } - private NPCDataScript.ToStringHelper addHolder(@CheckForNull Object value) { - NPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); + private GlobalNPCDataScript.ToStringHelper addHolder(@CheckForNull Object value) { + GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); valueHolder.value = value; return this; } - private NPCDataScript.ToStringHelper addHolder(String name, @CheckForNull Object value) { - NPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); + private GlobalNPCDataScript.ToStringHelper addHolder(String name, @CheckForNull Object value) { + GlobalNPCDataScript.ToStringHelper.ValueHolder valueHolder = this.addHolder(); valueHolder.value = value; valueHolder.name = (String)Preconditions.checkNotNull(name); return this; } - private NPCDataScript.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() { - NPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = new NPCDataScript.ToStringHelper.UnconditionalValueHolder(); + private GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder addUnconditionalHolder() { + GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = new GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder(); this.holderTail = this.holderTail.next = valueHolder; return valueHolder; } - private NPCDataScript.ToStringHelper addUnconditionalHolder(Object value) { - NPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); + private GlobalNPCDataScript.ToStringHelper addUnconditionalHolder(Object value) { + GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); valueHolder.value = value; return this; } - private NPCDataScript.ToStringHelper addUnconditionalHolder(String name, Object value) { - NPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); + private GlobalNPCDataScript.ToStringHelper addUnconditionalHolder(String name, Object value) { + GlobalNPCDataScript.ToStringHelper.UnconditionalValueHolder valueHolder = this.addUnconditionalHolder(); valueHolder.value = value; valueHolder.name = (String)Preconditions.checkNotNull(name); return this; } - private static final class UnconditionalValueHolder extends NPCDataScript.ToStringHelper.ValueHolder { + private static final class UnconditionalValueHolder extends GlobalNPCDataScript.ToStringHelper.ValueHolder { private UnconditionalValueHolder() { super(); } @@ -294,12 +294,12 @@ public class NPCDataScript implements IScriptHandler { @CheckForNull Object value; @CheckForNull - NPCDataScript.ToStringHelper.ValueHolder next; + GlobalNPCDataScript.ToStringHelper.ValueHolder next; private ValueHolder() { } } } - public static NPCDataScript.ToStringHelper toStringHelper(Object self) { - return new NPCDataScript.ToStringHelper(self.getClass().getSimpleName()); + public static GlobalNPCDataScript.ToStringHelper toStringHelper(Object self) { + return new GlobalNPCDataScript.ToStringHelper(self.getClass().getSimpleName()); } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index e00e9b159..063fdc543 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -943,6 +943,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti stats.readToNBT(compound); ai.readToNBT(compound); script.readFromNBT(compound); + script.readEventsFromNBT(compound); timers.readFromNBT(compound); if (compound.hasKey("ItemGiverId")) { itemGiverId = compound.getInteger("ItemGiverId"); @@ -980,6 +981,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti stats.writeToNBT(compound); ai.writeToNBT(compound); script.writeToNBT(compound); + script.writeEventsToNBT(compound); timers.writeToNBT(compound); advanced.writeToNBT(compound); if (advanced.role != EnumRoleType.None && roleInterface != null) diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 8dba7963a..5f4eb0b92 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -524,6 +524,7 @@ script.collide=Collide script.kills=Kills script.dialog_closed=Dialog Closed +eventscript.eventScripts=Event Scripts eventscript.playerevent=Player Events playerscript.disabled=Disabled From fe780d69ee57ae53dee4956b7e5385cbc0a12d8d Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 04:56:33 -0500 Subject: [PATCH 07/27] Added target lost event. Added all new NPC events to the old 1.7.10 script system. --- src/main/java/noppes/npcs/EventHooks.java | 10 ++++++++++ .../java/noppes/npcs/client/gui/GuiScript.java | 3 +++ .../npcs/client/gui/script/GuiNPCEventScripts.java | 3 +++ .../npcs/client/gui/script/GuiScriptAllNPCs.java | 3 +++ .../java/noppes/npcs/constants/EnumScriptType.java | 6 +++--- .../noppes/npcs/controllers/data/DataScript.java | 2 +- .../noppes/npcs/entity/EntityNPCInterface.java | 3 +++ .../java/noppes/npcs/scripted/event/NpcEvent.java | 14 ++++++++++---- .../resources/assets/customnpcs/lang/en_US.lang | 3 +++ 9 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index a563ac5fc..6d415abdd 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -204,6 +204,16 @@ public class EventHooks { return NpcAPI.EVENT_BUS.post(event); } + public static boolean onNPCTargetLost(EntityNPCInterface npc, EntityLivingBase prevtarget, EntityLivingBase newTarget) { + if(npc.script.isClient()) + return false; + NpcEvent.TargetLostEvent event = new NpcEvent.TargetLostEvent(npc.wrappedNPC, prevtarget, newTarget); + + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TARGET_LOST, event); + npc.script.callScript(EnumScriptType.TARGET_LOST, event); + return NpcAPI.EVENT_BUS.post(event); + } + public static void onNPCCollide(EntityNPCInterface npc, Entity entity){ if(npc == null || npc.wrappedNPC == null) return; diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index 03ad2744c..a5f6b786d 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -63,6 +63,9 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall list.add("script.kills"); list.add("script.dialog_closed"); list.add("script.timer"); + list.add("script.targetLost"); + list.add("script.projectileTick"); + list.add("script.projectileImpact"); if(showScript){ addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java b/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java index 899c987fa..10945bdd6 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiNPCEventScripts.java @@ -29,6 +29,9 @@ public class GuiNPCEventScripts extends GuiScriptInterface { hookList.add("kills"); hookList.add("dialogClose"); hookList.add("timer"); + hookList.add("targetLost"); + hookList.add("projectileTick"); + hookList.add("projectileImpact"); this.script = new DataScript(npc); this.handler = this.script; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java index 8b52a993e..8bb387593 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java @@ -26,6 +26,9 @@ public class GuiScriptAllNPCs extends GuiScriptInterface { hookList.add("kills"); hookList.add("dialogClose"); hookList.add("timer"); + hookList.add("targetLost"); + hookList.add("projectileTick"); + hookList.add("projectileImpact"); this.handler = this.script; Client.sendData(EnumPacketServer.ScriptGlobalNPCGet); diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index a6f3aa704..58e1bb0bd 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -13,10 +13,12 @@ public enum EnumScriptType { KILLS("kills"), DIALOG_CLOSE("dialogClose"), TIMER("timer"), + TARGET_LOST("targetLost"), + PROJECTILE_TICK("projectileTick"), + PROJECTILE_IMPACT("projectileImpact"), ATTACKED("attacked"), ATTACK_MELEE("meleeAttack"), - TARGET_LOST("targetLost"), ROLE("role"), RANGED_CHARGE("rangedCharge"), RANGED_LAUNCHED("rangedLaunched"), @@ -41,8 +43,6 @@ public enum EnumScriptType { TOSSED("tossed"), PICKEDUP("pickedUp"), PICKUP("pickUp"), - PROJECTILE_TICK("projectileTick"), - PROJECTILE_IMPACT("projectileImpact"), LEVEL_UP("levelUp"), KEY_PRESSED("keyPressed"), QUEST_EVENT("questEvent"), diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index a49529c91..9fe3351e0 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -48,7 +48,7 @@ public class DataScript implements IScriptHandler { public boolean hasInited = false; public DataScript(EntityNPCInterface npc) { - for (int i = 0; i < 12; i++) { + for (int i = 0; i < 15; i++) { scripts.add(new ScriptContainer(this)); } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 063fdc543..ce7a2f603 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -551,6 +551,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti entity = null; else entity = event.getTarget().getMCEntity(); + } else { + if(EventHooks.onNPCTargetLost(this, getAttackTarget(), entity)) + return; } if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking()) { Line line = advanced.getAttackLine(); diff --git a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java index 7035ce145..fe9ee47c7 100644 --- a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java @@ -420,11 +420,13 @@ public class NpcEvent extends CustomNPCsEvent implements INpcEvent { @Cancelable public static class TargetLostEvent extends NpcEvent implements INpcEvent.TargetLostEvent { - public final IEntityLivingBase entity; + public final IEntityLivingBase oldTarget; + public final IEntityLivingBase newTarget; - public TargetLostEvent(ICustomNpc npc, EntityLivingBase entity) { + public TargetLostEvent(ICustomNpc npc, EntityLivingBase oldTarget, EntityLivingBase newTarget) { super(npc); - this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity); + this.oldTarget = (IEntityLivingBase) NpcAPI.Instance().getIEntity(oldTarget); + this.newTarget = (IEntityLivingBase) NpcAPI.Instance().getIEntity(newTarget); } public String getHookName() { @@ -432,7 +434,11 @@ public class NpcEvent extends CustomNPCsEvent implements INpcEvent { } public IEntityLivingBase getTarget() { - return entity; + return oldTarget; + } + + public IEntityLivingBase getNewTarget() { + return newTarget; } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 5f4eb0b92..63a920406 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -518,6 +518,9 @@ script.killed=Killed script.attack=Attack script.target=Target script.timer=Timer +script.targetLost=Target Lost +script.projectileTick=Proj. Tick +script.projectileImpact=Proj. Impact script.availableScripts=Available Scripts script.loadedScripts=Loaded Scripts script.collide=Collide From f5cf78e1fb24c4119f30847ef1b4de34d5c1430f Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 04:56:42 -0500 Subject: [PATCH 08/27] Added target lost event. Added all new NPC events to the old 1.7.10 script system. --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index c3a023021..026d6d25e 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit c3a023021d94aa86edfaf8262b25354a8acddf01 +Subproject commit 026d6d25eff2f5088b65ed69e6ec16462d41c579 From fd7f55031683509c273d8efef60e8cd49b9de9c5 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 05:07:38 -0500 Subject: [PATCH 09/27] IEntityItem added --- .../java/noppes/npcs/scripted/NpcAPI.java | 3 + .../scripted/entity/ScriptEntityItem.java | 71 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/main/java/noppes/npcs/scripted/entity/ScriptEntityItem.java diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index f53337d83..496aaacb5 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -14,6 +14,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.INpc; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; @@ -205,6 +206,8 @@ public class NpcAPI extends AbstractNpcAPI { data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase)entity)); else if(entity instanceof EntityProjectile) data = new ScriptEntityData(new ScriptProjectile<>((EntityProjectile)entity)); + else if(entity instanceof EntityItem) + data = new ScriptEntityData(new ScriptEntityItem<>((EntityItem)entity)); else data = new ScriptEntityData(new ScriptEntity<>(entity)); entity.registerExtendedProperties("ScriptedObject", data); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntityItem.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntityItem.java new file mode 100644 index 000000000..e55aa98b9 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntityItem.java @@ -0,0 +1,71 @@ +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import noppes.npcs.api.entity.IEntityItem; +import noppes.npcs.api.item.IItemStack; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.constants.EntityType; + +public class ScriptEntityItem extends ScriptEntity implements IEntityItem { + private T entity; + + public ScriptEntityItem(T entityItem) { + super(entityItem); + this.entity = entityItem; + } + + public String getOwner() { + return this.entity.func_145798_i(); + } + + public void setOwner(String name) { + this.entity.func_145797_a(name); + } + + public String getThrower() { + return this.entity.func_145800_j(); + } + + public void setThrower(String name) { + this.entity.func_145799_b(name); + } + + public int getPickupDelay() { + return this.entity.delayBeforeCanPickup; + } + + public void setPickupDelay(int delay) { + this.entity.delayBeforeCanPickup = delay; + } + + public int getType() { + return EntityType.ITEM; + } + + public long getAge() { + return this.entity.age; + } + + public void setAge(long age) { + age = Math.max(Math.min(age, Integer.MAX_VALUE), Integer.MIN_VALUE); + this.entity.age = (int)age; + } + + public int getLifeSpawn() { + return this.entity.lifespan; + } + + public void setLifeSpawn(int age) { + this.entity.lifespan = age; + } + + public IItemStack getItem() { + return NpcAPI.Instance().getIItemStack(this.entity.getEntityItem()); + } + + public void setItem(IItemStack item) { + ItemStack stack = item == null? null : item.getMCItemStack(); + this.entity.setEntityItemStack(stack); + } +} From 57bd628357d85d6f4879ec427f9fb64b0318816f Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 05:07:46 -0500 Subject: [PATCH 10/27] IEntityItem added --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index 026d6d25e..b4ed688e6 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 026d6d25eff2f5088b65ed69e6ec16462d41c579 +Subproject commit b4ed688e6170accec3f981d017e809483399a1ef From e58b4949797abe7e49932949479ad59db6e157b0 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 16:43:05 -0500 Subject: [PATCH 11/27] All global NPC scripts are now called before local NPC scripts Fixed event NPC scripts not running after erroring, and not outputting to the console --- src/main/java/noppes/npcs/EventHooks.java | 4 ++- .../java/noppes/npcs/PacketHandlerServer.java | 2 +- .../noppes/npcs/client/gui/GuiScript.java | 4 +-- .../npcs/controllers/data/DataScript.java | 29 +++++++++++++------ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 6d415abdd..b16fc4323 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -247,13 +247,14 @@ public class EventHooks { return; NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); - npc.script.callScript(EnumScriptType.TIMER, event); ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.TIMER, event); + npc.script.callScript(EnumScriptType.TIMER, event); NpcAPI.EVENT_BUS.post(event); } public static void onProjectileTick(EntityProjectile projectile) { ProjectileEvent.UpdateEvent event = new ProjectileEvent.UpdateEvent((IProjectile) NpcAPI.Instance().getIEntity(projectile)); + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.PROJECTILE_TICK, event); for(ScriptContainer script : projectile.scripts) { if(script.isValid()) { script.run(EnumScriptType.PROJECTILE_TICK, event); @@ -263,6 +264,7 @@ public class EventHooks { } public static void onProjectileImpact(EntityProjectile projectile, ProjectileEvent.ImpactEvent event) { + ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.PROJECTILE_IMPACT, event); for(ScriptContainer script : projectile.scripts) { if(script.isValid()) { script.run(EnumScriptType.PROJECTILE_IMPACT, event); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index baf0c2b61..f1bc59ec2 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -207,7 +207,7 @@ public class PacketHandlerServer{ } } - private void getScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) throws Exception { + private void getScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) { NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("ScriptEnabled", data.getEnabled()); compound.setString("ScriptLanguage", data.getLanguage()); diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index a5f6b786d..5604974d2 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -44,7 +44,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall guiTop += 10; GuiMenuTopButton top; addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "script.scripts")); - addTopButton(new GuiMenuTopButton(16, guiLeft + (xSize - 100), guiTop - 17, "eventscript.eventScripts")); + addTopButton(new GuiMenuTopButton(16, guiLeft + (xSize - 82), guiTop - 17, "eventscript.eventScripts")); top.active = showScript; addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); top.active = !showScript; @@ -133,7 +133,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall } private String getConsoleText() { - Map map = this.script.getConsoleText(); + Map map = this.script.getOldConsoleText(); StringBuilder builder = new StringBuilder(); Iterator var3 = map.entrySet().iterator(); diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index 9fe3351e0..6a2ae1e7a 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -136,9 +136,13 @@ public class DataScript implements IScriptHandler { if(!hasInited && !npc.isRemote() && type != EnumScriptType.INIT){ hasInited = true; + for (ScriptContainer scriptContainer : this.eventScripts) { + scriptContainer.errored = false; + } EventHooks.onNPCInit(this.npc); } - for (ScriptContainer script : eventScripts) { + + for (ScriptContainer script : this.eventScripts) { script.run(type, event); } @@ -193,9 +197,7 @@ public class DataScript implements IScriptHandler { return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty() && ConfigScript.ScriptingEnabled; } - public void setConsoleText(Map map) {} - - public Map getConsoleText() { + public Map getOldConsoleText() { Map map = new TreeMap(); int tab = 0; Iterator var3 = this.scripts.iterator(); @@ -214,14 +216,23 @@ public class DataScript implements IScriptHandler { return map; } - public void clearConsole() { - Iterator var1 = this.scripts.iterator(); + public Map getConsoleText() { + TreeMap map = new TreeMap<>(); + int tab = 0; + for (ScriptContainer script : this.getScripts()) { + ++tab; - while(var1.hasNext()) { - ScriptContainer script = (ScriptContainer)var1.next(); + for (Map.Entry longStringEntry : script.console.entrySet()) { + map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + longStringEntry.getValue()); + } + } + return map; + } + + public void clearConsole() { + for (ScriptContainer script : this.getScripts()) { script.console.clear(); } - } @Override From df069c82c2a5f3e6199a4f0a83dadbd41927fbfc Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:37:57 -0500 Subject: [PATCH 12/27] Added a quest alert toggle for each quest in the quest log. Fixed instant complete quests not finishing sometimes. --- .../java/noppes/npcs/NoppesUtilPlayer.java | 36 ++++++++------- .../java/noppes/npcs/NoppesUtilServer.java | 2 +- .../java/noppes/npcs/PacketHandlerPlayer.java | 2 +- .../java/noppes/npcs/PacketHandlerServer.java | 45 ++++++++++++------- src/main/java/noppes/npcs/QuestLogData.java | 13 +++++- .../java/noppes/npcs/ServerEventsHandler.java | 44 ++++++++++-------- .../npcs/client/gui/player/GuiQuestLog.java | 19 ++++++-- .../npcs/constants/EnumPacketServer.java | 2 +- .../controllers/PlayerQuestController.java | 18 ++++---- .../controllers/data/PlayerQuestData.java | 12 ++--- .../noppes/npcs/controllers/data/Quest.java | 5 +-- .../npcs/controllers/data/QuestData.java | 3 ++ .../noppes/npcs/roles/JobConversation.java | 3 +- .../assets/customnpcs/lang/en_US.lang | 4 ++ 14 files changed, 133 insertions(+), 75 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index abb17460d..8bd76ac41 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -18,10 +18,7 @@ import net.minecraftforge.oredict.OreDictionary; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.data.IQuestObjective; import noppes.npcs.api.item.IItemStack; -import noppes.npcs.constants.EnumOptionType; -import noppes.npcs.constants.EnumPacketClient; -import noppes.npcs.constants.EnumPlayerPacket; -import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.constants.*; import noppes.npcs.containers.ContainerNPCBankInterface; import noppes.npcs.containers.ContainerNPCFollower; import noppes.npcs.containers.ContainerNPCFollowerHire; @@ -329,25 +326,27 @@ public class NoppesUtilPlayer { data.setData(player); Server.sendData(player, EnumPacketClient.GUI_DATA, data.writeNBT()); } - public static void questCompletion(EntityPlayerMP player, int questId) { + public static boolean questCompletion(EntityPlayerMP player, int questId) { if(player == null) - return; + return false; PlayerData playerData = PlayerDataController.instance.getPlayerData(player); PlayerQuestData questData = playerData.questData; QuestData data = questData.activeQuests.get(questId); - if(data == null) - return; + if (data == null) + return false; - if(!data.quest.questInterface.isCompleted(playerData)) - return; + if (!data.quest.questInterface.isCompleted(playerData)) + return false; + + if (data.quest.completion == EnumQuestCompletion.Instant) { + EventHooks.onQuestFinished(player, data.quest); + } QuestEvent.QuestTurnedInEvent event = new QuestEvent.QuestTurnedInEvent((IPlayer) NpcAPI.Instance().getIEntity(player), data.quest); - if (event.isCancelled()) - return; - event.expReward = data.quest.rewardExp; + event.expReward = data.quest.rewardExp; List list = new ArrayList(); Iterator var8 = data.quest.rewardItems.items.values().iterator(); @@ -368,6 +367,9 @@ public class NoppesUtilPlayer { } EventHooks.onQuestTurnedIn(event); + if (event.isCancelled()) + return false; + IItemStack[] var12 = event.itemRewards; int var14 = var12.length; for(int var10 = 0; var10 < var14; ++var10) { @@ -393,11 +395,13 @@ public class NoppesUtilPlayer { PlayerQuestController.setQuestFinished(data.quest, player); if (data.quest.hasNewQuest()) { - Quest nextQuest = data.quest.getNextQuest(); + QuestData nextQuest = new QuestData(data.quest.getNextQuest()); + nextQuest.sendAlerts = data.quest.id != data.quest.getNextQuest().id || data.sendAlerts; PlayerQuestController.addActiveQuest(nextQuest, player); - NoppesUtilPlayer.sendTrackedQuestData(player,nextQuest); + NoppesUtilPlayer.sendTrackedQuestData(player,nextQuest.quest); } - playerData.savePlayerDataOnFile(); + + return true; } public static boolean compareItems(ItemStack item, ItemStack item2, boolean ignoreDamage, boolean ignoreNBT){ diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index f6d8f0b5e..2f94ff001 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -179,7 +179,7 @@ public class NoppesUtilServer { Server.sendData((EntityPlayerMP)player, EnumPacketClient.DIALOG, npc.getEntityId(), dialog.writeToNBT(new NBTTagCompound())); dia.factionOptions.addPoints(player); if(dialog.hasQuest()) - PlayerQuestController.addActiveQuest(dialog.getQuest(),player); + PlayerQuestController.addActiveQuest(new QuestData(dialog.getQuest()),player); if(!dialog.command.isEmpty()){ runCommand(player, npc.getCommandSenderName(), dialog.command); } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 80efb2d71..75234c231 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -267,7 +267,7 @@ public class PacketHandlerPlayer{ if(mail.time == time && mail.sender.equals(username)){ mail.beenRead = true; if(mail.hasQuest()) - PlayerQuestController.addActiveQuest(mail.getQuest(), player); + PlayerQuestController.addActiveQuest(new QuestData(mail.getQuest()), player); } } } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index f1bc59ec2..0e9e2b65e 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -47,10 +47,7 @@ import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.item.ScriptCustomItem; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; +import java.util.*; public class PacketHandlerServer{ @@ -92,8 +89,8 @@ public class PacketHandlerServer{ } else if (type == EnumPacketServer.CustomGuiClose) { EventHooks.onCustomGuiClose((IPlayer) NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(Server.readNBT(buffer))); return; - } else if (type == EnumPacketServer.UpdateTrackedQuest) { - updateTrackedQuest(buffer, player); + } else if (type == EnumPacketServer.QuestLogToServer) { + updateQuestLogData(buffer, player); return; } @@ -142,12 +139,11 @@ public class PacketHandlerServer{ } } - private void updateTrackedQuest(ByteBuf buffer, EntityPlayerMP player) { - String trackedQuestString = Server.readString(buffer); - if (trackedQuestString != null && trackedQuestString.contains(":")) { - String[] splitString = trackedQuestString.split(":"); + private Quest getQuestFromString(String string) { + if (string != null && string.contains(":")) { + String[] splitString = string.split(":"); if(splitString.length < 2){ - return; + return null; } String categoryName = splitString[0]; String questName = splitString[1]; @@ -156,16 +152,35 @@ public class PacketHandlerServer{ if (category.title.equals(categoryName)) { for (Quest quest : category.quests.values()) { if (quest.title.equals(questName)) { - PlayerDataController.instance.getPlayerData(player).questData.trackedQuest = quest; - NoppesUtilPlayer.sendTrackedQuestData(player, quest); - return; + return quest; } } } } } + return null; + } - PlayerDataController.instance.getPlayerData(player).questData.trackedQuest = null; + private void updateQuestLogData(ByteBuf buffer, EntityPlayerMP player) throws IOException { + PlayerData playerData = PlayerDataController.instance.getPlayerData(player); + + NBTTagCompound compound = Server.readNBT(buffer); + HashMap questAlerts = NBTTags.getStringStringMap(compound.getTagList("Alerts", 10)); + for (Map.Entry entry : questAlerts.entrySet()) { + Quest quest = this.getQuestFromString(entry.getKey()); + if (quest != null) { + playerData.questData.activeQuests.get(quest.id).sendAlerts = Boolean.parseBoolean(entry.getValue()); + } + } + + String trackedQuestString = Server.readString(buffer); + Quest trackedQuest = this.getQuestFromString(trackedQuestString); + if (trackedQuest != null) { + playerData.questData.trackedQuest = trackedQuest; + NoppesUtilPlayer.sendTrackedQuestData(player, trackedQuest); + } + + playerData.questData.trackedQuest = null; Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING); } diff --git a/src/main/java/noppes/npcs/QuestLogData.java b/src/main/java/noppes/npcs/QuestLogData.java index 22ea6ce7a..10673c6aa 100644 --- a/src/main/java/noppes/npcs/QuestLogData.java +++ b/src/main/java/noppes/npcs/QuestLogData.java @@ -17,6 +17,7 @@ public class QuestLogData { public String selectedQuest = ""; public String selectedCategory = ""; public HashMap questText = new HashMap(); + public HashMap questAlerts = new HashMap<>(); public HashMap> questStatus = new HashMap>(); public HashMap finish = new HashMap(); @@ -24,6 +25,7 @@ public class QuestLogData { NBTTagCompound compound = new NBTTagCompound(); compound.setTag("Categories", NBTTags.nbtVectorMap(categories)); compound.setTag("Logs", NBTTags.nbtStringStringMap(questText)); + compound.setTag("Alerts", NBTTags.nbtStringStringMap(questAlerts)); compound.setTag("Status", NBTTags.nbtVectorMap(questStatus)); compound.setTag("QuestFinisher", NBTTags.nbtStringStringMap(finish)); compound.setString("TrackedQuestID", trackedQuestKey); @@ -33,6 +35,7 @@ public class QuestLogData { public void readNBT(NBTTagCompound compound){ categories = NBTTags.getVectorMap(compound.getTagList("Categories", 10)); questText = NBTTags.getStringStringMap(compound.getTagList("Logs", 10)); + questAlerts = NBTTags.getStringStringMap(compound.getTagList("Alerts", 10)); questStatus = NBTTags.getVectorMap(compound.getTagList("Status", 10)); finish = NBTTags.getStringStringMap(compound.getTagList("QuestFinisher", 10)); trackedQuestKey = compound.getString("TrackedQuestID"); @@ -49,7 +52,7 @@ public class QuestLogData { list.add(quest.title); questText.put(category + ":" + quest.title, quest.logText); - + questAlerts.put(category + ":" + quest.title, String.valueOf(playerData.questData.activeQuests.get(quest.id).sendAlerts)); questStatus.put(category + ":" + quest.title, quest.questInterface.getQuestLogStatus(player)); if(quest.completion == EnumQuestCompletion.Npc && quest.questInterface.isCompleted(playerData)) finish.put(category + ":" + quest.title, quest.completerNpc); @@ -70,6 +73,14 @@ public class QuestLogData { return questText.get(selectedCategory + ":" + selectedQuest); } + public Boolean getQuestAlerts() { + return Boolean.valueOf(questAlerts.get(selectedCategory+":"+selectedQuest)); + } + + public void toggleQuestAlerts() { + questAlerts.put(selectedCategory+":"+selectedQuest,String.valueOf(!getQuestAlerts())); + } + public Vector getQuestStatus() { return questStatus.get(selectedCategory + ":" + selectedQuest); } diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 3771af74b..0add96661 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -292,48 +292,54 @@ public class ServerEventsHandler { private void doQuest(EntityPlayer player, EntityLivingBase entity, boolean all) { PlayerData playerData = PlayerDataController.instance.getPlayerData(player); PlayerQuestData questData = playerData.questData; - boolean change = false; + boolean checkCompletion = false; String entityName = EntityList.getEntityString(entity); ArrayList activeQuestValues = new ArrayList<>(questData.activeQuests.values()); for(QuestData data : activeQuestValues){ - if(data.quest.type != EnumQuestType.Kill && data.quest.type != EnumQuestType.AreaKill) + if (data.quest.type != EnumQuestType.Kill && data.quest.type != EnumQuestType.AreaKill) continue; - if(data.quest.type == EnumQuestType.AreaKill && all){ - List list = player.worldObj.getEntitiesWithinAABB(EntityPlayer.class, entity.boundingBox.expand(10, 10, 10)); - for(EntityPlayer pl : list) - if(pl != player) - doQuest(pl, entity, false); + if (data.quest.type == EnumQuestType.AreaKill && all) { + List list = player.worldObj.getEntitiesWithinAABB(EntityPlayer.class, entity.boundingBox.expand(10, 10, 10)); + for (EntityPlayer pl : list) { + if (pl != player) { + doQuest(pl, entity, false); + } + } } String name = entityName; QuestKill quest = (QuestKill) data.quest.questInterface; Class entityType = EntityNPCInterface.class; - if(quest.targetType == 2) { + if (quest.targetType == 2) { try { entityType = Class.forName(quest.customTargetType); } catch (ClassNotFoundException notFoundException) { continue; } } - if(quest.targetType > 0 && !(entityType.isInstance(entity))) + + if (quest.targetType > 0 && !(entityType.isInstance(entity))) continue; - if(quest.targets.containsKey(entity.getCommandSenderName())) + + if (quest.targets.containsKey(entity.getCommandSenderName())) name = entity.getCommandSenderName(); - else if(!quest.targets.containsKey(name)) + else if (!quest.targets.containsKey(name)) continue; + + checkCompletion = true; + HashMap killed = quest.getKilled(data); - if(killed.containsKey(name) && killed.get(name) >= quest.targets.get(name)) - continue; - int amount = 0; - if(killed.containsKey(name)) - amount = killed.get(name); - killed.put(name, amount + 1); + if (!killed.containsKey(name)) { + killed.put(name, 1); + } else if(killed.get(name) < quest.targets.get(name)) { + int amount = killed.get(name); + killed.put(name, amount + 1); + } quest.setKilled(data, killed); - change = true; } - if(!change) + if(!checkCompletion) return; questData.checkQuestCompletion(playerData,EnumQuestType.Kill); diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java index cedbe2804..7b59feeca 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java @@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; +import noppes.npcs.NBTTags; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.QuestLogData; import noppes.npcs.client.Client; @@ -83,15 +84,19 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I addButton(new GuiButtonNextPage(1, guiLeft + 286, guiTop + 176, true)); addButton(new GuiButtonNextPage(2, guiLeft + 144, guiTop + 176, false)); - GuiNpcButton trackingButton = new GuiNpcButton(3, guiLeft + 260, guiTop + 151, 50, 20, new String[]{"Track", "Tracking"}, data.trackedQuestKey.equals(data.selectedCategory + ":" + data.selectedQuest) ? 1 : 0); - if (trackingButton.displayString.equals("Tracking")) { + GuiNpcButton trackingButton = new GuiNpcButton(3, guiLeft + 260, guiTop + 151, 50, 20, new String[]{"quest.track", "quest.tracking"}, data.trackedQuestKey.equals(data.selectedCategory + ":" + data.selectedQuest) ? 1 : 0); + if (trackingButton.displayString.equals("quest.tracking")) { trackingButton.packedFGColour = 0x32CD32; } addButton(trackingButton); + GuiNpcButton alertButton = new GuiNpcButton(4, guiLeft + 205, guiTop + 151, 50, 20, new String[]{"quest.alerts", "quest.noAlerts"}, data.getQuestAlerts() ? 0 : 1); + addButton(alertButton); + getButton(1).visible = questDetails && data.hasSelectedQuest(); getButton(2).visible = !questDetails && data.hasSelectedQuest(); getButton(3).visible = !data.selectedQuest.isEmpty() && getButton(1).visible; + getButton(4).visible = getButton(3).visible; } @Override protected void actionPerformed(GuiButton guibutton){ @@ -108,6 +113,9 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I data.trackedQuestKey = ""; } } + if(guibutton.id == 4){ + data.toggleQuestAlerts(); + } initGui(); } @Override @@ -248,8 +256,11 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I @Override public void save() { - if (this.data != null) - Client.sendData(EnumPacketServer.UpdateTrackedQuest, this.data.trackedQuestKey); + if (this.data != null) { + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("Alerts", NBTTags.nbtStringStringMap(data.questAlerts)); + Client.sendData(EnumPacketServer.QuestLogToServer, compound, this.data.trackedQuestKey); + } } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 2718504f9..0001a6117 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -85,7 +85,7 @@ public enum EnumPacketServer { AnimationListGet, AnimationGet, AnimationAdd, AnimationDelete, AnimationSave, - RecipesGet, RecipeGet, QuestOpenGui, PlayerDataGet, UpdateTrackedQuest, + RecipesGet, RecipeGet, QuestOpenGui, PlayerDataGet, QuestLogToServer, RemoteNpcsGet(CustomNpcsPermissions.NPC_GUI), RemoteTpToNpc,QuestGet, QuestCategoryGet, diff --git a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java index 6cd53c755..a24e981bf 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java @@ -35,19 +35,21 @@ public class PlayerQuestController { return data.finishedQuests.containsKey(questid); } - public static void addActiveQuest(Quest quest, EntityPlayer player) { + public static void addActiveQuest(QuestData questData, EntityPlayer player) { PlayerQuestData data = PlayerDataController.instance.getPlayerData(player).questData; - if(canQuestBeAccepted(quest, player)){ - if (EventHooks.onQuestStarted(player, quest)) { + if(canQuestBeAccepted(questData.quest, player)){ + if (EventHooks.onQuestStarted(player, questData.quest)) { return; } - data.activeQuests.put(quest.id,new QuestData(quest)); - Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title); - Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title); + data.activeQuests.put(questData.quest.id,questData); + if (questData.sendAlerts) { + Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.newquest", questData.quest.title); + Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.newquest", ": ", questData.quest.title); + } } else { - long timeUntilRepeat = quest.getTimeUntilRepeat(player); - if (timeUntilRepeat > 0 && quest.getIsRepeatable() && quest.repeat != EnumQuestRepeat.NONE && quest.repeat != EnumQuestRepeat.REPEATABLE) { + long timeUntilRepeat = questData.quest.getTimeUntilRepeat(player); + if (timeUntilRepeat > 0 && questData.quest.getIsRepeatable() && questData.quest.repeat != EnumQuestRepeat.NONE && questData.quest.repeat != EnumQuestRepeat.REPEATABLE) { String timeString = NoppesUtilServer.millisToTime(timeUntilRepeat); String message = "You have " + timeString + " left until you can repeat this quest."; player.addChatMessage(new ChatComponentTranslation(NoppesStringUtils.formatText(message,player))); diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java index 45400d870..709a8a183 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java @@ -124,18 +124,20 @@ public class PlayerQuestData implements IPlayerQuestData { QuestInterface inter = data.quest.questInterface; if(inter.isCompleted(playerData)){ - if(!data.isCompleted){ - if(!data.quest.complete(player,data) || data.quest.completeText.isEmpty()){ + if((!data.isCompleted && data.quest.completion == EnumQuestCompletion.Npc) || data.quest.instantComplete(player,data)){ + if (data.quest.completeText.isEmpty() && data.sendAlerts) { Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.completed", data.quest.title); Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.completed",": ",data.quest.title); } data.isCompleted = true; + if (data.quest.completion == EnumQuestCompletion.Npc) { + EventHooks.onQuestFinished(player, data.quest); + } bo = true; - EventHooks.onQuestFinished(player,data.quest); } - } - else + } else { data.isCompleted = false; + } } QuestItem.pickedUp = null; return bo; diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 3c73aa382..ee4eb0eab 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -130,9 +130,8 @@ public class Quest implements ICompatibilty, IQuest { return QuestController.instance == null?null:QuestController.instance.quests.get(nextQuestid); } - public boolean complete(EntityPlayer player, QuestData data) { - if(completion == EnumQuestCompletion.Instant){ - NoppesUtilPlayer.questCompletion((EntityPlayerMP) player, data.quest.id); + public boolean instantComplete(EntityPlayer player, QuestData data) { + if(completion == EnumQuestCompletion.Instant && NoppesUtilPlayer.questCompletion((EntityPlayerMP) player, data.quest.id)){ Server.sendData((EntityPlayerMP)player, EnumPacketClient.QUEST_COMPLETION, data.quest.writeToNBT(new NBTTagCompound())); return true; } diff --git a/src/main/java/noppes/npcs/controllers/data/QuestData.java b/src/main/java/noppes/npcs/controllers/data/QuestData.java index 7db1bd6b8..d19fd30dc 100644 --- a/src/main/java/noppes/npcs/controllers/data/QuestData.java +++ b/src/main/java/noppes/npcs/controllers/data/QuestData.java @@ -5,16 +5,19 @@ import net.minecraft.nbt.NBTTagCompound; public class QuestData { public Quest quest; public boolean isCompleted; + public boolean sendAlerts = true; public NBTTagCompound extraData = new NBTTagCompound(); public QuestData(Quest quest){ this.quest = quest; } public void writeEntityToNBT(NBTTagCompound nbttagcompound){ nbttagcompound.setBoolean("QuestCompleted", isCompleted); + nbttagcompound.setBoolean("SendAlerts", sendAlerts); nbttagcompound.setTag("ExtraData", extraData); } public void readEntityFromNBT(NBTTagCompound nbttagcompound){ isCompleted = nbttagcompound.getBoolean("QuestCompleted"); + sendAlerts = nbttagcompound.getBoolean("SendAlerts"); extraData = nbttagcompound.getCompoundTag("ExtraData"); } } diff --git a/src/main/java/noppes/npcs/roles/JobConversation.java b/src/main/java/noppes/npcs/roles/JobConversation.java index 91b356c92..96db172bf 100644 --- a/src/main/java/noppes/npcs/roles/JobConversation.java +++ b/src/main/java/noppes/npcs/roles/JobConversation.java @@ -8,6 +8,7 @@ import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.Availability; import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.data.Quest; +import noppes.npcs.controllers.data.QuestData; import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; @@ -123,7 +124,7 @@ public class JobConversation extends JobInterface{ for (EntityPlayer player : inRange){ if(availability.isAvailable(player)) - PlayerQuestController.addActiveQuest(getQuest(), player); + PlayerQuestController.addActiveQuest(new QuestData(getQuest()), player); } } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 63a920406..63c1528a7 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -500,6 +500,10 @@ quest.randomitem=Random Item quest.exp=Exp quest.takeitems=Take Items quest.objectives=Objectives +quest.track=Track +quest.tracking=Tracking +quest.alerts=Alerts +quest.noAlerts=No Alerts script.apidoc=API Docs script.apisrc=API Source From 2ef93dd35f40edeb88d9d758a7d2ebf47f41d5ad Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:58:45 -0500 Subject: [PATCH 13/27] Fixed index out of bounds exception --- src/main/java/noppes/npcs/controllers/data/DataScript.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index 6a2ae1e7a..789277719 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -96,7 +96,7 @@ public class DataScript implements IScriptHandler { private List readScript(NBTTagList list){ List scripts = new ArrayList<>(); - for (int i = 0; i < 12; i++) { + for (int i = 0; i < 15; i++) { scripts.add(new ScriptContainer(this)); } From f0b33cf913099a419184c17fd2f349db9f332fc2 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 02:36:28 -0500 Subject: [PATCH 14/27] Moved model scale parts into a single ModelScale class, similar to ModelRotate. Added NPC model data interfaces to the API. --- .../noppes/npcs/VersionCompatibility.java | 1 + .../java/noppes/npcs/client/ClientProxy.java | 2 + .../npcs/client/controllers/Preset.java | 78 ++++++++-------- .../noppes/npcs/client/fx/EntityEnderFX.java | 2 +- .../client/gui/model/GuiEntitySelection.java | 2 +- .../npcs/client/gui/model/GuiModelArms.java | 2 +- .../npcs/client/gui/model/GuiModelBody.java | 2 +- .../npcs/client/gui/model/GuiModelColor.java | 2 +- .../npcs/client/gui/model/GuiModelHead.java | 2 +- .../npcs/client/gui/model/GuiModelLegs.java | 2 +- .../npcs/client/gui/model/GuiModelRotate.java | 5 +- .../npcs/client/gui/model/GuiModelScale.java | 30 +++--- .../npcs/client/gui/model/GuiPresetSave.java | 2 +- .../client/gui/model/GuiPresetSelection.java | 2 +- .../client/gui/util/GuiModelInterface.java | 2 +- .../noppes/npcs/client/model/ModelMPM.java | 18 ++-- .../npcs/client/model/part/ModelBeard.java | 4 +- .../npcs/client/model/part/ModelBreasts.java | 2 +- .../npcs/client/model/part/ModelClaws.java | 4 +- .../npcs/client/model/part/ModelEars.java | 4 +- .../npcs/client/model/part/ModelFin.java | 4 +- .../npcs/client/model/part/ModelHair.java | 4 +- .../npcs/client/model/part/ModelHorns.java | 4 +- .../npcs/client/model/part/ModelLegs.java | 6 +- .../npcs/client/model/part/ModelMohawk.java | 4 +- .../npcs/client/model/part/ModelSkirt.java | 4 +- .../npcs/client/model/part/ModelSnout.java | 4 +- .../npcs/client/model/part/ModelTail.java | 10 +- .../npcs/client/model/part/ModelWings.java | 4 +- .../client/model/util/ModelPartInterface.java | 4 +- .../client/model/util/ModelScaleRenderer.java | 6 +- .../client/renderer/RenderNPCHumanMale.java | 22 ++--- .../noppes/npcs/entity/EntityCustomNpc.java | 6 +- .../noppes/npcs/entity/EntityNPCGolem.java | 2 +- .../noppes/npcs/entity/EntityNpcCrystal.java | 2 +- .../noppes/npcs/entity/EntityNpcDragon.java | 2 +- .../noppes/npcs/entity/EntityNpcPony.java | 2 +- .../noppes/npcs/entity/EntityNpcSlime.java | 2 +- .../npcs/{ => entity/data}/ModelData.java | 2 +- .../{ => entity/data}/ModelDataShared.java | 92 +++++++++---------- .../npcs/{ => entity/data}/ModelPartData.java | 2 +- .../npcs/{ => entity/data}/ModelRotate.java | 47 +++++++++- .../{ => entity/data}/ModelRotatePart.java | 30 +++++- .../noppes/npcs/entity/data/ModelScale.java | 43 +++++++++ .../data/ModelScalePart.java} | 30 ++++-- .../npcs/entity/old/EntityNPCDwarfFemale.java | 10 +- .../npcs/entity/old/EntityNPCDwarfMale.java | 10 +- .../npcs/entity/old/EntityNPCElfFemale.java | 10 +- .../npcs/entity/old/EntityNPCElfMale.java | 10 +- .../npcs/entity/old/EntityNPCEnderman.java | 2 +- .../npcs/entity/old/EntityNPCFurryFemale.java | 12 +-- .../npcs/entity/old/EntityNPCFurryMale.java | 4 +- .../npcs/entity/old/EntityNPCHumanFemale.java | 10 +- .../npcs/entity/old/EntityNPCOrcFemale.java | 10 +- .../npcs/entity/old/EntityNPCOrcMale.java | 10 +- .../npcs/entity/old/EntityNPCVillager.java | 2 +- .../npcs/entity/old/EntityNpcEnderchibi.java | 8 +- .../entity/old/EntityNpcMonsterFemale.java | 10 +- .../npcs/entity/old/EntityNpcNagaFemale.java | 12 +-- .../npcs/entity/old/EntityNpcNagaMale.java | 4 +- .../npcs/entity/old/EntityNpcSkeleton.java | 2 +- .../java/noppes/npcs/roles/RoleCompanion.java | 32 +++---- .../npcs/scripted/entity/ScriptNpc.java | 31 ++++--- 63 files changed, 412 insertions(+), 283 deletions(-) rename src/main/java/noppes/npcs/{ => entity/data}/ModelData.java (97%) rename src/main/java/noppes/npcs/{ => entity/data}/ModelDataShared.java (71%) rename src/main/java/noppes/npcs/{ => entity/data}/ModelPartData.java (98%) rename src/main/java/noppes/npcs/{ => entity/data}/ModelRotate.java (64%) rename src/main/java/noppes/npcs/{ => entity/data}/ModelRotatePart.java (58%) create mode 100644 src/main/java/noppes/npcs/entity/data/ModelScale.java rename src/main/java/noppes/npcs/{ModelLimbConfig.java => entity/data/ModelScalePart.java} (67%) diff --git a/src/main/java/noppes/npcs/VersionCompatibility.java b/src/main/java/noppes/npcs/VersionCompatibility.java index b5e9121aa..fa63cb159 100644 --- a/src/main/java/noppes/npcs/VersionCompatibility.java +++ b/src/main/java/noppes/npcs/VersionCompatibility.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagList; import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.data.Lines; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.entity.data.ModelRotate; import java.util.Collection; import java.util.List; diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 033af7f52..a67176e11 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -61,6 +61,8 @@ import noppes.npcs.constants.EnumGuiType; import noppes.npcs.containers.*; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.*; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.items.ItemScripted; import org.lwjgl.input.Keyboard; import tconstruct.client.tabs.InventoryTabFactions; diff --git a/src/main/java/noppes/npcs/client/controllers/Preset.java b/src/main/java/noppes/npcs/client/controllers/Preset.java index 71f18bdaa..97c801ffa 100644 --- a/src/main/java/noppes/npcs/client/controllers/Preset.java +++ b/src/main/java/noppes/npcs/client/controllers/Preset.java @@ -1,8 +1,8 @@ package noppes.npcs.client.controllers; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import java.util.HashMap; @@ -28,10 +28,10 @@ public class Preset { Preset preset = new Preset(); preset.name = "Elf Male"; preset.data = data; - data.legs.setScale(0.85f,1.15f); - data.arms.setScale(0.85f,1.15f); - data.body.setScale(0.85f,1.15f); - data.head.setScale(0.85f,0.95f); + data.modelScale.legs.setScale(0.85f,1.15f); + data.modelScale.arms.setScale(0.85f,1.15f); + data.modelScale.body.setScale(0.85f,1.15f); + data.modelScale.head.setScale(0.85f,0.95f); presets.put("elf male", preset); data = new ModelData(); @@ -39,20 +39,20 @@ public class Preset { preset.name = "Elf Female"; preset.data = data; data.breasts = 2; - data.legs.setScale(0.8f,1.05f); - data.arms.setScale(0.8f,1.05f); - data.body.setScale(0.8f,1.05f); - data.head.setScale(0.8f,0.85f); + data.modelScale.legs.setScale(0.8f,1.05f); + data.modelScale.arms.setScale(0.8f,1.05f); + data.modelScale.body.setScale(0.8f,1.05f); + data.modelScale.head.setScale(0.8f,0.85f); presets.put("elf female", preset); data = new ModelData(); preset = new Preset(); preset.name = "Dwarf Male"; preset.data = data; - data.legs.setScale(1.1f,0.7f, 0.9f); - data.arms.setScale(0.9f,0.7f); - data.body.setScale(1.2f, 0.7f, 1.5f); - data.head.setScale(0.85f,0.85f); + data.modelScale.legs.setScale(1.1f,0.7f, 0.9f); + data.modelScale.arms.setScale(0.9f,0.7f); + data.modelScale.body.setScale(1.2f, 0.7f, 1.5f); + data.modelScale.head.setScale(0.85f,0.85f); presets.put("dwarf male", preset); data = new ModelData(); @@ -60,20 +60,20 @@ public class Preset { preset.name = "Dwarf Female"; preset.data = data; data.breasts = 2; - data.legs.setScale(0.9f,0.65f); - data.arms.setScale(0.9f,0.65f); - data.body.setScale(1f, 0.65f, 1.1f); - data.head.setScale(0.85f,0.85f); + data.modelScale.legs.setScale(0.9f,0.65f); + data.modelScale.arms.setScale(0.9f,0.65f); + data.modelScale.body.setScale(1f, 0.65f, 1.1f); + data.modelScale.head.setScale(0.85f,0.85f); presets.put("dwarf female", preset); data = new ModelData(); preset = new Preset(); preset.name = "Orc Male"; preset.data = data; - data.legs.setScale(1.2f,1.05f); - data.arms.setScale(1.2f,1.05f); - data.body.setScale(1.4f, 1.1f, 1.5f); - data.head.setScale(1.2f,1.1f); + data.modelScale.legs.setScale(1.2f,1.05f); + data.modelScale.arms.setScale(1.2f,1.05f); + data.modelScale.body.setScale(1.4f, 1.1f, 1.5f); + data.modelScale.head.setScale(1.2f,1.1f); presets.put("orc male", preset); data = new ModelData(); @@ -81,9 +81,9 @@ public class Preset { preset.name = "Orc Female"; preset.data = data; data.breasts = 2; - data.legs.setScale(1.1f,1); - data.arms.setScale(1.1f,1); - data.body.setScale(1.1f, 1f, 1.25f); + data.modelScale.legs.setScale(1.1f,1); + data.modelScale.arms.setScale(1.1f,1); + data.modelScale.body.setScale(1.1f, 1f, 1.25f); presets.put("orc female", preset); data = new ModelData(); @@ -97,10 +97,10 @@ public class Preset { preset.name = "Human Female"; preset.data = data; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); presets.put("human female", preset); data = new ModelData(); @@ -132,10 +132,10 @@ public class Preset { tail.setTexture("tail/tail1", 0); tail.color = 0xD9A64E; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); presets.put("cat female", preset); data = new ModelData(); @@ -167,18 +167,18 @@ public class Preset { tail.setTexture("tail/tail2", 0); tail.color = 0x5E5855; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); presets.put("wolf female", preset); data = new ModelData(); preset = new Preset(); preset.name = "Enderchibi"; preset.data = data; - data.legs.setScale(0.65f,0.75f); - data.arms.setScale(0.50f,1.45f); + data.modelScale.legs.setScale(0.65f,0.75f); + data.modelScale.arms.setScale(0.50f,1.45f); ModelPartData part = data.getOrCreatePart("particles"); part.setTexture("particle/type1", 1); part.color = 0xFF0000; diff --git a/src/main/java/noppes/npcs/client/fx/EntityEnderFX.java b/src/main/java/noppes/npcs/client/fx/EntityEnderFX.java index 9c630c4e7..11cdf2279 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityEnderFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityEnderFX.java @@ -3,7 +3,7 @@ package noppes.npcs.client.fx; import net.minecraft.client.particle.EntityPortalFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.ResourceLocation; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.ClientProxy; import noppes.npcs.entity.EntityCustomNpc; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java index 40eaf34f5..223d2efc7 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java @@ -8,7 +8,7 @@ import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RendererLivingEntity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.client.EntityUtil; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNPCStringSlot; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelArms.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelArms.java index 300379079..f56424d23 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelArms.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelArms.java @@ -2,7 +2,7 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.gui.util.GuiModelInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java index e1bb8c373..ca1f5c376 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelBody.java @@ -2,7 +2,7 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.gui.util.GuiModelInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelColor.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelColor.java index efe34d234..9bd4be172 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelColor.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelColor.java @@ -4,7 +4,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.IResource; import net.minecraft.util.ResourceLocation; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.gui.util.GuiModelInterface; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.ITextfieldListener; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelHead.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelHead.java index e35836c34..8bab6b4dd 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelHead.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelHead.java @@ -2,7 +2,7 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.gui.util.GuiModelInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelLegs.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelLegs.java index e15775b62..0dfaf06a3 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelLegs.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelLegs.java @@ -2,7 +2,7 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.gui.util.GuiModelInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelRotate.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelRotate.java index 92bbb48b8..1ca7e4635 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelRotate.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelRotate.java @@ -2,9 +2,8 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelData; -import noppes.npcs.ModelLimbConfig; -import noppes.npcs.ModelRotatePart; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelRotatePart; import noppes.npcs.client.gui.util.GuiModelInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiModelScale.java b/src/main/java/noppes/npcs/client/gui/model/GuiModelScale.java index 3ff91ebfc..b933d2c51 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiModelScale.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiModelScale.java @@ -2,8 +2,8 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelData; -import noppes.npcs.ModelLimbConfig; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelScalePart; import noppes.npcs.client.gui.util.*; import noppes.npcs.entity.EntityCustomNpc; @@ -32,7 +32,7 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ addLabel(new GuiNpcLabel(20, "Head", guiLeft + 55, y + 5, 0xFFFFFF)); if(type == 0){ - drawSlider(y, playerdata.head); + drawSlider(y, playerdata.modelScale.head); y += 88; } else{ @@ -42,7 +42,7 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ addLabel(new GuiNpcLabel(21, "Body", guiLeft + 55, y + 5, 0xFFFFFF)); if(type == 1){ - drawSlider(y, playerdata.body); + drawSlider(y, playerdata.modelScale.body); y += 88; } else{ @@ -52,7 +52,7 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ addLabel(new GuiNpcLabel(22, "Arms", guiLeft + 55, y + 5, 0xFFFFFF)); if(type == 2){ - drawSlider(y, playerdata.arms); + drawSlider(y, playerdata.modelScale.arms); y += 88; } else { @@ -62,7 +62,7 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ addLabel(new GuiNpcLabel(23, "Legs", guiLeft + 55, y + 5, 0xFFFFFF)); if(type == 3){ - drawSlider(y, playerdata.legs); + drawSlider(y, playerdata.modelScale.legs); y += 88; } else{ @@ -71,7 +71,7 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ } } - private void drawSlider(int y, ModelLimbConfig config){ + private void drawSlider(int y, ModelScalePart config){ y += 20; addLabel(new GuiNpcLabel(10, "Width", guiLeft - 25 + offset, y + 5, 0xFFFFFF)); scaleWidth = new GuiNpcSlider(this, 10, guiLeft + 50 + offset, y, config.scaleX - 0.5f); @@ -100,13 +100,13 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ } else{ // Resetting Type - ModelLimbConfig config = playerdata.head; + ModelScalePart config = playerdata.modelScale.head; if(type == 1) - config = playerdata.body; + config = playerdata.modelScale.body; else if(type == 2) - config = playerdata.arms; + config = playerdata.modelScale.arms; else if(type == 3) - config = playerdata.legs; + config = playerdata.modelScale.legs; if(btn.id == 170){ config.scaleX = 1.0f; @@ -143,13 +143,13 @@ public class GuiModelScale extends GuiModelInterface implements ISliderListener{ public void mouseDragged(GuiNpcSlider slider) { int percent = (int) (50 + slider.sliderValue * 100); slider.setString(percent + "%"); - ModelLimbConfig config = playerdata.head; + ModelScalePart config = playerdata.modelScale.head; if(type == 1) - config = playerdata.body; + config = playerdata.modelScale.body; else if(type == 2) - config = playerdata.arms; + config = playerdata.modelScale.arms; else if(type == 3) - config = playerdata.legs; + config = playerdata.modelScale.legs; if(slider.id == 10) config.scaleX = slider.sliderValue + 0.5f; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiPresetSave.java b/src/main/java/noppes/npcs/client/gui/model/GuiPresetSave.java index a9e7b9f12..87ca3e954 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiPresetSave.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiPresetSave.java @@ -2,7 +2,7 @@ package noppes.npcs.client.gui.model; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.client.controllers.Preset; import noppes.npcs.client.controllers.PresetController; import noppes.npcs.client.gui.util.GuiNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiPresetSelection.java b/src/main/java/noppes/npcs/client/gui/model/GuiPresetSelection.java index cf792e4d4..4bfa77a11 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiPresetSelection.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiPresetSelection.java @@ -8,7 +8,7 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.client.EntityUtil; import noppes.npcs.client.controllers.Preset; import noppes.npcs.client.controllers.PresetController; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java index 31c03f588..2087e41d2 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java @@ -6,7 +6,7 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.client.EntityUtil; import noppes.npcs.entity.EntityCustomNpc; import org.lwjgl.input.Mouse; diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index a5004bd7d..42e4157ca 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -24,6 +24,8 @@ import noppes.npcs.controllers.data.Frame; import noppes.npcs.controllers.data.FramePart; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.data.ModelPartData; +import noppes.npcs.entity.data.ModelScalePart; import org.lwjgl.opengl.GL11; import java.util.HashMap; @@ -632,7 +634,7 @@ public class ModelMPM extends ModelNPCMale{ bipedRightArm.rotateAngleZ = (float) (Math.PI - 1f - Math.sin(entity.ticksExisted * 0.27f) * 0.5f ); } else if(isSneak){ - this.bipedBody.rotateAngleX = 0.5F / npc.modelData.body.scaleY; + this.bipedBody.rotateAngleX = 0.5F / npc.modelData.modelScale.body.scaleY; } AnimationData animationData = npc.display.animationData; @@ -736,7 +738,7 @@ public class ModelMPM extends ModelNPCMale{ float dancing = entity.ticksExisted / 4f; GL11.glTranslatef((float)Math.sin(dancing) * 0.075F, (float)Math.abs(Math.cos(dancing)) * 0.125F - 0.02F, (float)(-Math.abs(Math.cos(dancing))) * 0.075F); } - ModelLimbConfig head = entity.modelData.head; + ModelScalePart head = entity.modelData.modelScale.head; this.copyAnglesPivots(headwear,bipedHead); this.copyAnglesPivots(bipedHeadwear,bipedHead); @@ -772,7 +774,7 @@ public class ModelMPM extends ModelNPCMale{ GL11.glTranslatef((float)Math.sin(dancing) * 0.015F, 0.0F, 0.0F); } - ModelLimbConfig body = entity.modelData.body; + ModelScalePart body = entity.modelData.modelScale.body; // Hide Body ((ModelScaleRenderer)this.bipedBody).isHidden = entity.modelData.hideBody == 1; @@ -782,7 +784,7 @@ public class ModelMPM extends ModelNPCMale{ if(bipedBodywear.showModel && !bipedBodywear.isHidden){ if(entity.modelData.bodywear == 1 || isArmor){ - ((ModelScaleRenderer)this.bipedBodywear).setConfig(entity.modelData.body,x,y,z); + ((ModelScaleRenderer)this.bipedBodywear).setConfig(entity.modelData.modelScale.body,x,y,z); ((ModelScaleRenderer)this.bipedBodywear).render(f); } else if(entity.modelData.bodywear == 2){ @@ -792,7 +794,7 @@ public class ModelMPM extends ModelNPCMale{ this.bodywear.rotationPointX = bipedBodywear.rotationPointX; this.bodywear.rotationPointY = bipedBodywear.rotationPointY; this.bodywear.rotationPointZ = bipedBodywear.rotationPointZ; - this.bodywear.setConfig(entity.modelData.body,x,y,z); + this.bodywear.setConfig(entity.modelData.modelScale.body,x,y,z); this.bodywear.render(f); } } @@ -804,9 +806,9 @@ public class ModelMPM extends ModelNPCMale{ } public void renderArms(EntityCustomNpc entity, float f, boolean bo){ loadPlayerTexture(entity); - ModelLimbConfig arms = entity.modelData.arms; + ModelScalePart arms = entity.modelData.modelScale.arms; - float x = (1 - entity.modelData.body.scaleX) * 0.25f + (1 - arms.scaleX) * 0.075f; + float x = (1 - entity.modelData.modelScale.body.scaleX) * 0.25f + (1 - arms.scaleX) * 0.075f; float y = entity.modelData.getBodyY() + (1 - arms.scaleY) * -0.1f; float z = 0; @@ -883,7 +885,7 @@ public class ModelMPM extends ModelNPCMale{ } private void renderLegs(EntityCustomNpc entity, float f) { loadPlayerTexture(entity); - ModelLimbConfig legs = entity.modelData.legs; + ModelScalePart legs = entity.modelData.modelScale.legs; float x = (1 - legs.scaleX) * 0.125f; float y = entity.modelData.getLegsY(); diff --git a/src/main/java/noppes/npcs/client/model/part/ModelBeard.java b/src/main/java/noppes/npcs/client/model/part/ModelBeard.java index 420c5006e..794e7022e 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelBeard.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelBeard.java @@ -1,8 +1,8 @@ package noppes.npcs.client.model.part; import net.minecraft.entity.Entity; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelBreasts.java b/src/main/java/noppes/npcs/client/model/part/ModelBreasts.java index 0e2b969a2..03dc236f6 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelBreasts.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelBreasts.java @@ -2,7 +2,7 @@ package noppes.npcs.client.model.part; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelClaws.java b/src/main/java/noppes/npcs/client/model/part/ModelClaws.java index 3abef9802..88706cb0a 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelClaws.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelClaws.java @@ -1,7 +1,7 @@ package noppes.npcs.client.model.part; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelEars.java b/src/main/java/noppes/npcs/client/model/part/ModelEars.java index 877b83950..c6152a250 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelEars.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelEars.java @@ -1,8 +1,8 @@ package noppes.npcs.client.model.part; import net.minecraft.client.model.ModelRenderer; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelFin.java b/src/main/java/noppes/npcs/client/model/part/ModelFin.java index 42f715504..b3c74ccc3 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelFin.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelFin.java @@ -1,7 +1,7 @@ package noppes.npcs.client.model.part; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelHair.java b/src/main/java/noppes/npcs/client/model/part/ModelHair.java index 4a4c12389..4e7d985ea 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelHair.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelHair.java @@ -2,8 +2,8 @@ package noppes.npcs.client.model.part; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelHorns.java b/src/main/java/noppes/npcs/client/model/part/ModelHorns.java index 30c31ff73..ce5d81004 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelHorns.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelHorns.java @@ -2,8 +2,8 @@ package noppes.npcs.client.model.part; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.part.horns.ModelAntennasBack; import noppes.npcs.client.model.part.horns.ModelAntennasFront; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java index 1ede81e50..0d87b4512 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java @@ -3,7 +3,7 @@ package noppes.npcs.client.model.part; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.ClientProxy; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.part.legs.ModelDigitigradeLegs; @@ -294,8 +294,8 @@ public class ModelLegs extends ModelScaleRenderer{ spiderNeck.rotateAngleX = (float) (Math.PI / -8); } if(base.isSleeping(entity) || this.entity.currentAnimation == EnumAnimation.CRAWLING){ - rotationPointY = 12 * this.entity.modelData.legs.scaleY; - rotationPointZ = 15 * this.entity.modelData.legs.scaleY; + rotationPointY = 12 * this.entity.modelData.modelScale.legs.scaleY; + rotationPointZ = 15 * this.entity.modelData.modelScale.legs.scaleY; this.rotateAngleX = (float) (Math.PI / -2); } diff --git a/src/main/java/noppes/npcs/client/model/part/ModelMohawk.java b/src/main/java/noppes/npcs/client/model/part/ModelMohawk.java index 2d9b1e291..f66397bc9 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelMohawk.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelMohawk.java @@ -1,8 +1,8 @@ package noppes.npcs.client.model.part; import net.minecraft.entity.Entity; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelSkirt.java b/src/main/java/noppes/npcs/client/model/part/ModelSkirt.java index b3489a624..42e7bf763 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelSkirt.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelSkirt.java @@ -3,8 +3,8 @@ package noppes.npcs.client.model.part; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.ModelPartInterface; import noppes.npcs.client.model.util.ModelPlaneRenderer; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelSnout.java b/src/main/java/noppes/npcs/client/model/part/ModelSnout.java index 6157cea71..d31abdd9f 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelSnout.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelSnout.java @@ -2,8 +2,8 @@ package noppes.npcs.client.model.part; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelTail.java b/src/main/java/noppes/npcs/client/model/part/ModelTail.java index 87c3bad53..f8ddd87c6 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelTail.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelTail.java @@ -5,7 +5,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.ClientProxy; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.part.tails.*; @@ -87,18 +87,18 @@ public class ModelTail extends ModelScaleRenderer { if(this.entity.modelData.legParts.type == 2){ rotationPointY = 13f; - rotationPointZ = 14 * this.entity.modelData.legs.scaleZ; + rotationPointZ = 14 * this.entity.modelData.modelScale.legs.scaleZ; if(base.isSleeping(entity) || this.entity.currentAnimation == EnumAnimation.CRAWLING){ - rotationPointY = 12 + 16 * this.entity.modelData.legs.scaleZ; - rotationPointZ = 1f * this.entity.modelData.legs.scaleY; + rotationPointY = 12 + 16 * this.entity.modelData.modelScale.legs.scaleZ; + rotationPointZ = 1f * this.entity.modelData.modelScale.legs.scaleY; rotateAngleX = (float) (Math.PI / -4); } } else if(this.entity.modelData.legParts.type == 3){ rotationPointY = 8.6f; - rotationPointZ = 19 * this.entity.modelData.legs.scaleZ; + rotationPointZ = 19 * this.entity.modelData.modelScale.legs.scaleZ; } else{ rotationPointY = 11; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelWings.java b/src/main/java/noppes/npcs/client/model/part/ModelWings.java index f5eece043..ced9f8e83 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelWings.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelWings.java @@ -2,8 +2,8 @@ package noppes.npcs.client.model.part; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.util.Model2DRenderer; import noppes.npcs.client.model.util.ModelPartInterface; diff --git a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java index b9651f217..fabc81710 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java @@ -4,8 +4,8 @@ import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ResourceLocation; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.client.ClientProxy; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.entity.EntityCustomNpc; diff --git a/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java b/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java index cd2e6c90a..2e64ab9a5 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java @@ -5,7 +5,7 @@ import net.minecraft.client.model.ModelBox; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.Tessellator; -import noppes.npcs.ModelLimbConfig; +import noppes.npcs.entity.data.ModelScalePart; import org.lwjgl.opengl.GL11; public class ModelScaleRenderer extends ModelRenderer { @@ -15,7 +15,7 @@ public class ModelScaleRenderer extends ModelRenderer { /** The GL display list rendered by the Tessellator for this model */ public int displayList; - protected ModelLimbConfig config; + protected ModelScalePart config; public float x, y, z; @@ -28,7 +28,7 @@ public class ModelScaleRenderer extends ModelRenderer { this.setTextureOffset(par2, par3); } - public void setConfig(ModelLimbConfig config, float x, float y, float z){ + public void setConfig(ModelScalePart config, float x, float y, float z){ this.config = config; this.x = x; this.y = y; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java index abd10c726..927d09683 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java @@ -145,17 +145,17 @@ public class RenderNPCHumanMale extends RenderNPCInterface modelArmorChestplate.heldItemRight = modelArmor.heldItemRight = modelBipedMain.heldItemRight = itemstack == null ? 0 : npc.hurtResistantTime > 0 ? 3 : 1; - modelArmorChestplate.heldItemLeft = modelArmor.heldItemLeft = modelBipedMain.heldItemLeft = + modelArmorChestplate.heldItemLeft = modelArmor.heldItemLeft = modelBipedMain.heldItemLeft = npc.getOffHand() == null ? 0 : npc.hurtResistantTime > 0 ? 3 : 1; - + modelArmorChestplate.isSneak = modelArmor.isSneak = modelBipedMain.isSneak = npc.isSneaking(); modelArmorChestplate.isSleeping = modelArmor.isSleeping = modelBipedMain.isSleeping = npc.isPlayerSleeping(); modelArmorChestplate.isDancing = modelArmor.isDancing = modelBipedMain.isDancing = npc.currentAnimation == EnumAnimation.DANCING; modelArmorChestplate.aimedBow = modelArmor.aimedBow = modelBipedMain.aimedBow = npc.currentAnimation == EnumAnimation.AIMING; - + modelArmorChestplate.isRiding = modelArmor.isRiding = modelBipedMain.isRiding = npc.isRiding(); - + double d3 = d1 - (double)npc.yOffset; if(npc.isSneaking()) { @@ -185,7 +185,7 @@ public class RenderNPCHumanMale extends RenderNPCInterface EntityCustomNpc cnpc = (EntityCustomNpc) npc; GL11.glTranslatef(0, cnpc.modelData.getBodyY(), 0); this.modelBipedMain.bipedHead.postRender(0.0625F); - GL11.glScalef(cnpc.modelData.head.scaleX, cnpc.modelData.head.scaleY, cnpc.modelData.head.scaleZ); + GL11.glScalef(cnpc.modelData.modelScale.head.scaleX, cnpc.modelData.modelScale.head.scaleY, cnpc.modelData.modelScale.head.scaleZ); } else this.modelBipedMain.bipedHead.postRender(0.0625F); @@ -218,8 +218,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface float x = 0; if(npc instanceof EntityCustomNpc){ EntityCustomNpc cnpc = (EntityCustomNpc) npc; - y = (cnpc.modelData.arms.scaleY - 1) * 0.7f; - x = (1 - cnpc.modelData.body.scaleX) * 0.28f + (1 - cnpc.modelData.arms.scaleX) * 0.175f; + y = (cnpc.modelData.modelScale.arms.scaleY - 1) * 0.7f; + x = (1 - cnpc.modelData.modelScale.body.scaleX) * 0.28f + (1 - cnpc.modelData.modelScale.arms.scaleX) * 0.175f; GL11.glTranslatef(x, cnpc.modelData.getBodyY(), 0); } this.modelBipedMain.bipedRightArm.postRender(0.0625F); @@ -263,7 +263,7 @@ public class RenderNPCHumanMale extends RenderNPCInterface GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); GL11.glTranslatef(0.0F, -0.125F, 0.0F); } - + if (npc.hurtResistantTime > 0 && npc.stats.resistances.playermelee > 1f) { GL11.glTranslatef(0.05F, 0.0F, -0.1F); @@ -309,7 +309,7 @@ public class RenderNPCHumanMale extends RenderNPCInterface } else renderManager.itemRenderer.renderItem(npc, itemstack2, 0); - + GL11.glPopMatrix(); } GL11.glColor4f(1, 1, 1, 1.0F); @@ -321,8 +321,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface float x = 0; if(npc instanceof EntityCustomNpc){ EntityCustomNpc cnpc = (EntityCustomNpc) npc; - y = (cnpc.modelData.arms.scaleY - 1) * 0.7f; - x = (1 - cnpc.modelData.body.scaleX) * -0.28f + (1 - cnpc.modelData.arms.scaleX) * -0.175f; + y = (cnpc.modelData.modelScale.arms.scaleY - 1) * 0.7f; + x = (1 - cnpc.modelData.modelScale.body.scaleX) * -0.28f + (1 - cnpc.modelData.modelScale.arms.scaleX) * -0.175f; GL11.glTranslatef(x, cnpc.modelData.getBodyY(), 0); } this.modelBipedMain.bipedLeftArm.postRender(0.0625F); diff --git a/src/main/java/noppes/npcs/entity/EntityCustomNpc.java b/src/main/java/noppes/npcs/entity/EntityCustomNpc.java index 7fc3ca108..735be27ab 100644 --- a/src/main/java/noppes/npcs/entity/EntityCustomNpc.java +++ b/src/main/java/noppes/npcs/entity/EntityCustomNpc.java @@ -5,8 +5,8 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.VersionCompatibility; import noppes.npcs.client.EntityUtil; @@ -64,7 +64,7 @@ public class EntityCustomNpc extends EntityNPCFlying { public void updateHitbox() { Entity entity = modelData.getEntity(this); if(modelData == null || entity == null){ - baseHeight = 1.9f - modelData.getBodyY() + (modelData.head.scaleY - 1) / 2; + baseHeight = 1.9f - modelData.getBodyY() + (modelData.modelScale.head.scaleY - 1) / 2; super.updateHitbox(); } else{ diff --git a/src/main/java/noppes/npcs/entity/EntityNPCGolem.java b/src/main/java/noppes/npcs/entity/EntityNPCGolem.java index cb74d847a..8ae0c67c5 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCGolem.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCGolem.java @@ -6,7 +6,7 @@ package noppes.npcs.entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.constants.EnumAnimation; // Referenced classes of package net.minecraft.src: diff --git a/src/main/java/noppes/npcs/entity/EntityNpcCrystal.java b/src/main/java/noppes/npcs/entity/EntityNpcCrystal.java index acc159443..de1c4aa1c 100644 --- a/src/main/java/noppes/npcs/entity/EntityNpcCrystal.java +++ b/src/main/java/noppes/npcs/entity/EntityNpcCrystal.java @@ -6,7 +6,7 @@ package noppes.npcs.entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; // Referenced classes of package net.minecraft.src: // EntityAnimal, Item, EntityPlayer, InventoryPlayer, diff --git a/src/main/java/noppes/npcs/entity/EntityNpcDragon.java b/src/main/java/noppes/npcs/entity/EntityNpcDragon.java index 45d49956c..64d23e282 100644 --- a/src/main/java/noppes/npcs/entity/EntityNpcDragon.java +++ b/src/main/java/noppes/npcs/entity/EntityNpcDragon.java @@ -3,7 +3,7 @@ package noppes.npcs.entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; public class EntityNpcDragon extends EntityNPCInterface{ public EntityNpcDragon(World world) diff --git a/src/main/java/noppes/npcs/entity/EntityNpcPony.java b/src/main/java/noppes/npcs/entity/EntityNpcPony.java index 7b8032421..b0e92cd10 100644 --- a/src/main/java/noppes/npcs/entity/EntityNpcPony.java +++ b/src/main/java/noppes/npcs/entity/EntityNpcPony.java @@ -3,7 +3,7 @@ package noppes.npcs.entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; public class EntityNpcPony extends EntityNPCInterface { diff --git a/src/main/java/noppes/npcs/entity/EntityNpcSlime.java b/src/main/java/noppes/npcs/entity/EntityNpcSlime.java index b2cf83ec0..a0cea00f9 100644 --- a/src/main/java/noppes/npcs/entity/EntityNpcSlime.java +++ b/src/main/java/noppes/npcs/entity/EntityNpcSlime.java @@ -2,7 +2,7 @@ package noppes.npcs.entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; public class EntityNpcSlime extends EntityNPCInterface{ public EntityNpcSlime(World world) diff --git a/src/main/java/noppes/npcs/ModelData.java b/src/main/java/noppes/npcs/entity/data/ModelData.java similarity index 97% rename from src/main/java/noppes/npcs/ModelData.java rename to src/main/java/noppes/npcs/entity/data/ModelData.java index 90eb41025..6f1c569b2 100644 --- a/src/main/java/noppes/npcs/ModelData.java +++ b/src/main/java/noppes/npcs/entity/data/ModelData.java @@ -1,4 +1,4 @@ -package noppes.npcs; +package noppes.npcs.entity.data; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; diff --git a/src/main/java/noppes/npcs/ModelDataShared.java b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java similarity index 71% rename from src/main/java/noppes/npcs/ModelDataShared.java rename to src/main/java/noppes/npcs/entity/data/ModelDataShared.java index 2455aa461..bf5ae19d1 100644 --- a/src/main/java/noppes/npcs/ModelDataShared.java +++ b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java @@ -1,18 +1,18 @@ -package noppes.npcs; +package noppes.npcs.entity.data; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.passive.EntityHorse; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.api.entity.data.IModelData; +import noppes.npcs.api.entity.data.IModelRotate; +import noppes.npcs.api.entity.data.IModelScale; import java.util.HashMap; -public class ModelDataShared{ - public ModelLimbConfig head = new ModelLimbConfig(); - public ModelLimbConfig arms = new ModelLimbConfig(); - public ModelLimbConfig body = new ModelLimbConfig(); - public ModelLimbConfig legs = new ModelLimbConfig(); +public class ModelDataShared implements IModelData { + public ModelScale modelScale = new ModelScale(); public boolean enableRotation = false; public ModelRotate rotation = new ModelRotate(); @@ -48,10 +48,7 @@ public class ModelDataShared{ if(entityClass != null) compound.setString("EntityClass", entityClass.getCanonicalName()); - compound.setTag("HeadConfig", head.writeToNBT()); - compound.setTag("BodyConfig", body.writeToNBT()); - compound.setTag("ArmsConfig", arms.writeToNBT()); - compound.setTag("LegsConfig", legs.writeToNBT()); + compound = this.modelScale.writeToNBT(compound); compound.setTag("LegParts", legParts.writeToNBT()); @@ -87,12 +84,9 @@ public class ModelDataShared{ } public void readFromNBT(NBTTagCompound compound){ - setEntityClass(compound.getString("EntityClass")); + setEntity(compound.getString("EntityClass")); - head.readFromNBT(compound.getCompoundTag("HeadConfig")); - body.readFromNBT(compound.getCompoundTag("BodyConfig")); - arms.readFromNBT(compound.getCompoundTag("ArmsConfig")); - legs.readFromNBT(compound.getCompoundTag("LegsConfig")); + this.modelScale.readFromNBT(compound); legParts.readFromNBT(compound.getCompoundTag("LegParts")); @@ -127,33 +121,6 @@ public class ModelDataShared{ this.parts = parts; } - - public void readPartsFromNBT(NBTTagCompound compound){ - legParts.readFromNBT(compound.getCompoundTag("LegParts")); - - HashMap parts = new HashMap(); - NBTTagList list = compound.getTagList("Parts", 10); - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound item = list.getCompoundTagAt(i); - ModelPartData part = new ModelPartData(); - part.readFromNBT(item); - parts.put(item.getString("PartName"), part); - } - this.parts = parts; - } - - private void setEntityClass(String string) { - entityClass = null; - entity = null; - try { - Class cls = Class.forName(string); - if (EntityLivingBase.class.isAssignableFrom(cls)) - entityClass = cls.asSubclass(EntityLivingBase.class); - - } catch (ClassNotFoundException e) { - - } - } public void setEntityClass(Class entityClass){ this.entityClass = entityClass; @@ -195,15 +162,46 @@ public class ModelDataShared{ public float getBodyY(){ if(legParts.type == 3) - return (0.9f - body.scaleY) * 0.75f + getLegsY(); + return (0.9f - modelScale.body.scaleY) * 0.75f + getLegsY(); if(legParts.type == 3) - return (0.5f - body.scaleY) * 0.75f + getLegsY(); - return (1 - body.scaleY) * 0.75f + getLegsY(); + return (0.5f - modelScale.body.scaleY) * 0.75f + getLegsY(); + return (1 - modelScale.body.scaleY) * 0.75f + getLegsY(); } public float getLegsY() { if(legParts.type == 3) - return (0.87f - legs.scaleY) * 1f; - return (1 - legs.scaleY) * 0.75f; + return (0.87f - modelScale.legs.scaleY); + return (1 - modelScale.legs.scaleY) * 0.75f; + } + + public void enableRotation(boolean enableRotation) { + this.enableRotation = enableRotation; + } + + public boolean enableRotation() { + return this.enableRotation; + } + + public IModelRotate getRotation() { + return this.rotation; + } + + public IModelScale getScale() { + return this.modelScale; + } + + public void setEntity(String string) { + entityClass = null; + entity = null; + try { + Class cls = Class.forName(string); + if (EntityLivingBase.class.isAssignableFrom(cls)) + entityClass = cls.asSubclass(EntityLivingBase.class); + + } catch (ClassNotFoundException ignored) {} + } + + public String getEntity() { + return entityClass == null ? null : entityClass.getName(); } } diff --git a/src/main/java/noppes/npcs/ModelPartData.java b/src/main/java/noppes/npcs/entity/data/ModelPartData.java similarity index 98% rename from src/main/java/noppes/npcs/ModelPartData.java rename to src/main/java/noppes/npcs/entity/data/ModelPartData.java index 2cbe59974..77db24599 100644 --- a/src/main/java/noppes/npcs/ModelPartData.java +++ b/src/main/java/noppes/npcs/entity/data/ModelPartData.java @@ -1,4 +1,4 @@ -package noppes.npcs; +package noppes.npcs.entity.data; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/noppes/npcs/ModelRotate.java b/src/main/java/noppes/npcs/entity/data/ModelRotate.java similarity index 64% rename from src/main/java/noppes/npcs/ModelRotate.java rename to src/main/java/noppes/npcs/entity/data/ModelRotate.java index 1dc07bf74..00f85ba69 100644 --- a/src/main/java/noppes/npcs/ModelRotate.java +++ b/src/main/java/noppes/npcs/entity/data/ModelRotate.java @@ -1,9 +1,11 @@ -package noppes.npcs; +package noppes.npcs.entity.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.entity.data.IModelRotate; +import noppes.npcs.api.entity.data.IModelRotatePart; import noppes.npcs.util.ValueUtil; -public class ModelRotate { +public class ModelRotate implements IModelRotate { // Rotation public boolean whileStanding = true; public boolean whileAttacking = false; @@ -42,4 +44,45 @@ public class ModelRotate { lleg.readFromNBT(compound.getCompoundTag("PuppetLLeg")); } + public boolean whileStanding() { + return this.whileStanding; + } + + public void whileStanding(boolean whileStanding) { + this.whileStanding = whileStanding; + } + + public boolean whileAttacking() { + return this.whileAttacking; + } + + public void whileAttacking(boolean whileAttacking) { + this.whileAttacking = whileAttacking; + } + + public boolean whileMoving() { + return this.whileMoving; + } + + public void whileMoving(boolean whileMoving) { + this.whileMoving = whileMoving; + } + + public IModelRotatePart getPart(int part) { + switch (ValueUtil.CorrectInt(part,0,5)) { + case 0: + return head; + case 1: + return body; + case 2: + return larm; + case 3: + return rarm; + case 4: + return lleg; + case 5: + return rleg; + } + return null; + } } diff --git a/src/main/java/noppes/npcs/ModelRotatePart.java b/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java similarity index 58% rename from src/main/java/noppes/npcs/ModelRotatePart.java rename to src/main/java/noppes/npcs/entity/data/ModelRotatePart.java index e8be64fd7..63598e023 100644 --- a/src/main/java/noppes/npcs/ModelRotatePart.java +++ b/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java @@ -1,9 +1,10 @@ -package noppes.npcs; +package noppes.npcs.entity.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.entity.data.IModelRotatePart; import noppes.npcs.util.ValueUtil; -public class ModelRotatePart { +public class ModelRotatePart implements IModelRotatePart { public float rotationX = 0f, rotationY = 0f, rotationZ = 0f; public boolean disabled = false; @@ -23,4 +24,29 @@ public class ModelRotatePart { rotationZ = ValueUtil.correctFloat(compound.getFloat("RotationZ"), -0.5f, 0.5f); } + public void setRotation(float x, float y, float z) { + this.rotationX = x; + this.rotationY = y; + this.rotationZ = z; + } + + public float getRotateX() { + return this.rotationX; + } + + public float getRotateY() { + return this.rotationY; + } + + public float getRotateZ() { + return this.rotationZ; + } + + public void disabled(boolean disabled) { + this.disabled = disabled; + } + + public boolean disabled() { + return this.disabled; + } } diff --git a/src/main/java/noppes/npcs/entity/data/ModelScale.java b/src/main/java/noppes/npcs/entity/data/ModelScale.java new file mode 100644 index 000000000..935e9fede --- /dev/null +++ b/src/main/java/noppes/npcs/entity/data/ModelScale.java @@ -0,0 +1,43 @@ +package noppes.npcs.entity.data; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.entity.data.IModelScale; +import noppes.npcs.api.entity.data.IModelScalePart; +import noppes.npcs.util.ValueUtil; + +public class ModelScale implements IModelScale { + public ModelScalePart head = new ModelScalePart(); + public ModelScalePart body = new ModelScalePart(); + public ModelScalePart arms = new ModelScalePart(); + public ModelScalePart legs = new ModelScalePart(); + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setTag("HeadConfig", head.writeToNBT()); + compound.setTag("BodyConfig", body.writeToNBT()); + compound.setTag("ArmsConfig", arms.writeToNBT()); + compound.setTag("LegsConfig", legs.writeToNBT()); + return compound; + } + + public void readFromNBT(NBTTagCompound compound) { + head.readFromNBT(compound.getCompoundTag("HeadConfig")); + body.readFromNBT(compound.getCompoundTag("BodyConfig")); + arms.readFromNBT(compound.getCompoundTag("ArmsConfig")); + legs.readFromNBT(compound.getCompoundTag("LegsConfig")); + } + + @Override + public IModelScalePart getPart(int part) { + switch (ValueUtil.CorrectInt(part,0,3)) { + case 0: + return head; + case 1: + return body; + case 2: + return arms; + case 3: + return legs; + } + return null; + } +} diff --git a/src/main/java/noppes/npcs/ModelLimbConfig.java b/src/main/java/noppes/npcs/entity/data/ModelScalePart.java similarity index 67% rename from src/main/java/noppes/npcs/ModelLimbConfig.java rename to src/main/java/noppes/npcs/entity/data/ModelScalePart.java index aa334e916..63f8d9361 100644 --- a/src/main/java/noppes/npcs/ModelLimbConfig.java +++ b/src/main/java/noppes/npcs/entity/data/ModelScalePart.java @@ -1,19 +1,17 @@ -package noppes.npcs; +package noppes.npcs.entity.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.entity.data.IModelScalePart; import noppes.npcs.util.ValueUtil; -public class ModelLimbConfig { - +public class ModelScalePart implements IModelScalePart { public float scaleX = 1, scaleY = 1, scaleZ = 1; - public boolean shared = false; public NBTTagCompound writeToNBT(){ NBTTagCompound compound = new NBTTagCompound(); compound.setFloat("ScaleX", scaleX); compound.setFloat("ScaleY", scaleY); compound.setFloat("ScaleZ", scaleZ); - compound.setBoolean("Shared", shared); return compound; } @@ -28,14 +26,26 @@ public class ModelLimbConfig { return "ScaleX: " + scaleX + " - ScaleY: " + scaleY + " - ScaleZ: " + scaleZ; } - public void setScale(float x, float y, float z) { - scaleX = x; - scaleY = y; - scaleZ = z; - } public void setScale(float x, float y) { scaleZ = scaleX = x; scaleY = y; } + public void setScale(float x, float y, float z) { + scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); + scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); + scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + } + + public float getScaleX() { + return scaleX; + } + + public float getScaleY() { + return scaleY; + } + + public float getScaleZ() { + return scaleZ; + } } diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfFemale.java index 81dbbff3e..bcdef3828 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfFemale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -35,10 +35,10 @@ public class EntityNPCDwarfFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.legs.setScale(0.8f,1.05f); - data.arms.setScale(0.8f,1.05f); - data.body.setScale(0.8f,1.05f); - data.head.setScale(0.8f,0.85f); + data.modelScale.legs.setScale(0.8f,1.05f); + data.modelScale.arms.setScale(0.8f,1.05f); + data.modelScale.body.setScale(0.8f,1.05f); + data.modelScale.head.setScale(0.8f,0.85f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfMale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfMale.java index de050923b..1771d58ab 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfMale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCDwarfMale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -34,10 +34,10 @@ public class EntityNPCDwarfMale extends EntityNPCInterface EntityCustomNpc npc = new EntityCustomNpc(worldObj); npc.readFromNBT(compound); ModelData data = npc.modelData; - data.legs.setScale(1.1f,0.7f, 0.9f); - data.arms.setScale(0.9f,0.7f); - data.body.setScale(1.2f, 0.7f, 1.5f); - data.head.setScale(0.85f,0.85f); + data.modelScale.legs.setScale(1.1f,0.7f, 0.9f); + data.modelScale.arms.setScale(0.9f,0.7f); + data.modelScale.body.setScale(1.2f, 0.7f, 1.5f); + data.modelScale.head.setScale(0.85f,0.85f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCElfFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCElfFemale.java index ee56f2d1b..ccf1b572f 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCElfFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCElfFemale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -37,10 +37,10 @@ public class EntityNPCElfFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.legs.setScale(0.8f,1.05f); - data.arms.setScale(0.8f,1.05f); - data.body.setScale(0.8f,1.05f); - data.head.setScale(0.8f,0.85f); + data.modelScale.legs.setScale(0.8f,1.05f); + data.modelScale.arms.setScale(0.8f,1.05f); + data.modelScale.body.setScale(0.8f,1.05f); + data.modelScale.head.setScale(0.8f,0.85f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCElfMale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCElfMale.java index 0d56843da..cbd22b4ed 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCElfMale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCElfMale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -36,10 +36,10 @@ public class EntityNPCElfMale extends EntityNPCInterface EntityCustomNpc npc = new EntityCustomNpc(worldObj); npc.readFromNBT(compound); ModelData data = npc.modelData; - data.legs.setScale(0.85f,1.15f); - data.arms.setScale(0.85f,1.15f); - data.body.setScale(0.85f,1.15f); - data.head.setScale(0.85f,0.95f); + data.modelScale.legs.setScale(0.85f,1.15f); + data.modelScale.arms.setScale(0.85f,1.15f); + data.modelScale.body.setScale(0.85f,1.15f); + data.modelScale.head.setScale(0.85f,0.95f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java index bfc85d14d..71748b8d9 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java @@ -7,7 +7,7 @@ package noppes.npcs.entity.old; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.constants.EnumAnimation; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCFurryFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCFurryFemale.java index 824a8c7d0..f3472d9df 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCFurryFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCFurryFemale.java @@ -6,8 +6,8 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -35,10 +35,10 @@ public class EntityNPCFurryFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); ModelPartData hair = data.getOrCreatePart("ears"); hair.playerTexture = true; ModelPartData snout = data.getOrCreatePart("snout"); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCFurryMale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCFurryMale.java index 78b6ad0c9..206e19d70 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCFurryMale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCFurryMale.java @@ -6,8 +6,8 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCHumanFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCHumanFemale.java index 80009c494..20e0f5629 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCHumanFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCHumanFemale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -34,10 +34,10 @@ public class EntityNPCHumanFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCOrcFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCOrcFemale.java index 53f3e4b02..bb5a73bcb 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCOrcFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCOrcFemale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -34,10 +34,10 @@ public class EntityNPCOrcFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.legs.setScale(0.9f,0.65f); - data.arms.setScale(0.9f,0.65f); - data.body.setScale(1f, 0.65f, 1.1f); - data.head.setScale(0.85f,0.85f); + data.modelScale.legs.setScale(0.9f,0.65f); + data.modelScale.arms.setScale(0.9f,0.65f); + data.modelScale.body.setScale(1f, 0.65f, 1.1f); + data.modelScale.head.setScale(0.85f,0.85f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCOrcMale.java b/src/main/java/noppes/npcs/entity/old/EntityNPCOrcMale.java index 4ae4f68e4..5789b5c54 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCOrcMale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCOrcMale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -34,10 +34,10 @@ public class EntityNPCOrcMale extends EntityNPCInterface EntityCustomNpc npc = new EntityCustomNpc(worldObj); npc.readFromNBT(compound); ModelData data = npc.modelData; - data.legs.setScale(1.2f,1.05f); - data.arms.setScale(1.2f,1.05f); - data.body.setScale(1.4f, 1.1f, 1.5f); - data.head.setScale(1.2f,1.1f); + data.modelScale.legs.setScale(1.2f,1.05f); + data.modelScale.arms.setScale(1.2f,1.05f); + data.modelScale.body.setScale(1.4f, 1.1f, 1.5f); + data.modelScale.head.setScale(1.2f,1.1f); worldObj.spawnEntityInWorld(npc); } super.onUpdate(); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCVillager.java b/src/main/java/noppes/npcs/entity/old/EntityNPCVillager.java index 6d7f1aa47..13159a68f 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCVillager.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCVillager.java @@ -7,7 +7,7 @@ package noppes.npcs.entity.old; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNpcEnderchibi.java b/src/main/java/noppes/npcs/entity/old/EntityNpcEnderchibi.java index 83923b2b0..8a33fe661 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNpcEnderchibi.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNpcEnderchibi.java @@ -6,8 +6,8 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -34,8 +34,8 @@ public class EntityNpcEnderchibi extends EntityNPCInterface EntityCustomNpc npc = new EntityCustomNpc(worldObj); npc.readFromNBT(compound); ModelData data = npc.modelData; - data.legs.setScale(0.65f,0.75f); - data.arms.setScale(0.50f,1.45f); + data.modelScale.legs.setScale(0.65f,0.75f); + data.modelScale.arms.setScale(0.50f,1.45f); ModelPartData part = data.getOrCreatePart("particles"); part.playerTexture = true; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNpcMonsterFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNpcMonsterFemale.java index 77c41bb64..0c9029cb8 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNpcMonsterFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNpcMonsterFemale.java @@ -6,7 +6,7 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.constants.EnumAnimation; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -35,10 +35,10 @@ public class EntityNpcMonsterFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); npc.ai.animationType = EnumAnimation.HUG; worldObj.spawnEntityInWorld(npc); } diff --git a/src/main/java/noppes/npcs/entity/old/EntityNpcNagaFemale.java b/src/main/java/noppes/npcs/entity/old/EntityNpcNagaFemale.java index 879832d59..f18f4c5c2 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNpcNagaFemale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNpcNagaFemale.java @@ -6,8 +6,8 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -35,10 +35,10 @@ public class EntityNpcNagaFemale extends EntityNPCInterface npc.readFromNBT(compound); ModelData data = npc.modelData; data.breasts = 2; - data.head.setScale(0.95f,0.95f); - data.legs.setScale(0.92f,0.92f); - data.arms.setScale(0.80f,0.92f); - data.body.setScale(0.92f, 0.92f); + data.modelScale.head.setScale(0.95f,0.95f); + data.modelScale.legs.setScale(0.92f,0.92f); + data.modelScale.arms.setScale(0.80f,0.92f); + data.modelScale.body.setScale(0.92f, 0.92f); ModelPartData legs = data.legParts; legs.playerTexture = true; legs.type = 1; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNpcNagaMale.java b/src/main/java/noppes/npcs/entity/old/EntityNpcNagaMale.java index 7ca57c7b5..424f1b5a8 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNpcNagaMale.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNpcNagaMale.java @@ -6,8 +6,8 @@ package noppes.npcs.entity.old; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; -import noppes.npcs.ModelPartData; +import noppes.npcs.entity.data.ModelData; +import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/entity/old/EntityNpcSkeleton.java b/src/main/java/noppes/npcs/entity/old/EntityNpcSkeleton.java index c0766ad67..a240850e8 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNpcSkeleton.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNpcSkeleton.java @@ -7,7 +7,7 @@ package noppes.npcs.entity.old; import net.minecraft.entity.monster.EntitySkeleton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import noppes.npcs.ModelData; +import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/roles/RoleCompanion.java b/src/main/java/noppes/npcs/roles/RoleCompanion.java index 5ef66d515..9a1b1badc 100644 --- a/src/main/java/noppes/npcs/roles/RoleCompanion.java +++ b/src/main/java/noppes/npcs/roles/RoleCompanion.java @@ -189,10 +189,10 @@ public class RoleCompanion extends RoleInterface { EntityCustomNpc npc = (EntityCustomNpc) this.npc; npc.ai.animationType = stage.animation; if(stage == EnumCompanionStage.BABY){ - npc.modelData.arms.setScale(0.5f, 0.5f, 0.5f); - npc.modelData.legs.setScale(0.5f, 0.5f, 0.5f); - npc.modelData.body.setScale(0.5f, 0.5f, 0.5f); - npc.modelData.head.setScale(0.7f, 0.7f, 0.7f); + npc.modelData.modelScale.arms.setScale(0.5f, 0.5f, 0.5f); + npc.modelData.modelScale.legs.setScale(0.5f, 0.5f, 0.5f); + npc.modelData.modelScale.body.setScale(0.5f, 0.5f, 0.5f); + npc.modelData.modelScale.head.setScale(0.7f, 0.7f, 0.7f); npc.ai.onAttack = 1; npc.ai.setWalkingSpeed(3); @@ -200,10 +200,10 @@ public class RoleCompanion extends RoleInterface { talents.put(EnumCompanionTalent.INVENTORY, 0); } if(stage == EnumCompanionStage.CHILD){ - npc.modelData.arms.setScale(0.6f, 0.6f, 0.6f); - npc.modelData.legs.setScale(0.6f, 0.6f, 0.6f); - npc.modelData.body.setScale(0.6f, 0.6f, 0.6f); - npc.modelData.head.setScale(0.8f, 0.8f, 0.8f); + npc.modelData.modelScale.arms.setScale(0.6f, 0.6f, 0.6f); + npc.modelData.modelScale.legs.setScale(0.6f, 0.6f, 0.6f); + npc.modelData.modelScale.body.setScale(0.6f, 0.6f, 0.6f); + npc.modelData.modelScale.head.setScale(0.8f, 0.8f, 0.8f); npc.ai.onAttack = 0; npc.ai.setWalkingSpeed(4); @@ -211,10 +211,10 @@ public class RoleCompanion extends RoleInterface { talents.put(EnumCompanionTalent.SWORD, 0); } if(stage == EnumCompanionStage.TEEN){ - npc.modelData.arms.setScale(0.8f, 0.8f, 0.8f); - npc.modelData.legs.setScale(0.8f, 0.8f, 0.8f); - npc.modelData.body.setScale(0.8f, 0.8f, 0.8f); - npc.modelData.head.setScale(0.9f, 0.9f, 0.9f); + npc.modelData.modelScale.arms.setScale(0.8f, 0.8f, 0.8f); + npc.modelData.modelScale.legs.setScale(0.8f, 0.8f, 0.8f); + npc.modelData.modelScale.body.setScale(0.8f, 0.8f, 0.8f); + npc.modelData.modelScale.head.setScale(0.9f, 0.9f, 0.9f); npc.ai.onAttack = 0; npc.ai.setWalkingSpeed(5); @@ -222,10 +222,10 @@ public class RoleCompanion extends RoleInterface { talents.put(EnumCompanionTalent.ARMOR, 0); } if(stage == EnumCompanionStage.ADULT || stage == EnumCompanionStage.FULLGROWN){ - npc.modelData.arms.setScale(1f, 1f, 1f); - npc.modelData.legs.setScale(1f, 1f, 1f); - npc.modelData.body.setScale(1f, 1f, 1f); - npc.modelData.head.setScale(1f, 1f, 1f); + npc.modelData.modelScale.arms.setScale(1f, 1f, 1f); + npc.modelData.modelScale.legs.setScale(1f, 1f, 1f); + npc.modelData.modelScale.body.setScale(1f, 1f, 1f); + npc.modelData.modelScale.head.setScale(1f, 1f, 1f); npc.ai.onAttack = 0; npc.ai.setWalkingSpeed(5); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 8d10ff3e6..40465e942 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -7,6 +7,7 @@ import noppes.npcs.api.ITimers; import noppes.npcs.api.entity.ICustomNpc; import noppes.npcs.api.entity.IEntityLivingBase; 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.IFaction; @@ -931,12 +932,16 @@ public class ScriptNpc extends ScriptLiving imp public void executeCommand(String command){ NoppesUtilServer.runCommand(npc, npc.getCommandSenderName(), command, null); } - + + public IModelData getModelData() { + return npc instanceof EntityCustomNpc ? ((EntityCustomNpc) npc).modelData : null; + } + public void setHeadScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.head.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.head.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.head.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -944,9 +949,9 @@ public class ScriptNpc extends ScriptLiving imp public void setBodyScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.body.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.body.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.body.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -954,9 +959,9 @@ public class ScriptNpc extends ScriptLiving imp public void setArmsScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.arms.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.arms.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.arms.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -964,9 +969,9 @@ public class ScriptNpc extends ScriptLiving imp public void setLegsScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.legs.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.legs.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.legs.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } From 992e6fd169ca599b8878ef14e4656f70b9c76a49 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 02:36:39 -0500 Subject: [PATCH 15/27] Added NPC model data interfaces to the API. --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index b4ed688e6..140b16d52 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit b4ed688e6170accec3f981d017e809483399a1ef +Subproject commit 140b16d52f4d3ce42d86b637c4d18ba7869dcdab From 9a77e2f1462da5d5e25ab191b46304881af9b96f Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 02:38:15 -0500 Subject: [PATCH 16/27] Made setRotation() function in ModelRotatePart clamp float values. --- src/main/java/noppes/npcs/entity/data/ModelRotatePart.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java b/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java index 63598e023..2d1e975d6 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java +++ b/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java @@ -25,9 +25,9 @@ public class ModelRotatePart implements IModelRotatePart { } public void setRotation(float x, float y, float z) { - this.rotationX = x; - this.rotationY = y; - this.rotationZ = z; + this.rotationX = ValueUtil.correctFloat(x, -0.5f, 0.5f); + this.rotationY = ValueUtil.correctFloat(y, -0.5f, 0.5f); + this.rotationZ = ValueUtil.correctFloat(z, -0.5f, 0.5f); } public float getRotateX() { From 6913cadc790110a6969afd09561dae011a87d477 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 02:59:33 -0500 Subject: [PATCH 17/27] IModelData: -Implemented hidePart() abd hidden() functions --- src/main/java/noppes/npcs/DataDisplay.java | 6 +-- src/main/java/noppes/npcs/DataStats.java | 6 +-- .../npcs/entity/data/ModelDataShared.java | 38 +++++++++++++++++++ .../noppes/npcs/entity/data/ModelRotate.java | 2 +- .../npcs/entity/data/ModelRotatePart.java | 12 +++--- .../noppes/npcs/entity/data/ModelScale.java | 2 +- .../npcs/entity/data/ModelScalePart.java | 12 +++--- .../java/noppes/npcs/quests/QuestItem.java | 2 +- .../npcs/scripted/entity/ScriptNpc.java | 32 ++++++++-------- .../npcs/scripted/entity/ScriptPixelmon.java | 4 +- .../npcs/scripted/entity/ScriptPlayer.java | 6 +-- src/main/java/noppes/npcs/util/ValueUtil.java | 26 ++++++++++--- 12 files changed, 101 insertions(+), 47 deletions(-) diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index 62e157b23..6840d3572 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -163,7 +163,7 @@ public class DataDisplay { animationData.readFromNBT(nbttagcompound); - modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE); + modelSize = ValueUtil.clamp(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE); if(modelSize > ConfigMain.NpcSizeLimit) modelSize = ConfigMain.NpcSizeLimit; @@ -253,7 +253,7 @@ public class DataDisplay { public void setMarkovGender(int gender) { if(markovGender == gender) return; - this.markovGender = ValueUtil.CorrectInt(gender, 0, 2); + this.markovGender = ValueUtil.clamp(gender, 0, 2); } public int getMarkovGeneratorId(){ @@ -263,7 +263,7 @@ public class DataDisplay { public void setMarkovGeneratorId(int id) { if(markovGeneratorId == id) return; - this.markovGeneratorId = ValueUtil.CorrectInt(id, 0, CustomNpcs.MARKOV_GENERATOR.length-1); + this.markovGeneratorId = ValueUtil.clamp(id, 0, CustomNpcs.MARKOV_GENERATOR.length-1); } } diff --git a/src/main/java/noppes/npcs/DataStats.java b/src/main/java/noppes/npcs/DataStats.java index 272760485..a061901cd 100644 --- a/src/main/java/noppes/npcs/DataStats.java +++ b/src/main/java/noppes/npcs/DataStats.java @@ -136,10 +136,10 @@ public class DataStats { rangedRange = compound.getInteger("MaxFiringRange"); fireRate = compound.getInteger("FireRate"); - minDelay = ValueUtil.CorrectInt(compound.getInteger("minDelay"), 1, 9999); - maxDelay = ValueUtil.CorrectInt(compound.getInteger("maxDelay"), 1, 9999); + minDelay = ValueUtil.clamp(compound.getInteger("minDelay"), 1, 9999); + maxDelay = ValueUtil.clamp(compound.getInteger("maxDelay"), 1, 9999); burstCount = compound.getInteger("BurstCount"); - shotCount = ValueUtil.CorrectInt(compound.getInteger("ShotCount"), 1, 10); + shotCount = ValueUtil.clamp(compound.getInteger("ShotCount"), 1, 10); accuracy = compound.getInteger("Accuracy"); pDamage = compound.getFloat("pDamage"); diff --git a/src/main/java/noppes/npcs/entity/data/ModelDataShared.java b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java index bf5ae19d1..890cf1ff3 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelDataShared.java +++ b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagList; import noppes.npcs.api.entity.data.IModelData; import noppes.npcs.api.entity.data.IModelRotate; import noppes.npcs.api.entity.data.IModelScale; +import noppes.npcs.util.ValueUtil; import java.util.HashMap; @@ -174,6 +175,43 @@ public class ModelDataShared implements IModelData { return (1 - modelScale.legs.scaleY) * 0.75f; } + // Hide Body Parts + // [0: Head, 1: Body, 2: Arms, 3: Legs] + // [0: None, 1: Both, 2: Right, 3: Left] + public void hidePart(int part, byte hide) { + part = ValueUtil.clamp(part,0,3); + hide = part > 1 ? ValueUtil.clamp(hide,(byte) 0,(byte) 3) : ValueUtil.clamp(hide,(byte) 0,(byte) 1); + switch (part) { + case 0: + this.hideHead = hide; + break; + case 1: + this.hideBody = hide; + break; + case 2: + this.hideArms = hide; + break; + case 3: + this.hideLegs = hide; + break; + } + } + + public int hidden(int part) { + part = ValueUtil.clamp(part,0,3); + switch (part) { + case 0: + return this.hideHead; + case 1: + return this.hideBody; + case 2: + return this.hideArms; + case 3: + return this.hideLegs; + } + return 0; + } + public void enableRotation(boolean enableRotation) { this.enableRotation = enableRotation; } diff --git a/src/main/java/noppes/npcs/entity/data/ModelRotate.java b/src/main/java/noppes/npcs/entity/data/ModelRotate.java index 00f85ba69..72c8fc10f 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelRotate.java +++ b/src/main/java/noppes/npcs/entity/data/ModelRotate.java @@ -69,7 +69,7 @@ public class ModelRotate implements IModelRotate { } public IModelRotatePart getPart(int part) { - switch (ValueUtil.CorrectInt(part,0,5)) { + switch (ValueUtil.clamp(part,0,5)) { case 0: return head; case 1: diff --git a/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java b/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java index 2d1e975d6..58152764f 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java +++ b/src/main/java/noppes/npcs/entity/data/ModelRotatePart.java @@ -19,15 +19,15 @@ public class ModelRotatePart implements IModelRotatePart { public void readFromNBT(NBTTagCompound compound){ disabled = compound.getBoolean("Disabled"); - rotationX = ValueUtil.correctFloat(compound.getFloat("RotationX"), -0.5f, 0.5f); - rotationY = ValueUtil.correctFloat(compound.getFloat("RotationY"), -0.5f, 0.5f); - rotationZ = ValueUtil.correctFloat(compound.getFloat("RotationZ"), -0.5f, 0.5f); + rotationX = ValueUtil.clamp(compound.getFloat("RotationX"), -0.5f, 0.5f); + rotationY = ValueUtil.clamp(compound.getFloat("RotationY"), -0.5f, 0.5f); + rotationZ = ValueUtil.clamp(compound.getFloat("RotationZ"), -0.5f, 0.5f); } public void setRotation(float x, float y, float z) { - this.rotationX = ValueUtil.correctFloat(x, -0.5f, 0.5f); - this.rotationY = ValueUtil.correctFloat(y, -0.5f, 0.5f); - this.rotationZ = ValueUtil.correctFloat(z, -0.5f, 0.5f); + this.rotationX = ValueUtil.clamp(x, -0.5f, 0.5f); + this.rotationY = ValueUtil.clamp(y, -0.5f, 0.5f); + this.rotationZ = ValueUtil.clamp(z, -0.5f, 0.5f); } public float getRotateX() { diff --git a/src/main/java/noppes/npcs/entity/data/ModelScale.java b/src/main/java/noppes/npcs/entity/data/ModelScale.java index 935e9fede..5785764ea 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelScale.java +++ b/src/main/java/noppes/npcs/entity/data/ModelScale.java @@ -28,7 +28,7 @@ public class ModelScale implements IModelScale { @Override public IModelScalePart getPart(int part) { - switch (ValueUtil.CorrectInt(part,0,3)) { + switch (ValueUtil.clamp(part,0,3)) { case 0: return head; case 1: diff --git a/src/main/java/noppes/npcs/entity/data/ModelScalePart.java b/src/main/java/noppes/npcs/entity/data/ModelScalePart.java index 63f8d9361..4c369d62d 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelScalePart.java +++ b/src/main/java/noppes/npcs/entity/data/ModelScalePart.java @@ -17,9 +17,9 @@ public class ModelScalePart implements IModelScalePart { } public void readFromNBT(NBTTagCompound compound){ - scaleX = ValueUtil.correctFloat(compound.getFloat("ScaleX"), 0.5f, 1.5f); - scaleY = ValueUtil.correctFloat(compound.getFloat("ScaleY"), 0.5f, 1.5f); - scaleZ = ValueUtil.correctFloat(compound.getFloat("ScaleZ"), 0.5f, 1.5f); + scaleX = ValueUtil.clamp(compound.getFloat("ScaleX"), 0.5f, 1.5f); + scaleY = ValueUtil.clamp(compound.getFloat("ScaleY"), 0.5f, 1.5f); + scaleZ = ValueUtil.clamp(compound.getFloat("ScaleZ"), 0.5f, 1.5f); } public String toString(){ @@ -32,9 +32,9 @@ public class ModelScalePart implements IModelScalePart { } public void setScale(float x, float y, float z) { - scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + scaleX = ValueUtil.clamp(x, 0.5f, 1.5f); + scaleY = ValueUtil.clamp(y, 0.5f, 1.5f); + scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f); } public float getScaleX() { diff --git a/src/main/java/noppes/npcs/quests/QuestItem.java b/src/main/java/noppes/npcs/quests/QuestItem.java index 51e0ac937..8aa442b68 100644 --- a/src/main/java/noppes/npcs/quests/QuestItem.java +++ b/src/main/java/noppes/npcs/quests/QuestItem.java @@ -187,7 +187,7 @@ public class QuestItem extends QuestInterface implements IQuestItem { } } - return ValueUtil.CorrectInt(count, 0, this.questItem.stackSize); + return ValueUtil.clamp(count, 0, this.questItem.stackSize); } public void setProgress(int progress) { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 40465e942..a90216a0a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -939,9 +939,9 @@ public class ScriptNpc extends ScriptLiving imp public void setHeadScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -949,9 +949,9 @@ public class ScriptNpc extends ScriptLiving imp public void setBodyScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -959,9 +959,9 @@ public class ScriptNpc extends ScriptLiving imp public void setArmsScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -969,9 +969,9 @@ public class ScriptNpc extends ScriptLiving imp public void setLegsScale(float x, float y, float z){ if(npc instanceof EntityCustomNpc) { - ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f); - ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f); + ((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f); npc.script.clientNeedsUpdate = true; } @@ -982,7 +982,7 @@ public class ScriptNpc extends ScriptLiving imp * @param resistance Explosion resistance (0-2) default is 1 */ public void setExplosionResistance(float resistance){ - npc.stats.resistances.explosion = ValueUtil.correctFloat(resistance, 0, 2); + npc.stats.resistances.explosion = ValueUtil.clamp(resistance, 0, 2); } /** @@ -997,7 +997,7 @@ public class ScriptNpc extends ScriptLiving imp * @param resistance Melee resistance (0-2) default is 1 */ public void setMeleeResistance(float resistance){ - npc.stats.resistances.playermelee = ValueUtil.correctFloat(resistance, 0, 2); + npc.stats.resistances.playermelee = ValueUtil.clamp(resistance, 0, 2); } /** @@ -1011,7 +1011,7 @@ public class ScriptNpc extends ScriptLiving imp * @param resistance Arrow resistance (0-2) default is 1 */ public void setArrowResistance(float resistance){ - npc.stats.resistances.arrow = ValueUtil.correctFloat(resistance, 0, 2); + npc.stats.resistances.arrow = ValueUtil.clamp(resistance, 0, 2); } /** @@ -1025,7 +1025,7 @@ public class ScriptNpc extends ScriptLiving imp * @param resistance Knockback resistance (0-2) default is 1 */ public void setKnockbackResistance(double resistance){ - npc.stats.resistances.knockback = ValueUtil.correctFloat((float) resistance, 0, 2); + npc.stats.resistances.knockback = ValueUtil.clamp((float) resistance, 0, 2); } /** diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java index b1a9349c4..a5b4f4c20 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java @@ -184,7 +184,7 @@ public class ScriptPixelmon extends ScriptAnimal im * @param value 0-255 */ public void setHapiness(int value){ - value = ValueUtil.CorrectInt(value, 0, 255); + value = ValueUtil.clamp(value, 0, 255); compound.setInteger("Friendship", value); pixelmon.readEntityFromNBT(compound); } @@ -241,7 +241,7 @@ public class ScriptPixelmon extends ScriptAnimal im } public void setMove(int slot, String move){ - slot = ValueUtil.CorrectInt(slot, 0, 3); + slot = ValueUtil.clamp(slot, 0, 3); int id = PixelmonHelper.getAttackID(move); compound.removeTag("PixelmonMovePP" + slot); compound.removeTag("PixelmonMovePPBase" + slot); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 3e960a4a1..5b7babab6 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -535,9 +535,9 @@ public class ScriptPlayer extends ScriptLivingBase * @param z The z position */ public void setSpawnpoint(int x, int y, int z){ - x = ValueUtil.CorrectInt(x, -30000000, 30000000); - z = ValueUtil.CorrectInt(z, -30000000, 30000000); - y = ValueUtil.CorrectInt(y, 0, 256); + x = ValueUtil.clamp(x, -30000000, 30000000); + z = ValueUtil.clamp(z, -30000000, 30000000); + y = ValueUtil.clamp(y, 0, 256); player.setSpawnChunk(new ChunkCoordinates(x, y, z), true); } diff --git a/src/main/java/noppes/npcs/util/ValueUtil.java b/src/main/java/noppes/npcs/util/ValueUtil.java index 08f016b86..5f01534a3 100644 --- a/src/main/java/noppes/npcs/util/ValueUtil.java +++ b/src/main/java/noppes/npcs/util/ValueUtil.java @@ -1,7 +1,19 @@ package noppes.npcs.util; public class ValueUtil { - public static float correctFloat(float given, float min, float max){ + public static float clamp(float given, float min, float max){ + if(given < min) + return min; + return Math.min(given, max); + } + + public static int clamp(int given, int min, int max) { + if(given < min) + return min; + return Math.min(given, max); + } + + public static byte clamp(byte given, byte min, byte max) { if(given < min) return min; if(given > max) @@ -9,11 +21,15 @@ public class ValueUtil { return given; } - public static int CorrectInt(int given, int min, int max) { + public static double clamp(double given, double min, double max) { if(given < min) return min; - if(given > max) - return max; - return given; + return Math.min(given, max); + } + + public static long clamp(long given, long min, long max) { + if(given < min) + return min; + return Math.min(given, max); } } From f5aa6b58dbb70b3e9452549fdecbb7146876e441 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 02:59:42 -0500 Subject: [PATCH 18/27] IModelData: -Implemented hidePart() abd hidden() functions --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index 140b16d52..a26ef4766 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 140b16d52f4d3ce42d86b637c4d18ba7869dcdab +Subproject commit a26ef4766388f99e9bdec8fe2b52ae8cfa3fdfaa From 58aaaa158ac0b0c43221284ff2da0c7a30bca370 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 03:04:26 -0500 Subject: [PATCH 19/27] IModelData: -Added hidePart() comment --- src/main/java/noppes/npcs/entity/data/ModelDataShared.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/data/ModelDataShared.java b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java index 890cf1ff3..5f2a8be1c 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelDataShared.java +++ b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java @@ -175,9 +175,6 @@ public class ModelDataShared implements IModelData { return (1 - modelScale.legs.scaleY) * 0.75f; } - // Hide Body Parts - // [0: Head, 1: Body, 2: Arms, 3: Legs] - // [0: None, 1: Both, 2: Right, 3: Left] public void hidePart(int part, byte hide) { part = ValueUtil.clamp(part,0,3); hide = part > 1 ? ValueUtil.clamp(hide,(byte) 0,(byte) 3) : ValueUtil.clamp(hide,(byte) 0,(byte) 1); From 6a5d84b9aa0af796f127a80ca55ba032203caf35 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 03:04:39 -0500 Subject: [PATCH 20/27] IModelData: -Added hidePart() comment --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index a26ef4766..141ce1e17 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit a26ef4766388f99e9bdec8fe2b52ae8cfa3fdfaa +Subproject commit 141ce1e170550468232f7f307c4b087bf9c171ab From b04a35efc4b79954296fb9f74328b7d2981c7ab3 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 04:34:14 -0500 Subject: [PATCH 21/27] Added armwear functions --- .../npcs/entity/data/ModelDataShared.java | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/src/main/java/noppes/npcs/entity/data/ModelDataShared.java b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java index 5f2a8be1c..f7db2aa52 100644 --- a/src/main/java/noppes/npcs/entity/data/ModelDataShared.java +++ b/src/main/java/noppes/npcs/entity/data/ModelDataShared.java @@ -30,6 +30,7 @@ public class ModelDataShared implements IModelData { public byte headwear = 2; public byte bodywear = 0; + // Hide Arm/Legwear [0: None, 1: Both, 2: Right, 3: Left], public byte armwear = 0; public byte legwear = 0; @@ -175,6 +176,178 @@ public class ModelDataShared implements IModelData { return (1 - modelScale.legs.scaleY) * 0.75f; } + //0 - hidden, 1 - 2d, 2 - 3d + public void headWear(byte config) { + headwear = ValueUtil.clamp(config, (byte)0, (byte)2); + } + + public byte headWear() { + return this.headwear; + } + + //0 - hidden, 1 - 2d, 2 - 3d + public void bodyWear(byte config) { + bodywear = ValueUtil.clamp(config, (byte)0, (byte)2); + } + + public byte bodyWear() { + return this.bodywear; + } + + //0 - hidden, 1 - 2d, 2 - 3d + public void rightArmWear(byte config) { + config = ValueUtil.clamp(config, (byte)0, (byte)2); + + // Hide Arm/Legwear [0: None, 1: Both, 2: Right, 3: Left], + if (config == 1 || config == 2) { + if (armwear == 0) + armwear = 2; + else if (armwear == 3) + armwear = 1; + } else { + if (armwear == 1) + armwear = 3; + else if (armwear == 2) + armwear = 0; + } + + // Solid or normal arm/legwear [0: None, 1: Both, 2: Right, 3: Left] + if (config == 1) { + solidArmwear = 0; + } else if (config == 2) { + if (solidArmwear == 0) { + solidArmwear = 2; + } else if (solidArmwear == 3) { + solidArmwear = 1; + } + } + } + + public byte rightArmWear() { + if (armwear == 0 || armwear == 3) { + return 0; + } else if (solidArmwear == 1 || solidArmwear == 2) { + return 2; + } else { + return 1; + } + } + + //0 - hidden, 1 - 2d, 2 - 3d + public void leftArmWear(byte config) { + config = ValueUtil.clamp(config, (byte)0, (byte)2); + + // Hide Arm/Legwear [0: None, 1: Both, 2: Right, 3: Left], + if (config == 1 || config == 2) { + if (armwear == 0) + armwear = 3; + else if (armwear == 2) + armwear = 1; + } else { + if (armwear == 1) + armwear = 2; + else if (armwear == 3) + armwear = 0; + } + + // Solid or normal arm/legwear [0: None, 1: Both, 2: Right, 3: Left] + if (config == 1) { + solidArmwear = 0; + } else if (config == 2) { + if (solidArmwear == 0) { + solidArmwear = 3; + } else if (solidArmwear == 2) { + solidArmwear = 1; + } + } + } + + public byte leftArmWear() { + if (armwear == 0 || armwear == 2) { + return 0; + } else if (solidArmwear == 1 || solidArmwear == 3) { + return 2; + } else { + return 1; + } + } + + public void rightLegWear(byte config) { + config = ValueUtil.clamp(config, (byte)0, (byte)2); + + // Hide Arm/Legwear [0: None, 1: Both, 2: Right, 3: Left], + if (config == 1 || config == 2) { + if (legwear == 0) + legwear = 2; + else if (legwear == 3) + legwear = 1; + } else { + if (legwear == 1) + legwear = 3; + else if (legwear == 2) + legwear = 0; + } + + // Solid or normal arm/legwear [0: None, 1: Both, 2: Right, 3: Left] + if (config == 1) { + solidLegwear = 0; + } else if (config == 2) { + if (solidLegwear == 0) { + solidLegwear = 2; + } else if (solidLegwear == 3) { + solidLegwear = 1; + } + } + } + + public byte rightLegWear() { + if (legwear == 0 || legwear == 3) { + return 0; + } else if (solidLegwear == 1 || solidLegwear == 2) { + return 2; + } else { + return 1; + } + } + + public void leftLegWear(byte config) { + config = ValueUtil.clamp(config, (byte)0, (byte)2); + + // Hide Arm/Legwear [0: None, 1: Both, 2: Right, 3: Left], + if (config == 1 || config == 2) { + if (legwear == 0) + legwear = 3; + else if (legwear == 2) + legwear = 1; + } else { + if (legwear == 1) + legwear = 2; + else if (legwear == 3) + legwear = 0; + } + + // Solid or normal arm/legwear [0: None, 1: Both, 2: Right, 3: Left] + if (config == 1) { + solidLegwear = 0; + } else if (config == 2) { + if (solidLegwear == 0) { + solidLegwear = 3; + } else if (solidLegwear == 2) { + solidLegwear = 1; + } + } + } + + public byte leftLegWear() { + if (legwear == 0 || legwear == 2) { + return 0; + } else if (solidLegwear == 1 || solidLegwear == 3) { + return 2; + } else { + return 1; + } + } + public void hidePart(int part, byte hide) { part = ValueUtil.clamp(part,0,3); hide = part > 1 ? ValueUtil.clamp(hide,(byte) 0,(byte) 3) : ValueUtil.clamp(hide,(byte) 0,(byte) 1); From f7576ffc90ae3ecf74ec9b86db5a8637c6907202 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 17 Mar 2023 04:34:22 -0500 Subject: [PATCH 22/27] Added armwear functions --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index 141ce1e17..97e163ec3 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 141ce1e170550468232f7f307c4b087bf9c171ab +Subproject commit 97e163ec3c658374a4553c42cf566ea544ada309 From 2c012f2693b4b599aaa79f6bc0c431f74c4cfecf Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 18 Mar 2023 02:07:37 -0500 Subject: [PATCH 23/27] Fixed puppet behavior when used with animations --- src/main/java/noppes/npcs/client/model/ModelMPM.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index 42e4157ca..0426520cd 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -446,7 +446,7 @@ public class ModelMPM extends ModelNPCMale{ setPlayerData(npc); currentlyPlayerTexture = true; this.setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity); - if(npc.modelData.enableRotation){ + if(npc.modelData.enableRotation && !npc.display.animationData.isActive()){ if(isRotationActive(npc)){ float pi = (float) Math.PI; From 586c451f0621811cca5d831f830aa87b91c0c68a Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 18 Mar 2023 03:04:46 -0500 Subject: [PATCH 24/27] ICustomGui: -Added IDs to custom GUI slots. --- src/api | 2 +- src/main/java/noppes/npcs/EventHooks.java | 4 +-- .../gui/custom/components/CustomGuiSlot.java | 6 +++-- .../npcs/containers/ContainerCustomGui.java | 17 ++++++------ .../npcs/scripted/event/CustomGuiEvent.java | 9 ++++++- .../noppes/npcs/scripted/gui/ScriptGui.java | 26 +++++++++++++++++-- .../npcs/scripted/gui/ScriptGuiItemSlot.java | 7 ++--- 7 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/api b/src/api index 97e163ec3..c24047127 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 97e163ec3c658374a4553c42cf566ea544ada309 +Subproject commit c2404712713b7c4745082f8f11681e80f817ea95 diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index b16fc4323..0214fcf7e 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -560,8 +560,8 @@ public class EventHooks { CustomGuiController.onSlotChange(event); } - public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, int dragType, int clickType) { - CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, player.getOpenContainer().getSlot(slotId), dragType, clickType); + public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, int dragType, int clickType) { + CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, guiSlotId, player.getOpenContainer().getSlot(slotId), dragType, clickType); return CustomGuiController.onSlotClick(event); } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java index 61c31ce4c..1d3d57b6c 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java @@ -12,12 +12,14 @@ import noppes.npcs.client.gui.custom.GuiCustom; public class CustomGuiSlot extends Slot { public boolean clientSide; - public int slotNumber; + public final int slotNumber; + public final int guiSlotId; - public CustomGuiSlot(IInventory inventoryIn, int index, int xPosition, int yPosition, boolean clientSide) { + public CustomGuiSlot(IInventory inventoryIn, int index, int guiSlotId, int xPosition, int yPosition, boolean clientSide) { super(inventoryIn, index, xPosition, yPosition); this.clientSide = clientSide; this.slotNumber = index; + this.guiSlotId = guiSlotId; } public void onSlotChanged() { diff --git a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java index b241cd803..df398327d 100644 --- a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java +++ b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java @@ -44,9 +44,9 @@ public class ContainerCustomGui extends Container { while(var3.hasNext()) { IItemSlot slot = (IItemSlot)var3.next(); if (slot.hasStack()) { - this.addSlot(slot.getPosX(), slot.getPosY(), slot.getStack().getMCItemStack(), player.worldObj.isRemote); + this.addSlot(slot.getPosX(), slot.getPosY(), slot.getID(), slot.getStack().getMCItemStack(), player.worldObj.isRemote); } else { - this.addSlot(slot.getPosX(), slot.getPosY(), player.worldObj.isRemote); + this.addSlot(slot.getPosX(), slot.getPosY(), slot.getID(), player.worldObj.isRemote); } } } @@ -75,13 +75,13 @@ public class ContainerCustomGui extends Container { return itemstack; } - void addSlot(int x, int y, boolean clientSide) { - this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, x, y, clientSide)); + void addSlot(int x, int y, int guiSlotId, boolean clientSide) { + this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, guiSlotId, x, y, clientSide)); } - void addSlot(int x, int y, ItemStack itemStack, boolean clientSide) { + void addSlot(int x, int y, int guiSlotId, ItemStack itemStack, boolean clientSide) { this.guiInventory.setInventorySlotContents(this.slotCount, itemStack); - this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, x, y, clientSide)); + this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, guiSlotId, x, y, clientSide)); } void addPlayerInventory(EntityPlayer player, int x, int y) { @@ -108,8 +108,9 @@ public class ContainerCustomGui extends Container { public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) { if(slotId < 0) return super.slotClick(slotId, dragType, clickTypeIn, player); - if(!player.worldObj.isRemote) { - if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, dragType, clickTypeIn)) { + if(!player.worldObj.isRemote && this.getSlot(slotId) instanceof CustomGuiSlot) { + CustomGuiSlot guiSlot = (CustomGuiSlot) this.getSlot(slotId); + if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, guiSlot.guiSlotId, dragType, clickTypeIn)) { ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player); EntityPlayerMP p = (EntityPlayerMP) player; p.sendContainerToPlayer(this); diff --git a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java index 7dcf7fecd..6e5a6989f 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java @@ -1,10 +1,13 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.event.ICustomGuiEvent; import noppes.npcs.api.gui.ICustomGui; +import noppes.npcs.api.gui.IItemSlot; import noppes.npcs.api.item.IItemStack; +import noppes.npcs.client.gui.custom.components.CustomGuiSlot; import noppes.npcs.constants.EnumScriptType; public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { @@ -114,11 +117,13 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { public static class SlotEvent extends CustomGuiEvent implements ICustomGuiEvent.SlotEvent { public final int slotId; public final IItemStack stack; + public final IItemSlot slot; public SlotEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack) { super(player, gui); this.slotId = slotId; this.stack = stack; + this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot)(((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId); } public String getHookName() { @@ -139,17 +144,19 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { public final int slotId; public final IItemStack stack; public final int dragType; + public final IItemSlot slot; /** * */ public final int clickType; - public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack, int dragType, int clickType) { + public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, IItemStack stack, int dragType, int clickType) { super(player,gui); this.slotId = slotId; this.stack = stack; this.dragType = dragType; this.clickType = clickType; + this.slot = (IItemSlot) gui.getComponent(guiSlotId); } public String getHookName() { diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java index 0a34c85d4..4541ed496 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -143,13 +143,25 @@ public class ScriptGui implements ICustomGui { } public IItemSlot addItemSlot(int x, int y) { - ScriptGuiItemSlot slot = new ScriptGuiItemSlot(x, y); + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y); this.slots.add(slot); return (IItemSlot)this.slots.get(this.slots.size() - 1); } public IItemSlot addItemSlot(int x, int y, IItemStack stack) { - ScriptGuiItemSlot slot = new ScriptGuiItemSlot(x, y, stack); + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y, stack); + this.slots.add(slot); + return (IItemSlot)this.slots.get(this.slots.size() - 1); + } + + public IItemSlot addItemSlot(int id, int x, int y) { + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y); + this.slots.add(slot); + return (IItemSlot)this.slots.get(this.slots.size() - 1); + } + + public IItemSlot addItemSlot(int id, int x, int y, IItemStack stack) { + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y, stack); this.slots.add(slot); return (IItemSlot)this.slots.get(this.slots.size() - 1); } @@ -230,6 +242,16 @@ public class ScriptGui implements ICustomGui { return this.playerInvY; } + private int getMaxId() { + int max = 0; + for (ICustomGuiComponent component : this.getComponents()) { + if (component.getID() >= max) { + max = component.getID(); + } + } + return max; + } + public ICustomGui fromNBT(NBTTagCompound tag) { this.id = tag.getInteger("id"); this.width = tag.getIntArray("size")[0]; diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java index 9f0a21a41..d7276d1c2 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java @@ -13,12 +13,13 @@ public class ScriptGuiItemSlot extends ScriptGuiComponent implements IItemSlot { public ScriptGuiItemSlot() { } - public ScriptGuiItemSlot(int x, int y) { + public ScriptGuiItemSlot(int id, int x, int y) { + this.setID(id); this.setPos(x, y); } - public ScriptGuiItemSlot(int x, int y, IItemStack stack) { - this(x, y); + public ScriptGuiItemSlot(int id, int x, int y, IItemStack stack) { + this(id, x, y); this.setStack(stack); } From e3405d22e9220bcb55ce16a0147d5af5e4adf679 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 18 Mar 2023 03:47:24 -0500 Subject: [PATCH 25/27] Fixed null pointer exceptions from new custom gui slot commit. --- src/main/java/noppes/npcs/EventHooks.java | 5 +++-- .../noppes/npcs/containers/ContainerCustomGui.java | 9 ++++++--- .../noppes/npcs/scripted/event/CustomGuiEvent.java | 14 +++++++++++--- .../java/noppes/npcs/scripted/gui/ScriptGui.java | 7 +++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 0214fcf7e..86948f307 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -26,6 +26,7 @@ import noppes.npcs.api.entity.IProjectile; import noppes.npcs.api.gui.ICustomGui; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.api.item.IItemStack; +import noppes.npcs.client.gui.custom.components.CustomGuiSlot; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.CustomGuiController; import noppes.npcs.controllers.ScriptContainer; @@ -560,8 +561,8 @@ public class EventHooks { CustomGuiController.onSlotChange(event); } - public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, int dragType, int clickType) { - CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, guiSlotId, player.getOpenContainer().getSlot(slotId), dragType, clickType); + public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, CustomGuiSlot guiSlot, int dragType, int clickType) { + CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, guiSlot, player.getOpenContainer().getSlot(slotId), dragType, clickType); return CustomGuiController.onSlotClick(event); } diff --git a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java index df398327d..d937b895c 100644 --- a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java +++ b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java @@ -108,9 +108,12 @@ public class ContainerCustomGui extends Container { public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) { if(slotId < 0) return super.slotClick(slotId, dragType, clickTypeIn, player); - if(!player.worldObj.isRemote && this.getSlot(slotId) instanceof CustomGuiSlot) { - CustomGuiSlot guiSlot = (CustomGuiSlot) this.getSlot(slotId); - if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, guiSlot.guiSlotId, dragType, clickTypeIn)) { + if(!player.worldObj.isRemote) { + CustomGuiSlot guiSlot = null; + if (this.getSlot(slotId) instanceof CustomGuiSlot) { + guiSlot = (CustomGuiSlot) this.getSlot(slotId); + } + if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, guiSlot, dragType, clickTypeIn)) { ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player); EntityPlayerMP p = (EntityPlayerMP) player; p.sendContainerToPlayer(this); diff --git a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java index 6e5a6989f..571d699c6 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java @@ -123,7 +123,11 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { super(player, gui); this.slotId = slotId; this.stack = stack; - this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot)(((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId); + if ((((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId) instanceof CustomGuiSlot)) { + this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot) (((EntityPlayerMP) player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId); + } else { + this.slot = null; + } } public String getHookName() { @@ -150,13 +154,17 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { */ public final int clickType; - public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, IItemStack stack, int dragType, int clickType) { + public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, CustomGuiSlot guiSlot, IItemStack stack, int dragType, int clickType) { super(player,gui); this.slotId = slotId; this.stack = stack; this.dragType = dragType; this.clickType = clickType; - this.slot = (IItemSlot) gui.getComponent(guiSlotId); + if (guiSlot != null) { + this.slot = (IItemSlot) gui.getComponent(guiSlot.guiSlotId); + } else { + this.slot = null; + } } public String getHookName() { diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java index 4541ed496..f4456ce31 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -143,13 +143,13 @@ public class ScriptGui implements ICustomGui { } public IItemSlot addItemSlot(int x, int y) { - ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y); + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(-1, x, y); this.slots.add(slot); return (IItemSlot)this.slots.get(this.slots.size() - 1); } public IItemSlot addItemSlot(int x, int y, IItemStack stack) { - ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y, stack); + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(-1, x, y, stack); this.slots.add(slot); return (IItemSlot)this.slots.get(this.slots.size() - 1); } @@ -308,6 +308,9 @@ public class ScriptGui implements ICustomGui { while(var3.hasNext()) { c = (ICustomGuiComponent)var3.next(); + if (c.getID() == -1) { + c.setID(this.getMaxId()+1); + } list.appendTag(((ScriptGuiComponent)c).toNBT(new NBTTagCompound())); } From 80352741b90e6650a14db95270795c10d1af3d08 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 18 Mar 2023 15:52:50 -0500 Subject: [PATCH 26/27] Fixed custom gui slot behavior --- src/main/java/noppes/npcs/EventHooks.java | 9 +- .../java/noppes/npcs/PacketHandlerServer.java | 4 - .../npcs/client/gui/custom/GuiCustom.java | 6 +- .../gui/custom/components/CustomGuiSlot.java | 20 +-- .../npcs/constants/EnumPacketServer.java | 2 +- .../npcs/containers/ContainerCustomGui.java | 40 ++++-- .../npcs/scripted/event/CustomGuiEvent.java | 20 +-- .../noppes/npcs/scripted/gui/ScriptGui.java | 136 ++++++++---------- 8 files changed, 113 insertions(+), 124 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 86948f307..d5ff8c41a 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -24,6 +24,7 @@ import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.entity.IProjectile; import noppes.npcs.api.gui.ICustomGui; +import noppes.npcs.api.gui.IItemSlot; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.api.item.IItemStack; import noppes.npcs.client.gui.custom.components.CustomGuiSlot; @@ -556,13 +557,13 @@ public class EventHooks { CustomGuiController.onButton(event); } - public static void onCustomGuiSlot(IPlayer player, ICustomGui gui, int slotId) { - CustomGuiEvent.SlotEvent event = new CustomGuiEvent.SlotEvent(player, gui, slotId, player.getOpenContainer().getSlot(slotId)); + public static void onCustomGuiSlot(IPlayer player, ICustomGui gui, int slotId, ItemStack stack, IItemSlot slot) { + CustomGuiEvent.SlotEvent event = new CustomGuiEvent.SlotEvent(player, gui, slotId, stack, slot); CustomGuiController.onSlotChange(event); } - public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, CustomGuiSlot guiSlot, int dragType, int clickType) { - CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, guiSlot, player.getOpenContainer().getSlot(slotId), dragType, clickType); + public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, IItemSlot slot, int dragType, int clickType) { + CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, slot, player.getOpenContainer().getSlot(slotId), dragType, clickType); return CustomGuiController.onSlotClick(event); } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 0e9e2b65e..18957d7c0 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -74,10 +74,6 @@ public class PacketHandlerServer{ ((ContainerCustomGui) player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); EventHooks.onCustomGuiButton((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt()); return; - } else if (type == EnumPacketServer.CustomGuiSlotChange && player.openContainer instanceof ContainerCustomGui) { - ((ContainerCustomGui) player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); - EventHooks.onCustomGuiSlot((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt()); - return; } else if (type == EnumPacketServer.CustomGuiUnfocused && player.openContainer instanceof ContainerCustomGui) { ((ContainerCustomGui) player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); EventHooks.onCustomGuiUnfocused((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt()); diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index f85078f3b..217c85816 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -454,10 +454,6 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD Client.sendData(EnumPacketServer.CustomGuiButton, new Object[]{this.updateGui().toNBT(), button.id}); } - public void slotChange(CustomGuiSlot slot) { - Client.sendData(EnumPacketServer.CustomGuiSlotChange, new Object[]{this.updateGui().toNBT(), slot.slotNumber}); - } - public String prevScrollClicked = null; public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { Client.sendData(EnumPacketServer.CustomGuiScrollClick, new Object[]{this.updateGui().toNBT(), scroll.id, scroll.selected, this.getScrollSelection((CustomGuiScrollComponent)scroll), false}); @@ -636,7 +632,7 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD } public boolean doesGuiPauseGame() { - return this.gui == null || this.gui.getDoesPauseGame(); + return this.gui == null || this.gui.doesPauseGame(); } public void addDataHolder(IDataHolder component) { diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java index 1d3d57b6c..34748b77c 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java @@ -5,28 +5,22 @@ package noppes.npcs.client.gui.custom.components; -import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.api.gui.IItemSlot; public class CustomGuiSlot extends Slot { public boolean clientSide; public final int slotNumber; - public final int guiSlotId; + public final IItemSlot slot; + public final EntityPlayer player; - public CustomGuiSlot(IInventory inventoryIn, int index, int guiSlotId, int xPosition, int yPosition, boolean clientSide) { + public CustomGuiSlot(EntityPlayer player, IInventory inventoryIn, int index, IItemSlot slot, int xPosition, int yPosition, boolean clientSide) { super(inventoryIn, index, xPosition, yPosition); this.clientSide = clientSide; this.slotNumber = index; - this.guiSlotId = guiSlotId; - } - - public void onSlotChanged() { - if (this.clientSide) { - ((GuiCustom)Minecraft.getMinecraft().currentScreen).slotChange(this); - } - - super.onSlotChanged(); + this.slot = slot; + this.player = player; } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 0001a6117..194837038 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -93,7 +93,7 @@ public enum EnumPacketServer { NaturalSpawnGetAll, MailOpenSetup, DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, - CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, + CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, ServerUpdateSkinOverlays; diff --git a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java index d937b895c..56e74f101 100644 --- a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java +++ b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java @@ -7,9 +7,11 @@ package noppes.npcs.containers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import noppes.npcs.EventHooks; import noppes.npcs.api.entity.IPlayer; @@ -44,9 +46,9 @@ public class ContainerCustomGui extends Container { while(var3.hasNext()) { IItemSlot slot = (IItemSlot)var3.next(); if (slot.hasStack()) { - this.addSlot(slot.getPosX(), slot.getPosY(), slot.getID(), slot.getStack().getMCItemStack(), player.worldObj.isRemote); + this.addSlot(player, slot.getPosX(), slot.getPosY(), slot, slot.getStack().getMCItemStack(), player.worldObj.isRemote); } else { - this.addSlot(slot.getPosX(), slot.getPosY(), slot.getID(), player.worldObj.isRemote); + this.addSlot(player, slot.getPosX(), slot.getPosY(), slot, player.worldObj.isRemote); } } } @@ -75,13 +77,13 @@ public class ContainerCustomGui extends Container { return itemstack; } - void addSlot(int x, int y, int guiSlotId, boolean clientSide) { - this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, guiSlotId, x, y, clientSide)); + void addSlot(EntityPlayer player, int x, int y, IItemSlot slot, boolean clientSide) { + this.addSlotToContainer(new CustomGuiSlot(player, this.guiInventory, this.slotCount++, slot, x, y, clientSide)); } - void addSlot(int x, int y, int guiSlotId, ItemStack itemStack, boolean clientSide) { + void addSlot(EntityPlayer player, int x, int y, IItemSlot slot, ItemStack itemStack, boolean clientSide) { this.guiInventory.setInventorySlotContents(this.slotCount, itemStack); - this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, guiSlotId, x, y, clientSide)); + this.addSlotToContainer(new CustomGuiSlot(player, this.guiInventory, this.slotCount++, slot, x, y, clientSide)); } void addPlayerInventory(EntityPlayer player, int x, int y) { @@ -108,20 +110,36 @@ public class ContainerCustomGui extends Container { public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) { if(slotId < 0) return super.slotClick(slotId, dragType, clickTypeIn, player); - if(!player.worldObj.isRemote) { - CustomGuiSlot guiSlot = null; + Slot mcSlot = (Slot)this.inventorySlots.get(slotId); + if(!player.worldObj.isRemote && mcSlot != null) { + IItemSlot slot = null; if (this.getSlot(slotId) instanceof CustomGuiSlot) { - guiSlot = (CustomGuiSlot) this.getSlot(slotId); + slot = ((CustomGuiSlot)this.getSlot(slotId)).slot; } - if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, guiSlot, dragType, clickTypeIn)) { + if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, slot, dragType, clickTypeIn)) { + ItemStack prevStack = mcSlot.getStack(); + if (slot != null) { + prevStack = slot.getStack() == null ? null : slot.getStack().getMCItemStack(); + } ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player); + + if (!ItemStack.areItemStacksEqual(prevStack,item)) { + if (slot != null) { + slot.setStack(NpcAPI.Instance().getIItemStack(mcSlot.getStack())); + } + if (player.openContainer instanceof ContainerCustomGui) { + EventHooks.onCustomGuiSlot((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, + mcSlot.slotNumber, prevStack, slot); + } + } + EntityPlayerMP p = (EntityPlayerMP) player; p.sendContainerToPlayer(this); return item; } - } + return null; } diff --git a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java index 571d699c6..c34357c16 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java @@ -2,6 +2,7 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Cancelable; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.event.ICustomGuiEvent; import noppes.npcs.api.gui.ICustomGui; @@ -9,6 +10,7 @@ import noppes.npcs.api.gui.IItemSlot; import noppes.npcs.api.item.IItemStack; import noppes.npcs.client.gui.custom.components.CustomGuiSlot; import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.scripted.NpcAPI; public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { public final IPlayer player; @@ -119,15 +121,11 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { public final IItemStack stack; public final IItemSlot slot; - public SlotEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack) { + public SlotEvent(IPlayer player, ICustomGui gui, int slotId, ItemStack stack, IItemSlot slot) { super(player, gui); this.slotId = slotId; - this.stack = stack; - if ((((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId) instanceof CustomGuiSlot)) { - this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot) (((EntityPlayerMP) player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId); - } else { - this.slot = null; - } + this.stack = NpcAPI.Instance().getIItemStack(stack); + this.slot = slot; } public String getHookName() { @@ -154,17 +152,13 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent { */ public final int clickType; - public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, CustomGuiSlot guiSlot, IItemStack stack, int dragType, int clickType) { + public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, IItemSlot slot, IItemStack stack, int dragType, int clickType) { super(player,gui); this.slotId = slotId; this.stack = stack; this.dragType = dragType; this.clickType = clickType; - if (guiSlot != null) { - this.slot = (IItemSlot) gui.getComponent(guiSlot.guiSlotId); - } else { - this.slot = null; - } + this.slot = slot; } public String getHookName() { diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java index f4456ce31..4c228d7f4 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -14,8 +14,10 @@ import noppes.npcs.api.item.IItemStack; import noppes.npcs.controllers.CustomGuiController; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.PlayerDataScript; +import scala.actors.threadpool.Arrays; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -28,8 +30,7 @@ public class ScriptGui implements ICustomGui { boolean pauseGame; boolean showPlayerInv; String backgroundTexture = ""; - //ScriptContainer scriptHandler; - List components = new ArrayList(); + HashMap components = new HashMap<>(); List slots = new ArrayList(); public ScriptGui() { @@ -56,7 +57,7 @@ public class ScriptGui implements ICustomGui { } public List getComponents() { - return this.components; + return Arrays.asList(this.components.values().toArray()); } public List getSlots() { @@ -76,7 +77,7 @@ public class ScriptGui implements ICustomGui { this.pauseGame = pauseGame; } - public boolean getDoesPauseGame() { + public boolean doesPauseGame() { return this.pauseGame; } @@ -90,98 +91,94 @@ public class ScriptGui implements ICustomGui { public IButton addButton(int id, String label, int x, int y) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y); - this.components.add(component); - return (IButton)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (IButton)this.getComponent(id); } public IButton addButton(int id, String label, int x, int y, int width, int height) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height); - this.components.add(component); - return (IButton)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (IButton)this.getComponent(id); } public IButton addTexturedButton(int id, String label, int x, int y, int width, int height, String texture) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height, texture); - this.components.add(component); - return (IButton)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (IButton)this.getComponent(id); } public IButton addTexturedButton(int id, String label, int x, int y, int width, int height, String texture, int textureX, int textureY) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height, texture, textureX, textureY); - this.components.add(component); - return (IButton)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (IButton)this.getComponent(id); } public ILabel addLabel(int id, String label, int x, int y, int width, int height) { ScriptGuiLabel component = new ScriptGuiLabel(id, label, x, y, width, height); - this.components.add(component); - return (ILabel)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (ILabel)this.getComponent(id); } public ILabel addLabel(int id, String label, int x, int y, int width, int height, int color) { ScriptGuiLabel component = new ScriptGuiLabel(id, label, x, y, width, height, color); - this.components.add(component); - return (ILabel)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (ILabel)this.getComponent(id); } public ITextField addTextField(int id, int x, int y, int width, int height) { ScriptGuiTextField component = new ScriptGuiTextField(id, x, y, width, height); - this.components.add(component); - return (ITextField)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (ITextField)this.getComponent(id); } public ITexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height) { ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(id, texture, x, y, width, height); - this.components.add(component); - return (ITexturedRect)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (ITexturedRect)this.getComponent(id); } public ITexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(id, texture, x, y, width, height, textureX, textureY); - this.components.add(component); - return (ITexturedRect)this.components.get(this.components.size() - 1); - } - - public IItemSlot addItemSlot(int x, int y) { - ScriptGuiItemSlot slot = new ScriptGuiItemSlot(-1, x, y); - this.slots.add(slot); - return (IItemSlot)this.slots.get(this.slots.size() - 1); - } - - public IItemSlot addItemSlot(int x, int y, IItemStack stack) { - ScriptGuiItemSlot slot = new ScriptGuiItemSlot(-1, x, y, stack); - this.slots.add(slot); - return (IItemSlot)this.slots.get(this.slots.size() - 1); + this.updateComponent(component); + return (ITexturedRect)this.getComponent(id); } public IItemSlot addItemSlot(int id, int x, int y) { ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y); - this.slots.add(slot); - return (IItemSlot)this.slots.get(this.slots.size() - 1); + this.updateComponent(slot); + return (IItemSlot)this.getComponent(id); } public IItemSlot addItemSlot(int id, int x, int y, IItemStack stack) { ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y, stack); - this.slots.add(slot); - return (IItemSlot)this.slots.get(this.slots.size() - 1); + this.updateComponent(slot); + return (IItemSlot)this.getComponent(id); + } + + public IItemSlot addItemSlot(int x, int y) { + return this.addItemSlot(-1, x, y); + } + + public IItemSlot addItemSlot(int x, int y, IItemStack stack) { + return this.addItemSlot(-1, x, y, stack); } public IScroll addScroll(int id, int x, int y, int width, int height, String[] list) { ScriptGuiScroll component = new ScriptGuiScroll(id, x, y, width, height, list); - this.components.add(component); - return (IScroll)this.components.get(this.components.size() - 1); + this.updateComponent(component); + return (IScroll)this.getComponent(id); } public ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) { - ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2, color, thickness); - this.components.add(line); - return (ILine) this.components.get(this.components.size() - 1); + ScriptGuiLine component = new ScriptGuiLine(id, x1, y1, x2, y2, color, thickness); + this.updateComponent(component); + return (ILine) this.getComponent(id); } public ILine addLine(int id, int x1, int y1, int x2, int y2) { - ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2); - this.components.add(line); - return (ILine) this.components.get(this.components.size() - 1); + ScriptGuiLine component = new ScriptGuiLine(id, x1, y1, x2, y2); + this.updateComponent(component); + return (ILine) this.getComponent(id); } public void showPlayerInventory(int x, int y) { @@ -191,39 +188,32 @@ public class ScriptGui implements ICustomGui { } public ICustomGuiComponent getComponent(int componentID) { - Iterator var2 = this.components.iterator(); - - ICustomGuiComponent component; - do { - if (!var2.hasNext()) { - return null; - } - - component = (ICustomGuiComponent)var2.next(); - } while(component.getID() != componentID); - - return component; + return this.components.get(componentID); } public void removeComponent(int componentID) { - for(int i = 0; i < this.components.size(); ++i) { - if (((ICustomGuiComponent)this.components.get(i)).getID() == componentID) { - this.components.remove(i); - return; + if (this.components.containsKey(componentID)) { + ICustomGuiComponent component = this.getComponent(componentID); + if (component instanceof IItemSlot) { + for (IItemSlot slot : this.slots) { + if (slot.getID() == componentID) { + this.slots.remove(slot); + break; + } + } } + this.components.remove(componentID); } - } public void updateComponent(ICustomGuiComponent component) { - for(int i = 0; i < this.components.size(); ++i) { - ICustomGuiComponent c = (ICustomGuiComponent)this.components.get(i); - if (c.getID() == component.getID()) { - this.components.set(i, component); - return; + if (component != null) { + this.removeComponent(component.getID()); + this.components.put(component.getID(), component); + if (component instanceof IItemSlot) { + this.slots.add((IItemSlot) component); } } - } public void update(IPlayer player) { @@ -258,16 +248,16 @@ public class ScriptGui implements ICustomGui { this.height = tag.getIntArray("size")[1]; this.pauseGame = tag.getBoolean("pause"); this.backgroundTexture = tag.getString("bgTexture"); - List components = new ArrayList(); NBTTagList list = tag.getTagList("components", 10); for(int i = 0; i < list.tagCount(); i++){ NBTBase b = list.getCompoundTagAt(i); ScriptGuiComponent component = ScriptGuiComponent.createFromNBT((NBTTagCompound)b); - components.add(component); + if (component != null) { + components.put(component.getID(), component); + } } - this.components = components; List slots = new ArrayList(); list = tag.getTagList("slots", 10); @@ -294,7 +284,7 @@ public class ScriptGui implements ICustomGui { tag.setBoolean("pause", this.pauseGame); tag.setString("bgTexture", this.backgroundTexture); NBTTagList list = new NBTTagList(); - Iterator var3 = this.components.iterator(); + Iterator var3 = this.components.values().iterator(); ICustomGuiComponent c; while(var3.hasNext()) { From 45217f3afc02f8a20d1820bf356befa50d63b139 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 18 Mar 2023 15:58:17 -0500 Subject: [PATCH 27/27] Fixed custom gui slot behavior --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index c24047127..da937ad6b 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit c2404712713b7c4745082f8f11681e80f817ea95 +Subproject commit da937ad6be1f3ecae3c33175b26d480c9b3f7d4b