|
17 | 17 | */
|
18 | 18 | package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
|
19 | 19 |
|
| 20 | +import com.viaversion.nbt.tag.CompoundTag; |
| 21 | +import com.viaversion.nbt.tag.FloatTag; |
| 22 | +import com.viaversion.nbt.tag.IntTag; |
| 23 | +import com.viaversion.nbt.tag.ListTag; |
20 | 24 | import com.viaversion.nbt.tag.Tag;
|
21 | 25 | import com.viaversion.viabackwards.ViaBackwards;
|
22 | 26 | import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
@@ -103,12 +107,30 @@ public void registerPackets() {
|
103 | 107 | registryDataRewriter.addEnchantmentEffectRewriter("change_item_damage", tag -> tag.putString("type", "damage_item"));
|
104 | 108 | protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
|
105 | 109 | final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
| 110 | + final RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY); |
106 | 111 | if (registryKey.equals("instrument")) {
|
107 | 112 | wrapper.cancel();
|
108 | 113 | return;
|
109 | 114 | }
|
110 | 115 |
|
111 |
| - final RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY); |
| 116 | + if (registryKey.equals("worldgen/biome")) { |
| 117 | + for (final RegistryEntry entry : entries) { |
| 118 | + if (entry.tag() == null) { |
| 119 | + continue; |
| 120 | + } |
| 121 | + |
| 122 | + final CompoundTag effects = ((CompoundTag) entry.tag()).getCompoundTag("effects"); |
| 123 | + final CompoundTag particle = effects.getCompoundTag("particle"); |
| 124 | + if (particle == null) { |
| 125 | + continue; |
| 126 | + } |
| 127 | + |
| 128 | + final CompoundTag particleOptions = particle.getCompoundTag("options"); |
| 129 | + final String particleType = particleOptions.getString("type"); |
| 130 | + updateParticleFormat(particleOptions, Key.stripMinecraftNamespace(particleType)); |
| 131 | + } |
| 132 | + } |
| 133 | + |
112 | 134 | wrapper.write(Types.REGISTRY_ENTRY_ARRAY, registryDataRewriter.handle(wrapper.user(), registryKey, entries));
|
113 | 135 | });
|
114 | 136 |
|
@@ -427,6 +449,29 @@ public void register() {
|
427 | 449 | });
|
428 | 450 | }
|
429 | 451 |
|
| 452 | + private void updateParticleFormat(final CompoundTag options, final String particleType) { |
| 453 | + // Have to be float lists in older versions |
| 454 | + if ("dust_color_transition".equals(particleType)) { |
| 455 | + replaceColor(options, "from_color"); |
| 456 | + replaceColor(options, "to_color"); |
| 457 | + } else if ("dust".equals(particleType)) { |
| 458 | + replaceColor(options, "color"); |
| 459 | + } |
| 460 | + } |
| 461 | + |
| 462 | + private void replaceColor(final CompoundTag options, final String to_color) { |
| 463 | + final IntTag toColorTag = options.getIntTag(to_color); |
| 464 | + if (toColorTag == null) { |
| 465 | + return; |
| 466 | + } |
| 467 | + |
| 468 | + final int rgb = toColorTag.asInt(); |
| 469 | + final float r = ((rgb >> 16) & 0xFF) / 255F; |
| 470 | + final float g = ((rgb >> 8) & 0xFF) / 255F; |
| 471 | + final float b = (rgb & 0xFF) / 255F; |
| 472 | + options.put(to_color, new ListTag<>(List.of(new FloatTag(r), new FloatTag(g), new FloatTag(b)))); |
| 473 | + } |
| 474 | + |
430 | 475 | private void writePackedRotation(final PacketWrapper wrapper, final float yaw, final float pitch) {
|
431 | 476 | // Pack y and x rot
|
432 | 477 | wrapper.write(Types.BYTE, (byte) Math.floor(yaw * 256F / 360F));
|
|
0 commit comments