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.blockentity.MachineBaseBlockEntity;
|
||||||
import reborncore.common.fluid.FluidUtil;
|
import reborncore.common.fluid.FluidUtil;
|
||||||
import reborncore.common.fluid.FluidValue;
|
import reborncore.common.fluid.FluidValue;
|
||||||
|
import reborncore.common.fluid.container.FluidInstance;
|
||||||
import reborncore.common.util.RebornInventory;
|
import reborncore.common.util.RebornInventory;
|
||||||
import reborncore.common.util.Tank;
|
import reborncore.common.util.Tank;
|
||||||
import techreborn.init.TRBlockEntities;
|
import techreborn.init.TRBlockEntities;
|
||||||
|
@ -53,6 +54,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
|
public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {
|
||||||
protected Tank tank;
|
protected Tank tank;
|
||||||
|
private int serverMaxCapacity = -1;
|
||||||
|
|
||||||
protected RebornInventory<TankUnitBaseBlockEntity> inventory = new RebornInventory<>(2, "TankInventory", 64, this);
|
protected RebornInventory<TankUnitBaseBlockEntity> inventory = new RebornInventory<>(2, "TankInventory", 64, this);
|
||||||
|
|
||||||
private TRContent.TankUnit type;
|
private TRContent.TankUnit type;
|
||||||
|
@ -68,7 +71,7 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
||||||
|
|
||||||
private void configureEntity(TRContent.TankUnit type) {
|
private void configureEntity(TRContent.TankUnit type) {
|
||||||
this.type = 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() {
|
public ItemStack getDropWithNBT() {
|
||||||
|
@ -174,7 +177,22 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
|
||||||
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
|
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
|
||||||
return new ScreenHandlerBuilder("tank").player(player.inventory).inventory().hotbar()
|
return new ScreenHandlerBuilder("tank").player(player.inventory).inventory().hotbar()
|
||||||
.addInventory().blockEntity(this).fluidSlot(0, 100, 53).outputSlot(1, 140, 53)
|
.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
|
@Nullable
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
|
|
||||||
protected RebornInventory<StorageUnitBaseBlockEntity> inventory;
|
protected RebornInventory<StorageUnitBaseBlockEntity> inventory;
|
||||||
private int maxCapacity;
|
private int maxCapacity;
|
||||||
|
private int serverCapacity = -1;
|
||||||
|
|
||||||
private ItemStack storeItemStack;
|
private ItemStack storeItemStack;
|
||||||
|
|
||||||
|
@ -82,7 +83,12 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureEntity(TRContent.StorageUnit type) {
|
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;
|
storeItemStack = ItemStack.EMPTY;
|
||||||
inventory = new RebornInventory<>(2, "ItemInventory", 64, this);
|
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();
|
return storeItemStack.getCount() + inventory.getStack(OUTPUT_SLOT).getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxCapacity() {
|
|
||||||
return maxCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// MachineBaseBlockEntity
|
// MachineBaseBlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
@ -457,6 +459,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
|
||||||
.sync(this::isLockedInt, this::setLockedInt)
|
.sync(this::isLockedInt, this::setLockedInt)
|
||||||
.sync(this::getStoredStackNBT, this::setStoredStackFromNBT)
|
.sync(this::getStoredStackNBT, this::setStoredStackFromNBT)
|
||||||
.sync(this::getStoredAmount, this::setStoredAmount)
|
.sync(this::getStoredAmount, this::setStoredAmount)
|
||||||
|
.sync(this::getMaxCapacity, this::setMaxCapacity)
|
||||||
.addInventory().create(this, syncID);
|
.addInventory().create(this, syncID);
|
||||||
|
|
||||||
// Note that inventory is synced, and it gets the stack from that
|
// 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;
|
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() {
|
public CompoundTag getStoredStackNBT() {
|
||||||
CompoundTag tag = new CompoundTag();
|
CompoundTag tag = new CompoundTag();
|
||||||
getStoredStack().toTag(tag);
|
getStoredStack().toTag(tag);
|
||||||
|
|
Loading…
Reference in a new issue