Skip to content

Commit d118fc9

Browse files
committed
more work on syncing and recipe logic
1 parent f24fbbe commit d118fc9

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void performRecipe() {
213213
if (!getSyncManager().isClient())
214214
syncToClient(1, this::writeAvailableStacks);
215215

216-
if (!attemptMatchRecipe() || !consumeRecipeItems()) {
216+
if (!attemptMatchRecipe() || !consumeRecipeItems(false)) {
217217
return;
218218
}
219219

@@ -247,7 +247,7 @@ public void performRecipe() {
247247
}
248248
}
249249

250-
protected boolean consumeRecipeItems() {
250+
protected boolean consumeRecipeItems(boolean simulate) {
251251
if (requiredItems.isEmpty()) {
252252
return false;
253253
}
@@ -284,9 +284,9 @@ protected boolean consumeRecipeItems() {
284284
if (stack.getItem() instanceof IGTTool gtTool) {
285285
damage = gtTool.getToolStats().getDamagePerCraftingAction(stack);
286286
}
287-
stack.damageItem(damage, getSyncManager().getPlayer());
287+
if (!simulate) stack.damageItem(damage, getSyncManager().getPlayer());
288288
} else {
289-
availableHandlers.extractItem(slot, stack.getCount(), false);
289+
availableHandlers.extractItem(slot, stack.getCount(), simulate);
290290
}
291291
extracted = true;
292292
}
@@ -365,6 +365,8 @@ public void readOnClient(int id, PacketBuffer buf) {
365365
updateClientStacks(buf);
366366
} else if (id == 3) {
367367
syncToServer(3);
368+
} else if (id == 4) {
369+
getSyncManager().setCursorItem(readStackSafe(buf));
368370
} else if (id == 5) {
369371
int slot = buf.readVarInt();
370372
var stack = readStackSafe(buf);
@@ -384,7 +386,13 @@ public void readOnServer(int id, PacketBuffer buf) {
384386
} else if (id == 1) {
385387
syncToClient(1, this::writeAvailableStacks);
386388
} else if (id == 3) {
387-
syncToClient(1, this::writeAvailableStacks);
389+
// syncToClient(1, this::writeAvailableStacks);
390+
var curStack = getSyncManager().getCursorItem();
391+
var outStack = getCachedRecipe().getRecipeOutput();
392+
if (ItemStack.areItemStacksEqual(curStack, outStack)) {
393+
curStack.grow(outStack.getCount());
394+
syncToClient(4, buffer -> writeStackSafe(buffer, curStack));
395+
}
388396
} else if (id == 4) {
389397
int slot = buf.readVarInt();
390398
syncToClient(5, buffer -> {

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityWorkbench.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,11 @@ public CraftingOutputSlot(IItemHandler itemHandler, IntSyncValue syncValue) {
531531

532532
@Override
533533
public boolean canTakeStack(EntityPlayer playerIn) {
534-
if (recipeLogic.getSyncManager().isClient()) recipeLogic.syncToServer(3);
535-
return recipeLogic.isRecipeValid();
534+
if (recipeLogic.getSyncManager().isClient()) {
535+
recipeLogic.syncToServer(3);
536+
return false;
537+
}
538+
return recipeLogic.isRecipeValid() && recipeLogic.consumeRecipeItems(true);
536539
}
537540

538541
@Override

0 commit comments

Comments
 (0)