use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetworkClient method processRedirectedMessage.
public static void processRedirectedMessage(PacketContext context, PacketByteBuf buf) {
int dimensionId = buf.readInt();
int messageType = buf.readInt();
DimensionType dimension = DimensionType.byRawId(dimensionId);
Packet packet = MyNetwork.createEmptyPacketByType(messageType);
try {
packet.read(buf);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
if (dimension == null) {
Helper.err(String.format("Invalid redirected packet %s %s \nRegistered dimensions %s", dimensionId, packet, Registry.DIMENSION.stream().map(dim -> dim.toString() + " " + dim.getRawId()).collect(Collectors.joining("\n"))));
return;
}
processRedirectedPacket(dimension, packet);
}
use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createStcSpawnEntity.
// NOTE my packet is redirected but I cannot get the packet handler info here
public static CustomPayloadS2CPacket createStcSpawnEntity(Entity entity) {
EntityType entityType = entity.getType();
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeString(EntityType.getId(entityType).toString());
buf.writeInt(entity.getEntityId());
buf.writeInt(entity.dimension.getRawId());
CompoundTag tag = new CompoundTag();
entity.toTag(tag);
buf.writeCompoundTag(tag);
return new CustomPayloadS2CPacket(id_stcSpawnEntity, buf);
}
use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createSpawnLoadingIndicator.
public static CustomPayloadS2CPacket createSpawnLoadingIndicator(DimensionType dimensionType, Vec3d pos) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(dimensionType.getRawId());
buf.writeDouble(pos.x);
buf.writeDouble(pos.y);
buf.writeDouble(pos.z);
return new CustomPayloadS2CPacket(id_stcSpawnLoadingIndicator, buf);
}
use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.
the class TweedClothBridge method open.
public Screen open() {
inGame = MinecraftClient.getInstance().world != null;
parentScreen = MinecraftClient.getInstance().currentScreen;
if (inGame) {
boolean requiresSync = false;
for (ConfigFileEntry entry : configFiles) {
if (entry.configFile.getRootCategory().entryStream().anyMatch(configEntry -> configEntry.getValue().getEnvironment() != ConfigEnvironment.CLIENT)) {
requiresSync = true;
break;
}
}
if (!requiresSync) {
return buildScreen();
}
for (ConfigFileEntry entry : configFiles) {
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
buffer.writeString(entry.configFile.getName());
buffer.writeEnumConstant(ConfigEnvironment.UNIVERSAL);
buffer.writeEnumConstant(ConfigScope.SMALLEST);
buffer.writeEnumConstant(ConfigOrigin.MAIN);
ClientSidePacketRegistry.INSTANCE.sendToServer(Tweed.REQUEST_SYNC_C2S_PACKET, buffer);
entry.awaitSync = true;
}
ClientCore.scheduledClothBridge = this;
return new NoticeScreen(() -> {
MinecraftClient.getInstance().openScreen(parentScreen);
ClientCore.scheduledClothBridge = null;
}, new TranslatableText("tweed.gui.screen.syncFromServer"), new TranslatableText("tweed.gui.screen.syncFromServer.note"));
} else {
return buildScreen();
}
}
use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.
the class MixinClientPlayNetworkHandler method onGameJoined.
@Inject(method = "onGameJoin", at = @At("RETURN"), require = 0)
public void onGameJoined(GameJoinS2CPacket packet, CallbackInfo callbackInfo) {
for (ConfigFile configFile : TweedRegistry.getConfigFiles()) {
Tweed.LOGGER.info("Requested config sync for " + configFile.getName());
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeString(configFile.getName());
packetByteBuf.writeEnumConstant(ConfigEnvironment.SYNCED);
packetByteBuf.writeEnumConstant(ConfigScope.WORLD);
packetByteBuf.writeEnumConstant(ConfigOrigin.DATAPACK);
ClientSidePacketRegistry.INSTANCE.sendToServer(Tweed.REQUEST_SYNC_C2S_PACKET, packetByteBuf);
}
}
Aggregations