Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix duplicate recipe memory
Browse files Browse the repository at this point in the history
clarify todo
ghzdude committed Feb 1, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 09a8ee5 commit 6162861
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gregtech.common.metatileentities.storage;

import gregtech.api.util.ItemStackHashStrategy;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -12,6 +14,7 @@
import com.cleanroommc.modularui.network.NetworkUtils;
import com.cleanroommc.modularui.utils.MouseData;
import com.cleanroommc.modularui.value.sync.SyncHandler;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -32,6 +35,11 @@ public class CraftingRecipeMemory extends SyncHandler {
// server only
public static final int MOUSE_CLICK = 2;

private final Hash.Strategy<ItemStack> strategy = ItemStackHashStrategy.builder()
.compareItem(true)
.compareMetadata(true)
.build();

private final MemorizedRecipe[] memorizedRecipes;
private final IItemHandlerModifiable craftingMatrix;

@@ -84,16 +92,18 @@ private MemorizedRecipe findOrCreateRecipe(ItemStack resultItemStack) {
MemorizedRecipe existing = null;
for (MemorizedRecipe memorizedRecipe : memorizedRecipes) {
if (memorizedRecipe != null &&
ItemStack.areItemStacksEqual(memorizedRecipe.recipeResult, resultItemStack)) {
strategy.equals(memorizedRecipe.recipeResult, resultItemStack)) {
existing = memorizedRecipe;
break;
}
}

// we already have a recipe that matches
// move it to the front
if (existing != null && !existing.recipeLocked) {
if (existing.index == 0) return existing; // it's already at the front
if (existing != null) {
// it's already at the front or it's locked
if (existing.index == 0 || existing.recipeLocked) return existing;

int removed = existing.index;
removeRecipe(existing.index);
syncToClient(REMOVE_RECIPE, buffer -> buffer.writeByte(removed));
Original file line number Diff line number Diff line change
@@ -317,7 +317,7 @@ public IWidget createCraftingGrid() {
public IWidget createCraftingOutput(PosGuiData guiData, PanelSyncManager syncManager) {
var amountCrafted = new IntSyncValue(this::getItemsCrafted, this::setItemsCrafted);
syncManager.syncValue("amount_crafted", amountCrafted);
amountCrafted.updateCacheFromSource(true); // todo remove
amountCrafted.updateCacheFromSource(true); // todo remove on mui2 rc3

return Flow.column()
.size(54)

0 comments on commit 6162861

Please sign in to comment.