Skip to content

Commit

Permalink
more work on syncing and recipe logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Apr 19, 2024
1 parent f24fbbe commit d118fc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void performRecipe() {
if (!getSyncManager().isClient())
syncToClient(1, this::writeAvailableStacks);

if (!attemptMatchRecipe() || !consumeRecipeItems()) {
if (!attemptMatchRecipe() || !consumeRecipeItems(false)) {
return;
}

Expand Down Expand Up @@ -247,7 +247,7 @@ public void performRecipe() {
}
}

protected boolean consumeRecipeItems() {
protected boolean consumeRecipeItems(boolean simulate) {
if (requiredItems.isEmpty()) {
return false;
}
Expand Down Expand Up @@ -284,9 +284,9 @@ protected boolean consumeRecipeItems() {
if (stack.getItem() instanceof IGTTool gtTool) {
damage = gtTool.getToolStats().getDamagePerCraftingAction(stack);
}
stack.damageItem(damage, getSyncManager().getPlayer());
if (!simulate) stack.damageItem(damage, getSyncManager().getPlayer());
} else {
availableHandlers.extractItem(slot, stack.getCount(), false);
availableHandlers.extractItem(slot, stack.getCount(), simulate);
}
extracted = true;
}
Expand Down Expand Up @@ -365,6 +365,8 @@ public void readOnClient(int id, PacketBuffer buf) {
updateClientStacks(buf);
} else if (id == 3) {
syncToServer(3);
} else if (id == 4) {
getSyncManager().setCursorItem(readStackSafe(buf));
} else if (id == 5) {
int slot = buf.readVarInt();
var stack = readStackSafe(buf);
Expand All @@ -384,7 +386,13 @@ public void readOnServer(int id, PacketBuffer buf) {
} else if (id == 1) {
syncToClient(1, this::writeAvailableStacks);
} else if (id == 3) {
syncToClient(1, this::writeAvailableStacks);
// syncToClient(1, this::writeAvailableStacks);
var curStack = getSyncManager().getCursorItem();
var outStack = getCachedRecipe().getRecipeOutput();
if (ItemStack.areItemStacksEqual(curStack, outStack)) {
curStack.grow(outStack.getCount());
syncToClient(4, buffer -> writeStackSafe(buffer, curStack));
}
} else if (id == 4) {
int slot = buf.readVarInt();
syncToClient(5, buffer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,11 @@ public CraftingOutputSlot(IItemHandler itemHandler, IntSyncValue syncValue) {

@Override
public boolean canTakeStack(EntityPlayer playerIn) {
if (recipeLogic.getSyncManager().isClient()) recipeLogic.syncToServer(3);
return recipeLogic.isRecipeValid();
if (recipeLogic.getSyncManager().isClient()) {
recipeLogic.syncToServer(3);
return false;
}
return recipeLogic.isRecipeValid() && recipeLogic.consumeRecipeItems(true);
}

@Override
Expand Down

0 comments on commit d118fc9

Please sign in to comment.