From 28a194c48d85c071a9f0fcf80cc4ffc8f7a83153 Mon Sep 17 00:00:00 2001 From: someaddons <38401808+someaddons@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:16:13 +0200 Subject: [PATCH 1/2] Sync and other improvements (#10135) Sync and other improvements --- .../AbstractCraftingBuildingModule.java | 67 ++++++++++++------- .../moduleviews/CraftingModuleView.java | 33 ++++----- .../MinecoloniesAdvancedPathNavigate.java | 9 ++- .../minecolonies/lang/manual_en_us.json | 2 +- 4 files changed, 68 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java b/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java index 88c98ad2f93..fac38964d18 100644 --- a/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/modules/AbstractCraftingBuildingModule.java @@ -106,6 +106,11 @@ public abstract class AbstractCraftingBuildingModule extends AbstractBuildingMod */ protected AbstractBuilding building; + /** + * Dirty flag for recipes + */ + private boolean recipesDirty = true; + /** * Create a new module. * @param jobEntry the entry of the job. @@ -248,7 +253,7 @@ public void deserializeNBT(CompoundTag compound) } @Override - public void serializeToView(@NotNull final FriendlyByteBuf buf) + public void serializeToView(@NotNull final FriendlyByteBuf buf, final boolean fullSync) { if (jobEntry != null) { @@ -267,39 +272,46 @@ public void serializeToView(@NotNull final FriendlyByteBuf buf) buf.writeRegistryIdUnsafe(MinecoloniesAPIProxy.getInstance().getCraftingTypeRegistry(), type); } - final List storages = new ArrayList<>(); - final List disabledStorages = new ArrayList<>(); - final Map crafterRecipes = CustomRecipeManager.getInstance().getAllRecipes().getOrDefault(getCustomRecipeKey(), Collections.emptyMap()); - for (final IToken token : new ArrayList<>(recipes)) + buf.writeBoolean(recipesDirty || fullSync); + if (recipesDirty || fullSync) { - final IRecipeStorage storage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(token); - - if (storage == null || (storage.getRecipeSource() != null && !crafterRecipes.containsKey(storage.getRecipeSource())) || (!isRecipeCompatibleWithCraftingModule(token) && !isPreTaughtRecipe(storage, crafterRecipes))) - { - removeRecipe(token); - } - else + final List storages = new ArrayList<>(); + final List disabledStorages = new ArrayList<>(); + final Map crafterRecipes = CustomRecipeManager.getInstance().getAllRecipes().getOrDefault(getCustomRecipeKey(), Collections.emptyMap()); + for (final IToken token : new ArrayList<>(recipes)) { - storages.add(storage); - if (disabledRecipes.contains(token)) + final IRecipeStorage storage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(token); + + if (storage == null || (storage.getRecipeSource() != null && !crafterRecipes.containsKey(storage.getRecipeSource())) || ( + !isRecipeCompatibleWithCraftingModule(token) && !isPreTaughtRecipe(storage, crafterRecipes))) { - disabledStorages.add(storage); + removeRecipe(token); + } + else + { + storages.add(storage); + if (disabledRecipes.contains(token)) + { + disabledStorages.add(storage); + } } } - } - buf.writeInt(storages.size()); - for (final IRecipeStorage storage : storages) - { - buf.writeNbt(StandardFactoryController.getInstance().serialize(storage)); - } + buf.writeInt(storages.size()); + for (final IRecipeStorage storage : storages) + { + buf.writeNbt(StandardFactoryController.getInstance().serialize(storage)); + } - buf.writeInt(disabledStorages.size()); - for (final IRecipeStorage storage : disabledStorages) - { - buf.writeNbt(StandardFactoryController.getInstance().serialize(storage)); + buf.writeInt(disabledStorages.size()); + for (final IRecipeStorage storage : disabledStorages) + { + buf.writeNbt(StandardFactoryController.getInstance().serialize(storage)); + } } + recipesDirty = false; + buf.writeInt(getMaxRecipes()); buf.writeUtf(getId()); buf.writeBoolean(isVisible()); @@ -558,6 +570,7 @@ else if((forceReplace || newRecipe.getMustExist()) && !(duplicateFound.equals(re public void clearRecipes() { recipes.clear(); + recipesDirty = true; } @Override @@ -822,6 +835,7 @@ public void replaceRecipe(final IToken oldRecipe, final IToken newRecipe) { if (recipes.contains(oldRecipe)) { + recipesDirty = true; int oldIndex = recipes.indexOf(oldRecipe); recipes.add(oldIndex, newRecipe); recipes.remove(oldRecipe); @@ -834,6 +848,7 @@ public void removeRecipe(final IToken token) { if(recipes.remove(token)) { + recipesDirty = true; disabledRecipes.remove(token); markDirty(); } @@ -849,6 +864,7 @@ public void addRecipeToList(final IToken token, boolean atTop) { if (!recipes.contains(token)) { + recipesDirty = true; if(atTop) { recipes.add(0, token); @@ -863,6 +879,7 @@ public void addRecipeToList(final IToken token, boolean atTop) @Override public void switchOrder(final int i, final int j, final boolean fullMove) { + recipesDirty = true; if (fullMove) { if (i > j) diff --git a/src/main/java/com/minecolonies/core/colony/buildings/moduleviews/CraftingModuleView.java b/src/main/java/com/minecolonies/core/colony/buildings/moduleviews/CraftingModuleView.java index 98b02ee8852..18f7b4722f3 100644 --- a/src/main/java/com/minecolonies/core/colony/buildings/moduleviews/CraftingModuleView.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/moduleviews/CraftingModuleView.java @@ -89,26 +89,29 @@ public void deserialize(@NotNull FriendlyByteBuf buf) } } - recipes.clear(); - disabledRecipes.clear(); - - final int recipesSize = buf.readInt(); - for (int i = 0; i < recipesSize; i++) + if (buf.readBoolean()) { - final IRecipeStorage storage = StandardFactoryController.getInstance().deserialize(buf.readNbt()); - if (storage != null) + recipes.clear(); + disabledRecipes.clear(); + + final int recipesSize = buf.readInt(); + for (int i = 0; i < recipesSize; i++) { - recipes.add(storage); + final IRecipeStorage storage = StandardFactoryController.getInstance().deserialize(buf.readNbt()); + if (storage != null) + { + recipes.add(storage); + } } - } - final int disabledRecipeSize = buf.readInt(); - for (int i = 0; i < disabledRecipeSize; i++) - { - final IRecipeStorage storage = StandardFactoryController.getInstance().deserialize(buf.readNbt()); - if (storage != null) + final int disabledRecipeSize = buf.readInt(); + for (int i = 0; i < disabledRecipeSize; i++) { - disabledRecipes.add(storage); + final IRecipeStorage storage = StandardFactoryController.getInstance().deserialize(buf.readNbt()); + if (storage != null) + { + disabledRecipes.add(storage); + } } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java index ea1f65f9a99..e34fa87818f 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java @@ -248,6 +248,11 @@ public PathResult setPathJob( return null; } + if (PathfindingUtils.trackingMap.containsValue(ourEntity.getUUID())) + { + Log.getLogger().info(ourEntity + " started pathjob to:" + dest + " job type:" + job.getClass().getSimpleName()); + } + stop(); this.destination = dest; @@ -984,7 +989,7 @@ protected void followThePath() } } - if (isTracking) + if (isTracking && reached != null) { PathfindingUtils.syncDebugReachedPositions(reached, ourEntity); reached.clear(); @@ -1028,7 +1033,7 @@ else if (isTracking) } } - if (isTracking) + if (isTracking && reached != null) { PathfindingUtils.syncDebugReachedPositions(reached, ourEntity); reached.clear(); diff --git a/src/main/resources/assets/minecolonies/lang/manual_en_us.json b/src/main/resources/assets/minecolonies/lang/manual_en_us.json index 96441c23650..ac8c054448a 100644 --- a/src/main/resources/assets/minecolonies/lang/manual_en_us.json +++ b/src/main/resources/assets/minecolonies/lang/manual_en_us.json @@ -2668,7 +2668,7 @@ "com.minecolonies.creativetab.general": "Minecolonies General", "com.minecolonies.creativetab.food": "Minecolonies Food", - "item.minecolonies.large_empty_bottle": "Large Empty Bottle", + "item.minecolonies.large_empty_bottle": "Large Bottle", "item.minecolonies.large_water_bottle": "Large Water Bottle", "item.minecolonies.large_milk_bottle": "Large Milk Bottle", "item.minecolonies.large_soy_milk_bottle": "Large Soy Milk Bottle", From d15fb4ce90c0428fd7f9d7ba1e8d3f56f1be3dae Mon Sep 17 00:00:00 2001 From: Raycoms Date: Tue, 20 Aug 2024 10:16:32 +0200 Subject: [PATCH 2/2] fix 10132 (#10134) Miner before Quarrier in Mine hut --- .../core/colony/buildings/views/AbstractBuildingView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minecolonies/core/colony/buildings/views/AbstractBuildingView.java b/src/main/java/com/minecolonies/core/colony/buildings/views/AbstractBuildingView.java index d5fe869b7c0..52e719e378a 100755 --- a/src/main/java/com/minecolonies/core/colony/buildings/views/AbstractBuildingView.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/views/AbstractBuildingView.java @@ -23,6 +23,7 @@ import com.minecolonies.core.colony.buildings.moduleviews.WorkerBuildingModuleView; import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage; import com.minecolonies.core.network.messages.server.colony.building.HutRenameMessage; +import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -148,7 +149,7 @@ public abstract class AbstractBuildingView implements IBuildingView /** * Set of building modules this building has. */ - protected Int2ObjectOpenHashMap moduleViews = new Int2ObjectOpenHashMap<>(); + protected Int2ObjectLinkedOpenHashMap moduleViews = new Int2ObjectLinkedOpenHashMap<>(); /** * Building type