diff --git a/src/main/java/pokecube/adventures/PokecubeAdv.java b/src/main/java/pokecube/adventures/PokecubeAdv.java index 1f75c277a4..f9473133df 100644 --- a/src/main/java/pokecube/adventures/PokecubeAdv.java +++ b/src/main/java/pokecube/adventures/PokecubeAdv.java @@ -23,9 +23,6 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.entity.EntityAttributeCreationEvent; @@ -105,17 +102,6 @@ public static void onEntityAttributes(final EntityAttributeCreationEvent event) event.put(EntityTypes.getTrainer(), attribs.build()); event.put(EntityTypes.getLeader(), attribs.build()); } - - @OnlyIn(Dist.CLIENT) - @SubscribeEvent - public static void textureStitch(final TextureStitchEvent.Pre event) - { - if (!event.getAtlas().location().toString().equals("minecraft:textures/atlas/blocks.png")) return; - event.addSprite(new ResourceLocation(PokecubeAdv.MODID, "gui/slot_dna")); - event.addSprite(new ResourceLocation(PokecubeAdv.MODID, "gui/slot_egg")); - event.addSprite(new ResourceLocation(PokecubeAdv.MODID, "gui/slot_bottle")); - event.addSprite(new ResourceLocation(PokecubeAdv.MODID, "gui/slot_selector")); - } } public static final String MODID = "pokecube_adventures"; diff --git a/src/main/java/pokecube/adventures/client/gui/trainer/editor/pages/AI.java b/src/main/java/pokecube/adventures/client/gui/trainer/editor/pages/AI.java index f577ed530f..ab34919323 100644 --- a/src/main/java/pokecube/adventures/client/gui/trainer/editor/pages/AI.java +++ b/src/main/java/pokecube/adventures/client/gui/trainer/editor/pages/AI.java @@ -7,6 +7,7 @@ import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button.OnPress; import net.minecraft.client.gui.components.EditBox; @@ -34,9 +35,20 @@ public class AI extends Page EditBox battleCooldown; EditBox faceDirection; + Runnable callback = () -> { + if (Minecraft.getInstance().screen == this.parent) + { + // Re-add the callback + this.parent.guard.attachChangeListener(this.callback); + // Re-initialise the list + this.onPageOpened(); + } + }; + public AI(final EditorGui parent) { super(TComponent.literal(""), parent); + parent.guard.attachChangeListener(callback); } @Override diff --git a/src/main/java/pokecube/core/ai/routes/GuardAICapability.java b/src/main/java/pokecube/core/ai/routes/GuardAICapability.java index f580e30002..b9096cf5eb 100644 --- a/src/main/java/pokecube/core/ai/routes/GuardAICapability.java +++ b/src/main/java/pokecube/core/ai/routes/GuardAICapability.java @@ -163,6 +163,8 @@ protected void setWalkTo(final Mob entity, final Vec3 pos, final double speed, f private final List tasks = Lists.newArrayList(new GuardTask()); + private List listeners = Lists.newArrayList(); + private GuardState state = GuardState.IDLE; private IGuardTask activeTask; @@ -189,6 +191,20 @@ public void setTask(final int index, final IGuardTask task) IGuardAICapability.super.setTask(index, task); } + @Override + public void attachChangeListener(Runnable onChanged) + { + this.listeners.add(onChanged); + } + + @Override + public void onChanged() + { + List dirty = Lists.newArrayList(listeners); + this.listeners.clear(); + dirty.forEach(r -> r.run()); + } + @Override public GuardState getState() { diff --git a/src/main/java/pokecube/core/ai/routes/IGuardAICapability.java b/src/main/java/pokecube/core/ai/routes/IGuardAICapability.java index e2cfe6313d..3a74495160 100644 --- a/src/main/java/pokecube/core/ai/routes/IGuardAICapability.java +++ b/src/main/java/pokecube/core/ai/routes/IGuardAICapability.java @@ -104,6 +104,12 @@ default void setTask(final int index, final IGuardTask task) this.getTasks().set(index, task); } + default void attachChangeListener(Runnable onChanged) + {} + + default void onChanged() + {} + // do we have a task with a location, and a position boolean hasActiveTask(long time, long daylength); diff --git a/src/main/java/pokecube/core/client/gui/helper/GuardEntry.java b/src/main/java/pokecube/core/client/gui/helper/GuardEntry.java index 201eeaa869..0e0866a2d1 100644 --- a/src/main/java/pokecube/core/client/gui/helper/GuardEntry.java +++ b/src/main/java/pokecube/core/client/gui/helper/GuardEntry.java @@ -378,5 +378,10 @@ public void update() final Component mess = TComponent.translatable("pokemob.route.updated"); this.parent.getMinecraft().player.displayClientMessage(mess, false); } + else + { + final Component mess = TComponent.translatable("pokecube.route.info.incomplete"); + this.parent.getMinecraft().player.displayClientMessage(mess, false); + } } } diff --git a/src/main/java/pokecube/core/client/gui/pokemob/tabs/Routes.java b/src/main/java/pokecube/core/client/gui/pokemob/tabs/Routes.java index fab486dd06..87eeb01b61 100644 --- a/src/main/java/pokecube/core/client/gui/pokemob/tabs/Routes.java +++ b/src/main/java/pokecube/core/client/gui/pokemob/tabs/Routes.java @@ -7,6 +7,7 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.nbt.CompoundTag; @@ -32,11 +33,28 @@ public class Routes extends Tab List variations = Lists.newArrayList(); int num; + Runnable callback = () -> { + if (Minecraft.getInstance().screen == this.parent) + { + // This does 1 set of disabling. + this.setEnabled(false); + // then we clear + this.clear(); + // Then re-initialise + this.init(); + // Then re-add the callback + this.guard.attachChangeListener(this.callback); + // and finally re-enable. + this.setEnabled(true); + } + }; + public Routes(GuiPokemob parent) { super(parent, "routes"); this.entity = this.menu.pokemob.getEntity(); this.guard = this.entity.getCapability(CapHolders.GUARDAI_CAP, null).orElse(null); + this.guard.attachChangeListener(callback); this.icon = Resources.TAB_ICON_ROUTES; } @@ -75,6 +93,7 @@ public void init() }; final int dx = 3; final int dy = 25; + RouteEditHelper.getGuiList(this.list, this.guard, function, this.entity, this.parent, 60, dx, dy, 50); for (var entry : list.children) diff --git a/src/main/java/pokecube/core/network/packets/PacketSyncRoutes.java b/src/main/java/pokecube/core/network/packets/PacketSyncRoutes.java index 5d822b9708..5ef23d23c3 100644 --- a/src/main/java/pokecube/core/network/packets/PacketSyncRoutes.java +++ b/src/main/java/pokecube/core/network/packets/PacketSyncRoutes.java @@ -14,12 +14,12 @@ import pokecube.core.ai.routes.IGuardAICapability.IGuardTask; import pokecube.core.network.pokemobs.PacketPokemobGui; import pokecube.core.utils.CapHolders; -import thut.core.common.network.EntityUpdate; import thut.core.common.network.Packet; public class PacketSyncRoutes extends Packet { - public static void applyServerPacket(final Tag tag, final Entity mob, final IGuardAICapability guard) + public static void applyServerPacket(final Tag tag, final Entity mob, final IGuardAICapability guard, + ServerPlayer player) { final CompoundTag nbt = (CompoundTag) tag; final int index = nbt.getInt("I"); @@ -40,7 +40,8 @@ else if (nbt.contains("N")) guard.getTasks().set(index2, temp); } else if (index < guard.getTasks().size()) guard.getTasks().remove(index); - EntityUpdate.sendEntityUpdate(mob); + // Send back a packet to notify of the changes. + sendUpdateClientPacket(mob, player, false); } public static void sendServerPacket(final Entity mob, final Tag tag) @@ -86,6 +87,9 @@ public void handleClient() final IGuardAICapability guard = e.getCapability(CapHolders.GUARDAI_CAP, null).orElse(null); guard.loadTasks((ListTag) data.get("R")); if (data.getBoolean("O")) PacketSyncRoutes.sendServerPacket(e, null); + else + // Notifies the guis of the updates. + guard.onChanged(); } @Override @@ -103,7 +107,7 @@ public void handleServer(final ServerPlayer player) { PacketPokemobGui.sendOpenPacket(e, player, PacketPokemobGui.ROUTES); } - else PacketSyncRoutes.applyServerPacket(data.get("T"), e, guard); + else PacketSyncRoutes.applyServerPacket(data.get("T"), e, guard, player); } } diff --git a/src/main/resources/assets/pokecube/lang/en_us.json b/src/main/resources/assets/pokecube/lang/en_us.json index 76554b07bf..018873edf6 100644 --- a/src/main/resources/assets/pokecube/lang/en_us.json +++ b/src/main/resources/assets/pokecube/lang/en_us.json @@ -134,6 +134,8 @@ "pokecube.route.info.time.formatinfo": "§cError, Wrong format; Correct time format is: (startick endtick)", "pokecube.route.info.pos.formatinfo": "§cError, Wrong format; Correct location format is: (x y z)", + "pokecube.route.info.incomplete": "§cError, requires all three boxes to be filled out correctly!", + "_comment": "Pokemob Gui", "pokemob.stance.guard": "Guarding",