3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 00:00:33 +01:00

Fix dust/dust_color_transition particles in biome data

Fixes #926
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-12-05 17:16:57 +01:00
Ursprung 9d5cd04d4b
Commit b67d7c076f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F

Datei anzeigen

@ -17,6 +17,10 @@
*/ */
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
@ -103,12 +107,30 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
registryDataRewriter.addEnchantmentEffectRewriter("change_item_damage", tag -> tag.putString("type", "damage_item")); registryDataRewriter.addEnchantmentEffectRewriter("change_item_damage", tag -> tag.putString("type", "damage_item"));
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> { protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
final RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY);
if (registryKey.equals("instrument")) { if (registryKey.equals("instrument")) {
wrapper.cancel(); wrapper.cancel();
return; return;
} }
final RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY); if (registryKey.equals("worldgen/biome")) {
for (final RegistryEntry entry : entries) {
if (entry.tag() == null) {
continue;
}
final CompoundTag effects = ((CompoundTag) entry.tag()).getCompoundTag("effects");
final CompoundTag particle = effects.getCompoundTag("particle");
if (particle == null) {
continue;
}
final CompoundTag particleOptions = particle.getCompoundTag("options");
final String particleType = particleOptions.getString("type");
updateParticleFormat(particleOptions, Key.stripMinecraftNamespace(particleType));
}
}
wrapper.write(Types.REGISTRY_ENTRY_ARRAY, registryDataRewriter.handle(wrapper.user(), registryKey, entries)); wrapper.write(Types.REGISTRY_ENTRY_ARRAY, registryDataRewriter.handle(wrapper.user(), registryKey, entries));
}); });
@ -427,6 +449,29 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
}); });
} }
private void updateParticleFormat(final CompoundTag options, final String particleType) {
// Have to be float lists in older versions
if ("dust_color_transition".equals(particleType)) {
replaceColor(options, "from_color");
replaceColor(options, "to_color");
} else if ("dust".equals(particleType)) {
replaceColor(options, "color");
}
}
private void replaceColor(final CompoundTag options, final String to_color) {
final IntTag toColorTag = options.getIntTag(to_color);
if (toColorTag == null) {
return;
}
final int rgb = toColorTag.asInt();
final float r = ((rgb >> 16) & 0xFF) / 255F;
final float g = ((rgb >> 8) & 0xFF) / 255F;
final float b = (rgb & 0xFF) / 255F;
options.put(to_color, new ListTag<>(List.of(new FloatTag(r), new FloatTag(g), new FloatTag(b))));
}
private void writePackedRotation(final PacketWrapper wrapper, final float yaw, final float pitch) { private void writePackedRotation(final PacketWrapper wrapper, final float yaw, final float pitch) {
// Pack y and x rot // Pack y and x rot
wrapper.write(Types.BYTE, (byte) Math.floor(yaw * 256F / 360F)); wrapper.write(Types.BYTE, (byte) Math.floor(yaw * 256F / 360F));