fix #2296 - Sync server config for fluid/item storage for clients
This commit is contained in:
parent
46eaa22eb5
commit
b1a975233a
2 changed files with 38 additions and 7 deletions
|
@ -43,6 +43,7 @@ import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
|||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.fluid.FluidUtil;
|
||||
import reborncore.common.fluid.FluidValue;
|
||||
import reborncore.common.fluid.container.FluidInstance;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import reborncore.common.util.Tank;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
@ -53,6 +54,8 @@ import java.util.List;
|
|||
|
||||
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
|
||||
protected Tank tank;
|
||||
private int serverMaxCapacity = -1;
|
||||
|
||||
protected RebornInventory<TankUnitBaseBlockEntity> inventory = new RebornInventory<>(2, "TankInventory", 64, this);
|
||||
|
||||
private TRContent.TankUnit type;
|
||||
|
@ -68,7 +71,7 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
|
||||
private void configureEntity(TRContent.TankUnit type) {
|
||||
this.type = type;
|
||||
this.tank = new Tank("TankStorage", type.capacity, this);
|
||||
this.tank = new Tank("TankStorage", serverMaxCapacity == -1 ? type.capacity : FluidValue.fromRaw(serverMaxCapacity), this);
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT() {
|
||||
|
@ -174,7 +177,22 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
|||
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
|
||||
return new ScreenHandlerBuilder("tank").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().blockEntity(this).fluidSlot(0, 100, 53).outputSlot(1, 140, 53)
|
||||
.sync(tank).addInventory().create(this, syncID);
|
||||
.sync(tank)
|
||||
.sync(this::getMaxCapacity, this::setMaxCapacity)
|
||||
|
||||
.addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
// Sync between server/client if configs are mis-matched.
|
||||
public int getMaxCapacity() {
|
||||
return this.tank.getCapacity().getRawValue();
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
FluidInstance instance = tank.getFluidInstance();
|
||||
this.tank = new Tank("TankStorage", FluidValue.fromRaw(maxCapacity), this);
|
||||
this.tank.setFluidInstance(instance);
|
||||
this.serverMaxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -63,6 +63,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
|
||||
protected RebornInventory<StorageUnitBaseBlockEntity> inventory;
|
||||
private int maxCapacity;
|
||||
private int serverCapacity = -1;
|
||||
|
||||
private ItemStack storeItemStack;
|
||||
|
||||
|
@ -82,7 +83,12 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
}
|
||||
|
||||
private void configureEntity(TRContent.StorageUnit type) {
|
||||
this.maxCapacity = type.capacity;
|
||||
|
||||
// Set capacity to local config unless overridden by server
|
||||
if(serverCapacity == -1){
|
||||
this.maxCapacity = type.capacity;
|
||||
}
|
||||
|
||||
storeItemStack = ItemStack.EMPTY;
|
||||
inventory = new RebornInventory<>(2, "ItemInventory", 64, this);
|
||||
|
||||
|
@ -236,10 +242,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
return storeItemStack.getCount() + inventory.getStack(OUTPUT_SLOT).getCount();
|
||||
}
|
||||
|
||||
public int getMaxCapacity() {
|
||||
return maxCapacity;
|
||||
}
|
||||
|
||||
// MachineBaseBlockEntity
|
||||
@Override
|
||||
public void tick() {
|
||||
|
@ -457,6 +459,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
.sync(this::isLockedInt, this::setLockedInt)
|
||||
.sync(this::getStoredStackNBT, this::setStoredStackFromNBT)
|
||||
.sync(this::getStoredAmount, this::setStoredAmount)
|
||||
.sync(this::getMaxCapacity, this::setMaxCapacity)
|
||||
.addInventory().create(this, syncID);
|
||||
|
||||
// Note that inventory is synced, and it gets the stack from that
|
||||
|
@ -479,6 +482,16 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
|||
this.storedAmount = storedAmount;
|
||||
}
|
||||
|
||||
// Sync between server/client if configs are mis-matched.
|
||||
public int getMaxCapacity() {
|
||||
return this.maxCapacity;
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
this.maxCapacity = maxCapacity;
|
||||
this.serverCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
public CompoundTag getStoredStackNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
getStoredStack().toTag(tag);
|
||||
|
|
Loading…
Reference in a new issue