Skip to content

Commit

Permalink
fix: jei transfer not working in single player
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Feb 16, 2024
1 parent 6959fbc commit 9888c0b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Fixed

- Fixed JEI transfer in the Pattern Grid wrongly choosing "Processing" mode.
- Fixed JEI transfer not working in single player.

## [1.13.0-beta.1] - 2024-02-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void neighborChanged(BlockState state, Level level, BlockPos pos, Block b
}

@Override
@SuppressWarnings("deprecation")
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = level.getBlockEntity(pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ private void move(IRecipeSlotsView recipeSlotsView) {
return stacks;
}).toList();

RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(inputs));
final ItemStack[][] inputsArray = new ItemStack[inputs.size()][];
for (int i = 0; i < inputs.size(); i++) {
inputsArray[i] = inputs.get(i).toArray(new ItemStack[0]);
}

RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(inputsArray));
}

private void moveForProcessing(IRecipeSlotsView recipeLayout, GridContainerMenu gridContainer, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,23 @@
public class GridTransferMessage implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "grid_transfer");

private ItemStack[][] recipe;
private List<List<ItemStack>> inputs;
private final ItemStack[][] recipe;

public GridTransferMessage() {
}

public GridTransferMessage(List<List<ItemStack>> inputs) {
this.inputs = inputs;
public GridTransferMessage(final ItemStack[][] recipe) {
this.recipe = recipe;
}

public static GridTransferMessage decode(FriendlyByteBuf buf) {
GridTransferMessage msg = new GridTransferMessage();
int slots = buf.readInt();
msg.recipe = new ItemStack[slots][];
final ItemStack[][] recipe = new ItemStack[slots][];
for (int i = 0; i < slots; i++) {
int numberOfIngredients = buf.readInt();
msg.recipe[i] = new ItemStack[numberOfIngredients];

recipe[i] = new ItemStack[numberOfIngredients];
for (int j = 0; j < numberOfIngredients; j++) {
msg.recipe[i][j] = StackUtils.readItemStack(buf);
recipe[i][j] = StackUtils.readItemStack(buf);
}
}

return msg;
return new GridTransferMessage(recipe);
}

public static void handle(GridTransferMessage message, PlayPayloadContext ctx) {
Expand All @@ -56,10 +49,9 @@ public static void handle(GridTransferMessage message, PlayPayloadContext ctx) {

@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(inputs.size());
for (List<ItemStack> stacks : inputs) {
buf.writeInt(stacks.size());

buf.writeInt(recipe.length);
for (ItemStack[] stacks : recipe) {
buf.writeInt(stacks.length);
for (ItemStack possibleStack : stacks) {
StackUtils.writeItemStack(buf, possibleStack);
}
Expand Down

0 comments on commit 9888c0b

Please sign in to comment.