1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-07-07 20:34:25 +00:00

Merge branch 'mc-1.16.x' into mc-1.17.x

This commit is contained in:
Jonathan Coates 2021-11-30 22:37:07 +00:00
commit 92fd93c0e0
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
5 changed files with 36 additions and 44 deletions

View File

@ -73,42 +73,14 @@ public boolean isUsable( Player player, boolean ignoreRange )
player.distanceToSqr( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range;
}
protected void writeDescription( @Nonnull CompoundTag nbt )
{
}
protected void readDescription( @Nonnull CompoundTag nbt )
{
}
@Nonnull
@Override
public final ClientboundBlockEntityDataPacket getUpdatePacket()
{
CompoundTag nbt = new CompoundTag();
writeDescription( nbt );
return new ClientboundBlockEntityDataPacket( worldPosition, 0, nbt );
}
@Override
public final void onDataPacket( Connection net, ClientboundBlockEntityDataPacket packet )
{
if( packet.getType() == 0 ) readDescription( packet.getTag() );
}
@Nonnull
@Override
public CompoundTag getUpdateTag()
{
CompoundTag tag = super.getUpdateTag();
writeDescription( tag );
return tag;
if( packet.getType() == 0 ) handleUpdateTag( packet.getTag() );
}
@Override
public void handleUpdateTag( @Nonnull CompoundTag tag )
{
super.handleUpdateTag( tag );
readDescription( tag );
}
}

View File

@ -59,7 +59,7 @@ public void onPlace( @Nonnull BlockState state, @Nonnull Level world, @Nonnull B
super.onPlace( state, world, pos, oldState, isMoving );
BlockEntity tile = world.getBlockEntity( pos );
if( tile instanceof TileComputerBase computer ) computer.updateInputsImmediately( );
if( tile instanceof TileComputerBase computer ) computer.updateInputsImmediately();
}
@Override

View File

@ -24,6 +24,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
@ -383,18 +384,27 @@ public ServerComputer getServerComputer()
// Networking stuff
@Nonnull
@Override
protected void writeDescription( @Nonnull CompoundTag nbt )
public final ClientboundBlockEntityDataPacket getUpdatePacket()
{
super.writeDescription( nbt );
return new ClientboundBlockEntityDataPacket( worldPosition, 0, getUpdateTag() );
}
@Nonnull
@Override
public CompoundTag getUpdateTag()
{
// We need this for pick block on the client side.
CompoundTag 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 CompoundTag nbt )
public void handleUpdateTag( @Nonnull CompoundTag nbt )
{
super.readDescription( nbt );
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
}

View File

@ -17,6 +17,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
@ -236,7 +237,6 @@ private ServerMonitor createServerMonitor()
{
// 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();
BlockEntity te = level.getBlockEntity( toWorldPos( 0, 0 ) );
if( !(te instanceof TileMonitor) ) return null;
@ -249,7 +249,6 @@ public ClientMonitor getClientMonitor()
{
if( clientMonitor != null ) return clientMonitor;
BlockPos pos = getBlockPos();
BlockEntity te = level.getBlockEntity( toWorldPos( 0, 0 ) );
if( !(te instanceof TileMonitor) ) return null;
@ -258,20 +257,29 @@ public ClientMonitor getClientMonitor()
// Networking stuff
@Nonnull
@Override
protected void writeDescription( @Nonnull CompoundTag nbt )
public final ClientboundBlockEntityDataPacket getUpdatePacket()
{
super.writeDescription( nbt );
return new ClientboundBlockEntityDataPacket( worldPosition, 0, getUpdateTag() );
}
@Nonnull
@Override
public final CompoundTag getUpdateTag()
{
CompoundTag 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 CompoundTag nbt )
public final void handleUpdateTag( @Nonnull CompoundTag nbt )
{
super.readDescription( nbt );
super.handleUpdateTag( nbt );
int oldXIndex = xIndex;
int oldYIndex = yIndex;

View File

@ -504,17 +504,19 @@ public void onTileEntityChange()
// Networking stuff
@Nonnull
@Override
protected void writeDescription( @Nonnull CompoundTag nbt )
public CompoundTag getUpdateTag()
{
super.writeDescription( nbt );
CompoundTag nbt = super.getUpdateTag();
brain.writeDescription( nbt );
return nbt;
}
@Override
protected void readDescription( @Nonnull CompoundTag nbt )
public void handleUpdateTag( @Nonnull CompoundTag nbt )
{
super.readDescription( nbt );
super.handleUpdateTag( nbt );
brain.readDescription( nbt );
}