mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 12:10:30 +00:00
parent
5927e9bb10
commit
3929dba4a5
@ -73,42 +73,19 @@ public abstract class TileGeneric extends TileEntity
|
||||
player.distanceToSqr( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
|
||||
}
|
||||
|
||||
protected void writeDescription( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
}
|
||||
|
||||
protected void readDescription( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final SUpdateTileEntityPacket getUpdatePacket()
|
||||
{
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
writeDescription( nbt );
|
||||
return new SUpdateTileEntityPacket( worldPosition, 0, nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onDataPacket( NetworkManager net, SUpdateTileEntityPacket packet )
|
||||
{
|
||||
if( packet.getType() == 0 ) readDescription( packet.getTag() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompoundNBT getUpdateTag()
|
||||
{
|
||||
CompoundNBT tag = super.getUpdateTag();
|
||||
writeDescription( tag );
|
||||
return tag;
|
||||
if( packet.getType() == 0 ) handleUpdateTag( packet.getTag() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag( @Nonnull BlockState state, @Nonnull CompoundNBT tag )
|
||||
public final void handleUpdateTag( @Nonnull BlockState state, @Nonnull CompoundNBT tag )
|
||||
{
|
||||
handleUpdateTag( tag );
|
||||
}
|
||||
|
||||
protected void handleUpdateTag( @Nonnull CompoundNBT tag )
|
||||
{
|
||||
super.handleUpdateTag( state, tag );
|
||||
readDescription( tag );
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
@ -387,18 +388,27 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
|
||||
// Networking stuff
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected void writeDescription( @Nonnull CompoundNBT nbt )
|
||||
public final SUpdateTileEntityPacket getUpdatePacket()
|
||||
{
|
||||
super.writeDescription( nbt );
|
||||
return new SUpdateTileEntityPacket( worldPosition, 0, getUpdateTag() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompoundNBT getUpdateTag()
|
||||
{
|
||||
// We need this for pick block on the client side.
|
||||
CompoundNBT nbt = super.getUpdateTag();
|
||||
if( label != null ) nbt.putString( NBT_LABEL, label );
|
||||
if( computerID >= 0 ) nbt.putInt( NBT_ID, computerID );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readDescription( @Nonnull CompoundNBT nbt )
|
||||
public void handleUpdateTag( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
|
||||
computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import dan200.computercraft.shared.util.TickScheduler;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
@ -236,7 +237,6 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
// Otherwise fetch the origin and attempt to get its monitor
|
||||
// Note this may load chunks, but we don't really have a choice here.
|
||||
BlockPos pos = getBlockPos();
|
||||
TileEntity te = level.getBlockEntity( toWorldPos( 0, 0 ) );
|
||||
if( !(te instanceof TileMonitor) ) return null;
|
||||
|
||||
@ -249,7 +249,6 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
if( clientMonitor != null ) return clientMonitor;
|
||||
|
||||
BlockPos pos = getBlockPos();
|
||||
TileEntity te = level.getBlockEntity( toWorldPos( 0, 0 ) );
|
||||
if( !(te instanceof TileMonitor) ) return null;
|
||||
|
||||
@ -258,20 +257,29 @@ public class TileMonitor extends TileGeneric
|
||||
|
||||
// Networking stuff
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected void writeDescription( @Nonnull CompoundNBT nbt )
|
||||
public final SUpdateTileEntityPacket getUpdatePacket()
|
||||
{
|
||||
super.writeDescription( nbt );
|
||||
return new SUpdateTileEntityPacket( worldPosition, 0, getUpdateTag() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final CompoundNBT getUpdateTag()
|
||||
{
|
||||
CompoundNBT nbt = super.getUpdateTag();
|
||||
nbt.putInt( NBT_X, xIndex );
|
||||
nbt.putInt( NBT_Y, yIndex );
|
||||
nbt.putInt( NBT_WIDTH, width );
|
||||
nbt.putInt( NBT_HEIGHT, height );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void readDescription( @Nonnull CompoundNBT nbt )
|
||||
public final void handleUpdateTag( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
super.handleUpdateTag( nbt );
|
||||
|
||||
int oldXIndex = xIndex;
|
||||
int oldYIndex = yIndex;
|
||||
|
@ -495,17 +495,19 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
|
||||
// Networking stuff
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected void writeDescription( @Nonnull CompoundNBT nbt )
|
||||
public CompoundNBT getUpdateTag()
|
||||
{
|
||||
super.writeDescription( nbt );
|
||||
CompoundNBT nbt = super.getUpdateTag();
|
||||
brain.writeDescription( nbt );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readDescription( @Nonnull CompoundNBT nbt )
|
||||
public void handleUpdateTag( @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
super.handleUpdateTag( nbt );
|
||||
brain.readDescription( nbt );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user