Skip to content

Instantly share code, notes, and snippets.

@RandomOnlineName
Created June 2, 2020 12:44
Show Gist options
  • Save RandomOnlineName/419646ca18bf5c093a2db8a22984e2a7 to your computer and use it in GitHub Desktop.
Save RandomOnlineName/419646ca18bf5c093a2db8a22984e2a7 to your computer and use it in GitHub Desktop.
@Override
public void encode(updateBlockStateMessage message, PacketBuffer buffer) {
buffer.writeInt(message.entity);
buffer.writeFloat(message.BlockStateID);
}
@Override
public updateBlockStateMessage decode(PacketBuffer buffer) {
return new updateBlockStateMessage(buffer.readInt(), buffer.readFloat());
}
@Override
public void handle(updateBlockStateMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
NetworkEvent.Context context = contextSupplier.get();
Optional<World> world;
world = LogicalSidedProvider.CLIENTWORLD.get(context.getDirection().getReceptionSide());
if(context.getDirection() == NetworkDirection.PLAY_TO_CLIENT){
try {
context.enqueueWork(() ->
((FlexibleBlockEntity) world.get().getEntityByID(message.entity))
.blockState = Block.getStateById((int) message.BlockStateID));
context.setPacketHandled(true);
}catch (NullPointerException nullPointerException){
FlexibleBlockMod.LOGGER.info(nullPointerException);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment