Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync and other improvements #10135

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand All @@ -267,39 +272,46 @@ public void serializeToView(@NotNull final FriendlyByteBuf buf)
buf.writeRegistryIdUnsafe(MinecoloniesAPIProxy.getInstance().getCraftingTypeRegistry(), type);
}

final List<IRecipeStorage> storages = new ArrayList<>();
final List<IRecipeStorage> disabledStorages = new ArrayList<>();
final Map<ResourceLocation, CustomRecipe> 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<IRecipeStorage> storages = new ArrayList<>();
final List<IRecipeStorage> disabledStorages = new ArrayList<>();
final Map<ResourceLocation, CustomRecipe> 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());
Expand Down Expand Up @@ -558,6 +570,7 @@ else if((forceReplace || newRecipe.getMustExist()) && !(duplicateFound.equals(re
public void clearRecipes()
{
recipes.clear();
recipesDirty = true;
}

@Override
Expand Down Expand Up @@ -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);
Expand All @@ -834,6 +848,7 @@ public void removeRecipe(final IToken<?> token)
{
if(recipes.remove(token))
{
recipesDirty = true;
disabledRecipes.remove(token);
markDirty();
}
Expand All @@ -849,6 +864,7 @@ public void addRecipeToList(final IToken<?> token, boolean atTop)
{
if (!recipes.contains(token))
{
recipesDirty = true;
if(atTop)
{
recipes.add(0, token);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ public PathResult<AbstractPathJob> 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;
Expand Down Expand Up @@ -984,7 +989,7 @@ protected void followThePath()
}
}

if (isTracking)
if (isTracking && reached != null)
{
PathfindingUtils.syncDebugReachedPositions(reached, ourEntity);
reached.clear();
Expand Down Expand Up @@ -1028,7 +1033,7 @@ else if (isTracking)
}
}

if (isTracking)
if (isTracking && reached != null)
{
PathfindingUtils.syncDebugReachedPositions(reached, ourEntity);
reached.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down