From dc54551d0c98828eff6a892ffd26b8c2386b4318 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 10 Nov 2019 16:36:36 +0100 Subject: [PATCH] fix area effect cloud add 1.14 particle type --- .../metadata/types/MetaType1_14.java | 2 +- .../us/myles/ViaVersion/api/type/Type.java | 3 ++ .../types/minecraft/Particle1_14Type.java | 46 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Particle1_14Type.java diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_14.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_14.java index 86a6418bb..013ee97e3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_14.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/types/MetaType1_14.java @@ -24,7 +24,7 @@ public enum MetaType1_14 implements MetaType { OptUUID(12, Type.OPTIONAL_UUID), BlockID(13, Type.VAR_INT), NBTTag(14, Type.NBT), - PARTICLE(15, Protocol1_13_2To1_13_1.PARTICLE_TYPE), + PARTICLE(15, Type.PARTICLE_1_14), VillagerData(16, Type.VILLAGER_DATA), OptVarInt(17, Type.OPTIONAL_VAR_INT), Pose(18, Type.VAR_INT), diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java index 25c6cd0ab..2262d7c05 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.minecraft.*; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.type.types.*; import us.myles.ViaVersion.api.type.types.minecraft.*; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import java.util.UUID; @@ -76,6 +77,8 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type VILLAGER_DATA = new VillagerDataType(); + public static final Type PARTICLE_1_14 = new Particle1_14Type(); + /* 1.13 Flat Item (no data) */ public static final Type FLAT_ITEM = new FlatItemType(); public static final Type FLAT_VAR_INT_ITEM = new FlatVarIntItemType(); diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Particle1_14Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Particle1_14Type.java new file mode 100644 index 000000000..35dd30fa8 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Particle1_14Type.java @@ -0,0 +1,46 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import io.netty.buffer.ByteBuf; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; + +public class Particle1_14Type extends Type { + + public Particle1_14Type() { + super("Particle", Particle.class); + } + + @Override + public void write(ByteBuf buffer, Particle object) throws Exception { + Type.VAR_INT.write(buffer, object.getId()); + for (Particle.ParticleData data : object.getArguments()) + data.getType().write(buffer, data.getValue()); + } + + @Override + public Particle read(ByteBuf buffer) throws Exception { + int type = Type.VAR_INT.read(buffer); + Particle particle = new Particle(type); + + switch (type) { + // Block / Falling Dust / + case 3: + case 23: + particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, Type.VAR_INT.read(buffer))); // Flat Block + break; + // Dust + case 14: + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Red 0 - 1 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Green 0 - 1 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Blue 0 - 1 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer)));// Scale 0.01 - 4 + break; + // Item + case 32: + particle.getArguments().add(new Particle.ParticleData(Type.FLAT_VAR_INT_ITEM, Type.FLAT_VAR_INT_ITEM.read(buffer))); // Flat item + break; + } + return particle; + } +} +