mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Fixed a massive bug with tiles not syncing properly when re-entering unloaded chunks >_>
This commit is contained in:
parent
a48f6ae232
commit
b4a64c1270
1 changed files with 25 additions and 18 deletions
|
@ -87,29 +87,28 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
GameRegistry.registerTileEntity(TileEntityLaserRelayEnergy.class, ModUtil.MOD_ID+":tileEntityLaserRelay");
|
GameRegistry.registerTileEntity(TileEntityLaserRelayEnergy.class, ModUtil.MOD_ID+":tileEntityLaserRelay");
|
||||||
GameRegistry.registerTileEntity(TileEntityLaserRelayItemWhitelist.class, ModUtil.MOD_ID+":tileEntityLaserRelayItemWhitelist");
|
GameRegistry.registerTileEntity(TileEntityLaserRelayItemWhitelist.class, ModUtil.MOD_ID+":tileEntityLaserRelayItemWhitelist");
|
||||||
GameRegistry.registerTileEntity(TileEntityItemViewer.class, ModUtil.MOD_ID+":tileItemViewer");
|
GameRegistry.registerTileEntity(TileEntityItemViewer.class, ModUtil.MOD_ID+":tileItemViewer");
|
||||||
|
GameRegistry.registerTileEntity(TileEntityBookletStand.class, ModUtil.MOD_ID+":tileEntityBookletStand");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void readFromNBT(NBTTagCompound compound){
|
public void readFromNBT(NBTTagCompound compound){
|
||||||
super.readFromNBT(compound);
|
super.readFromNBT(compound);
|
||||||
this.isRedstonePowered = compound.getBoolean("Redstone");
|
|
||||||
this.readSyncableNBT(compound, false);
|
this.readSyncableNBT(compound, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final NBTTagCompound writeToNBT(NBTTagCompound compound){
|
public NBTTagCompound writeToNBT(NBTTagCompound compound){
|
||||||
NBTTagCompound newCompound = super.writeToNBT(compound);
|
compound = super.writeToNBT(compound);
|
||||||
newCompound.setBoolean("Redstone", this.isRedstonePowered);
|
this.writeSyncableNBT(compound, false);
|
||||||
this.writeSyncableNBT(newCompound, false);
|
return compound;
|
||||||
return newCompound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final SPacketUpdateTileEntity getUpdatePacket(){
|
public SPacketUpdateTileEntity getUpdatePacket(){
|
||||||
NBTTagCompound compound = this.getSyncCompound();
|
NBTTagCompound compound = this.getUpdateTag();
|
||||||
if(compound != null){
|
if(compound != null){
|
||||||
return new SPacketUpdateTileEntity(this.pos, 3, compound);
|
return new SPacketUpdateTileEntity(this.pos, 0, compound);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return null;
|
return null;
|
||||||
|
@ -117,7 +116,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
||||||
if(pkt != null){
|
if(pkt != null){
|
||||||
this.receiveSyncCompound(pkt.getNbtCompound());
|
this.receiveSyncCompound(pkt.getNbtCompound());
|
||||||
}
|
}
|
||||||
|
@ -132,26 +131,34 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
this.readSyncableNBT(compound, true);
|
this.readSyncableNBT(compound, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound getSyncCompound(){
|
@Nonnull
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
@Override
|
||||||
|
public NBTTagCompound getUpdateTag(){
|
||||||
|
NBTTagCompound tag = super.getUpdateTag();
|
||||||
this.writeSyncableNBT(tag, true);
|
this.writeSyncableNBT(tag, true);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
||||||
|
if(!isForSync){
|
||||||
|
compound.setBoolean("Redstone", this.isRedstonePowered);
|
||||||
|
}
|
||||||
if(this instanceof IRedstoneToggle){
|
if(this instanceof IRedstoneToggle){
|
||||||
compound.setBoolean("IsPulseMode", ((IRedstoneToggle)this).isPulseMode());
|
compound.setBoolean("IsPulseMode", ((IRedstoneToggle)this).isPulseMode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
||||||
|
if(!isForSync){
|
||||||
|
this.isRedstonePowered = compound.getBoolean("Redstone");
|
||||||
|
}
|
||||||
if(this instanceof IRedstoneToggle){
|
if(this instanceof IRedstoneToggle){
|
||||||
((IRedstoneToggle)this).toggle(compound.getBoolean("IsPulseMode"));
|
((IRedstoneToggle)this).toggle(compound.getBoolean("IsPulseMode"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void update(){
|
public void update(){
|
||||||
this.updateEntity();
|
this.updateEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +166,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
this.ticksElapsed++;
|
this.ticksElapsed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setRedstonePowered(boolean powered){
|
public void setRedstonePowered(boolean powered){
|
||||||
this.isRedstonePowered = powered;
|
this.isRedstonePowered = powered;
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
@ -168,7 +175,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
return player.getDistanceSq(this.getPos().getX()+0.5D, this.pos.getY()+0.5D, this.pos.getZ()+0.5D) <= 64 && !this.isInvalid() && this.worldObj.getTileEntity(this.pos) == this;
|
return player.getDistanceSq(this.getPos().getX()+0.5D, this.pos.getY()+0.5D, this.pos.getZ()+0.5D) <= 64 && !this.isInvalid() && this.worldObj.getTileEntity(this.pos) == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean sendUpdateWithInterval(){
|
protected boolean sendUpdateWithInterval(){
|
||||||
if(this.ticksElapsed%ConfigIntValues.TILE_ENTITY_UPDATE_INTERVAL.getValue() == 0){
|
if(this.ticksElapsed%ConfigIntValues.TILE_ENTITY_UPDATE_INTERVAL.getValue() == 0){
|
||||||
this.sendUpdate();
|
this.sendUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
@ -178,9 +185,9 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void sendUpdate(){
|
public void sendUpdate(){
|
||||||
if(!this.worldObj.isRemote){
|
if(!this.worldObj.isRemote){
|
||||||
NBTTagCompound compound = this.getSyncCompound();
|
NBTTagCompound compound = this.getUpdateTag();
|
||||||
if(compound != null){
|
if(compound != null){
|
||||||
PacketHandler.theNetwork.sendToAllAround(new PacketUpdateTileEntity(compound, this.getPos()), new NetworkRegistry.TargetPoint(this.worldObj.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 64));
|
PacketHandler.theNetwork.sendToAllAround(new PacketUpdateTileEntity(compound, this.getPos()), new NetworkRegistry.TargetPoint(this.worldObj.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 64));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue