Fix fluid generator client/server desync, fixes #1474
This commit is contained in:
parent
f9d99aad1d
commit
9a566e0583
6 changed files with 45 additions and 24 deletions
|
@ -25,8 +25,6 @@
|
||||||
package techreborn.tiles.generator;
|
package techreborn.tiles.generator;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
@ -74,17 +72,20 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
|
||||||
super.update();
|
super.update();
|
||||||
this.ticksSinceLastChange++;
|
this.ticksSinceLastChange++;
|
||||||
|
|
||||||
|
if(world.isRemote){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check cells input slot 2 time per second
|
// Check cells input slot 2 time per second
|
||||||
// Please, keep ticks counting on client also to report progress to GUI
|
// Please, keep ticks counting on client also to report progress to GUI
|
||||||
if (this.ticksSinceLastChange >= 10) {
|
if (this.ticksSinceLastChange >= 10) {
|
||||||
if (!world.isRemote) {
|
if (!this.inventory.getStackInSlot(0).isEmpty()) {
|
||||||
if (!this.inventory.getStackInSlot(0).isEmpty()) {
|
FluidUtils.drainContainers(this.tank, this.inventory, 0, 1);
|
||||||
FluidUtils.drainContainers(this.tank, this.inventory, 0, 1);
|
FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType());
|
||||||
FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType());
|
|
||||||
}
|
|
||||||
tank.setTileEntity(this);
|
|
||||||
tank.compareAndUpdate();
|
|
||||||
}
|
}
|
||||||
|
tank.setTileEntity(this);
|
||||||
|
tank.compareAndUpdate();
|
||||||
|
|
||||||
this.ticksSinceLastChange = 0;
|
this.ticksSinceLastChange = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,12 +107,11 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.world.isRemote) {
|
if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive())
|
||||||
if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive())
|
this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
||||||
this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive())
|
||||||
else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive())
|
this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
||||||
this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +130,7 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
|
||||||
addEnergy(this.getMaxPower() - this.getEnergy());
|
addEnergy(this.getMaxPower() - this.getEnergy());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,15 +202,24 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
|
||||||
return tagCompound;
|
return tagCompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
|
||||||
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
|
||||||
getPos().getY(), getPos().getZ());
|
|
||||||
readFromNBT(packet.getNbtCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeUpgraded() {
|
public boolean canBeUpgraded() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTicksSinceLastChange() {
|
||||||
|
return ticksSinceLastChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTicksSinceLastChange(int ticksSinceLastChange) {
|
||||||
|
this.ticksSinceLastChange = ticksSinceLastChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTankAmount(){
|
||||||
|
return tank.getFluidAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTankAmount(int amount){
|
||||||
|
tank.setFluidAmount(amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class TileDieselGenerator extends TileBaseFluidGenerator implements ICont
|
||||||
public BuiltContainer createContainer(final EntityPlayer player) {
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
||||||
return new ContainerBuilder("dieselgenerator").player(player.inventory).inventory().hotbar()
|
return new ContainerBuilder("dieselgenerator").player(player.inventory).inventory().hotbar()
|
||||||
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||||
|
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||||
|
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||||
.addInventory().create(this);
|
.addInventory().create(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class TileGasTurbine extends TileBaseFluidGenerator implements IContainer
|
||||||
public BuiltContainer createContainer(final EntityPlayer player) {
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
||||||
return new ContainerBuilder("gasturbine").player(player.inventory).inventory().hotbar()
|
return new ContainerBuilder("gasturbine").player(player.inventory).inventory().hotbar()
|
||||||
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||||
|
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||||
|
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||||
.addInventory().create(this);
|
.addInventory().create(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,10 @@ public class TilePlasmaGenerator extends TileBaseFluidGenerator implements ICont
|
||||||
@Override
|
@Override
|
||||||
public BuiltContainer createContainer(final EntityPlayer player) {
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
||||||
return new ContainerBuilder("plasmagenerator").player(player.inventory).inventory().hotbar().addInventory()
|
return new ContainerBuilder("plasmagenerator").player(player.inventory).inventory().hotbar().addInventory()
|
||||||
.tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue().addInventory().create(this);
|
.tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||||
|
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||||
|
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||||
|
.addInventory().create(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class TileSemiFluidGenerator extends TileBaseFluidGenerator implements IC
|
||||||
public BuiltContainer createContainer(final EntityPlayer player) {
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
||||||
return new ContainerBuilder("semifluidgenerator").player(player.inventory).inventory().hotbar()
|
return new ContainerBuilder("semifluidgenerator").player(player.inventory).inventory().hotbar()
|
||||||
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||||
|
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||||
|
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||||
.addInventory().create(this);
|
.addInventory().create(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class TileThermalGenerator extends TileBaseFluidGenerator implements ICon
|
||||||
public BuiltContainer createContainer(final EntityPlayer player) {
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
||||||
return new ContainerBuilder("thermalgenerator").player(player.inventory).inventory().hotbar()
|
return new ContainerBuilder("thermalgenerator").player(player.inventory).inventory().hotbar()
|
||||||
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
.addInventory().tile(this).slot(0, 25, 35).outputSlot(1, 25, 55).syncEnergyValue()
|
||||||
|
.syncIntegerValue(this::getTicksSinceLastChange, this::setTicksSinceLastChange)
|
||||||
|
.syncIntegerValue(this::getTankAmount, this::setTankAmount)
|
||||||
.addInventory().create(this);
|
.addInventory().create(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue