use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createRedirectedMessage.
public static CustomPayloadS2CPacket createRedirectedMessage(DimensionType dimension, Packet packet) {
int messageType = 0;
try {
messageType = NetworkState.PLAY.getPacketId(NetworkSide.CLIENTBOUND, packet);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(dimension.getRawId());
buf.writeInt(messageType);
try {
packet.write(buf);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return new CustomPayloadS2CPacket(id_stcRedirected, buf);
}
use of net.minecraft.client.network.packet.CustomPayloadS2CPacket 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.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.
the class NetherPortalGenerator method spawnLoadingIndicator.
public static void spawnLoadingIndicator(ServerWorld world, ObsidianFrame obsidianFrame) {
IntegerAABBInclusive box = obsidianFrame.boxWithoutObsidian;
Vec3d center = new Vec3d((double) (box.h.getX() + box.l.getX() + 1) / 2, (double) (box.h.getY() + box.l.getY() + 1) / 2 - 1, (double) (box.h.getZ() + box.l.getZ() + 1) / 2);
CustomPayloadS2CPacket packet = MyNetwork.createSpawnLoadingIndicator(world.dimension.getType(), center);
McHelper.getEntitiesNearby(world, center, ServerPlayerEntity.class, 64).forEach(player -> player.networkHandler.sendPacket(packet));
}
use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project ImmersivePortalsMod by qouteall.
the class GlobalPortalStorage method onDataChanged.
public void onDataChanged() {
setDirty(true);
CustomPayloadS2CPacket packet = MyNetwork.createGlobalPortalUpdate(this);
McHelper.getCopiedPlayerList().forEach(player -> player.networkHandler.sendPacket(packet));
}
use of net.minecraft.client.network.packet.CustomPayloadS2CPacket in project fabric by FabricMC.
the class ContainerProviderImpl method openContainer.
@Override
public void openContainer(Identifier identifier, ServerPlayerEntity player, Consumer<PacketByteBuf> writer) {
int syncId;
if (player instanceof ServerPlayerEntitySyncHook) {
ServerPlayerEntitySyncHook serverPlayerEntitySyncHook = (ServerPlayerEntitySyncHook) player;
syncId = serverPlayerEntitySyncHook.fabric_incrementSyncId();
} else if (player instanceof ServerPlayerEntityAccessor) {
if (!emittedNoSyncHookWarning) {
LOGGER.warn("ServerPlayerEntitySyncHook could not be applied - fabric-containers is using a hack!");
emittedNoSyncHookWarning = true;
}
syncId = (((ServerPlayerEntityAccessor) player).getContainerSyncId() + 1) % 100;
((ServerPlayerEntityAccessor) player).setContainerSyncId(syncId);
} else {
throw new RuntimeException("Neither ServerPlayerEntitySyncHook nor Accessor present! This should not happen!");
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeIdentifier(identifier);
buf.writeByte(syncId);
writer.accept(buf);
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(PacketTypes.OPEN_CONTAINER, buf));
PacketByteBuf clonedBuf = new PacketByteBuf(buf.duplicate());
clonedBuf.readIdentifier();
clonedBuf.readUnsignedByte();
Container container = createContainer(syncId, identifier, player, clonedBuf);
if (container == null) {
return;
}
player.container = container;
player.container.addListener(player);
}
Aggregations