Skip to content

Commit

Permalink
reset ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Jan 30, 2025
1 parent e3039a6 commit e59aebd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class CachedRecipeData {

private IRecipe recipe;
private IRecipe previousRecipe;

public CachedRecipeData() {
this(null);
Expand All @@ -27,13 +28,18 @@ public boolean matches(InventoryCrafting inventoryCrafting, World world) {
}

public void setRecipe(IRecipe newRecipe) {
this.previousRecipe = this.recipe;
this.recipe = newRecipe;
}

public IRecipe getRecipe() {
return recipe;
}

public IRecipe getPreviousRecipe() {
return previousRecipe;
}

public ItemStack getRecipeOutput() {
return recipe == null ? ItemStack.EMPTY : recipe.getRecipeOutput();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CraftingRecipeLogic extends SyncHandler {

// client only
public static final int UPDATE_INGREDIENTS = 1;
public static final int RESET_INGREDIENTS = 2;
public static final int SYNC_STACK = 4;

// server only
Expand Down Expand Up @@ -336,7 +337,16 @@ public IRecipe getCachedRecipe() {
@Override
public void detectAndSendChanges(boolean init) {
var recipe = getCachedRecipe();
if (recipe == null) return;
if (recipe == null) {
var prevRecipe = cachedRecipeData.getPreviousRecipe();
if (prevRecipe == null) return;
cachedRecipeData.setRecipe(null);
for (CraftingInputSlot inputSlot : this.inputSlots) {
inputSlot.hasIngredients = true;
}
syncToClient(RESET_INGREDIENTS);
return;
}

requiredItems.clear();
final Map<Integer, Boolean> map = new Int2BooleanArrayMap();
Expand Down Expand Up @@ -424,9 +434,12 @@ public void readOnClient(int id, PacketBuffer buf) {
for (int i = 0; i < size; i++) {
this.inputSlots[buf.readByte()].hasIngredients = buf.readBoolean();
}
}
if (id == SYNC_STACK) {
} else if (id == SYNC_STACK) {
getSyncManager().setCursorItem(NetworkUtils.readItemStack(buf));
} else if (id == RESET_INGREDIENTS) {
for (CraftingInputSlot inputSlot : this.inputSlots) {
inputSlot.hasIngredients = true;
}
}
}

Expand Down

0 comments on commit e59aebd

Please sign in to comment.