use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createGlobalPortalUpdate.
public static CustomPayloadS2CPacket createGlobalPortalUpdate(GlobalPortalStorage storage) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(storage.world.get().dimension.getType().getRawId());
buf.writeCompoundTag(storage.toTag(new CompoundTag()));
return new CustomPayloadS2CPacket(id_stcUpdateGlobalPortal, buf);
}
use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetworkClient method createCtsTeleport.
public static CustomPayloadC2SPacket createCtsTeleport(DimensionType dimensionBefore, Vec3d posBefore, UUID portalEntityId) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(dimensionBefore.getRawId());
buf.writeDouble(posBefore.x);
buf.writeDouble(posBefore.y);
buf.writeDouble(posBefore.z);
buf.writeUuid(portalEntityId);
return new CustomPayloadC2SPacket(MyNetwork.id_ctsTeleport, buf);
}
use of net.minecraft.util.PacketByteBuf in project FastAsyncWorldEdit by IntellectualSites.
the class FabricPlayer method dispatchCUIEvent.
@Override
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
ServerPlayNetworking.send(this.player, WECUIPacketHandler.CUI_IDENTIFIER, new PacketByteBuf(Unpooled.copiedBuffer(send, StandardCharsets.UTF_8)));
}
use of net.minecraft.util.PacketByteBuf in project FastAsyncWorldEdit by IntellectualSites.
the class FabricPlayer method sendFakeBlock.
@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
World world = getWorld();
if (!(world instanceof FabricWorld)) {
return;
}
BlockPos loc = FabricAdapter.toBlockPos(pos);
if (block == null) {
final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket(((FabricWorld) world).getWorld(), loc);
player.networkHandler.sendPacket(packetOut);
} else {
final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket();
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeBlockPos(loc);
buf.writeVarInt(Block.getRawIdFromState(FabricAdapter.adapt(block.toImmutableState())));
try {
packetOut.read(buf);
} catch (IOException e) {
return;
}
player.networkHandler.sendPacket(packetOut);
if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
final BaseBlock baseBlock = (BaseBlock) block;
final CompoundTag nbtData = baseBlock.getNbtData();
if (nbtData != null) {
player.networkHandler.sendPacket(new BlockEntityUpdateS2CPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
}
}
}
}
use of net.minecraft.util.PacketByteBuf in project nbt-crafting by Siphalor.
the class NbtCrafting method onInitialize.
@Override
public void onInitialize() {
ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> {
sender.sendPacket(PRESENCE_CHANNEL, new PacketByteBuf(Unpooled.buffer()));
});
ServerLoginConnectionEvents.DISCONNECT.register((handler, server) -> {
hasModClientConnectionHashes.remove(handler.client.hashCode());
});
ServerLoginNetworking.registerGlobalReceiver(PRESENCE_CHANNEL, (server, handler, understood, buf, synchronizer, responseSender) -> {
if (understood) {
hasModClientConnectionHashes.add(handler.client.hashCode());
}
});
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
if (hasModClientConnectionHashes.contains(handler.client.hashCode())) {
((IServerPlayerEntity) handler.player).nbtCrafting$setClientModPresent(true);
hasModClientConnectionHashes.remove(handler.client.hashCode());
}
});
}
Aggregations