From a203c17e0691db1c6e8d25ed61ebdd4c79b2c015 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 2 Feb 2019 11:21:19 -0200 Subject: [PATCH 1/2] Fix reddust, particle metadata rewriting, translations --- .../protocol1_13to1_12_2/MetadataRewriter.java | 4 +++- .../protocol1_13to1_12_2/data/MappingData.java | 2 +- .../data/ParticleRewriter.java | 15 +++++++-------- .../packets/WorldPackets.java | 11 ++++++++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java index a838d96a1..431bccf94 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java @@ -98,7 +98,9 @@ public class MetadataRewriter { // Handle AreaEffectCloud outside the loop if (type != null && type.is(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) && particleId != -1) { Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2}); - metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle)); + if (particle != null && particle.getId() != -1) { + metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle)); + } } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index 0e9322060..8dcbff56a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -67,7 +67,7 @@ public class MappingData { String[] keyAndTranslation = line.split("=", 2); if (keyAndTranslation.length != 2) continue; String key = keyAndTranslation[0]; - String translation = keyAndTranslation[1]; + String translation = keyAndTranslation[1].replaceAll("%(\\d\\$)?d", "%$1s"); if (!translateData.containsKey(key)) { translateMapping.put(key, translation); } else { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index 804c09f12..e700ac779 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -11,11 +11,10 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; public class ParticleRewriter { private static List particles = new LinkedList<>(); - private static Random rand = new Random(); static { add(34); // (0->34) explode -> minecraft:poof @@ -108,17 +107,17 @@ public class ParticleRewriter { return new ParticleDataHandler() { @Override public Particle handler(Particle particle, Integer[] data) { - particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomFloat())); // Red 0 - 1 - particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomFloat())); // Green 0 - 1 - particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomFloat())); // Blue 0 - 1 - particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 1));// Scale 0.01 - 4 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomBool() ? 1f : 0f)); // Red 0 - 1 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 0f)); // Green 0 - 1 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomBool() ? 1f : 0f)); // Blue 0 - 1 + particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 1f));// Scale 0.01 - 4 return particle; } }; } - private static float randomFloat() { - return rand.nextFloat(); + private static boolean randomBool() { + return ThreadLocalRandom.current().nextBoolean(); } // Rewrite IconCrack items to new format :) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 0c932eaf6..be1d08ea2 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -415,15 +415,20 @@ public class WorldPackets { if (particle.getId() == 11) { int count = wrapper.get(Type.INT, 1); float speed = wrapper.get(Type.FLOAT, 6); - // Only handle for count = 0 & speed = 1 - if (count == 0 && speed == 1) { + // Only handle for count = 0 + if (count == 0) { wrapper.set(Type.INT, 1, 1); wrapper.set(Type.FLOAT, 6, 0f); List arguments = particle.getArguments(); for (int i = 0; i < 3; i++) { //RGB values are represented by the X/Y/Z offset - arguments.get(i).setValue(wrapper.get(Type.FLOAT, i + 3)); + float colorValue = wrapper.get(Type.FLOAT, i + 3) * speed; + if (colorValue == 0 && i == 0) { + // https://minecraft.gamepedia.com/User:Alphappy/reddust + colorValue = 1; + } + arguments.get(i).setValue(colorValue); wrapper.set(Type.FLOAT, i + 3, 0f); } } From 9a92d180d0d2819d8e2b55506e1fe9d7e877c26d Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Wed, 23 Jan 2019 14:03:10 -0200 Subject: [PATCH 2/2] Fix typo --- .../protocol1_13to1_12_2/packets/InventoryPackets.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 2b1866c1a..cf4312d22 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -615,7 +615,7 @@ public class InventoryPackets { ench.add(enchEntry); } } - tag.remove("Enchantment"); + tag.remove("Enchantments"); tag.put(ench); } if (tag.get("StoredEnchantments") instanceof ListTag) {