Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void writeInitialSyncData(@NotNull PacketBuffer buf) {
NetworkUtils.writeItemStack(buf, craftingGrid.getStackInSlot(i));
}
this.recipeMemory.writeInitialSyncData(buf);
buf.writeVarInt(computeConnectedInventory().getSlots());
}

@Override
Expand All @@ -134,6 +135,8 @@ public void receiveInitialSyncData(@NotNull PacketBuffer buf) {
craftingGrid.setStackInSlot(i, NetworkUtils.readItemStack(buf));
}
this.recipeMemory.receiveInitialSyncData(buf);
this.connectedInventory = new ItemHandlerList(
Collections.singletonList(new GTItemStackHandler(this, buf.readVarInt())));
}

@Override
Expand All @@ -158,28 +161,39 @@ public void readFromNBT(NBTTagCompound data) {
}

public IItemHandlerModifiable getAvailableHandlers() {
var handlers = new ArrayList<IItemHandler>();
ArrayList<IItemHandler> handlers = new ArrayList<>();
handlers.add(this.internalInventory);
handlers.add(this.toolInventory);
if (getWorld().isRemote) {
// this might be called on client, so just return the existing inventory instead
handlers.add(this.connectedInventory);
} else {
handlers.add(computeConnectedInventory());
}
return this.combinedInventory = new ItemHandlerList(handlers);
}

// this should only be called server-side
private ItemHandlerList computeConnectedInventory() {
ArrayList<IItemHandler> handlers = new ArrayList<>();
for (var facing : EnumFacing.VALUES) {
var neighbor = getNeighbor(facing);
if (neighbor == null) continue;
var handler = neighbor.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
if (handler != null) handlers.add(handler);
}
this.connectedInventory = new ItemHandlerList(handlers);
handlers.clear();

handlers.add(this.internalInventory);
handlers.add(this.toolInventory);
handlers.add(this.connectedInventory);
return this.combinedInventory = new ItemHandlerList(handlers);
return this.connectedInventory = new ItemHandlerList(handlers);
}

@Override
public void onNeighborChanged() {
getCraftingRecipeLogic().updateInventory(getAvailableHandlers());
writeCustomData(GregtechDataCodes.UPDATE_CLIENT_HANDLER, this::sendHandlerToClient);
if (!getWorld().isRemote) {
writeCustomData(GregtechDataCodes.UPDATE_CLIENT_HANDLER, this::sendHandlerToClient);
}
}

// this is called on client and server
public @NotNull CraftingRecipeLogic getCraftingRecipeLogic() {
Preconditions.checkState(getWorld() != null, "getRecipeResolver called too early");
if (this.recipeLogic == null) {
Expand Down
Loading