mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Did a change to NBT saving and syncing that might fix weird bugs that are happening :v
This commit is contained in:
parent
41e2daa0be
commit
a89ff4bc29
3 changed files with 60 additions and 69 deletions
|
@ -59,7 +59,7 @@ public final class PacketHandler{
|
||||||
if(world != null){
|
if(world != null){
|
||||||
TileEntity tile = world.getTileEntity(new BlockPos(compound.getInteger("X"), compound.getInteger("Y"), compound.getInteger("Z")));
|
TileEntity tile = world.getTileEntity(new BlockPos(compound.getInteger("X"), compound.getInteger("Y"), compound.getInteger("Z")));
|
||||||
if(tile != null && tile instanceof TileEntityBase){
|
if(tile != null && tile instanceof TileEntityBase){
|
||||||
((TileEntityBase)tile).receiveSyncCompound(compound.getCompoundTag("Data"));
|
((TileEntityBase)tile).readSyncableNBT(compound.getCompoundTag("Data"), TileEntityBase.NBTType.SYNC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ITickable;
|
import net.minecraft.util.ITickable;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentTranslation;
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -130,41 +129,30 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound compound){
|
public final NBTTagCompound writeToNBT(NBTTagCompound compound){
|
||||||
this.readSyncableNBT(compound, NBTType.SAVE_TILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound compound){
|
|
||||||
this.writeSyncableNBT(compound, NBTType.SAVE_TILE);
|
this.writeSyncableNBT(compound, NBTType.SAVE_TILE);
|
||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SPacketUpdateTileEntity getUpdatePacket(){
|
public final void readFromNBT(NBTTagCompound compound){
|
||||||
NBTTagCompound compound = this.getUpdateTag();
|
this.readSyncableNBT(compound, NBTType.SAVE_TILE);
|
||||||
if(compound != null){
|
|
||||||
return new SPacketUpdateTileEntity(this.pos, 0, compound);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final SPacketUpdateTileEntity getUpdatePacket(){
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
this.writeSyncableNBT(compound, NBTType.SYNC);
|
||||||
|
return new SPacketUpdateTileEntity(this.pos, -1, compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
||||||
if(pkt != null){
|
this.readSyncableNBT(pkt.getNbtCompound(), NBTType.SYNC);
|
||||||
NBTTagCompound compound = pkt.getNbtCompound();
|
|
||||||
this.receiveSyncCompound(compound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void receiveSyncCompound(NBTTagCompound compound){
|
|
||||||
this.readSyncableNBT(compound, NBTType.SYNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound getUpdateTag(){
|
public final NBTTagCompound getUpdateTag(){
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
this.writeSyncableNBT(compound, NBTType.SYNC);
|
this.writeSyncableNBT(compound, NBTType.SYNC);
|
||||||
return compound;
|
return compound;
|
||||||
|
@ -172,12 +160,21 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void handleUpdateTag(NBTTagCompound compound){
|
public final void handleUpdateTag(NBTTagCompound compound){
|
||||||
this.receiveSyncCompound(compound);
|
this.readSyncableNBT(compound, NBTType.SYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public final void sendUpdate(){
|
||||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState){
|
if(!this.worldObj.isRemote){
|
||||||
return !oldState.getBlock().isAssociatedBlock(newState.getBlock());
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
this.writeSyncableNBT(compound, NBTType.SYNC);
|
||||||
|
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
data.setTag("Data", compound);
|
||||||
|
data.setInteger("X", this.pos.getX());
|
||||||
|
data.setInteger("Y", this.pos.getY());
|
||||||
|
data.setInteger("Z", this.pos.getZ());
|
||||||
|
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.TILE_ENTITY_HANDLER), new NetworkRegistry.TargetPoint(this.worldObj.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 128));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
||||||
|
@ -192,11 +189,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ITextComponent getDisplayName(){
|
|
||||||
return new TextComponentTranslation("container."+ModUtil.MOD_ID+"."+this.name+".name");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
||||||
super.readFromNBT(compound);
|
super.readFromNBT(compound);
|
||||||
|
|
||||||
|
@ -210,7 +202,17 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState){
|
||||||
|
return !oldState.getBlock().isAssociatedBlock(newState.getBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITextComponent getDisplayName(){
|
||||||
|
return new TextComponentTranslation("container."+ModUtil.MOD_ID+"."+this.name+".name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void update(){
|
||||||
this.updateEntity();
|
this.updateEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,20 +277,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendUpdate(){
|
|
||||||
if(!this.worldObj.isRemote){
|
|
||||||
NBTTagCompound compound = this.getUpdateTag();
|
|
||||||
if(compound != null){
|
|
||||||
NBTTagCompound data = new NBTTagCompound();
|
|
||||||
data.setTag("Data", compound);
|
|
||||||
data.setInteger("X", this.pos.getX());
|
|
||||||
data.setInteger("Y", this.pos.getY());
|
|
||||||
data.setInteger("Z", this.pos.getZ());
|
|
||||||
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.TILE_ENTITY_HANDLER), new NetworkRegistry.TargetPoint(this.worldObj.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 128));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
|
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
|
||||||
return this.getCapability(capability, facing) != null;
|
return this.getCapability(capability, facing) != null;
|
||||||
|
|
|
@ -48,7 +48,10 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveSyncCompound(NBTTagCompound compound){
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
||||||
|
super.readSyncableNBT(compound, type);
|
||||||
|
|
||||||
|
if(type == NBTType.SYNC){
|
||||||
ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
||||||
|
|
||||||
NBTTagList list = compound.getTagList("Connections", 10);
|
NBTTagList list = compound.getTagList("Connections", 10);
|
||||||
|
@ -58,14 +61,14 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj, pair.suppressConnectionRender);
|
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj, pair.suppressConnectionRender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.receiveSyncCompound(compound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound getUpdateTag(){
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
||||||
NBTTagCompound compound = super.getUpdateTag();
|
super.writeSyncableNBT(compound, type);
|
||||||
|
|
||||||
|
if(type == NBTType.SYNC){
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
ConcurrentSet<ConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
ConcurrentSet<ConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
||||||
|
@ -76,7 +79,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
compound.setTag("Connections", list);
|
compound.setTag("Connections", list);
|
||||||
return compound;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue