mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
packet conversion
This commit is contained in:
parent
852ea30b63
commit
9010b9708e
5 changed files with 163 additions and 164 deletions
|
@ -5,18 +5,22 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||||
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
||||||
import de.ellpeck.naturesaura.events.ClientEvents;
|
import de.ellpeck.naturesaura.events.ClientEvents;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.neoforged.neoforge.network.NetworkEvent;
|
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PacketAuraChunk {
|
public class PacketAuraChunk implements CustomPacketPayload {
|
||||||
|
|
||||||
private int chunkX;
|
public static final ResourceLocation ID = new ResourceLocation(NaturesAura.MOD_ID, "aura_chunk");
|
||||||
private int chunkZ;
|
|
||||||
private Collection<AuraChunk.DrainSpot> drainSpots;
|
private final int chunkX;
|
||||||
|
private final int chunkZ;
|
||||||
|
private final Collection<AuraChunk.DrainSpot> drainSpots;
|
||||||
|
|
||||||
public PacketAuraChunk(int chunkX, int chunkZ, Collection<AuraChunk.DrainSpot> drainSpots) {
|
public PacketAuraChunk(int chunkX, int chunkZ, Collection<AuraChunk.DrainSpot> drainSpots) {
|
||||||
this.chunkX = chunkX;
|
this.chunkX = chunkX;
|
||||||
|
@ -24,34 +28,33 @@ public class PacketAuraChunk {
|
||||||
this.drainSpots = drainSpots;
|
this.drainSpots = drainSpots;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketAuraChunk() {
|
public PacketAuraChunk(FriendlyByteBuf buf) {
|
||||||
}
|
this.chunkX = buf.readInt();
|
||||||
|
this.chunkZ = buf.readInt();
|
||||||
|
|
||||||
public static PacketAuraChunk fromBytes(FriendlyByteBuf buf) {
|
this.drainSpots = new ArrayList<>();
|
||||||
var packet = new PacketAuraChunk();
|
|
||||||
packet.chunkX = buf.readInt();
|
|
||||||
packet.chunkZ = buf.readInt();
|
|
||||||
|
|
||||||
packet.drainSpots = new ArrayList<>();
|
|
||||||
var amount = buf.readInt();
|
var amount = buf.readInt();
|
||||||
for (var i = 0; i < amount; i++)
|
for (var i = 0; i < amount; i++)
|
||||||
packet.drainSpots.add(new AuraChunk.DrainSpot(buf.readNbt()));
|
this.drainSpots.add(new AuraChunk.DrainSpot(buf.readNbt()));
|
||||||
|
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toBytes(PacketAuraChunk packet, FriendlyByteBuf buf) {
|
@Override
|
||||||
buf.writeInt(packet.chunkX);
|
public void write(FriendlyByteBuf buf) {
|
||||||
buf.writeInt(packet.chunkZ);
|
buf.writeInt(this.chunkX);
|
||||||
|
buf.writeInt(this.chunkZ);
|
||||||
|
|
||||||
buf.writeInt(packet.drainSpots.size());
|
buf.writeInt(this.drainSpots.size());
|
||||||
for (var entry : packet.drainSpots)
|
for (var entry : this.drainSpots)
|
||||||
buf.writeNbt(entry.serializeNBT());
|
buf.writeNbt(entry.serializeNBT());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onMessage(PacketAuraChunk message, Supplier<NetworkEvent.Context> ctx) {
|
@Override
|
||||||
ctx.get().enqueueWork(() -> ClientEvents.PENDING_AURA_CHUNKS.add(message));
|
public ResourceLocation id() {
|
||||||
ctx.get().setPacketHandled(true);
|
return PacketAuraChunk.ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onMessage(PacketAuraChunk message, PlayPayloadContext ctx) {
|
||||||
|
ctx.workHandler().execute(() -> ClientEvents.PENDING_AURA_CHUNKS.add(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tryHandle(Level level) {
|
public boolean tryHandle(Level level) {
|
||||||
|
@ -69,4 +72,5 @@ public class PacketAuraChunk {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.ellpeck.naturesaura.packet;
|
package de.ellpeck.naturesaura.packet;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
|
import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
|
||||||
import de.ellpeck.naturesaura.items.ModItems;
|
import de.ellpeck.naturesaura.items.ModItems;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -7,45 +8,42 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.network.NetworkEvent;
|
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
public class PacketClient implements CustomPacketPayload {
|
||||||
|
|
||||||
public class PacketClient {
|
public static final ResourceLocation ID = new ResourceLocation(NaturesAura.MOD_ID, "client");
|
||||||
|
|
||||||
private int type;
|
private final int type;
|
||||||
private CompoundTag data;
|
private final CompoundTag data;
|
||||||
|
|
||||||
public PacketClient(int type, CompoundTag data) {
|
public PacketClient(int type, CompoundTag data) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketClient() {
|
public PacketClient(FriendlyByteBuf buf) {
|
||||||
|
this.type = buf.readByte();
|
||||||
|
this.data = buf.readNbt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketClient fromBytes(FriendlyByteBuf buf) {
|
|
||||||
var client = new PacketClient();
|
|
||||||
client.type = buf.readByte();
|
|
||||||
client.data = buf.readNbt();
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void toBytes(PacketClient packet, FriendlyByteBuf buf) {
|
|
||||||
buf.writeByte(packet.type);
|
|
||||||
buf.writeNbt(packet.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// lambda causes classloading issues on a server here
|
|
||||||
@SuppressWarnings("Convert2Lambda")
|
|
||||||
public static void onMessage(PacketClient message, Supplier<NetworkEvent.Context> ctx) {
|
|
||||||
ctx.get().enqueueWork(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void write(FriendlyByteBuf buf) {
|
||||||
|
buf.writeByte(this.type);
|
||||||
|
buf.writeNbt(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation id() {
|
||||||
|
return PacketClient.ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onMessage(PacketClient message, PlayPayloadContext ctx) {
|
||||||
|
ctx.workHandler().execute(() -> {
|
||||||
var mc = Minecraft.getInstance();
|
var mc = Minecraft.getInstance();
|
||||||
if (mc.level != null) {
|
if (mc.level != null) {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
|
@ -62,8 +60,7 @@ public class PacketClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,36 +2,37 @@ package de.ellpeck.naturesaura.packet;
|
||||||
|
|
||||||
import de.ellpeck.naturesaura.NaturesAura;
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import net.neoforged.neoforge.network.simple.SimpleChannel;
|
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
|
||||||
import net.neoforged.neoforge.network.NetworkRegistry;
|
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber
|
||||||
public final class PacketHandler {
|
public final class PacketHandler {
|
||||||
|
|
||||||
private static final String VERSION = "1";
|
@SubscribeEvent
|
||||||
private static SimpleChannel network;
|
public static void onPayloadRegister(RegisterPayloadHandlerEvent event) {
|
||||||
|
var registrar = event.registrar(NaturesAura.MOD_ID);
|
||||||
public static void init() {
|
registrar.play(PacketAuraChunk.ID, PacketAuraChunk::new, PacketAuraChunk::onMessage);
|
||||||
PacketHandler.network = NetworkRegistry.newSimpleChannel(new ResourceLocation(NaturesAura.MOD_ID, "network"), () -> PacketHandler.VERSION, PacketHandler.VERSION::equals, PacketHandler.VERSION::equals);
|
registrar.play(PacketClient.ID, PacketClient::new, PacketClient::onMessage);
|
||||||
PacketHandler.network.registerMessage(0, PacketParticleStream.class, PacketParticleStream::toBytes, PacketParticleStream::fromBytes, PacketParticleStream::onMessage);
|
registrar.play(PacketParticles.ID, PacketParticles::new, PacketParticles::onMessage);
|
||||||
PacketHandler.network.registerMessage(1, PacketParticles.class, PacketParticles::toBytes, PacketParticles::fromBytes, PacketParticles::onMessage);
|
registrar.play(PacketParticleStream.ID, PacketParticleStream::new, PacketParticleStream::onMessage);
|
||||||
PacketHandler.network.registerMessage(2, PacketAuraChunk.class, PacketAuraChunk::toBytes, PacketAuraChunk::fromBytes, PacketAuraChunk::onMessage);
|
|
||||||
PacketHandler.network.registerMessage(3, PacketClient.class, PacketClient::toBytes, PacketClient::fromBytes, PacketClient::onMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendToAllLoaded(Level level, BlockPos pos, Object message) {
|
public static void sendToAllLoaded(Level level, BlockPos pos, CustomPacketPayload message) {
|
||||||
PacketHandler.network.send(PacketDistributor.TRACKING_CHUNK.with(() -> level.getChunkAt(pos)), message);
|
PacketDistributor.TRACKING_CHUNK.with(level.getChunkAt(pos)).send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendToAllAround(Level level, BlockPos pos, int range, Object message) {
|
public static void sendToAllAround(Level level, BlockPos pos, int range, CustomPacketPayload message) {
|
||||||
PacketHandler.network.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), range, level.dimension())), message);
|
PacketDistributor.NEAR.with(new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), range, level.dimension())).send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendTo(Player player, Object message) {
|
public static void sendTo(Player player, CustomPacketPayload message) {
|
||||||
PacketHandler.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), message);
|
((ServerPlayer) player).connection.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
package de.ellpeck.naturesaura.packet;
|
package de.ellpeck.naturesaura.packet;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.neoforged.neoforge.network.NetworkEvent;
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
public class PacketParticleStream implements CustomPacketPayload {
|
||||||
|
|
||||||
public class PacketParticleStream {
|
public static final ResourceLocation ID = new ResourceLocation(NaturesAura.MOD_ID, "particle_stream");
|
||||||
|
|
||||||
private float startX;
|
private final float startX;
|
||||||
private float startY;
|
private final float startY;
|
||||||
private float startZ;
|
private final float startZ;
|
||||||
|
|
||||||
private float endX;
|
private final float endX;
|
||||||
private float endY;
|
private final float endY;
|
||||||
private float endZ;
|
private final float endZ;
|
||||||
|
|
||||||
private float speed;
|
private final float speed;
|
||||||
private int color;
|
private final int color;
|
||||||
private float scale;
|
private final float scale;
|
||||||
|
|
||||||
public PacketParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) {
|
public PacketParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) {
|
||||||
this.startX = startX;
|
this.startX = startX;
|
||||||
|
@ -32,43 +35,41 @@ public class PacketParticleStream {
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketParticleStream() {
|
public PacketParticleStream(FriendlyByteBuf buf) {
|
||||||
|
this.startX = buf.readFloat();
|
||||||
|
this.startY = buf.readFloat();
|
||||||
|
this.startZ = buf.readFloat();
|
||||||
|
this.endX = buf.readFloat();
|
||||||
|
this.endY = buf.readFloat();
|
||||||
|
this.endZ = buf.readFloat();
|
||||||
|
this.speed = buf.readFloat();
|
||||||
|
this.color = buf.readInt();
|
||||||
|
this.scale = buf.readFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketParticleStream fromBytes(FriendlyByteBuf buf) {
|
@Override
|
||||||
var packet = new PacketParticleStream();
|
public void write(FriendlyByteBuf buf) {
|
||||||
|
buf.writeFloat(this.startX);
|
||||||
packet.startX = buf.readFloat();
|
buf.writeFloat(this.startY);
|
||||||
packet.startY = buf.readFloat();
|
buf.writeFloat(this.startZ);
|
||||||
packet.startZ = buf.readFloat();
|
buf.writeFloat(this.endX);
|
||||||
packet.endX = buf.readFloat();
|
buf.writeFloat(this.endY);
|
||||||
packet.endY = buf.readFloat();
|
buf.writeFloat(this.endZ);
|
||||||
packet.endZ = buf.readFloat();
|
buf.writeFloat(this.speed);
|
||||||
packet.speed = buf.readFloat();
|
buf.writeInt(this.color);
|
||||||
packet.color = buf.readInt();
|
buf.writeFloat(this.scale);
|
||||||
packet.scale = buf.readFloat();
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toBytes(PacketParticleStream packet, FriendlyByteBuf buf) {
|
@Override
|
||||||
buf.writeFloat(packet.startX);
|
public ResourceLocation id() {
|
||||||
buf.writeFloat(packet.startY);
|
return PacketParticleStream.ID;
|
||||||
buf.writeFloat(packet.startZ);
|
|
||||||
buf.writeFloat(packet.endX);
|
|
||||||
buf.writeFloat(packet.endY);
|
|
||||||
buf.writeFloat(packet.endZ);
|
|
||||||
buf.writeFloat(packet.speed);
|
|
||||||
buf.writeInt(packet.color);
|
|
||||||
buf.writeFloat(packet.scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onMessage(PacketParticleStream message, Supplier<NetworkEvent.Context> ctx) {
|
public static void onMessage(PacketParticleStream message, PlayPayloadContext ctx) {
|
||||||
ctx.get().enqueueWork(() -> NaturesAuraAPI.instance().spawnParticleStream(
|
ctx.workHandler().execute(() -> NaturesAuraAPI.instance().spawnParticleStream(
|
||||||
message.startX, message.startY, message.startZ,
|
message.startX, message.startY, message.startZ,
|
||||||
message.endX, message.endY, message.endZ,
|
message.endX, message.endY, message.endZ,
|
||||||
message.speed, message.color, message.scale));
|
message.speed, message.color, message.scale));
|
||||||
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.ellpeck.naturesaura.packet;
|
package de.ellpeck.naturesaura.packet;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||||
|
@ -11,19 +12,22 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.particles.ItemParticleOption;
|
import net.minecraft.core.particles.ItemParticleOption;
|
||||||
import net.minecraft.core.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.neoforged.neoforge.network.NetworkEvent;
|
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class PacketParticles {
|
public class PacketParticles implements CustomPacketPayload {
|
||||||
|
|
||||||
private float posX;
|
public static final ResourceLocation ID = new ResourceLocation(NaturesAura.MOD_ID, "particles");
|
||||||
private float posY;
|
|
||||||
private float posZ;
|
private final float posX;
|
||||||
private Type type;
|
private final float posY;
|
||||||
private int[] data;
|
private final float posZ;
|
||||||
|
private final Type type;
|
||||||
|
private final int[] data;
|
||||||
|
|
||||||
public PacketParticles(float posX, float posY, float posZ, Type type, int... data) {
|
public PacketParticles(float posX, float posY, float posZ, Type type, int... data) {
|
||||||
this.posX = posX;
|
this.posX = posX;
|
||||||
|
@ -33,49 +37,40 @@ public class PacketParticles {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketParticles() {
|
public PacketParticles(FriendlyByteBuf buf) {
|
||||||
|
this.posX = buf.readFloat();
|
||||||
|
this.posY = buf.readFloat();
|
||||||
|
this.posZ = buf.readFloat();
|
||||||
|
this.type = Type.values()[buf.readByte()];
|
||||||
|
|
||||||
|
this.data = new int[buf.readByte()];
|
||||||
|
for (var i = 0; i < this.data.length; i++)
|
||||||
|
this.data[i] = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketParticles fromBytes(FriendlyByteBuf buf) {
|
@Override
|
||||||
var packet = new PacketParticles();
|
public void write(FriendlyByteBuf buf) {
|
||||||
|
buf.writeFloat(this.posX);
|
||||||
|
buf.writeFloat(this.posY);
|
||||||
|
buf.writeFloat(this.posZ);
|
||||||
|
buf.writeByte(this.type.ordinal());
|
||||||
|
|
||||||
packet.posX = buf.readFloat();
|
buf.writeByte(this.data.length);
|
||||||
packet.posY = buf.readFloat();
|
for (var i : this.data)
|
||||||
packet.posZ = buf.readFloat();
|
|
||||||
packet.type = Type.values()[buf.readByte()];
|
|
||||||
|
|
||||||
packet.data = new int[buf.readByte()];
|
|
||||||
for (var i = 0; i < packet.data.length; i++) {
|
|
||||||
packet.data[i] = buf.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void toBytes(PacketParticles packet, FriendlyByteBuf buf) {
|
|
||||||
buf.writeFloat(packet.posX);
|
|
||||||
buf.writeFloat(packet.posY);
|
|
||||||
buf.writeFloat(packet.posZ);
|
|
||||||
buf.writeByte(packet.type.ordinal());
|
|
||||||
|
|
||||||
buf.writeByte(packet.data.length);
|
|
||||||
for (var i : packet.data) {
|
|
||||||
buf.writeInt(i);
|
buf.writeInt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation id() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lambda causes classloading issues on a server here
|
public static void onMessage(PacketParticles message, PlayPayloadContext ctx) {
|
||||||
@SuppressWarnings("Convert2Lambda")
|
ctx.workHandler().execute(() -> {
|
||||||
public static void onMessage(PacketParticles message, Supplier<NetworkEvent.Context> ctx) {
|
|
||||||
ctx.get().enqueueWork(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Level level = Minecraft.getInstance().level;
|
Level level = Minecraft.getInstance().level;
|
||||||
if (level != null)
|
if (level != null)
|
||||||
message.type.action.accept(message, level);
|
message.type.action.accept(message, level);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
|
@ -578,4 +573,5 @@ public class PacketParticles {
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue