Lots of renames

This commit is contained in:
Nassim Jahnke 2024-05-11 14:55:38 +02:00
parent 5e7371d39b
commit a946632e8b
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
211 changed files with 6860 additions and 6786 deletions

View File

@ -23,7 +23,7 @@ import com.viaversion.viabackwards.listener.FireDamageListener;
import com.viaversion.viabackwards.listener.FireExtinguishListener; import com.viaversion.viabackwards.listener.FireExtinguishListener;
import com.viaversion.viabackwards.listener.LecternInteractListener; import com.viaversion.viabackwards.listener.LecternInteractListener;
import com.viaversion.viabackwards.listener.PlayerItemDropListener; import com.viaversion.viabackwards.listener.PlayerItemDropListener;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.provider.AdvancementCriteriaProvider; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.provider.AdvancementCriteriaProvider;
import com.viaversion.viabackwards.provider.BukkitAdvancementCriteriaProvider; import com.viaversion.viabackwards.provider.BukkitAdvancementCriteriaProvider;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.platform.providers.ViaProviders;

View File

@ -18,7 +18,7 @@
package com.viaversion.viabackwards.listener; package com.viaversion.viabackwards.listener;
import com.viaversion.viabackwards.BukkitPlugin; import com.viaversion.viabackwards.BukkitPlugin;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener; import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.SoundCategory; import org.bukkit.SoundCategory;
@ -31,7 +31,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
public class FireDamageListener extends ViaBukkitListener { public class FireDamageListener extends ViaBukkitListener {
public FireDamageListener(BukkitPlugin plugin) { public FireDamageListener(BukkitPlugin plugin) {
super(plugin, Protocol1_11_1To1_12.class); super(plugin, Protocol1_12To1_11_1.class);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -18,7 +18,7 @@
package com.viaversion.viabackwards.listener; package com.viaversion.viabackwards.listener;
import com.viaversion.viabackwards.BukkitPlugin; import com.viaversion.viabackwards.BukkitPlugin;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener; import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -31,7 +31,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
public class FireExtinguishListener extends ViaBukkitListener { public class FireExtinguishListener extends ViaBukkitListener {
public FireExtinguishListener(BukkitPlugin plugin) { public FireExtinguishListener(BukkitPlugin plugin) {
super(plugin, Protocol1_15_2To1_16.class); super(plugin, Protocol1_16To1_15_2.class);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -18,7 +18,7 @@
package com.viaversion.viabackwards.listener; package com.viaversion.viabackwards.listener;
import com.viaversion.viabackwards.BukkitPlugin; import com.viaversion.viabackwards.BukkitPlugin;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import com.viaversion.viabackwards.protocol.v1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener; import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -33,7 +33,7 @@ import org.bukkit.inventory.meta.BookMeta;
public class LecternInteractListener extends ViaBukkitListener { public class LecternInteractListener extends ViaBukkitListener {
public LecternInteractListener(BukkitPlugin plugin) { public LecternInteractListener(BukkitPlugin plugin) {
super(plugin, Protocol1_13_2To1_14.class); super(plugin, Protocol1_14To1_13_2.class);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -19,7 +19,7 @@
package com.viaversion.viabackwards.listener; package com.viaversion.viabackwards.listener;
import com.viaversion.viabackwards.BukkitPlugin; import com.viaversion.viabackwards.BukkitPlugin;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener; import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -30,7 +30,7 @@ import org.bukkit.inventory.ItemStack;
public class PlayerItemDropListener extends ViaBukkitListener { public class PlayerItemDropListener extends ViaBukkitListener {
public PlayerItemDropListener(final BukkitPlugin plugin) { public PlayerItemDropListener(final BukkitPlugin plugin) {
super(plugin, Protocol1_13To1_13_1.class); // Starts with 1.13 clients on 1.17 servers super(plugin, Protocol1_13_1To1_13.class); // Starts with 1.13 clients on 1.17 servers
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

View File

@ -17,7 +17,7 @@
*/ */
package com.viaversion.viabackwards.provider; package com.viaversion.viabackwards.provider;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.provider.AdvancementCriteriaProvider; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.provider.AdvancementCriteriaProvider;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.advancement.Advancement; import org.bukkit.advancement.Advancement;

View File

@ -17,7 +17,7 @@
*/ */
package com.viaversion.viabackwards.api; package com.viaversion.viabackwards.api;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
@ -48,7 +48,7 @@ public abstract class BackwardsProtocol<CU extends ClientboundPacketType, CM ext
protected void registerPackets() { protected void registerPackets() {
super.registerPackets(); super.registerPackets();
final BackwardsMappings mappingData = getMappingData(); final BackwardsMappingData mappingData = getMappingData();
if (mappingData != null && mappingData.getViaVersionProtocolClass() != null) { if (mappingData != null && mappingData.getViaVersionProtocolClass() != null) {
executeAsyncAfterLoaded(mappingData.getViaVersionProtocolClass(), this::loadMappingData); executeAsyncAfterLoaded(mappingData.getViaVersionProtocolClass(), this::loadMappingData);
} }
@ -61,7 +61,7 @@ public abstract class BackwardsProtocol<CU extends ClientboundPacketType, CM ext
} }
@Override @Override
public @Nullable BackwardsMappings getMappingData() { // Change return type to BackwardsMappings public @Nullable BackwardsMappingData getMappingData() { // Change return type to BackwardsMappings
return null; return null;
} }

View File

@ -21,42 +21,42 @@ package com.viaversion.viabackwards.api;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.ViaBackwardsConfig; import com.viaversion.viabackwards.ViaBackwardsConfig;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import com.viaversion.viabackwards.protocol.v1_11_1to1_11.Protocol1_11_1To1_11;
import com.viaversion.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2; import com.viaversion.viabackwards.protocol.v1_12_2to1_12_1.Protocol1_12_2To1_12_1;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1; import com.viaversion.viabackwards.protocol.v1_12_1to1_12.Protocol1_12_1To1_12;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2; import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import com.viaversion.viabackwards.protocol.v1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viabackwards.protocol.protocol1_14_1to1_14_2.Protocol1_14_1To1_14_2; import com.viaversion.viabackwards.protocol.v1_14_2to1_14_1.Protocol1_14_2To1_14_1;
import com.viaversion.viabackwards.protocol.protocol1_14_2to1_14_3.Protocol1_14_2To1_14_3; import com.viaversion.viabackwards.protocol.v1_14_3to1_14_2.Protocol1_14_3To1_14_2;
import com.viaversion.viabackwards.protocol.protocol1_14_3to1_14_4.Protocol1_14_3To1_14_4; import com.viaversion.viabackwards.protocol.v1_14_4to1_14_3.Protocol1_14_4To1_14_3;
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15; import com.viaversion.viabackwards.protocol.v1_15to1_14_4.Protocol1_15To1_14_4;
import com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1; import com.viaversion.viabackwards.protocol.v1_14_1to1_14.Protocol1_14_1To1_14;
import com.viaversion.viabackwards.protocol.protocol1_15_1to1_15_2.Protocol1_15_1To1_15_2; import com.viaversion.viabackwards.protocol.v1_15_2to1_15_1.Protocol1_15_2To1_15_1;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viabackwards.protocol.protocol1_15to1_15_1.Protocol1_15To1_15_1; import com.viaversion.viabackwards.protocol.v1_15_1to1_15.Protocol1_15_1To1_15;
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2; import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import com.viaversion.viabackwards.protocol.protocol1_16_2to1_16_3.Protocol1_16_2To1_16_3; import com.viaversion.viabackwards.protocol.v1_16_3to1_16_2.Protocol1_16_3To1_16_2;
import com.viaversion.viabackwards.protocol.protocol1_16_3to1_16_4.Protocol1_16_3To1_16_4; import com.viaversion.viabackwards.protocol.v1_16_4to1_16_3.Protocol1_16_4To1_16_3;
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17; import com.viaversion.viabackwards.protocol.v1_17to1_16_4.Protocol1_17To1_16_4;
import com.viaversion.viabackwards.protocol.protocol1_16to1_16_1.Protocol1_16To1_16_1; import com.viaversion.viabackwards.protocol.v1_16_1to1_16.Protocol1_16_1To1_16;
import com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18; import com.viaversion.viabackwards.protocol.v1_18to1_17_1.Protocol1_18To1_17_1;
import com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.Protocol1_17To1_17_1; import com.viaversion.viabackwards.protocol.v1_17_1to1_17.Protocol1_17_1To1_17;
import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.Protocol1_18_2To1_19; import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2;
import com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.Protocol1_18To1_18_2; import com.viaversion.viabackwards.protocol.v1_18_2to1_18.Protocol1_18_2To1_18;
import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3; import com.viaversion.viabackwards.protocol.v1_19_3to1_19_1.Protocol1_19_3To1_19_1;
import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4; import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.Protocol1_19_4To1_19_3;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20; import com.viaversion.viabackwards.protocol.v1_20to1_19_4.Protocol1_20To1_19_4;
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1; import com.viaversion.viabackwards.protocol.v1_19_1to1_19.Protocol1_19_1To1_19;
import com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.Protocol1_20_2To1_20_3; import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5; import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20;
import com.viaversion.viabackwards.protocol.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
import com.viaversion.viabackwards.protocol.protocol1_9to1_9_1.Protocol1_9To1_9_1; import com.viaversion.viabackwards.protocol.v1_9_1to1_9.Protocol1_9_1To1_9;
import com.viaversion.viabackwards.utils.VersionInfo; import com.viaversion.viabackwards.utils.VersionInfo;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.ProtocolManager; import com.viaversion.viaversion.api.protocol.ProtocolManager;
@ -92,52 +92,52 @@ public interface ViaBackwardsPlatform {
getLogger().info("Registering protocols..."); getLogger().info("Registering protocols...");
final ProtocolManager protocolManager = Via.getManager().getProtocolManager(); final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
protocolManager.registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_1); protocolManager.registerProtocol(new Protocol1_9_1To1_9(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_1);
protocolManager.registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1, ProtocolVersion.v1_9_2), ProtocolVersion.v1_9_3); protocolManager.registerProtocol(new Protocol1_9_3To1_9_1(), Arrays.asList(ProtocolVersion.v1_9_1, ProtocolVersion.v1_9_2), ProtocolVersion.v1_9_3);
protocolManager.registerProtocol(new Protocol1_9_4To1_10(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10); protocolManager.registerProtocol(new Protocol1_10To1_9_3(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10);
protocolManager.registerProtocol(new Protocol1_10To1_11(), ProtocolVersion.v1_10, ProtocolVersion.v1_11); protocolManager.registerProtocol(new Protocol1_11To1_10(), ProtocolVersion.v1_10, ProtocolVersion.v1_11);
protocolManager.registerProtocol(new Protocol1_11To1_11_1(), ProtocolVersion.v1_11, ProtocolVersion.v1_11_1); protocolManager.registerProtocol(new Protocol1_11_1To1_11(), ProtocolVersion.v1_11, ProtocolVersion.v1_11_1);
protocolManager.registerProtocol(new Protocol1_11_1To1_12(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_12); protocolManager.registerProtocol(new Protocol1_12To1_11_1(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_12);
protocolManager.registerProtocol(new Protocol1_12To1_12_1(), ProtocolVersion.v1_12, ProtocolVersion.v1_12_1); protocolManager.registerProtocol(new Protocol1_12_1To1_12(), ProtocolVersion.v1_12, ProtocolVersion.v1_12_1);
protocolManager.registerProtocol(new Protocol1_12_1To1_12_2(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12_2); protocolManager.registerProtocol(new Protocol1_12_2To1_12_1(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12_2);
protocolManager.registerProtocol(new Protocol1_12_2To1_13(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_13); protocolManager.registerProtocol(new Protocol1_13To1_12_2(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_13);
protocolManager.registerProtocol(new Protocol1_13To1_13_1(), ProtocolVersion.v1_13, ProtocolVersion.v1_13_1); protocolManager.registerProtocol(new Protocol1_13_1To1_13(), ProtocolVersion.v1_13, ProtocolVersion.v1_13_1);
protocolManager.registerProtocol(new Protocol1_13_1To1_13_2(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13_2); protocolManager.registerProtocol(new Protocol1_13_2To1_13_1(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13_2);
protocolManager.registerProtocol(new Protocol1_13_2To1_14(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_14); protocolManager.registerProtocol(new Protocol1_14To1_13_2(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_14);
protocolManager.registerProtocol(new Protocol1_14To1_14_1(), ProtocolVersion.v1_14, ProtocolVersion.v1_14_1); protocolManager.registerProtocol(new Protocol1_14_1To1_14(), ProtocolVersion.v1_14, ProtocolVersion.v1_14_1);
protocolManager.registerProtocol(new Protocol1_14_1To1_14_2(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14_2); protocolManager.registerProtocol(new Protocol1_14_2To1_14_1(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14_2);
protocolManager.registerProtocol(new Protocol1_14_2To1_14_3(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_3); protocolManager.registerProtocol(new Protocol1_14_3To1_14_2(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_3);
protocolManager.registerProtocol(new Protocol1_14_3To1_14_4(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_4); protocolManager.registerProtocol(new Protocol1_14_4To1_14_3(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_4);
protocolManager.registerProtocol(new Protocol1_14_4To1_15(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_15); protocolManager.registerProtocol(new Protocol1_15To1_14_4(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_15);
protocolManager.registerProtocol(new Protocol1_15To1_15_1(), ProtocolVersion.v1_15, ProtocolVersion.v1_15_1); protocolManager.registerProtocol(new Protocol1_15_1To1_15(), ProtocolVersion.v1_15, ProtocolVersion.v1_15_1);
protocolManager.registerProtocol(new Protocol1_15_1To1_15_2(), ProtocolVersion.v1_15_1, ProtocolVersion.v1_15_2); protocolManager.registerProtocol(new Protocol1_15_2To1_15_1(), ProtocolVersion.v1_15_1, ProtocolVersion.v1_15_2);
protocolManager.registerProtocol(new Protocol1_15_2To1_16(), ProtocolVersion.v1_15_2, ProtocolVersion.v1_16); protocolManager.registerProtocol(new Protocol1_16To1_15_2(), ProtocolVersion.v1_15_2, ProtocolVersion.v1_16);
protocolManager.registerProtocol(new Protocol1_16To1_16_1(), ProtocolVersion.v1_16, ProtocolVersion.v1_16_1); protocolManager.registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16, ProtocolVersion.v1_16_1);
protocolManager.registerProtocol(new Protocol1_16_1To1_16_2(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16_2); protocolManager.registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16_2);
protocolManager.registerProtocol(new Protocol1_16_2To1_16_3(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_3); protocolManager.registerProtocol(new Protocol1_16_3To1_16_2(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_3);
protocolManager.registerProtocol(new Protocol1_16_3To1_16_4(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_4); protocolManager.registerProtocol(new Protocol1_16_4To1_16_3(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_4);
protocolManager.registerProtocol(new Protocol1_16_4To1_17(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_17); protocolManager.registerProtocol(new Protocol1_17To1_16_4(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_17);
protocolManager.registerProtocol(new Protocol1_17To1_17_1(), ProtocolVersion.v1_17, ProtocolVersion.v1_17_1); protocolManager.registerProtocol(new Protocol1_17_1To1_17(), ProtocolVersion.v1_17, ProtocolVersion.v1_17_1);
protocolManager.registerProtocol(new Protocol1_17_1To1_18(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_18); protocolManager.registerProtocol(new Protocol1_18To1_17_1(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_18);
protocolManager.registerProtocol(new Protocol1_18To1_18_2(), ProtocolVersion.v1_18, ProtocolVersion.v1_18_2); protocolManager.registerProtocol(new Protocol1_18_2To1_18(), ProtocolVersion.v1_18, ProtocolVersion.v1_18_2);
protocolManager.registerProtocol(new Protocol1_18_2To1_19(), ProtocolVersion.v1_18_2, ProtocolVersion.v1_19); protocolManager.registerProtocol(new Protocol1_19To1_18_2(), ProtocolVersion.v1_18_2, ProtocolVersion.v1_19);
protocolManager.registerProtocol(new Protocol1_19To1_19_1(), ProtocolVersion.v1_19, ProtocolVersion.v1_19_1); protocolManager.registerProtocol(new Protocol1_19_1To1_19(), ProtocolVersion.v1_19, ProtocolVersion.v1_19_1);
protocolManager.registerProtocol(new Protocol1_19_1To1_19_3(), ProtocolVersion.v1_19_1, ProtocolVersion.v1_19_3); protocolManager.registerProtocol(new Protocol1_19_3To1_19_1(), ProtocolVersion.v1_19_1, ProtocolVersion.v1_19_3);
protocolManager.registerProtocol(new Protocol1_19_3To1_19_4(), ProtocolVersion.v1_19_3, ProtocolVersion.v1_19_4); protocolManager.registerProtocol(new Protocol1_19_4To1_19_3(), ProtocolVersion.v1_19_3, ProtocolVersion.v1_19_4);
protocolManager.registerProtocol(new Protocol1_19_4To1_20(), ProtocolVersion.v1_19_4, ProtocolVersion.v1_20); protocolManager.registerProtocol(new Protocol1_20To1_19_4(), ProtocolVersion.v1_19_4, ProtocolVersion.v1_20);
protocolManager.registerProtocol(new Protocol1_20To1_20_2(), ProtocolVersion.v1_20, ProtocolVersion.v1_20_2); protocolManager.registerProtocol(new Protocol1_20_2To1_20(), ProtocolVersion.v1_20, ProtocolVersion.v1_20_2);
protocolManager.registerProtocol(new Protocol1_20_2To1_20_3(), ProtocolVersion.v1_20_2, ProtocolVersion.v1_20_3); protocolManager.registerProtocol(new Protocol1_20_3To1_20_2(), ProtocolVersion.v1_20_2, ProtocolVersion.v1_20_3);
protocolManager.registerProtocol(new Protocol1_20_3To1_20_5(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5); protocolManager.registerProtocol(new Protocol1_20_5To1_20_3(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5);
} }
/** /**

View File

@ -30,10 +30,10 @@ import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectArrayMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectArrayMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,7 +41,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class BackwardsMappings extends MappingDataBase { public class BackwardsMappingData extends MappingDataBase {
private final Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass; private final Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass;
protected Int2ObjectMap<MappedItem> backwardsItemMappings; protected Int2ObjectMap<MappedItem> backwardsItemMappings;
@ -49,11 +49,11 @@ public class BackwardsMappings extends MappingDataBase {
private Map<String, String> entityNames; private Map<String, String> entityNames;
private Int2ObjectMap<String> enchantmentNames; private Int2ObjectMap<String> enchantmentNames;
public BackwardsMappings(final String unmappedVersion, final String mappedVersion) { public BackwardsMappingData(final String unmappedVersion, final String mappedVersion) {
this(unmappedVersion, mappedVersion, null); this(unmappedVersion, mappedVersion, null);
} }
public BackwardsMappings(final String unmappedVersion, final String mappedVersion, @Nullable final Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass) { public BackwardsMappingData(final String unmappedVersion, final String mappedVersion, @Nullable final Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass) {
super(unmappedVersion, mappedVersion); super(unmappedVersion, mappedVersion);
Preconditions.checkArgument(vvProtocolClass == null || !vvProtocolClass.isAssignableFrom(BackwardsProtocol.class)); Preconditions.checkArgument(vvProtocolClass == null || !vvProtocolClass.isAssignableFrom(BackwardsProtocol.class));
this.vvProtocolClass = vvProtocolClass; this.vvProtocolClass = vvProtocolClass;

View File

@ -19,8 +19,8 @@ package com.viaversion.viabackwards.api.data;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;

View File

@ -17,7 +17,7 @@
*/ */
package com.viaversion.viabackwards.api.data; package com.viaversion.viabackwards.api.data;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;

View File

@ -17,7 +17,7 @@
*/ */
package com.viaversion.viabackwards.api.data; package com.viaversion.viabackwards.api.data;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.util.IdAndData; import com.viaversion.viaversion.util.IdAndData;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;

View File

@ -19,7 +19,7 @@ package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
public class EntityObjectData extends EntityData { public class EntityObjectData extends EntityReplacement {
private final int objectData; private final int objectData;
public EntityObjectData(BackwardsProtocol<?, ?, ?, ?> protocol, String key, int id, int replacementId, int objectData) { public EntityObjectData(BackwardsProtocol<?, ?, ?, ?> protocol, String key, int id, int replacementId, int objectData) {

View File

@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import java.util.function.Supplier; import java.util.function.Supplier;
public class EntityPositionHandler { public class EntityPositionHandler {
@ -43,11 +43,11 @@ public class EntityPositionHandler {
public void cacheEntityPosition(PacketWrapper wrapper, boolean create, boolean relative) { public void cacheEntityPosition(PacketWrapper wrapper, boolean create, boolean relative) {
cacheEntityPosition(wrapper, cacheEntityPosition(wrapper,
wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative); wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2), create, relative);
} }
public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) { public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Types.VAR_INT, 0);
StoredEntityData storedEntity = entityRewriter.tracker(wrapper.user()).entityData(entityId); StoredEntityData storedEntity = entityRewriter.tracker(wrapper.user()).entityData(entityId);
if (storedEntity == null) { if (storedEntity == null) {
if (Via.getManager().isDebug()) { // There is too many plugins violating this out there, and reading seems to be hard! :> if (Via.getManager().isDebug()) { // There is too many plugins violating this out there, and reading seems to be hard! :>
@ -98,8 +98,8 @@ public class EntityPositionHandler {
} }
double pitch = -Math.asin(dY / r) / Math.PI * 180; double pitch = -Math.asin(dY / r) / Math.PI * 180;
wrapper.write(Type.BYTE, (byte) (yaw * 256f / 360f)); wrapper.write(Types.BYTE, (byte) (yaw * 256f / 360f));
wrapper.write(Type.BYTE, (byte) (pitch * 256f / 360f)); wrapper.write(Types.BYTE, (byte) (pitch * 256f / 360f));
} }
public static void writeFacingDegrees(PacketWrapper wrapper, double x, double y, double z, double targetX, double targetY, double targetZ) { public static void writeFacingDegrees(PacketWrapper wrapper, double x, double y, double z, double targetX, double targetY, double targetZ) {
@ -113,7 +113,7 @@ public class EntityPositionHandler {
} }
double pitch = -Math.asin(dY / r) / Math.PI * 180; double pitch = -Math.asin(dY / r) / Math.PI * 180;
wrapper.write(Type.FLOAT, (float) yaw); wrapper.write(Types.FLOAT, (float) yaw);
wrapper.write(Type.FLOAT, (float) pitch); wrapper.write(Types.FLOAT, (float) pitch);
} }
} }

View File

@ -20,12 +20,12 @@ package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import java.util.Locale; import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class EntityData { public class EntityReplacement {
private final BackwardsProtocol<?, ?, ?, ?> protocol; private final BackwardsProtocol<?, ?, ?, ?> protocol;
private final int id; private final int id;
private final int replacementId; private final int replacementId;
@ -33,33 +33,33 @@ public class EntityData {
private ComponentType componentType = ComponentType.NONE; private ComponentType componentType = ComponentType.NONE;
private MetaCreator defaultMeta; private MetaCreator defaultMeta;
public EntityData(BackwardsProtocol<?, ?, ?, ?> protocol, EntityType type, int replacementId) { public EntityReplacement(BackwardsProtocol<?, ?, ?, ?> protocol, EntityType type, int replacementId) {
this(protocol, type.name(), type.getId(), replacementId); this(protocol, type.name(), type.getId(), replacementId);
} }
public EntityData(BackwardsProtocol<?, ?, ?, ?> protocol, String key, int id, int replacementId) { public EntityReplacement(BackwardsProtocol<?, ?, ?, ?> protocol, String key, int id, int replacementId) {
this.protocol = protocol; this.protocol = protocol;
this.id = id; this.id = id;
this.replacementId = replacementId; this.replacementId = replacementId;
this.key = key.toLowerCase(Locale.ROOT); this.key = key.toLowerCase(Locale.ROOT);
} }
public EntityData jsonName() { public EntityReplacement jsonName() {
this.componentType = ComponentType.JSON; this.componentType = ComponentType.JSON;
return this; return this;
} }
public EntityData tagName() { public EntityReplacement tagName() {
this.componentType = ComponentType.TAG; this.componentType = ComponentType.TAG;
return this; return this;
} }
public EntityData plainName() { public EntityReplacement plainName() {
this.componentType = ComponentType.PLAIN; this.componentType = ComponentType.PLAIN;
return this; return this;
} }
public EntityData spawnMetadata(MetaCreator handler) { public EntityReplacement spawnMetadata(MetaCreator handler) {
this.defaultMeta = handler; this.defaultMeta = handler;
return this; return this;
} }

View File

@ -19,7 +19,7 @@ package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
public abstract class PlayerPositionStorage implements StorableObject { public abstract class PlayerPositionStorage implements StorableObject {
private double x; private double x;
@ -54,7 +54,7 @@ public abstract class PlayerPositionStorage implements StorableObject {
} }
public void setCoordinates(PacketWrapper wrapper, boolean relative) { public void setCoordinates(PacketWrapper wrapper, boolean relative) {
setCoordinates(wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), relative); setCoordinates(wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2), relative);
} }
public void setCoordinates(double x, double y, double z, boolean relative) { public void setCoordinates(double x, double y, double z, boolean relative) {

View File

@ -18,17 +18,17 @@
package com.viaversion.viabackwards.api.entities.storage; package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public record WrappedMetadata(List<Metadata> metadataList) { public record WrappedMetadata(List<EntityData> metadataList) {
public boolean has(Metadata data) { public boolean has(EntityData data) {
return this.metadataList.contains(data); return this.metadataList.contains(data);
} }
public void remove(Metadata data) { public void remove(EntityData data) {
this.metadataList.remove(data); this.metadataList.remove(data);
} }
@ -36,12 +36,12 @@ public record WrappedMetadata(List<Metadata> metadataList) {
metadataList.removeIf(meta -> meta.id() == index); metadataList.removeIf(meta -> meta.id() == index);
} }
public void add(Metadata data) { public void add(EntityData data) {
this.metadataList.add(data); this.metadataList.add(data);
} }
public @Nullable Metadata get(int index) { public @Nullable EntityData get(int index) {
for (Metadata meta : this.metadataList) { for (EntityData meta : this.metadataList) {
if (index == meta.id()) { if (index == meta.id()) {
return meta; return meta;
} }

View File

@ -25,14 +25,15 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.nbt.tag.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType, public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
@ -106,7 +107,7 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
} }
if (!display.contains("Name")) { if (!display.contains("Name")) {
display.put("Name", new StringTag(data.jsonName())); display.put("Name", new StringTag(data.jsonName()));
display.put(nbtTagName("customName"), new ByteTag()); display.put(nbtTagName("customName"), new ByteTag(false));
} }
return item; return item;
} }
@ -131,16 +132,16 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
@Override @Override
public void register() { public void register() {
handler(wrapper -> { handler(wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear wrapper.passthrough(Types.BOOLEAN); // Reset/clear
final int size = wrapper.passthrough(Type.VAR_INT); // Mapping size final int size = wrapper.passthrough(Types.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier wrapper.passthrough(Types.STRING); // Identifier
wrapper.passthrough(Type.OPTIONAL_STRING); // Parent wrapper.passthrough(Types.OPTIONAL_STRING); // Parent
// Display data // Display data
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Types.BOOLEAN)) {
final JsonElement title = wrapper.passthrough(Type.COMPONENT); final JsonElement title = wrapper.passthrough(Types.COMPONENT);
final JsonElement description = wrapper.passthrough(Type.COMPONENT); final JsonElement description = wrapper.passthrough(Types.COMPONENT);
final TranslatableRewriter<C> translatableRewriter = protocol.getTranslatableRewriter(); final TranslatableRewriter<C> translatableRewriter = protocol.getTranslatableRewriter();
if (translatableRewriter != null) { if (translatableRewriter != null) {
translatableRewriter.processText(wrapper.user(), title); translatableRewriter.processText(wrapper.user(), title);
@ -150,20 +151,20 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType())); final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), icon); wrapper.write(mappedItemType(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Types.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Types.INT); // Flags
if ((flags & 1) != 0) { if ((flags & 1) != 0) {
wrapper.passthrough(Type.STRING); // Background texture wrapper.passthrough(Types.STRING); // Background texture
} }
wrapper.passthrough(Type.FLOAT); // X wrapper.passthrough(Types.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y wrapper.passthrough(Types.FLOAT); // Y
} }
wrapper.passthrough(Type.STRING_ARRAY); // Criteria wrapper.passthrough(Types.STRING_ARRAY); // Criteria
final int arrayLength = wrapper.passthrough(Type.VAR_INT); final int arrayLength = wrapper.passthrough(Types.VAR_INT);
for (int array = 0; array < arrayLength; array++) { for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array wrapper.passthrough(Types.STRING_ARRAY); // String array
} }
} }
}); });
@ -175,16 +176,16 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
public void registerAdvancements1_20_3(final C packetType) { public void registerAdvancements1_20_3(final C packetType) {
// Insert translatable rewriter // Insert translatable rewriter
protocol.registerClientbound(packetType, wrapper -> { protocol.registerClientbound(packetType, wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear wrapper.passthrough(Types.BOOLEAN); // Reset/clear
final int size = wrapper.passthrough(Type.VAR_INT); // Mapping size final int size = wrapper.passthrough(Types.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier wrapper.passthrough(Types.STRING); // Identifier
wrapper.passthrough(Type.OPTIONAL_STRING); // Parent wrapper.passthrough(Types.OPTIONAL_STRING); // Parent
// Display data // Display data
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Types.BOOLEAN)) {
final Tag title = wrapper.passthrough(Type.TAG); final Tag title = wrapper.passthrough(Types.TAG);
final Tag description = wrapper.passthrough(Type.TAG); final Tag description = wrapper.passthrough(Types.TAG);
final TranslatableRewriter<C> translatableRewriter = protocol.getTranslatableRewriter(); final TranslatableRewriter<C> translatableRewriter = protocol.getTranslatableRewriter();
if (translatableRewriter != null) { if (translatableRewriter != null) {
translatableRewriter.processTag(wrapper.user(), title); translatableRewriter.processTag(wrapper.user(), title);
@ -194,21 +195,21 @@ public class BackwardsItemRewriter<C extends ClientboundPacketType, S extends Se
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType())); final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), icon); wrapper.write(mappedItemType(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Types.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT); final int flags = wrapper.passthrough(Types.INT);
if ((flags & 1) != 0) { if ((flags & 1) != 0) {
wrapper.passthrough(Type.STRING); // Background texture wrapper.passthrough(Types.STRING); // Background texture
} }
wrapper.passthrough(Type.FLOAT); // X wrapper.passthrough(Types.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y wrapper.passthrough(Types.FLOAT); // Y
} }
final int requirements = wrapper.passthrough(Type.VAR_INT); final int requirements = wrapper.passthrough(Types.VAR_INT);
for (int array = 0; array < requirements; array++) { for (int array = 0; array < requirements; array++) {
wrapper.passthrough(Type.STRING_ARRAY); wrapper.passthrough(Types.STRING_ARRAY);
} }
wrapper.passthrough(Type.BOOLEAN); // Send telemetry wrapper.passthrough(Types.BOOLEAN); // Send telemetry
} }
}); });
} }

View File

@ -23,10 +23,10 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -18,7 +18,7 @@
package com.viaversion.viabackwards.api.rewriters; package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.api.data.MappedItem; import com.viaversion.viabackwards.api.data.MappedItem;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredData;
@ -28,10 +28,10 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.nbt.tag.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType, public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
@ -79,7 +79,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
} }
} }
final BackwardsMappings mappingData = protocol.getMappingData(); final BackwardsMappingData mappingData = protocol.getMappingData();
final MappedItem mappedItem = mappingData != null ? mappingData.getMappedItem(item.identifier()) : null; final MappedItem mappedItem = mappingData != null ? mappingData.getMappedItem(item.identifier()) : null;
if (mappedItem == null) { if (mappedItem == null) {
// Just rewrite the id // Just rewrite the id
@ -113,7 +113,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
return null; return null;
} }
final BackwardsMappings mappingData = protocol.getMappingData(); final BackwardsMappingData mappingData = protocol.getMappingData();
if (mappingData != null && mappingData.getItemMappings() != null) { if (mappingData != null && mappingData.getItemMappings() != null) {
item.setIdentifier(mappingData.getOldItemId(item.identifier())); item.setIdentifier(mappingData.getOldItemId(item.identifier()));
} }

View File

@ -18,10 +18,10 @@
package com.viaversion.viabackwards.api.rewriters; package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -20,21 +20,22 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.api.type.types.version.Types1_14;
public abstract class EntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriterBase<C, T> { public abstract class EntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriterBase<C, T> {
protected EntityRewriter(T protocol) { protected EntityRewriter(T protocol) {
this(protocol, Types1_14.META_TYPES.optionalComponentType, Types1_14.META_TYPES.booleanType); this(protocol, Types1_14.ENTITY_DATA_TYPES.optionalComponentType, Types1_14.ENTITY_DATA_TYPES.booleanType);
} }
protected EntityRewriter(T protocol, MetaType displayType, MetaType displayVisibilityType) { protected EntityRewriter(T protocol, EntityDataType displayType, EntityDataType displayVisibilityType) {
super(protocol, displayType, 2, displayVisibilityType, 3); super(protocol, displayType, 2, displayVisibilityType, 3);
} }
@ -43,15 +44,15 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity id map(Types.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - Entity UUID map(Types.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type map(Types.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X map(Types.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Types.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Types.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw map(Types.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data map(Types.INT); // 8 - Data
handler(getSpawnTrackerWithDataHandler(fallingBlockType)); handler(getSpawnTrackerWithDataHandler(fallingBlockType));
} }
}); });
@ -62,16 +63,16 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // Entity id map(Types.VAR_INT); // Entity id
map(Type.UUID); // Entity UUID map(Types.UUID); // Entity UUID
map(Type.VAR_INT); // Entity type map(Types.VAR_INT); // Entity type
map(Type.DOUBLE); // X map(Types.DOUBLE); // X
map(Type.DOUBLE); // Y map(Types.DOUBLE); // Y
map(Type.DOUBLE); // Z map(Types.DOUBLE); // Z
map(Type.BYTE); // Pitch map(Types.BYTE); // Pitch
map(Type.BYTE); // Yaw map(Types.BYTE); // Yaw
map(Type.BYTE); // Head yaw map(Types.BYTE); // Head yaw
map(Type.VAR_INT); // Data map(Types.VAR_INT); // Data
handler(getSpawnTrackerWithDataHandler1_19(fallingBlockType)); handler(getSpawnTrackerWithDataHandler1_19(fallingBlockType));
} }
}); });
@ -82,8 +83,8 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
// Check against the UNMAPPED entity type // Check against the UNMAPPED entity type
EntityType entityType = trackAndMapEntity(wrapper); EntityType entityType = trackAndMapEntity(wrapper);
if (entityType == fallingBlockType) { if (entityType == fallingBlockType) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Types.INT, 0);
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(blockState)); wrapper.set(Types.INT, 0, protocol.getMappingData().getNewBlockStateId(blockState));
} }
}; };
} }
@ -97,8 +98,8 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
// Check against the UNMAPPED entity type // Check against the UNMAPPED entity type
EntityType entityType = trackAndMapEntity(wrapper); EntityType entityType = trackAndMapEntity(wrapper);
if (entityType == fallingBlockType) { if (entityType == fallingBlockType) {
int blockState = wrapper.get(Type.VAR_INT, 2); int blockState = wrapper.get(Types.VAR_INT, 2);
wrapper.set(Type.VAR_INT, 2, protocol.getMappingData().getNewBlockStateId(blockState)); wrapper.set(Types.VAR_INT, 2, protocol.getMappingData().getNewBlockStateId(blockState));
} }
}; };
} }
@ -107,9 +108,9 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID map(Types.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type map(Types.VAR_INT); // 2 - Entity Type
handler(wrapper -> trackAndMapEntity(wrapper)); handler(wrapper -> trackAndMapEntity(wrapper));
} }
}); });
@ -123,7 +124,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
public PacketHandler worldTrackerHandlerByKey() { public PacketHandler worldTrackerHandlerByKey() {
return wrapper -> { return wrapper -> {
EntityTracker tracker = tracker(wrapper.user()); EntityTracker tracker = tracker(wrapper.user());
String world = wrapper.get(Type.STRING, 1); String world = wrapper.get(Types.STRING, 1);
if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) { if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) {
tracker.clearEntities(); tracker.clearEntities();
tracker.trackClientEntity(); tracker.trackClientEntity();
@ -139,13 +140,13 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
* @return unmapped (!) entity type * @return unmapped (!) entity type
*/ */
protected EntityType trackAndMapEntity(PacketWrapper wrapper) { protected EntityType trackAndMapEntity(PacketWrapper wrapper) {
int typeId = wrapper.get(Type.VAR_INT, 1); int typeId = wrapper.get(Types.VAR_INT, 1);
EntityType entityType = typeFromId(typeId); EntityType entityType = typeFromId(typeId);
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType); tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
int mappedTypeId = newEntityId(entityType.getId()); int mappedTypeId = newEntityId(entityType.getId());
if (typeId != mappedTypeId) { if (typeId != mappedTypeId) {
wrapper.set(Type.VAR_INT, 1, mappedTypeId); wrapper.set(Types.VAR_INT, 1, mappedTypeId);
} }
return entityType; return entityType;

View File

@ -20,7 +20,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.entities.storage.EntityData; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
@ -28,16 +28,17 @@ import com.viaversion.viaversion.api.data.entity.TrackedEntity;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent; import com.viaversion.viaversion.rewriter.entitydata.EntityDataHandlerEvent;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -48,14 +49,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* @see LegacyEntityRewriter * @see LegacyEntityRewriter
*/ */
public abstract class EntityRewriterBase<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriter<C, T> { public abstract class EntityRewriterBase<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriter<C, T> {
private final Int2ObjectMap<EntityData> entityDataMappings = new Int2ObjectOpenHashMap<>(); private final Int2ObjectMap<EntityReplacement> entityDataMappings = new Int2ObjectOpenHashMap<>();
private final MetaType displayNameMetaType; private final EntityDataType displayNameMetaType;
private final MetaType displayVisibilityMetaType; private final EntityDataType displayVisibilityMetaType;
private final int displayNameIndex; private final int displayNameIndex;
private final int displayVisibilityIndex; private final int displayVisibilityIndex;
EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex, EntityRewriterBase(T protocol, EntityDataType displayNameMetaType, int displayNameIndex,
MetaType displayVisibilityMetaType, int displayVisibilityIndex) { EntityDataType displayVisibilityMetaType, int displayVisibilityIndex) {
super(protocol, false); super(protocol, false);
this.displayNameMetaType = displayNameMetaType; this.displayNameMetaType = displayNameMetaType;
this.displayNameIndex = displayNameIndex; this.displayNameIndex = displayNameIndex;
@ -64,48 +65,48 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
} }
@Override @Override
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) { public void handleEntityData(int entityId, List<EntityData> entityDataList, UserConnection connection) {
final TrackedEntity entity = tracker(connection).entity(entityId); final TrackedEntity entity = tracker(connection).entity(entityId);
final boolean initialMetadata = !(entity != null && entity.hasSentMetadata()); final boolean initialMetadata = !(entity != null && entity.hasSentEntityData());
super.handleMetadata(entityId, metadataList, connection); super.handleEntityData(entityId, entityDataList, connection);
if (entity == null) { if (entity == null) {
return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling
} }
// Set the mapped entity name if there is no custom name set already // Set the mapped entity name if there is no custom name set already
final EntityData entityData = entityDataForType(entity.entityType()); final EntityReplacement entityMapping = entityDataForType(entity.entityType());
final Object displayNameObject; final Object displayNameObject;
if (entityData != null && (displayNameObject = entityData.entityName()) != null) { if (entityMapping != null && (displayNameObject = entityMapping.entityName()) != null) {
final Metadata displayName = getMeta(displayNameIndex, metadataList); final EntityData displayName = getData(displayNameIndex, entityDataList);
if (initialMetadata) { if (initialMetadata) {
if (displayName == null) { if (displayName == null) {
// Add it as new metadata // Add it as new metadata
metadataList.add(new Metadata(displayNameIndex, displayNameMetaType, displayNameObject)); entityDataList.add(new EntityData(displayNameIndex, displayNameMetaType, displayNameObject));
addDisplayVisibilityMeta(metadataList); addDisplayVisibilityMeta(entityDataList);
} else if (displayName.getValue() == null || displayName.getValue().toString().isEmpty()) { } else if (displayName.getValue() == null || displayName.getValue().toString().isEmpty()) {
// Overwrite the existing null/empty display name // Overwrite the existing null/empty display name
displayName.setValue(displayNameObject); displayName.setValue(displayNameObject);
addDisplayVisibilityMeta(metadataList); addDisplayVisibilityMeta(entityDataList);
} }
} else if (displayName != null && (displayName.getValue() == null || displayName.getValue().toString().isEmpty())) { } else if (displayName != null && (displayName.getValue() == null || displayName.getValue().toString().isEmpty())) {
// Overwrite null/empty display name // Overwrite null/empty display name
displayName.setValue(displayNameObject); displayName.setValue(displayNameObject);
addDisplayVisibilityMeta(metadataList); addDisplayVisibilityMeta(entityDataList);
} }
} }
// Add any other extra meta for mapped entities // Add any other extra meta for mapped entities
if (entityData != null && entityData.hasBaseMeta() && initialMetadata) { if (entityMapping != null && entityMapping.hasBaseMeta() && initialMetadata) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList)); entityMapping.defaultMeta().createMeta(new WrappedMetadata(entityDataList));
} }
} }
private void addDisplayVisibilityMeta(List<Metadata> metadataList) { private void addDisplayVisibilityMeta(List<EntityData> metadataList) {
if (alwaysShowOriginalMobName()) { if (alwaysShowOriginalMobName()) {
removeMeta(displayVisibilityIndex, metadataList); removeMeta(displayVisibilityIndex, metadataList);
metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, getDisplayVisibilityMetaValue())); metadataList.add(new EntityData(displayVisibilityIndex, displayVisibilityMetaType, getDisplayVisibilityMetaValue()));
} }
} }
@ -117,8 +118,8 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
return ViaBackwards.getConfig().alwaysShowOriginalMobName(); return ViaBackwards.getConfig().alwaysShowOriginalMobName();
} }
protected @Nullable Metadata getMeta(int metaIndex, List<Metadata> metadataList) { protected @Nullable EntityData getData(int metaIndex, List<EntityData> metadataList) {
for (Metadata metadata : metadataList) { for (EntityData metadata : metadataList) {
if (metadata.id() == metaIndex) { if (metadata.id() == metaIndex) {
return metadata; return metadata;
} }
@ -126,7 +127,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
return null; return null;
} }
protected void removeMeta(int metaIndex, List<Metadata> metadataList) { protected void removeMeta(int metaIndex, List<EntityData> metadataList) {
metadataList.removeIf(meta -> meta.id() == metaIndex); metadataList.removeIf(meta -> meta.id() == metaIndex);
} }
@ -134,11 +135,11 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
return entityDataMappings.containsKey(type.getId()); return entityDataMappings.containsKey(type.getId());
} }
protected @Nullable EntityData entityDataForType(EntityType type) { protected @Nullable EntityReplacement entityDataForType(EntityType type) {
return entityDataMappings.get(type.getId()); return entityDataMappings.get(type.getId());
} }
protected @Nullable StoredEntityData storedEntityData(MetaHandlerEvent event) { protected @Nullable StoredEntityData storedEntityData(EntityDataHandlerEvent event) {
return tracker(event.user()).entityData(event.entityId()); return tracker(event.user()).entityData(event.entityId());
} }
@ -151,27 +152,27 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
* @return created entity data * @return created entity data
* @see #mapEntityType(EntityType, EntityType) for id only rewriting * @see #mapEntityType(EntityType, EntityType) for id only rewriting
*/ */
protected EntityData mapEntityTypeWithData(EntityType type, EntityType mappedType) { protected EntityReplacement mapEntityTypeWithData(EntityType type, EntityType mappedType) {
Preconditions.checkArgument(type.getClass() == mappedType.getClass(), "Both entity types need to be of the same class"); Preconditions.checkArgument(type.getClass() == mappedType.getClass(), "Both entity types need to be of the same class");
// Already rewrite the id here // Already rewrite the id here
int mappedReplacementId = newEntityId(mappedType.getId()); int mappedReplacementId = newEntityId(mappedType.getId());
EntityData data = new EntityData(protocol, type, mappedReplacementId); EntityReplacement data = new EntityReplacement(protocol, type, mappedReplacementId);
mapEntityType(type.getId(), mappedReplacementId); mapEntityType(type.getId(), mappedReplacementId);
entityDataMappings.put(type.getId(), data); entityDataMappings.put(type.getId(), data);
return data; return data;
} }
public void registerMetaTypeHandler( public void registerMetaTypeHandler(
@Nullable MetaType itemType, @Nullable EntityDataType itemType,
@Nullable MetaType blockStateType, @Nullable EntityDataType blockStateType,
@Nullable MetaType optionalBlockStateType, @Nullable EntityDataType optionalBlockStateType,
@Nullable MetaType particleType, @Nullable EntityDataType particleType,
@Nullable MetaType componentType, @Nullable EntityDataType componentType,
@Nullable MetaType optionalComponentType @Nullable EntityDataType optionalComponentType
) { ) {
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
MetaType type = meta.metaType(); EntityDataType type = meta.dataType();
if (type == itemType) { if (type == itemType) {
protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()); protocol.getItemRewriter().handleItemToClient(event.user(), meta.value());
} else if (type == blockStateType) { } else if (type == blockStateType) {
@ -192,16 +193,16 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
} }
public void registerMetaTypeHandler1_20_3( public void registerMetaTypeHandler1_20_3(
@Nullable MetaType itemType, @Nullable EntityDataType itemType,
@Nullable MetaType blockStateType, @Nullable EntityDataType blockStateType,
@Nullable MetaType optionalBlockStateType, @Nullable EntityDataType optionalBlockStateType,
@Nullable MetaType particleType, @Nullable EntityDataType particleType,
@Nullable MetaType particlesType, @Nullable EntityDataType particlesType,
@Nullable MetaType componentType, @Nullable EntityDataType componentType,
@Nullable MetaType optionalComponentType @Nullable EntityDataType optionalComponentType
) { ) {
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
MetaType type = meta.metaType(); EntityDataType type = meta.dataType();
if (type == itemType) { if (type == itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())); meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
} else if (type == blockStateType) { } else if (type == blockStateType) {
@ -229,12 +230,12 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
protected PacketHandler getTrackerHandler(Type<? extends Number> intType, int typeIndex) { protected PacketHandler getTrackerHandler(Type<? extends Number> intType, int typeIndex) {
return wrapper -> { return wrapper -> {
Number id = wrapper.get(intType, typeIndex); Number id = wrapper.get(intType, typeIndex);
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), typeFromId(id.intValue())); tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), typeFromId(id.intValue()));
}; };
} }
protected PacketHandler getTrackerHandler() { protected PacketHandler getTrackerHandler() {
return getTrackerHandler(Type.VAR_INT, 1); return getTrackerHandler(Types.VAR_INT, 1);
} }
protected PacketHandler getTrackerHandler(EntityType entityType, Type<? extends Number> intType) { protected PacketHandler getTrackerHandler(EntityType entityType, Type<? extends Number> intType) {
@ -244,7 +245,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
protected PacketHandler getDimensionHandler(int index) { protected PacketHandler getDimensionHandler(int index) {
return wrapper -> { return wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, index); int dimensionId = wrapper.get(Types.INT, index);
clientWorld.setEnvironment(dimensionId); clientWorld.setEnvironment(dimensionId);
}; };
} }

View File

@ -21,7 +21,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem; import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader; import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.BlockColors;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@ -35,18 +35,19 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonPrimitive; import com.viaversion.viaversion.libs.gson.JsonPrimitive;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.nbt.tag.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag; import com.viaversion.nbt.tag.ShortTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -78,7 +79,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
} }
protected LegacyBlockItemRewriter(T protocol, String name) { protected LegacyBlockItemRewriter(T protocol, String name) {
this(protocol, name, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY); this(protocol, name, Types.ITEM1_8, Types.ITEM1_8_SHORT_ARRAY);
} }
private void addMappings(MappedLegacyBlockItem.Type type, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) { private void addMappings(MappedLegacyBlockItem.Type type, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
@ -134,12 +135,12 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // 0 - Block Position map(Types.BLOCK_POSITION1_8); // 0 - Block Position
map(Type.VAR_INT); // 1 - Block map(Types.VAR_INT); // 1 - Block
handler(wrapper -> { handler(wrapper -> {
int idx = wrapper.get(Type.VAR_INT, 0); int idx = wrapper.get(Types.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, handleBlockId(idx)); wrapper.set(Types.VAR_INT, 0, handleBlockId(idx));
}); });
} }
}); });
@ -149,12 +150,12 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Chunk X map(Types.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z map(Types.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY); map(Types.BLOCK_CHANGE_ARRAY);
handler(wrapper -> { handler(wrapper -> {
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { for (BlockChangeRecord record : wrapper.get(Types.BLOCK_CHANGE_ARRAY, 0)) {
record.setBlockId(handleBlockId(record.getBlockId())); record.setBlockId(handleBlockId(record.getBlockId()));
} }
}); });
@ -195,7 +196,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
if (nameTag == null) { if (nameTag == null) {
nameTag = new StringTag(data.getName()); nameTag = new StringTag(data.getName());
display.put("Name", nameTag); display.put("Name", nameTag);
display.put(nbtTagName("customName"), new ByteTag()); display.put(nbtTagName("customName"), new ByteTag(false));
} }
// Handle colors // Handle colors
@ -226,14 +227,14 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
public PacketHandler getFallingBlockHandler() { public PacketHandler getFallingBlockHandler() {
return wrapper -> { return wrapper -> {
final Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0)); final Optional<EntityTypes1_12.ObjectType> type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0));
if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) { if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) {
final int objectData = wrapper.get(Type.INT, 0); final int objectData = wrapper.get(Types.INT, 0);
final IdAndData block = handleBlock(objectData & 4095, objectData >> 12 & 15); final IdAndData block = handleBlock(objectData & 4095, objectData >> 12 & 15);
if (block == null) return; if (block == null) return;
wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12); wrapper.set(Types.INT, 0, block.getId() | block.getData() << 12);
} }
}; };
} }

View File

@ -18,13 +18,13 @@
package com.viaversion.viabackwards.api.rewriters; package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.nbt.tag.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -69,10 +69,10 @@ public class LegacyEnchantmentRewriter {
CompoundTag tag = item.tag(); CompoundTag tag = item.tag();
if (tag == null) return; if (tag == null) return;
if (tag.contains(nbtTagName + "|ench")) { if (tag.getListTag(nbtTagName + "|ench", CompoundTag.class) != null) {
rewriteEnchantmentsToServer(tag, false); rewriteEnchantmentsToServer(tag, false);
} }
if (tag.contains(nbtTagName + "|StoredEnchantments")) { if (tag.getListTag(nbtTagName + "|StoredEnchantments", CompoundTag.class) != null) {
rewriteEnchantmentsToServer(tag, true); rewriteEnchantmentsToServer(tag, true);
} }
} }
@ -107,7 +107,7 @@ public class LegacyEnchantmentRewriter {
dummyEnchantment.putShort("lvl", (short) 0); dummyEnchantment.putShort("lvl", (short) 0);
enchantments.add(dummyEnchantment); enchantments.add(dummyEnchantment);
tag.put(nbtTagName + "|dummyEnchant", new ByteTag()); tag.put(nbtTagName + "|dummyEnchant", new ByteTag(false));
NumberTag hideFlags = tag.getNumberTag("HideFlags"); NumberTag hideFlags = tag.getNumberTag("HideFlags");
if (hideFlags == null) { if (hideFlags == null) {
@ -165,7 +165,7 @@ public class LegacyEnchantmentRewriter {
CompoundTag display = tag.getCompoundTag("display"); CompoundTag display = tag.getCompoundTag("display");
// A few null checks just to be safe, though they shouldn't actually be // A few null checks just to be safe, though they shouldn't actually be
ListTag<StringTag> lore = display != null ? display.getListTag("Lore", StringTag.class) : null; ListTag<StringTag> lore = display != null ? display.getListTag("Lore", StringTag.class) : null;
ListTag<CompoundTag> remappedEnchantments = tag.remove(nbtTagName + "|" + key); ListTag<CompoundTag> remappedEnchantments = (ListTag<CompoundTag>) tag.remove(nbtTagName + "|" + key);
for (CompoundTag enchantment : remappedEnchantments.copy()) { for (CompoundTag enchantment : remappedEnchantments.copy()) {
enchantments.add(enchantment); enchantments.add(enchantment);
if (lore != null && !lore.isEmpty()) { if (lore != null && !lore.isEmpty()) {

View File

@ -17,22 +17,22 @@
*/ */
package com.viaversion.viabackwards.api.rewriters; package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.entities.storage.EntityData; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.EntityObjectData; import com.viaversion.viabackwards.api.entities.storage.EntityObjectData;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.ObjectType; import com.viaversion.viaversion.api.minecraft.entities.ObjectType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_9;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -40,13 +40,13 @@ import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriterBase<C, T> { public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T extends BackwardsProtocol<C, ?, ?, ?>> extends EntityRewriterBase<C, T> {
private final Map<ObjectType, EntityData> objectTypes = new HashMap<>(); private final Map<ObjectType, EntityReplacement> objectTypes = new HashMap<>();
protected LegacyEntityRewriter(T protocol) { protected LegacyEntityRewriter(T protocol) {
this(protocol, MetaType1_9.String, MetaType1_9.Boolean); this(protocol, EntityDataTypes1_9.STRING, EntityDataTypes1_9.BOOLEAN);
} }
protected LegacyEntityRewriter(T protocol, MetaType displayType, MetaType displayVisibilityType) { protected LegacyEntityRewriter(T protocol, EntityDataType displayType, EntityDataType displayVisibilityType) {
super(protocol, displayType, 2, displayVisibilityType, 3); super(protocol, displayType, 2, displayVisibilityType, 3);
} }
@ -56,7 +56,7 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
return entData; return entData;
} }
protected @Nullable EntityData getObjectData(ObjectType type) { protected @Nullable EntityReplacement getObjectData(ObjectType type) {
return objectTypes.get(type); return objectTypes.get(type);
} }
@ -64,10 +64,10 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); map(Types.INT);
handler(wrapper -> { handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
clientWorld.setEnvironment(wrapper.get(Type.INT, 0)); clientWorld.setEnvironment(wrapper.get(Types.INT, 0));
}); });
} }
}); });
@ -77,93 +77,93 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Entity ID map(Types.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode map(Types.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension map(Types.INT); // 2 - Dimension
handler(wrapper -> { handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
clientChunks.setEnvironment(wrapper.get(Type.INT, 1)); clientChunks.setEnvironment(wrapper.get(Types.INT, 1));
addTrackedEntity(wrapper, wrapper.get(Type.INT, 0), playerType); addTrackedEntity(wrapper, wrapper.get(Types.INT, 0), playerType);
}); });
} }
}); });
} }
@Override @Override
public void registerMetadataRewriter(C packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) { public void registerSetEntityData(C packetType, Type<List<EntityData>> oldMetaType, Type<List<EntityData>> newMetaType) {
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
if (oldMetaType != null) { if (oldMetaType != null) {
map(oldMetaType, newMetaType); map(oldMetaType, newMetaType);
} else { } else {
map(newMetaType); map(newMetaType);
} }
handler(wrapper -> { handler(wrapper -> {
List<Metadata> metadata = wrapper.get(newMetaType, 0); List<EntityData> metadata = wrapper.get(newMetaType, 0);
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user());
}); });
} }
}); });
} }
@Override @Override
public void registerMetadataRewriter(C packetType, Type<List<Metadata>> metaType) { public void registerSetEntityData(C packetType, Type<List<EntityData>> metaType) {
registerMetadataRewriter(packetType, null, metaType); registerSetEntityData(packetType, null, metaType);
} }
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType, IdSetter idSetter) { protected PacketHandler getMobSpawnRewriter(Type<List<EntityData>> metaType, IdSetter idSetter) {
return wrapper -> { return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Types.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId); EntityType type = tracker(wrapper.user()).entityType(entityId);
List<Metadata> metadata = wrapper.get(metaType, 0); List<EntityData> metadata = wrapper.get(metaType, 0);
handleMetadata(entityId, metadata, wrapper.user()); handleEntityData(entityId, metadata, wrapper.user());
EntityData entityData = entityDataForType(type); EntityReplacement entityReplacement = entityDataForType(type);
if (entityData != null) { if (entityReplacement != null) {
idSetter.setId(wrapper, entityData.replacementId()); idSetter.setId(wrapper, entityReplacement.replacementId());
if (entityData.hasBaseMeta()) { if (entityReplacement.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadata)); entityReplacement.defaultMeta().createMeta(new WrappedMetadata(metadata));
} }
} }
}; };
} }
public PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) { public PacketHandler getMobSpawnRewriter(Type<List<EntityData>> metaType) {
return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Type.UNSIGNED_BYTE, 0, (short) id)); return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Types.UNSIGNED_BYTE, 0, (short) id));
} }
public PacketHandler getMobSpawnRewriter1_11(Type<List<Metadata>> metaType) { public PacketHandler getMobSpawnRewriter1_11(Type<List<EntityData>> metaType) {
return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Type.VAR_INT, 1, id)); return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Types.VAR_INT, 1, id));
} }
protected PacketHandler getObjectTrackerHandler() { protected PacketHandler getObjectTrackerHandler() {
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), objectTypeFromId(wrapper.get(Type.BYTE, 0))); return wrapper -> addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), objectTypeFromId(wrapper.get(Types.BYTE, 0)));
} }
protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) { protected PacketHandler getTrackerAndMetaHandler(Type<List<EntityData>> metaType, EntityType entityType) {
return wrapper -> { return wrapper -> {
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType); addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), entityType);
List<Metadata> metadata = wrapper.get(metaType, 0); List<EntityData> metadata = wrapper.get(metaType, 0);
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user());
}; };
} }
protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGetter) { protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGetter) {
return wrapper -> { return wrapper -> {
ObjectType type = objectGetter.apply(wrapper.get(Type.BYTE, 0)); ObjectType type = objectGetter.apply(wrapper.get(Types.BYTE, 0));
if (type == null) { if (type == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0)); ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Types.BYTE, 0));
return; return;
} }
EntityData data = getObjectData(type); EntityReplacement data = getObjectData(type);
if (data != null) { if (data != null) {
wrapper.set(Type.BYTE, 0, (byte) data.replacementId()); wrapper.set(Types.BYTE, 0, (byte) data.replacementId());
if (data.objectData() != -1) { if (data.objectData() != -1) {
wrapper.set(Type.INT, 0, data.objectData()); wrapper.set(Types.INT, 0, data.objectData());
} }
} }
}; };

View File

@ -19,6 +19,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.rewriter.IdRewriteFunction; import com.viaversion.viaversion.rewriter.IdRewriteFunction;
public final class MapColorRewriter { public final class MapColorRewriter {
@ -31,22 +32,22 @@ public final class MapColorRewriter {
*/ */
public static PacketHandler getRewriteHandler(IdRewriteFunction rewriter) { public static PacketHandler getRewriteHandler(IdRewriteFunction rewriter) {
return wrapper -> { return wrapper -> {
int iconCount = wrapper.passthrough(Type.VAR_INT); int iconCount = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < iconCount; i++) { for (int i = 0; i < iconCount; i++) {
wrapper.passthrough(Type.VAR_INT); // Type wrapper.passthrough(Types.VAR_INT); // Type
wrapper.passthrough(Type.BYTE); // X wrapper.passthrough(Types.BYTE); // X
wrapper.passthrough(Type.BYTE); // Z wrapper.passthrough(Types.BYTE); // Z
wrapper.passthrough(Type.BYTE); // Direction wrapper.passthrough(Types.BYTE); // Direction
wrapper.passthrough(Type.OPTIONAL_COMPONENT); // Display Name wrapper.passthrough(Types.OPTIONAL_COMPONENT); // Display Name
} }
short columns = wrapper.passthrough(Type.UNSIGNED_BYTE); short columns = wrapper.passthrough(Types.UNSIGNED_BYTE);
if (columns < 1) return; if (columns < 1) return;
wrapper.passthrough(Type.UNSIGNED_BYTE); // Rows wrapper.passthrough(Types.UNSIGNED_BYTE); // Rows
wrapper.passthrough(Type.UNSIGNED_BYTE); // X wrapper.passthrough(Types.UNSIGNED_BYTE); // X
wrapper.passthrough(Type.UNSIGNED_BYTE); // Z wrapper.passthrough(Types.UNSIGNED_BYTE); // Z
byte[] data = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE); byte[] data = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
int color = data[i] & 0xFF; int color = data[i] & 0xFF;
int mappedColor = rewriter.rewrite(color); int mappedColor = rewriter.rewrite(color);

View File

@ -24,7 +24,7 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.SoundRewriter<C> { public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversion.viaversion.rewriter.SoundRewriter<C> {
@ -39,7 +39,7 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // Sound identifier map(Types.STRING); // Sound identifier
handler(getNamedSoundHandler()); handler(getNamedSoundHandler());
} }
}); });
@ -56,14 +56,14 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
public PacketHandler getNamedSoundHandler() { public PacketHandler getNamedSoundHandler() {
return wrapper -> { return wrapper -> {
final String soundId = wrapper.get(Type.STRING, 0); final String soundId = wrapper.get(Types.STRING, 0);
final String mappedId = protocol.getMappingData().getMappedNamedSound(soundId); final String mappedId = protocol.getMappingData().getMappedNamedSound(soundId);
if (mappedId == null) { if (mappedId == null) {
return; return;
} }
if (!mappedId.isEmpty()) { if (!mappedId.isEmpty()) {
wrapper.set(Type.STRING, 0, mappedId); wrapper.set(Types.STRING, 0, mappedId);
} else { } else {
wrapper.cancel(); wrapper.cancel();
} }
@ -72,23 +72,23 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
public PacketHandler getStopSoundHandler() { public PacketHandler getStopSoundHandler() {
return wrapper -> { return wrapper -> {
final byte flags = wrapper.passthrough(Type.BYTE); final byte flags = wrapper.passthrough(Types.BYTE);
if ((flags & 0x02) == 0) return; // No sound specified if ((flags & 0x02) == 0) return; // No sound specified
if ((flags & 0x01) != 0) { if ((flags & 0x01) != 0) {
wrapper.passthrough(Type.VAR_INT); // Source wrapper.passthrough(Types.VAR_INT); // Source
} }
final String soundId = wrapper.read(Type.STRING); final String soundId = wrapper.read(Types.STRING);
final String mappedId = protocol.getMappingData().getMappedNamedSound(soundId); final String mappedId = protocol.getMappingData().getMappedNamedSound(soundId);
if (mappedId == null) { if (mappedId == null) {
// No mapping found // No mapping found
wrapper.write(Type.STRING, soundId); wrapper.write(Types.STRING, soundId);
return; return;
} }
if (!mappedId.isEmpty()) { if (!mappedId.isEmpty()) {
wrapper.write(Type.STRING, mappedId); wrapper.write(Types.STRING, mappedId);
} else { } else {
// Cancel if set to empty // Cancel if set to empty
wrapper.cancel(); wrapper.cancel();
@ -97,15 +97,15 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
} }
@Override @Override
public void register1_19_3Sound(final C packetType) { public void registerSound1_19_3(final C packetType) {
protocol.registerClientbound(packetType, get1_19_3SoundHandler()); protocol.registerClientbound(packetType, getSoundHandler1_19_3());
} }
public PacketHandler get1_19_3SoundHandler() { public PacketHandler getSoundHandler1_19_3() {
return wrapper -> { return wrapper -> {
Holder<SoundEvent> soundEventHolder = wrapper.read(Type.SOUND_EVENT); Holder<SoundEvent> soundEventHolder = wrapper.read(Types.SOUND_EVENT);
if (soundEventHolder.isDirect()) { if (soundEventHolder.isDirect()) {
wrapper.write(Type.SOUND_EVENT, rewriteSoundEvent(wrapper, soundEventHolder)); wrapper.write(Types.SOUND_EVENT, rewriteSoundEvent(wrapper, soundEventHolder));
return; return;
} }
@ -119,7 +119,7 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
soundEventHolder = Holder.of(mappedId); soundEventHolder = Holder.of(mappedId);
} }
wrapper.write(Type.SOUND_EVENT, soundEventHolder); wrapper.write(Types.SOUND_EVENT, soundEventHolder);
}; };
} }

View File

@ -17,7 +17,7 @@
*/ */
package com.viaversion.viabackwards.api.rewriters; package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.IntIntPair; import com.viaversion.viaversion.libs.fastutil.ints.IntIntPair;
import com.viaversion.viaversion.libs.fastutil.objects.ObjectIterator; import com.viaversion.viaversion.libs.fastutil.objects.ObjectIterator;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -83,7 +83,7 @@ public class StructuredEnchantmentRewriter {
final List<IntIntPair> updatedIds = new ArrayList<>(); final List<IntIntPair> updatedIds = new ArrayList<>();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final Int2IntMap.Entry entry = iterator.next(); final Int2IntMap.Entry entry = iterator.next();
final BackwardsMappings mappingData = itemRewriter.protocol().getMappingData(); final BackwardsMappingData mappingData = itemRewriter.protocol().getMappingData();
final Mappings mappings = mappingData.getEnchantmentMappings(); final Mappings mappings = mappingData.getEnchantmentMappings();
final int mappedId = mappings.getNewId(entry.getIntKey()); final int mappedId = mappings.getNewId(entry.getIntKey());
if (mappedId != -1) { if (mappedId != -1) {

View File

@ -24,8 +24,8 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -48,7 +48,7 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
} }
public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type) { public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type) {
this(protocol, type, protocol.getClass().getSimpleName().split("To")[1].replace("_", ".")); this(protocol, type, protocol.getClass().getSimpleName().replace("Protocol", "").split("To")[0].replace("_", "."));
} }
public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String sectionIdentifier) { public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final ReadType type, final String sectionIdentifier) {

View File

@ -1,127 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
public class EntityPackets1_11_1 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_11To1_11_1> {
public EntityPackets1_11_1(Protocol1_11To1_11_1 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - x
map(Type.DOUBLE); // 4 - y
map(Type.DOUBLE); // 5 - z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - data
// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
}
});
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_9.METADATA_LIST); // 12 - Metadata
// Track entity
handler(getTrackerHandler());
// Rewrite entity type / metadata
handler(getMobSpawnRewriter1_11(Types1_9.METADATA_LIST));
}
});
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, EntityTypes1_11.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, EntityTypes1_11.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_9.METADATA_LIST); // 7 - Metadata list
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, EntityTypes1_11.EntityType.PLAYER));
}
});
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
}
@Override
protected void registerRewrites() {
// Handle non-existing firework metadata (index 7 entity id for boosting)
filter().type(EntityTypes1_11.EntityType.FIREWORK).cancel(7);
// Handle non-existing pig metadata (index 14 - boost time)
filter().type(EntityTypes1_11.EntityType.PIG).cancel(14);
}
@Override
public EntityType typeFromId(int typeId) {
return EntityTypes1_11.getTypeFromId(typeId, false);
}
@Override
public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_11.getTypeFromId(typeId, true);
}
}

View File

@ -1,80 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets1_13_2;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets1_13_2;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets1_13_2;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
public class Protocol1_13_1To1_13_2 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
public Protocol1_13_1To1_13_2() {
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
}
@Override
protected void registerPackets() {
InventoryPackets1_13_2.register(this);
WorldPackets1_13_2.register(this);
EntityPackets1_13_2.register(this);
registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketHandlers() {
@Override
public void register() {
map(Type.ITEM1_13, Type.ITEM1_13_2);
}
});
registerClientbound(ClientboundPackets1_13.ADVANCEMENTS, wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier
wrapper.passthrough(Type.OPTIONAL_STRING); // Parent
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
Item icon = wrapper.read(Type.ITEM1_13_2);
wrapper.write(Type.ITEM1_13, icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)
wrapper.passthrough(Type.STRING); // Background texture
wrapper.passthrough(Type.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y
}
wrapper.passthrough(Type.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array
}
}
});
}
}

View File

@ -1,92 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.packets;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
public class EntityPackets1_13_2 {
public static void register(Protocol1_13_1To1_13_2 protocol) {
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_13_2.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
handler(wrapper -> {
for (Metadata metadata : wrapper.get(Types1_13.METADATA_LIST, 0)) {
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId()));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_13_2.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata
handler(wrapper -> {
for (Metadata metadata : wrapper.get(Types1_13.METADATA_LIST, 0)) {
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId()));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.ENTITY_METADATA, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13_2.METADATA_LIST, Types1_13.METADATA_LIST); // 1 - Metadata list
handler(wrapper -> {
for (Metadata metadata : wrapper.get(Types1_13.METADATA_LIST, 0)) {
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId()));
}
});
}
});
}
}

View File

@ -1,136 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.packets;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
public class InventoryPackets1_13_2 {
public static void register(Protocol1_13_1To1_13_2 protocol) {
protocol.registerClientbound(ClientboundPackets1_13.SET_SLOT, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM1_13_2, Type.ITEM1_13); // 2 - Slot Value
}
});
protocol.registerClientbound(ClientboundPackets1_13.WINDOW_ITEMS, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM1_13_2_SHORT_ARRAY, Type.ITEM1_13_SHORT_ARRAY); // 1 - Window Values
}
});
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketHandlers() {
@Override
public void register() {
map(Type.STRING); // Channel
handler(wrapper -> {
String channel = wrapper.get(Type.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
// Input Item
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2));
// Output Item
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2));
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.ENTITY_EQUIPMENT, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM1_13_2, Type.ITEM1_13); // 2 - Item
}
});
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> {
int recipesNo = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < recipesNo; i++) {
wrapper.passthrough(Type.STRING); // Id
String type = wrapper.passthrough(Type.STRING);
if (type.equals("crafting_shapeless")) {
wrapper.passthrough(Type.STRING); // Group
int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.ITEM1_13_ARRAY, wrapper.read(Type.ITEM1_13_2_ARRAY));
}
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2));
} else if (type.equals("crafting_shaped")) {
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Group
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.ITEM1_13_ARRAY, wrapper.read(Type.ITEM1_13_2_ARRAY));
}
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2));
} else if (type.equals("smelting")) {
wrapper.passthrough(Type.STRING); // Group
// Ingredient start
wrapper.write(Type.ITEM1_13_ARRAY, wrapper.read(Type.ITEM1_13_2_ARRAY));
// Ingredient end
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2));
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
}
}
});
protocol.registerServerbound(ServerboundPackets1_13.CLICK_WINDOW, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.ITEM1_13, Type.ITEM1_13_2); // 5 - Clicked Item
}
});
protocol.registerServerbound(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, new PacketHandlers() {
@Override
public void register() {
map(Type.SHORT); // 0 - Slot
map(Type.ITEM1_13, Type.ITEM1_13_2); // 1 - Clicked Item
}
});
}
}

View File

@ -1,130 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.DifficultyStorage;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.rewriter.RewriterBase;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
public class PlayerPackets1_14 extends RewriterBase<Protocol1_13_2To1_14> {
public PlayerPackets1_14(Protocol1_13_2To1_14 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_14.SERVER_DIFFICULTY, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE);
read(Type.BOOLEAN); // Locked
handler(wrapper -> {
byte difficulty = wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue();
wrapper.user().get(DifficultyStorage.class).setDifficulty(difficulty);
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.OPEN_SIGN_EDITOR, new PacketHandlers() {
@Override
public void register() {
map(Type.POSITION1_14, Type.POSITION1_8);
}
});
protocol.registerServerbound(ServerboundPackets1_13.QUERY_BLOCK_NBT, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT);
map(Type.POSITION1_8, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.PLAYER_DIGGING, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // Action
map(Type.POSITION1_8, Type.POSITION1_14); // Position
}
});
protocol.registerServerbound(ServerboundPackets1_13.RECIPE_BOOK_DATA, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT);
handler(wrapper -> {
int type = wrapper.get(Type.VAR_INT, 0);
if (type == 0) {
wrapper.passthrough(Type.STRING);
} else if (type == 1) {
wrapper.passthrough(Type.BOOLEAN); // Crafting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN); // Crafting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN); // Smelting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN); // Smelting Recipe Filter Active
// Blast furnace/smoker data
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, new PacketHandlers() {
@Override
public void register() {
map(Type.POSITION1_8, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, new PacketHandlers() {
@Override
public void register() {
map(Type.POSITION1_8, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_SIGN, new PacketHandlers() {
@Override
public void register() {
map(Type.POSITION1_8, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.PLAYER_BLOCK_PLACEMENT, wrapper -> {
Position position = wrapper.read(Type.POSITION1_8);
int face = wrapper.read(Type.VAR_INT);
int hand = wrapper.read(Type.VAR_INT);
float x = wrapper.read(Type.FLOAT);
float y = wrapper.read(Type.FLOAT);
float z = wrapper.read(Type.FLOAT);
wrapper.write(Type.VAR_INT, hand);
wrapper.write(Type.POSITION1_14, position);
wrapper.write(Type.VAR_INT, face);
wrapper.write(Type.FLOAT, x);
wrapper.write(Type.FLOAT, y);
wrapper.write(Type.FLOAT, z);
wrapper.write(Type.BOOLEAN, false); // Inside block
});
}
}

View File

@ -1,73 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets1_13_1 extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13To1_13_1> {
public InventoryPackets1_13_1(Protocol1_13To1_13_1 protocol) {
super(protocol, Type.ITEM1_13, Type.ITEM1_13_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_13.SET_SLOT);
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, wrapper -> {
String channel = wrapper.passthrough(Type.STRING);
if (channel.equals("minecraft:trader_list")) {
wrapper.passthrough(Type.INT); //Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.passthrough(Type.ITEM1_13);
handleItemToClient(wrapper.user(), input);
//Output Item
Item output = wrapper.passthrough(Type.ITEM1_13);
handleItemToClient(wrapper.user(), output);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.passthrough(Type.ITEM1_13);
handleItemToClient(wrapper.user(), second);
}
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses
wrapper.passthrough(Type.INT); //Maximum number of trade uses
}
}
});
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLOAT);
}
}

View File

@ -1,227 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping;
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import java.util.ArrayList;
public class EntityPackets1_15 extends EntityRewriter<ClientboundPackets1_15, Protocol1_14_4To1_15> {
public EntityPackets1_15(Protocol1_14_4To1_15 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_15.UPDATE_HEALTH, wrapper -> {
float health = wrapper.passthrough(Type.FLOAT);
if (health > 0) return;
if (!wrapper.user().get(ImmediateRespawn.class).isImmediateRespawn()) return;
// Instantly request respawn when 1.15 gamerule is set
PacketWrapper statusPacket = wrapper.create(ServerboundPackets1_14.CLIENT_STATUS);
statusPacket.write(Type.VAR_INT, 0);
statusPacket.sendToServer(Protocol1_14_4To1_15.class);
});
protocol.registerClientbound(ClientboundPackets1_15.GAME_EVENT, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE);
map(Type.FLOAT);
handler(wrapper -> {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11) {
wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.get(Type.FLOAT, 0) == 1);
}
});
}
});
registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, EntityTypes1_15.FALLING_BLOCK);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_MOB, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
handler(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one
handler(wrapper -> {
int type = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = EntityTypes1_15.getTypeFromId(type);
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType);
wrapper.set(Type.VAR_INT, 1, EntityTypeMapping.getOldEntityId(type));
});
}
});
protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketHandlers() {
@Override
public void register() {
map(Type.INT);
read(Type.LONG); // Seed
}
});
protocol.registerClientbound(ClientboundPackets1_15.JOIN_GAME, new PacketHandlers() {
@Override
public void register() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
read(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE); // 3 - Max Players
map(Type.STRING); // 4 - Level Type
map(Type.VAR_INT); // 5 - View Distance
map(Type.BOOLEAN); // 6 - Reduce Debug Info
handler(getTrackerHandler(EntityTypes1_15.PLAYER, Type.INT));
handler(wrapper -> {
boolean immediateRespawn = !wrapper.read(Type.BOOLEAN); // Inverted
wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(immediateRespawn);
});
}
});
registerTracker(ClientboundPackets1_15.SPAWN_EXPERIENCE_ORB, EntityTypes1_15.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, EntityTypes1_15.LIGHTNING_BOLT);
registerTracker(ClientboundPackets1_15.SPAWN_PAINTING, EntityTypes1_15.PAINTING);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
handler(wrapper -> wrapper.write(Types1_14.METADATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one
handler(getTrackerHandler(EntityTypes1_15.PLAYER, Type.VAR_INT));
}
});
registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST);
// Attributes (get rid of generic.flyingSpeed for the Bee remap)
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT);
map(Type.INT);
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = tracker(wrapper.user()).entityType(entityId);
if (entityType != EntityTypes1_15.BEE) return;
int size = wrapper.get(Type.INT, 0);
int newSize = size;
for (int i = 0; i < size; i++) {
String key = wrapper.read(Type.STRING);
if (key.equals("generic.flyingSpeed")) {
newSize--;
wrapper.read(Type.DOUBLE);
int modSize = wrapper.read(Type.VAR_INT);
for (int j = 0; j < modSize; j++) {
wrapper.read(Type.UUID);
wrapper.read(Type.DOUBLE);
wrapper.read(Type.BYTE);
}
} else {
wrapper.write(Type.STRING, key);
wrapper.passthrough(Type.DOUBLE);
int modSize = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < modSize; j++) {
wrapper.passthrough(Type.UUID);
wrapper.passthrough(Type.DOUBLE);
wrapper.passthrough(Type.BYTE);
}
}
}
if (newSize != size) {
wrapper.set(Type.INT, 0, newSize);
}
});
}
});
}
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType,
Types1_14.META_TYPES.componentType, Types1_14.META_TYPES.optionalComponentType);
filter().type(EntityTypes1_15.LIVINGENTITY).removeIndex(12);
filter().type(EntityTypes1_15.BEE).cancel(15);
filter().type(EntityTypes1_15.BEE).cancel(16);
mapEntityTypeWithData(EntityTypes1_15.BEE, EntityTypes1_15.PUFFERFISH).jsonName().spawnMetadata(storage -> {
storage.add(new Metadata(14, Types1_14.META_TYPES.booleanType, false));
storage.add(new Metadata(15, Types1_14.META_TYPES.varIntType, 2));
});
filter().type(EntityTypes1_15.ENDERMAN).cancel(16);
filter().type(EntityTypes1_15.TRIDENT).cancel(10);
// Redundant health removed in 1.15
filter().type(EntityTypes1_15.WOLF).addIndex(17);
filter().type(EntityTypes1_15.WOLF).index(8).handler((event, meta) -> {
event.createExtraMeta(new Metadata(17/*WOLF_HEALTH*/, Types1_14.META_TYPES.floatType, event.meta().value()));
});
}
@Override
public EntityType typeFromId(int typeId) {
return EntityTypes1_15.getTypeFromId(typeId);
}
@Override
public int newEntityId(final int newId) {
return EntityTypeMapping.getOldEntityId(newId);
}
}

View File

@ -1,102 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import java.util.List;
public class EntityPackets1_14_1 extends LegacyEntityRewriter<ClientboundPackets1_14, Protocol1_14To1_14_1> {
public EntityPackets1_14_1(Protocol1_14To1_14_1 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
registerTracker(ClientboundPackets1_14.SPAWN_EXPERIENCE_ORB, EntityTypes1_14.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_14.SPAWN_GLOBAL_ENTITY, EntityTypes1_14.LIGHTNING_BOLT);
registerTracker(ClientboundPackets1_14.SPAWN_PAINTING, EntityTypes1_14.PAINTING);
registerTracker(ClientboundPackets1_14.SPAWN_PLAYER, EntityTypes1_14.PLAYER);
registerTracker(ClientboundPackets1_14.JOIN_GAME, EntityTypes1_14.PLAYER, Type.INT);
registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.VAR_INT); // 2 - Type
handler(getTrackerHandler());
}
});
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_MOB, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_14.METADATA_LIST); // 12 - Metadata
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1);
// Register Type ID
tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.getTypeFromId(type));
List<Metadata> metadata = wrapper.get(Types1_14.METADATA_LIST, 0);
handleMetadata(entityId, metadata, wrapper.user());
});
}
});
// Entity Metadata
registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
}
@Override
protected void registerRewrites() {
filter().type(EntityTypes1_14.VILLAGER).cancel(15);
filter().type(EntityTypes1_14.VILLAGER).index(16).toIndex(15);
filter().type(EntityTypes1_14.WANDERING_TRADER).cancel(15);
}
@Override
public EntityType typeFromId(int typeId) {
return EntityTypes1_14.getTypeFromId(typeId);
}
}

View File

@ -1,124 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.packets;
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.rewriter.RecipeRewriter1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.Key;
public final class BlockItemPackets1_19_4 extends BackwardsItemRewriter<ClientboundPackets1_19_4, ServerboundPackets1_19_3, Protocol1_19_3To1_19_4> {
public BlockItemPackets1_19_4(final Protocol1_19_3To1_19_4 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
}
@Override
public void registerPackets() {
final BlockRewriter<ClientboundPackets1_19_4> blockRewriter = BlockRewriter.for1_14(protocol);
blockRewriter.registerBlockAction(ClientboundPackets1_19_4.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_19_4.BLOCK_CHANGE);
blockRewriter.registerVarLongMultiBlockChange(ClientboundPackets1_19_4.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_19_4.EFFECT, 1010, 2001);
blockRewriter.registerChunkData1_19(ClientboundPackets1_19_4.CHUNK_DATA, ChunkType1_18::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_19_4.BLOCK_ENTITY_DATA);
protocol.registerClientbound(ClientboundPackets1_19_4.OPEN_WINDOW, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // Container id
map(Type.VAR_INT); // Container type
map(Type.COMPONENT); // Title
handler(wrapper -> {
final int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType == 21) { // New smithing menu
wrapper.cancel();
} else if (windowType > 21) {
wrapper.set(Type.VAR_INT, 1, windowType - 1);
}
protocol.getTranslatableRewriter().processText(wrapper.user(), wrapper.get(Type.COMPONENT, 0));
});
}
});
registerSetCooldown(ClientboundPackets1_19_4.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_19_4.WINDOW_ITEMS);
registerSetSlot1_17_1(ClientboundPackets1_19_4.SET_SLOT);
registerAdvancements(ClientboundPackets1_19_4.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_19_4.ENTITY_EQUIPMENT);
registerClickWindow1_17_1(ServerboundPackets1_19_3.CLICK_WINDOW);
registerTradeList1_19(ClientboundPackets1_19_4.TRADE_LIST);
registerCreativeInvAction(ServerboundPackets1_19_3.CREATIVE_INVENTORY_ACTION);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_4.WINDOW_PROPERTY);
registerSpawnParticle1_19(ClientboundPackets1_19_4.SPAWN_PARTICLE);
final RecipeRewriter1_19_3<ClientboundPackets1_19_4> recipeRewriter = new RecipeRewriter1_19_3<>(protocol) {
@Override
public void handleCraftingShaped(final PacketWrapper wrapper) {
final int ingredients = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.VAR_INT); // Crafting book category
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
rewrite(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
// Remove notification boolean
wrapper.read(Type.BOOLEAN);
}
};
protocol.registerClientbound(ClientboundPackets1_19_4.DECLARE_RECIPES, wrapper -> {
final int size = wrapper.passthrough(Type.VAR_INT);
int newSize = size;
for (int i = 0; i < size; i++) {
final String type = wrapper.read(Type.STRING);
final String cutType = Key.stripMinecraftNamespace(type);
if (cutType.equals("smithing_transform") || cutType.equals("smithing_trim")) {
newSize--;
wrapper.read(Type.STRING); // Recipe identifier
wrapper.read(Type.ITEM1_13_2_ARRAY); // Template
wrapper.read(Type.ITEM1_13_2_ARRAY); // Base
wrapper.read(Type.ITEM1_13_2_ARRAY); // Additions
if (cutType.equals("smithing_transform")) {
wrapper.read(Type.ITEM1_13_2); // Result
}
continue;
} else if (cutType.equals("crafting_decorated_pot")) {
newSize--;
wrapper.read(Type.STRING); // Recipe identifier
wrapper.read(Type.VAR_INT); // Crafting book category
continue;
}
wrapper.write(Type.STRING, type);
wrapper.passthrough(Type.STRING); // Recipe Identifier
recipeRewriter.handleRecipeType(wrapper, cutType);
}
wrapper.set(Type.VAR_INT, 0, newSize);
});
}
}

View File

@ -1,160 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.rewriter;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.Protocol1_20_2To1_20_3;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPacket1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.RecipeRewriter1_20_3;
import com.viaversion.viaversion.rewriter.BlockRewriter;
public final class BlockItemPacketRewriter1_20_3 extends BackwardsItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_2, Protocol1_20_2To1_20_3> {
public BlockItemPacketRewriter1_20_3(final Protocol1_20_2To1_20_3 protocol) {
super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY);
}
@Override
public void registerPackets() {
final BlockRewriter<ClientboundPacket1_20_3> blockRewriter = BlockRewriter.for1_20_2(protocol);
blockRewriter.registerBlockAction(ClientboundPackets1_20_3.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_20_3.BLOCK_CHANGE);
blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_3.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_20_3.EFFECT, 1010, 2001);
blockRewriter.registerChunkData1_19(ClientboundPackets1_20_3.CHUNK_DATA, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_20_3.BLOCK_ENTITY_DATA);
registerSetCooldown(ClientboundPackets1_20_3.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_20_3.WINDOW_ITEMS);
registerSetSlot1_17_1(ClientboundPackets1_20_3.SET_SLOT);
registerEntityEquipmentArray(ClientboundPackets1_20_3.ENTITY_EQUIPMENT);
registerClickWindow1_17_1(ServerboundPackets1_20_2.CLICK_WINDOW);
registerTradeList1_19(ClientboundPackets1_20_3.TRADE_LIST);
registerCreativeInvAction(ServerboundPackets1_20_2.CREATIVE_INVENTORY_ACTION);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_20_3.WINDOW_PROPERTY);
protocol.registerClientbound(ClientboundPackets1_20_3.SPAWN_PARTICLE, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
handler(wrapper -> {
final int id = wrapper.get(Type.VAR_INT, 0);
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (id == particleMappings.id("vibration")) {
final int positionSourceType = wrapper.read(Type.VAR_INT);
if (positionSourceType == 0) {
wrapper.write(Type.STRING, "minecraft:block");
} else if (positionSourceType == 1) {
wrapper.write(Type.STRING, "minecraft:entity");
} else {
ViaBackwards.getPlatform().getLogger().warning("Unknown position source type: " + positionSourceType);
wrapper.cancel();
}
}
});
handler(getSpawnParticleHandler(Type.VAR_INT));
}
});
new RecipeRewriter1_20_3<>(protocol) {
@Override
public void handleCraftingShaped(final PacketWrapper wrapper) {
// Move width and height up
final String group = wrapper.read(Type.STRING);
final int craftingBookCategory = wrapper.read(Type.VAR_INT);
final int width = wrapper.passthrough(Type.VAR_INT);
final int height = wrapper.passthrough(Type.VAR_INT);
wrapper.write(Type.STRING, group);
wrapper.write(Type.VAR_INT, craftingBookCategory);
final int ingredients = height * width;
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
rewrite(wrapper.user(), wrapper.passthrough(itemType())); // Result
wrapper.passthrough(Type.BOOLEAN); // Show notification
}
}.register(ClientboundPackets1_20_3.DECLARE_RECIPES);
protocol.registerClientbound(ClientboundPackets1_20_3.EXPLOSION, wrapper -> {
wrapper.passthrough(Type.DOUBLE); // X
wrapper.passthrough(Type.DOUBLE); // Y
wrapper.passthrough(Type.DOUBLE); // Z
wrapper.passthrough(Type.FLOAT); // Power
final int blocks = wrapper.read(Type.VAR_INT);
final byte[][] toBlow = new byte[blocks][3];
for (int i = 0; i < blocks; i++) {
toBlow[i] = new byte[]{
wrapper.read(Type.BYTE), // Relative X
wrapper.read(Type.BYTE), // Relative Y
wrapper.read(Type.BYTE) // Relative Z
};
}
final float knockbackX = wrapper.read(Type.FLOAT); // Knockback X
final float knockbackY = wrapper.read(Type.FLOAT); // Knockback Y
final float knockbackZ = wrapper.read(Type.FLOAT); // Knockback Z
final int blockInteraction = wrapper.read(Type.VAR_INT); // Block interaction type
// 0 = keep, 1 = destroy, 2 = destroy_with_decay, 3 = trigger_block
if (blockInteraction == 1 || blockInteraction == 2) {
wrapper.write(Type.VAR_INT, blocks);
for (final byte[] relativeXYZ : toBlow) {
wrapper.write(Type.BYTE, relativeXYZ[0]);
wrapper.write(Type.BYTE, relativeXYZ[1]);
wrapper.write(Type.BYTE, relativeXYZ[2]);
}
} else {
// Explosion doesn't destroy blocks
wrapper.write(Type.VAR_INT, 0);
}
wrapper.write(Type.FLOAT, knockbackX);
wrapper.write(Type.FLOAT, knockbackY);
wrapper.write(Type.FLOAT, knockbackZ);
// TODO Probably needs handling
wrapper.read(Types1_20_3.PARTICLE); // Small explosion particle
wrapper.read(Types1_20_3.PARTICLE); // Large explosion particle
wrapper.read(Type.STRING); // Explosion sound
wrapper.read(Type.OPTIONAL_FLOAT); // Sound range
});
}
}

View File

@ -1,415 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter;
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.provider.AdvancementCriteriaProvider;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects1_20_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.MathUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter<ClientboundPackets1_20_2, ServerboundPackets1_19_4, Protocol1_20To1_20_2> {
public BlockItemPacketRewriter1_20_2(final Protocol1_20To1_20_2 protocol) {
super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY);
}
@Override
public void registerPackets() {
final BlockRewriter<ClientboundPackets1_20_2> blockRewriter = BlockRewriter.for1_14(protocol);
blockRewriter.registerBlockAction(ClientboundPackets1_20_2.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_20_2.BLOCK_CHANGE);
blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_2.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_20_2.EFFECT, 1010, 2001);
protocol.cancelClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_START);
protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_FINISHED, null, wrapper -> {
wrapper.cancel();
final PacketWrapper receivedPacket = wrapper.create(ServerboundPackets1_20_2.CHUNK_BATCH_RECEIVED);
receivedPacket.write(Type.FLOAT, 500F); // Requested next batch size... arbitrary value here
receivedPacket.sendToServer(Protocol1_20To1_20_2.class);
});
protocol.registerClientbound(ClientboundPackets1_20_2.UNLOAD_CHUNK, wrapper -> {
final ChunkPosition chunkPosition = wrapper.read(Type.CHUNK_POSITION);
wrapper.write(Type.INT, chunkPosition.chunkX());
wrapper.write(Type.INT, chunkPosition.chunkZ());
});
protocol.registerClientbound(ClientboundPackets1_20_2.MAP_DATA, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Map id
wrapper.passthrough(Type.BYTE); // Scale
wrapper.passthrough(Type.BOOLEAN); // Locked
if (wrapper.passthrough(Type.BOOLEAN)) {
final int icons = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < icons; i++) {
// Map new marker types to red marker
final int markerType = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, markerType < 27 ? markerType : 2);
wrapper.passthrough(Type.BYTE); // X
wrapper.passthrough(Type.BYTE); // Y
wrapper.passthrough(Type.BYTE); // Rotation
wrapper.passthrough(Type.OPTIONAL_COMPONENT); // Display name
}
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.NBT_QUERY, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Transaction id
wrapper.write(Type.NAMED_COMPOUND_TAG, wrapper.read(Type.COMPOUND_TAG));
});
protocol.registerClientbound(ClientboundPackets1_20_2.BLOCK_ENTITY_DATA, wrapper -> {
wrapper.passthrough(Type.POSITION1_14); // Position
wrapper.passthrough(Type.VAR_INT); // Type
wrapper.write(Type.NAMED_COMPOUND_TAG, handleBlockEntity(wrapper.read(Type.COMPOUND_TAG)));
});
protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_DATA, wrapper -> {
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
final Type<Chunk> chunkType = new ChunkType1_20_2(tracker.currentWorldSectionHeight(),
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()),
MathUtil.ceilLog2(tracker.biomesSent()));
final Chunk chunk = wrapper.read(chunkType);
final Type<Chunk> newChunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(),
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
MathUtil.ceilLog2(tracker.biomesSent()));
wrapper.write(newChunkType, chunk);
for (final ChunkSection section : chunk.getSections()) {
final DataPalette blockPalette = section.palette(PaletteType.BLOCKS);
for (int i = 0; i < blockPalette.size(); i++) {
final int id = blockPalette.idByIndex(i);
blockPalette.setIdByIndex(i, protocol.getMappingData().getNewBlockStateId(id));
}
}
for (final BlockEntity blockEntity : chunk.blockEntities()) {
handleBlockEntity(blockEntity.tag());
}
});
protocol.registerServerbound(ServerboundPackets1_19_4.SET_BEACON_EFFECT, wrapper -> {
// Effects start at 1 before 1.20.2
if (wrapper.passthrough(Type.BOOLEAN)) { // Primary effect
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) - 1);
}
if (wrapper.passthrough(Type.BOOLEAN)) { // Secondary effect
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) - 1);
}
});
// Replace the NBT type everywhere
protocol.registerClientbound(ClientboundPackets1_20_2.WINDOW_ITEMS, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.VAR_INT); // State id
handler(wrapper -> {
final Item[] items = wrapper.read(Type.ITEM1_20_2_ARRAY);
for (final Item item : items) {
handleItemToClient(wrapper.user(), item);
}
wrapper.write(Type.ITEM1_13_2_ARRAY, items);
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Carried item
});
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.SET_SLOT, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.VAR_INT); // State id
map(Type.SHORT); // Slot id
handler(wrapper -> wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))));
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.ADVANCEMENTS, wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
final String advancement = wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.OPTIONAL_STRING); // Parent
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
wrapper.passthrough(Type.STRING); // Background texture
}
wrapper.passthrough(Type.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y
}
final AdvancementCriteriaProvider criteriaProvider = Via.getManager().getProviders().get(AdvancementCriteriaProvider.class);
wrapper.write(Type.STRING_ARRAY, criteriaProvider.getCriteria(advancement));
final int requirements = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < requirements; array++) {
wrapper.passthrough(Type.STRING_ARRAY);
}
wrapper.passthrough(Type.BOOLEAN); // Send telemetry
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.ENTITY_EQUIPMENT, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
handler(wrapper -> {
byte slot;
do {
slot = wrapper.passthrough(Type.BYTE);
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
} while ((slot & 0xFFFFFF80) != 0);
});
}
});
protocol.registerServerbound(ServerboundPackets1_19_4.CLICK_WINDOW, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // Window Id
map(Type.VAR_INT); // State id
map(Type.SHORT); // Slot
map(Type.BYTE); // Button
map(Type.VAR_INT); // Mode
handler(wrapper -> {
// Affected items
final int length = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < length; i++) {
wrapper.passthrough(Type.SHORT); // Slot
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
}
// Carried item
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
});
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.TRADE_LIST, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Container id
final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Input
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Output
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses
wrapper.passthrough(Type.INT); // XP
wrapper.passthrough(Type.INT); // Special price
wrapper.passthrough(Type.FLOAT); // Price multiplier
wrapper.passthrough(Type.INT); // Demand
}
});
protocol.registerServerbound(ServerboundPackets1_19_4.CREATIVE_INVENTORY_ACTION, new PacketHandlers() {
@Override
public void register() {
map(Type.SHORT); // 0 - Slot
handler(wrapper -> wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)))); // 1 - Clicked Item
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.SPAWN_PARTICLE, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
handler(wrapper -> {
final int id = wrapper.get(Type.VAR_INT, 0);
final ParticleMappings mappings = Protocol1_20To1_20_2.MAPPINGS.getParticleMappings();
if (mappings.isBlockParticle(id)) {
final int data = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
}
});
}
});
new RecipeRewriter1_20_2<>(protocol) {
@Override
public void handleCraftingShapeless(final PacketWrapper wrapper) {
wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.VAR_INT); // Crafting book category
handleIngredients(wrapper);
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@Override
public void handleSmelting(final PacketWrapper wrapper) {
wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.VAR_INT); // Crafting book category
handleIngredient(wrapper);
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
}
@Override
public void handleCraftingShaped(final PacketWrapper wrapper) {
final int ingredients = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.VAR_INT); // Crafting book category
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
wrapper.passthrough(Type.BOOLEAN); // Show notification
}
@Override
public void handleStonecutting(final PacketWrapper wrapper) {
wrapper.passthrough(Type.STRING); // Group
handleIngredient(wrapper);
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@Override
public void handleSmithing(final PacketWrapper wrapper) {
handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Addition
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@Override
public void handleSmithingTransform(final PacketWrapper wrapper) {
handleIngredient(wrapper); // Template
handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Additions
final Item result = wrapper.read(itemType());
rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_13_2, result);
}
@Override
protected void handleIngredient(final PacketWrapper wrapper) {
final Item[] items = wrapper.read(itemArrayType());
wrapper.write(Type.ITEM1_13_2_ARRAY, items);
for (final Item item : items) {
rewrite(wrapper.user(), item);
}
}
}.register(ClientboundPackets1_20_2.DECLARE_RECIPES);
}
@Override
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
if (item.tag() != null) {
com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.BlockItemPacketRewriter1_20_2.to1_20_1Effects(item);
}
return super.handleItemToClient(connection, item);
}
@Override
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
if (item.tag() != null) {
com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.BlockItemPacketRewriter1_20_2.to1_20_2Effects(item);
}
return super.handleItemToServer(connection, item);
}
private @Nullable CompoundTag handleBlockEntity(@Nullable final CompoundTag tag) {
if (tag == null) {
return null;
}
final Tag primaryEffect = tag.remove("primary_effect");
if (primaryEffect instanceof StringTag) {
final String effectKey = Key.stripMinecraftNamespace(((StringTag) primaryEffect).getValue());
tag.putInt("Primary", PotionEffects1_20_2.keyToId(effectKey) + 1); // Empty effect at 0
}
final Tag secondaryEffect = tag.remove("secondary_effect");
if (secondaryEffect instanceof StringTag) {
final String effectKey = Key.stripMinecraftNamespace(((StringTag) secondaryEffect).getValue());
tag.putInt("Secondary", PotionEffects1_20_2.keyToId(effectKey) + 1); // Empty effect at 0
}
return tag;
}
}

View File

@ -1,216 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.storage.ConfigurationPacketStorage;
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_20;
import com.viaversion.viaversion.api.type.types.version.Types1_20_2;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
public final class EntityPacketRewriter1_20_2 extends EntityRewriter<ClientboundPackets1_20_2, Protocol1_20To1_20_2> {
public EntityPacketRewriter1_20_2(final Protocol1_20To1_20_2 protocol) {
super(protocol, Types1_20.META_TYPES.optionalComponentType, Types1_20.META_TYPES.booleanType);
}
@Override
public void registerPackets() {
registerMetadataRewriter(ClientboundPackets1_20_2.ENTITY_METADATA, Types1_20_2.METADATA_LIST, Types1_20.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_20_2.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_20_2.SPAWN_ENTITY, new PacketHandlers() {
@Override
protected void register() {
handler(wrapper -> {
final int entityId = wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.UUID); // UUID
final int entityType = wrapper.read(Type.VAR_INT);
tracker(wrapper.user()).addEntity(entityId, typeFromId(entityType));
if (entityType != EntityTypes1_19_4.PLAYER.getId()) {
wrapper.write(Type.VAR_INT, entityType);
if (entityType == EntityTypes1_19_4.FALLING_BLOCK.getId()) {
wrapper.passthrough(Type.DOUBLE); // X
wrapper.passthrough(Type.DOUBLE); // Y
wrapper.passthrough(Type.DOUBLE); // Z
wrapper.passthrough(Type.BYTE); // Pitch
wrapper.passthrough(Type.BYTE); // Yaw
wrapper.passthrough(Type.BYTE); // Head yaw
final int blockState = wrapper.read(Type.VAR_INT); // Data
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockState));
}
return;
}
// Map to spawn player packet
wrapper.setPacketType(ClientboundPackets1_19_4.SPAWN_PLAYER);
wrapper.passthrough(Type.DOUBLE); // X
wrapper.passthrough(Type.DOUBLE); // Y
wrapper.passthrough(Type.DOUBLE); // Z
final byte pitch = wrapper.read(Type.BYTE);
wrapper.passthrough(Type.BYTE); // Yaw
wrapper.write(Type.BYTE, pitch);
wrapper.read(Type.BYTE); // Head yaw
wrapper.read(Type.VAR_INT); // Data
final short velocityX = wrapper.read(Type.SHORT);
final short velocityY = wrapper.read(Type.SHORT);
final short velocityZ = wrapper.read(Type.SHORT);
if (velocityX == 0 && velocityY == 0 && velocityZ == 0) {
return;
}
// Follow up with velocity packet
wrapper.send(Protocol1_20To1_20_2.class);
wrapper.cancel();
final PacketWrapper velocityPacket = wrapper.create(ClientboundPackets1_19_4.ENTITY_VELOCITY);
velocityPacket.write(Type.VAR_INT, entityId);
velocityPacket.write(Type.SHORT, velocityX);
velocityPacket.write(Type.SHORT, velocityY);
velocityPacket.write(Type.SHORT, velocityZ);
velocityPacket.send(Protocol1_20To1_20_2.class);
});
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.JOIN_GAME, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> {
final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().remove(ConfigurationPacketStorage.class);
wrapper.passthrough(Type.INT); // Entity id
wrapper.passthrough(Type.BOOLEAN); // Hardcore
final String[] worlds = wrapper.read(Type.STRING_ARRAY);
final int maxPlayers = wrapper.read(Type.VAR_INT);
final int viewDistance = wrapper.read(Type.VAR_INT);
final int simulationDistance = wrapper.read(Type.VAR_INT);
final boolean reducedDebugInfo = wrapper.read(Type.BOOLEAN);
final boolean showRespawnScreen = wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN); // Limited crafting
final String dimensionType = wrapper.read(Type.STRING);
final String world = wrapper.read(Type.STRING);
final long seed = wrapper.read(Type.LONG);
wrapper.passthrough(Type.BYTE); // Gamemode
wrapper.passthrough(Type.BYTE); // Previous gamemode
wrapper.write(Type.STRING_ARRAY, worlds);
wrapper.write(Type.NAMED_COMPOUND_TAG, configurationPacketStorage.registry());
wrapper.write(Type.STRING, dimensionType);
wrapper.write(Type.STRING, world);
wrapper.write(Type.LONG, seed);
wrapper.write(Type.VAR_INT, maxPlayers);
wrapper.write(Type.VAR_INT, viewDistance);
wrapper.write(Type.VAR_INT, simulationDistance);
wrapper.write(Type.BOOLEAN, reducedDebugInfo);
wrapper.write(Type.BOOLEAN, showRespawnScreen);
worldDataTrackerHandlerByKey().handle(wrapper);
wrapper.send(Protocol1_20To1_20_2.class);
wrapper.cancel();
if (configurationPacketStorage.enabledFeatures() != null) {
final PacketWrapper featuresPacket = wrapper.create(ClientboundPackets1_19_4.UPDATE_ENABLED_FEATURES);
featuresPacket.write(Type.STRING_ARRAY, configurationPacketStorage.enabledFeatures());
featuresPacket.send(Protocol1_20To1_20_2.class);
}
configurationPacketStorage.sendQueuedPackets(wrapper.user());
});
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.RESPAWN, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> {
wrapper.passthrough(Type.STRING); // Dimension type
wrapper.passthrough(Type.STRING); // World
wrapper.passthrough(Type.LONG); // Seed
wrapper.write(Type.UNSIGNED_BYTE, wrapper.read(Type.BYTE).shortValue()); // Gamemode
wrapper.passthrough(Type.BYTE); // Previous gamemode
wrapper.passthrough(Type.BOOLEAN); // Debug
wrapper.passthrough(Type.BOOLEAN); // Flat
final GlobalPosition lastDeathPosition = wrapper.read(Type.OPTIONAL_GLOBAL_POSITION);
final int portalCooldown = wrapper.read(Type.VAR_INT);
wrapper.passthrough(Type.BYTE); // Data to keep
wrapper.write(Type.OPTIONAL_GLOBAL_POSITION, lastDeathPosition);
wrapper.write(Type.VAR_INT, portalCooldown);
});
handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.ENTITY_EFFECT, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Entity id
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) + 1); // Effect id
wrapper.passthrough(Type.BYTE); // Amplifier
wrapper.passthrough(Type.VAR_INT); // Duration
wrapper.passthrough(Type.BYTE); // Flags
final CompoundTag factorData = wrapper.read(Type.OPTIONAL_COMPOUND_TAG);
wrapper.write(Type.OPTIONAL_NAMED_COMPOUND_TAG, factorData); // Factor data
});
protocol.registerClientbound(ClientboundPackets1_20_2.REMOVE_ENTITY_EFFECT, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Entity id
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) + 1); // Effect id
});
}
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> meta.setMetaType(Types1_20.META_TYPES.byId(meta.metaType().typeId())));
registerMetaTypeHandler(Types1_20.META_TYPES.itemType, Types1_20.META_TYPES.blockStateType, Types1_20.META_TYPES.optionalBlockStateType, Types1_20.META_TYPES.particleType, null, null);
filter().type(EntityTypes1_19_4.DISPLAY).removeIndex(10);
filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
}
@Override
public EntityType typeFromId(final int type) {
return EntityTypes1_19_4.getTypeFromId(type);
}
}

View File

@ -1,119 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_9_4To1_10> {
public BlockItemPackets1_10(Protocol1_9_4To1_10 protocol) {
super(protocol, "1.10");
}
@Override
protected void registerPackets() {
registerBlockChange(ClientboundPackets1_9_3.BLOCK_CHANGE);
registerMultiBlockChange(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE);
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
@Override
public void register() {
map(Type.STRING); // 0 - Channel
handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses
}
}
});
}
});
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk);
});
// Rewrite metadata items
protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
});
// Particle
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_PARTICLE, new PacketHandlers() {
@Override
public void register() {
map(Type.INT);
map(Type.BOOLEAN);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 46) { // new falling_dust
wrapper.set(Type.INT, 0, 38); // -> block_dust
}
});
}
});
}
}

View File

@ -1,171 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets;
import com.viaversion.viabackwards.api.entities.storage.EntityData;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import java.util.List;
public class EntityPackets1_10 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_9_4To1_10> {
public EntityPackets1_10(Protocol1_9_4To1_10 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - x
map(Type.DOUBLE); // 4 - y
map(Type.DOUBLE); // 5 - z
map(Type.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw
map(Type.INT); // 8 - data
// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
handler(protocol.getItemRewriter().getFallingBlockHandler());
}
});
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, EntityTypes1_10.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, EntityTypes1_10.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID
map(Type.UNSIGNED_BYTE); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_9.METADATA_LIST); // 12 - Metadata
// Track entity
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0);
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user());
EntityData entityData = entityDataForType(type);
if (entityData != null) {
WrappedMetadata storage = new WrappedMetadata(metadata);
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
if (entityData.hasBaseMeta())
entityData.defaultMeta().createMeta(storage);
}
});
}
});
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, EntityTypes1_10.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, EntityTypes1_10.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_9.METADATA_LIST); // 7 - Metadata list
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, EntityTypes1_11.EntityType.PLAYER));
}
});
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
}
@Override
protected void registerRewrites() {
mapEntityTypeWithData(EntityTypes1_10.EntityType.POLAR_BEAR, EntityTypes1_10.EntityType.SHEEP).plainName();
// Change the sheep color when the polar bear is standing up (index 13 -> Standing up)
filter().type(EntityTypes1_10.EntityType.POLAR_BEAR).index(13).handler((event, meta) -> {
boolean b = (boolean) meta.getValue();
meta.setTypeAndValue(MetaType1_9.Byte, b ? (byte) (14 & 0x0F) : (byte) (0));
});
// Handle husk (index 13 -> Zombie Type)
filter().type(EntityTypes1_10.EntityType.ZOMBIE).index(13).handler((event, meta) -> {
if ((int) meta.getValue() == 6) { // Is type Husk
meta.setValue(0);
}
});
// Handle Stray (index 12 -> Skeleton Type)
filter().type(EntityTypes1_10.EntityType.SKELETON).index(12).handler((event, meta) -> {
if ((int) meta.getValue() == 2) {
meta.setValue(0); // Change to default skeleton
}
});
// Handle the missing NoGravity tag for every metadata
filter().removeIndex(5);
}
@Override
public EntityType typeFromId(int typeId) {
return EntityTypes1_10.getTypeFromId(typeId, false);
}
@Override
public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_10.getTypeFromId(typeId, true);
}
}

View File

@ -16,36 +16,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_9_4to1_10; package com.viaversion.viabackwards.protocol.v1_10to1_9_3;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets.BlockItemPackets1_10; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter.BlockItemPacketRewriter1_10;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.packets.EntityPackets1_10; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter.EntityPacketRewriter1_10;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> { public class Protocol1_10To1_9_3 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.10", "1.9.4"); public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.10", "1.9.4");
private static final ValueTransformer<Float, Short> TO_OLD_PITCH = new ValueTransformer<>(Type.UNSIGNED_BYTE) { private static final ValueTransformer<Float, Short> TO_OLD_PITCH = new ValueTransformer<>(Types.UNSIGNED_BYTE) {
public Short transform(PacketWrapper packetWrapper, Float inputValue) { public Short transform(PacketWrapper packetWrapper, Float inputValue) {
return (short) Math.round(inputValue * 63.5F); return (short) Math.round(inputValue * 63.5F);
} }
}; };
private final EntityPackets1_10 entityPackets = new EntityPackets1_10(this); private final EntityPacketRewriter1_10 entityPackets = new EntityPacketRewriter1_10(this);
private final BlockItemPackets1_10 blockItemPackets = new BlockItemPackets1_10(this); private final BlockItemPacketRewriter1_10 blockItemPackets = new BlockItemPacketRewriter1_10(this);
public Protocol1_9_4To1_10() { public Protocol1_10To1_9_3() {
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
} }
@ -55,38 +55,38 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
blockItemPackets.register(); blockItemPackets.register();
SoundRewriter<ClientboundPackets1_9_3> soundRewriter = new SoundRewriter<>(this); SoundRewriter<ClientboundPackets1_9_3> soundRewriter = new SoundRewriter<>(this);
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketHandlers() { registerClientbound(ClientboundPackets1_9_3.CUSTOM_SOUND, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // 0 - Sound name map(Types.STRING); // 0 - Sound name
map(Type.VAR_INT); // 1 - Sound Category map(Types.VAR_INT); // 1 - Sound Category
map(Type.INT); // 2 - x map(Types.INT); // 2 - x
map(Type.INT); // 3 - y map(Types.INT); // 3 - y
map(Type.INT); // 4 - z map(Types.INT); // 4 - z
map(Type.FLOAT); // 5 - Volume map(Types.FLOAT); // 5 - Volume
map(Type.FLOAT, TO_OLD_PITCH); // 6 - Pitch map(Types.FLOAT, TO_OLD_PITCH); // 6 - Pitch
handler(soundRewriter.getNamedSoundHandler()); handler(soundRewriter.getNamedSoundHandler());
} }
}); });
registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketHandlers() { registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Sound name map(Types.VAR_INT); // 0 - Sound name
map(Type.VAR_INT); // 1 - Sound Category map(Types.VAR_INT); // 1 - Sound Category
map(Type.INT); // 2 - x map(Types.INT); // 2 - x
map(Type.INT); // 3 - y map(Types.INT); // 3 - y
map(Type.INT); // 4 - z map(Types.INT); // 4 - z
map(Type.FLOAT); // 5 - Volume map(Types.FLOAT); // 5 - Volume
map(Type.FLOAT, TO_OLD_PITCH); // 6 - Pitch map(Types.FLOAT, TO_OLD_PITCH); // 6 - Pitch
handler(soundRewriter.getSoundHandler()); handler(soundRewriter.getSoundHandler());
} }
}); });
registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketHandlers() { registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
read(Type.STRING); // 0 - Hash read(Types.STRING); // 0 - Hash
map(Type.VAR_INT); // 1 - Result map(Types.VAR_INT); // 1 - Result
} }
}); });
} }
@ -101,17 +101,17 @@ public class Protocol1_9_4To1_10 extends BackwardsProtocol<ClientboundPackets1_9
} }
@Override @Override
public BackwardsMappings getMappingData() { public BackwardsMappingData getMappingData() {
return MAPPINGS; return MAPPINGS;
} }
@Override @Override
public EntityPackets1_10 getEntityRewriter() { public EntityPacketRewriter1_10 getEntityRewriter() {
return entityPackets; return entityPackets;
} }
@Override @Override
public BlockItemPackets1_10 getItemRewriter() { public BlockItemPacketRewriter1_10 getItemRewriter() {
return blockItemPackets; return blockItemPackets;
} }

View File

@ -0,0 +1,120 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
public class BlockItemPacketRewriter1_10 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_10To1_9_3> {
public BlockItemPacketRewriter1_10(Protocol1_10To1_9_3 protocol) {
super(protocol, "1.10");
}
@Override
protected void registerPackets() {
registerBlockChange(ClientboundPackets1_9_3.BLOCK_UPDATE);
registerMultiBlockChange(ClientboundPackets1_9_3.CHUNK_BLOCKS_UPDATE);
registerSetSlot(ClientboundPackets1_9_3.CONTAINER_SET_SLOT);
registerSetContent(ClientboundPackets1_9_3.CONTAINER_SET_CONTENT);
registerSetEquippedItem(ClientboundPackets1_9_3.SET_EQUIPPED_ITEM);
protocol.registerClientbound(ClientboundPackets1_9_3.CUSTOM_PAYLOAD, new PacketHandlers() {
@Override
public void register() {
map(Types.STRING); // 0 - Channel
handler(wrapper -> {
if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Types.INT); // Passthrough Window ID
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
}
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Types.INT); // Number of tools uses
wrapper.passthrough(Types.INT); // Maximum number of trade uses
}
}
});
}
});
registerContainerClick(ServerboundPackets1_9_3.CONTAINER_CLICK);
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk);
});
// Rewrite metadata items
protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
});
// Particle
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_PARTICLES, new PacketHandlers() {
@Override
public void register() {
map(Types.INT);
map(Types.BOOLEAN);
map(Types.FLOAT);
map(Types.FLOAT);
map(Types.FLOAT);
map(Types.FLOAT);
map(Types.FLOAT);
map(Types.FLOAT);
map(Types.FLOAT);
map(Types.INT);
handler(wrapper -> {
int id = wrapper.get(Types.INT, 0);
if (id == 46) { // new falling_dust
wrapper.set(Types.INT, 0, 38); // -> block_dust
}
});
}
});
}
}

View File

@ -0,0 +1,171 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter;
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_9;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import java.util.List;
public class EntityPacketRewriter1_10 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_10To1_9_3> {
public EntityPacketRewriter1_10(Protocol1_10To1_9_3 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.BYTE); // 2 - Type
map(Types.DOUBLE); // 3 - x
map(Types.DOUBLE); // 4 - y
map(Types.DOUBLE); // 5 - z
map(Types.BYTE); // 6 - Pitch
map(Types.BYTE); // 7 - Yaw
map(Types.INT); // 8 - data
// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
handler(protocol.getItemRewriter().getFallingBlockHandler());
}
});
registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_10.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_10.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.UNSIGNED_BYTE); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.ENTITY_DATA_LIST); // 12 - Metadata
// Track entity
handler(getTrackerHandler(Types.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata
handler(wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
List<EntityData> metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user());
EntityReplacement entityReplacement = entityDataForType(type);
if (entityReplacement != null) {
WrappedMetadata storage = new WrappedMetadata(metadata);
wrapper.set(Types.UNSIGNED_BYTE, 0, (short) entityReplacement.replacementId());
if (entityReplacement.hasBaseMeta())
entityReplacement.defaultMeta().createMeta(storage);
}
});
}
});
registerTracker(ClientboundPackets1_9_3.ADD_PAINTING, EntityTypes1_10.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_9_3.LOGIN, EntityTypes1_10.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Player UUID
map(Types.DOUBLE); // 2 - X
map(Types.DOUBLE); // 3 - Y
map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch
map(Types1_9.ENTITY_DATA_LIST); // 7 - Metadata list
handler(getTrackerAndMetaHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER));
}
});
registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
registerSetEntityData(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.ENTITY_DATA_LIST);
}
@Override
protected void registerRewrites() {
mapEntityTypeWithData(EntityTypes1_10.EntityType.POLAR_BEAR, EntityTypes1_10.EntityType.SHEEP).plainName();
// Change the sheep color when the polar bear is standing up (index 13 -> Standing up)
filter().type(EntityTypes1_10.EntityType.POLAR_BEAR).index(13).handler((event, meta) -> {
boolean b = (boolean) meta.getValue();
meta.setTypeAndValue(EntityDataTypes1_9.BYTE, b ? (byte) (14 & 0x0F) : (byte) (0));
});
// Handle husk (index 13 -> Zombie Type)
filter().type(EntityTypes1_10.EntityType.ZOMBIE).index(13).handler((event, meta) -> {
if ((int) meta.getValue() == 6) { // Is type Husk
meta.setValue(0);
}
});
// Handle Stray (index 12 -> Skeleton Type)
filter().type(EntityTypes1_10.EntityType.SKELETON).index(12).handler((event, meta) -> {
if ((int) meta.getValue() == 2) {
meta.setValue(0); // Change to default skeleton
}
});
// Handle the missing NoGravity tag for every metadata
filter().removeIndex(5);
}
@Override
public EntityType typeFromId(int typeId) {
return EntityTypes1_10.getTypeFromId(typeId, false);
}
@Override
public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_10.getTypeFromId(typeId, true);
}
}

View File

@ -16,24 +16,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1; package com.viaversion.viabackwards.protocol.v1_11_1to1_11;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets.EntityPackets1_11_1; import com.viaversion.viabackwards.protocol.v1_11_1to1_11.rewriter.EntityPacketRewriter1_11_1;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets.ItemPackets1_11_1; import com.viaversion.viabackwards.protocol.v1_11_1to1_11.rewriter.ItemPacketRewriter1_11_1;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
public class Protocol1_11To1_11_1 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> { public class Protocol1_11_1To1_11 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
private final EntityPackets1_11_1 entityPackets = new EntityPackets1_11_1(this); private final EntityPacketRewriter1_11_1 entityPackets = new EntityPacketRewriter1_11_1(this);
private final ItemPackets1_11_1 itemRewriter = new ItemPackets1_11_1(this); private final ItemPacketRewriter1_11_1 itemRewriter = new ItemPacketRewriter1_11_1(this);
public Protocol1_11To1_11_1() { public Protocol1_11_1To1_11() {
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
} }
@ -53,12 +53,12 @@ public class Protocol1_11To1_11_1 extends BackwardsProtocol<ClientboundPackets1_
} }
@Override @Override
public EntityPackets1_11_1 getEntityRewriter() { public EntityPacketRewriter1_11_1 getEntityRewriter() {
return entityPackets; return entityPackets;
} }
@Override @Override
public ItemPackets1_11_1 getItemRewriter() { public ItemPacketRewriter1_11_1 getItemRewriter() {
return itemRewriter; return itemRewriter;
} }
} }

View File

@ -0,0 +1,128 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_11_1to1_11.rewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.v1_11_1to1_11.Protocol1_11_1To1_11;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_11_1To1_11> {
public EntityPacketRewriter1_11_1(Protocol1_11_1To1_11 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.BYTE); // 2 - Type
map(Types.DOUBLE); // 3 - x
map(Types.DOUBLE); // 4 - y
map(Types.DOUBLE); // 5 - z
map(Types.BYTE); // 6 - Pitch
map(Types.BYTE); // 7 - Yaw
map(Types.INT); // 8 - data
// Track Entity
handler(getObjectTrackerHandler());
handler(getObjectRewriter(id -> EntityTypes1_11.ObjectType.findById(id).orElse(null)));
}
});
registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.VAR_INT); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.ENTITY_DATA_LIST); // 12 - Metadata
// Track entity
handler(getTrackerHandler());
// Rewrite entity type / metadata
handler(getMobSpawnRewriter1_11(Types1_9.ENTITY_DATA_LIST));
}
});
registerTracker(ClientboundPackets1_9_3.ADD_PAINTING, EntityTypes1_11.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_9_3.LOGIN, EntityTypes1_11.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Player UUID
map(Types.DOUBLE); // 2 - X
map(Types.DOUBLE); // 3 - Y
map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch
map(Types1_9.ENTITY_DATA_LIST); // 7 - Metadata list
handler(getTrackerAndMetaHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER));
}
});
registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
registerSetEntityData(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.ENTITY_DATA_LIST);
}
@Override
protected void registerRewrites() {
// Handle non-existing firework metadata (index 7 entity id for boosting)
filter().type(EntityTypes1_11.EntityType.FIREWORK).cancel(7);
// Handle non-existing pig metadata (index 14 - boost time)
filter().type(EntityTypes1_11.EntityType.PIG).cancel(14);
}
@Override
public EntityType typeFromId(int typeId) {
return EntityTypes1_11.getTypeFromId(typeId, false);
}
@Override
public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_11.getTypeFromId(typeId, true);
}
}

View File

@ -16,67 +16,68 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets; package com.viaversion.viabackwards.protocol.v1_11_1to1_11.rewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import com.viaversion.viabackwards.protocol.v1_11_1to1_11.Protocol1_11_1To1_11;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11To1_11_1> { public class ItemPacketRewriter1_11_1 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11_1To1_11> {
private LegacyEnchantmentRewriter enchantmentRewriter; private LegacyEnchantmentRewriter enchantmentRewriter;
public ItemPackets1_11_1(Protocol1_11To1_11_1 protocol) { public ItemPacketRewriter1_11_1(Protocol1_11_1To1_11 protocol) {
super(protocol, "1.11.1"); super(protocol, "1.11.1");
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT); registerSetSlot(ClientboundPackets1_9_3.CONTAINER_SET_SLOT);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS); registerSetContent(ClientboundPackets1_9_3.CONTAINER_SET_CONTENT);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT); registerSetEquippedItem(ClientboundPackets1_9_3.SET_EQUIPPED_ITEM);
// Plugin message Packet -> Trading // Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.CUSTOM_PAYLOAD, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // 0 - Channel map(Types.STRING); // 0 - Channel
handler(wrapper -> { handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) { if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID wrapper.passthrough(Types.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
} }
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Types.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses wrapper.passthrough(Types.INT); // Maximum number of trade uses
} }
} }
}); });
} }
}); });
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW); registerContainerClick(ServerboundPackets1_9_3.CONTAINER_CLICK);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION); registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
// Handle item metadata // Handle item metadata
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) { // Is Item if (meta.dataType().type().equals(Types.ITEM1_8)) { // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
} }
}); });

View File

@ -16,29 +16,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11; package com.viaversion.viabackwards.protocol.v1_11to1_10;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets.BlockItemPackets1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter.BlockItemPacketRewriter1_11;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets.EntityPackets1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter.EntityPacketRewriter1_11;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets.PlayerPackets1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter.PlayerPacketRewriterRewriter1_11;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker; import com.viaversion.viabackwards.protocol.v1_11to1_10.storage.WindowTracker;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> { public class Protocol1_11To1_10 extends BackwardsProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.11", "1.10"); public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.11", "1.10");
private final EntityPackets1_11 entityPackets = new EntityPackets1_11(this); private final EntityPacketRewriter1_11 entityPackets = new EntityPacketRewriter1_11(this);
private final BlockItemPackets1_11 blockItemPackets = new BlockItemPackets1_11(this); private final BlockItemPacketRewriter1_11 blockItemPackets = new BlockItemPacketRewriter1_11(this);
public Protocol1_10To1_11() { public Protocol1_11To1_10() {
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
} }
@ -46,10 +46,10 @@ public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_
protected void registerPackets() { protected void registerPackets() {
blockItemPackets.register(); blockItemPackets.register();
entityPackets.register(); entityPackets.register();
PlayerPackets1_11.register(this); PlayerPacketRewriterRewriter1_11.register(this);
SoundRewriter<ClientboundPackets1_9_3> soundRewriter = new SoundRewriter<>(this); SoundRewriter<ClientboundPackets1_9_3> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerNamedSound(ClientboundPackets1_9_3.NAMED_SOUND); soundRewriter.registerNamedSound(ClientboundPackets1_9_3.CUSTOM_SOUND);
soundRewriter.registerSound(ClientboundPackets1_9_3.SOUND); soundRewriter.registerSound(ClientboundPackets1_9_3.SOUND);
} }
@ -67,17 +67,17 @@ public class Protocol1_10To1_11 extends BackwardsProtocol<ClientboundPackets1_9_
} }
@Override @Override
public BackwardsMappings getMappingData() { public BackwardsMappingData getMappingData() {
return MAPPINGS; return MAPPINGS;
} }
@Override @Override
public EntityPackets1_11 getEntityRewriter() { public EntityPacketRewriter1_11 getEntityRewriter() {
return entityPackets; return entityPackets;
} }
@Override @Override
public BlockItemPackets1_11 getItemRewriter() { public BlockItemPacketRewriter1_11 getItemRewriter() {
return blockItemPackets; return blockItemPackets;
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.data; package com.viaversion.viabackwards.protocol.v1_11to1_10.data;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;

View File

@ -16,14 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets; package com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter;
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem; import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; import com.viaversion.viabackwards.protocol.v1_11to1_10.storage.ChestedHorseStorage;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker; import com.viaversion.viabackwards.protocol.v1_11to1_10.storage.WindowTracker;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
@ -34,37 +34,38 @@ import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.rewriter.EntityIdRewriter; import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
import com.viaversion.viaversion.util.IdAndData; import com.viaversion.viaversion.util.IdAndData;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_10To1_11> { public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11To1_10> {
private LegacyEnchantmentRewriter enchantmentRewriter; private LegacyEnchantmentRewriter enchantmentRewriter;
public BlockItemPackets1_11(Protocol1_10To1_11 protocol) { public BlockItemPacketRewriter1_11(Protocol1_11To1_10 protocol) {
super(protocol, "1.11"); super(protocol, "1.11");
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
registerBlockChange(ClientboundPackets1_9_3.BLOCK_CHANGE); registerBlockChange(ClientboundPackets1_9_3.BLOCK_UPDATE);
registerMultiBlockChange(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE); registerMultiBlockChange(ClientboundPackets1_9_3.CHUNK_BLOCKS_UPDATE);
protocol.registerClientbound(ClientboundPackets1_9_3.SET_SLOT, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.CONTAINER_SET_SLOT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID map(Types.SHORT); // 1 - Slot ID
map(Type.ITEM1_8); // 2 - Slot Value map(Types.ITEM1_8); // 2 - Slot Value
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
// Handle Llama // Handle Llama
handler(wrapper -> { handler(wrapper -> {
@ -75,22 +76,22 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
} }
ChestedHorseStorage storage = horse.get(); ChestedHorseStorage storage = horse.get();
int currentSlot = wrapper.get(Type.SHORT, 0); int currentSlot = wrapper.get(Types.SHORT, 0);
wrapper.set(Type.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue()); wrapper.set(Types.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue());
wrapper.set(Type.ITEM1_8, 0, getNewItem(storage, currentSlot, wrapper.get(Type.ITEM1_8, 0))); wrapper.set(Types.ITEM1_8, 0, getNewItem(storage, currentSlot, wrapper.get(Types.ITEM1_8, 0)));
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_9_3.WINDOW_ITEMS, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.CONTAINER_SET_CONTENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM1_8_SHORT_ARRAY); // 1 - Window Values map(Types.ITEM1_8_SHORT_ARRAY); // 1 - Window Values
handler(wrapper -> { handler(wrapper -> {
Item[] stacks = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0); Item[] stacks = wrapper.get(Types.ITEM1_8_SHORT_ARRAY, 0);
for (int i = 0; i < stacks.length; i++) for (int i = 0; i < stacks.length; i++)
stacks[i] = handleItemToClient(wrapper.user(), stacks[i]); stacks[i] = handleItemToClient(wrapper.user(), stacks[i]);
@ -106,54 +107,54 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
stacks[getNewSlotId(storage, i)] = stacks[i]; stacks[getNewSlotId(storage, i)] = stacks[i];
stacks[i] = getNewItem(storage, i, stacks[i]); stacks[i] = getNewItem(storage, i, stacks[i]);
} }
wrapper.set(Type.ITEM1_8_SHORT_ARRAY, 0, stacks); wrapper.set(Types.ITEM1_8_SHORT_ARRAY, 0, stacks);
} }
}); });
} }
}); });
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT); registerSetEquippedItem(ClientboundPackets1_9_3.SET_EQUIPPED_ITEM);
// Plugin message -> Trading // Plugin message -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.CUSTOM_PAYLOAD, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // 0 - Channel map(Types.STRING); // 0 - Channel
handler(wrapper -> { handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) { if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID wrapper.passthrough(Types.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
} }
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Types.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses wrapper.passthrough(Types.INT); // Maximum number of trade uses
} }
} }
}); });
} }
}); });
protocol.registerServerbound(ServerboundPackets1_9_3.CLICK_WINDOW, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLICK, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot map(Types.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button map(Types.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number map(Types.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode map(Types.VAR_INT); // 4 - Mode
map(Type.ITEM1_8); // 5 - Clicked Item map(Types.ITEM1_8); // 5 - Clicked Item
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
// Llama slot // Llama slot
handler(wrapper -> { handler(wrapper -> {
@ -163,18 +164,18 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
return; return;
} }
ChestedHorseStorage storage = horse.get(); ChestedHorseStorage storage = horse.get();
int clickSlot = wrapper.get(Type.SHORT, 0); int clickSlot = wrapper.get(Types.SHORT, 0);
int correctSlot = getOldSlotId(storage, clickSlot); int correctSlot = getOldSlotId(storage, clickSlot);
wrapper.set(Type.SHORT, 0, ((Integer) correctSlot).shortValue()); wrapper.set(Types.SHORT, 0, ((Integer) correctSlot).shortValue());
} }
}); });
} }
}); });
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION); registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> { protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed. ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed.
@ -197,54 +198,54 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // 0 - Position map(Types.BLOCK_POSITION1_8); // 0 - Position
map(Type.UNSIGNED_BYTE); // 1 - Action map(Types.UNSIGNED_BYTE); // 1 - Action
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT map(Types.NAMED_COMPOUND_TAG); // 2 - NBT
handler(wrapper -> { handler(wrapper -> {
// Remove on shulkerbox decleration // Remove on shulkerbox decleration
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 10) { if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 10) {
wrapper.cancel(); wrapper.cancel();
} }
// Handler Spawners // Handler Spawners
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) { if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 1) {
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
EntityIdRewriter.toClientSpawner(tag, true); EntityIdRewriter.toClientSpawner(tag, true);
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_9_3.OPEN_WINDOW, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.OPEN_SCREEN, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Type.STRING); // 1 - Window Type map(Types.STRING); // 1 - Window Type
map(Type.COMPONENT); // 2 - Title map(Types.COMPONENT); // 2 - Title
map(Type.UNSIGNED_BYTE); // 3 - Slots map(Types.UNSIGNED_BYTE); // 3 - Slots
handler(wrapper -> { handler(wrapper -> {
int entityId = -1; int entityId = -1;
// Passthrough Entity ID // Passthrough Entity ID
if (wrapper.get(Type.STRING, 0).equals("EntityHorse")) { if (wrapper.get(Types.STRING, 0).equals("EntityHorse")) {
entityId = wrapper.passthrough(Type.INT); entityId = wrapper.passthrough(Types.INT);
} }
// Track Inventory // Track Inventory
String inventory = wrapper.get(Type.STRING, 0); String inventory = wrapper.get(Types.STRING, 0);
WindowTracker windowTracker = wrapper.user().get(WindowTracker.class); WindowTracker windowTracker = wrapper.user().get(WindowTracker.class);
windowTracker.setInventory(inventory); windowTracker.setInventory(inventory);
windowTracker.setEntityId(entityId); windowTracker.setEntityId(entityId);
// Change llama slotcount to the donkey one // Change llama slotcount to the donkey one
if (isLlama(wrapper.user())) { if (isLlama(wrapper.user())) {
wrapper.set(Type.UNSIGNED_BYTE, 1, (short) 17); wrapper.set(Types.UNSIGNED_BYTE, 1, (short) 17);
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_9_3.CLOSE_WINDOW, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.CONTAINER_CLOSE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
// Inventory tracking // Inventory tracking
@ -257,7 +258,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}); });
protocol.registerServerbound(ServerboundPackets1_9_3.CLOSE_WINDOW, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLOSE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
// Inventory tracking // Inventory tracking
@ -270,7 +271,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}); });
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
}); });
} }
@ -324,7 +325,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
private boolean isLlama(UserConnection user) { private boolean isLlama(UserConnection user) {
WindowTracker tracker = user.get(WindowTracker.class); WindowTracker tracker = user.get(WindowTracker.class);
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) { if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
EntityTracker entTracker = user.getEntityTracker(Protocol1_10To1_11.class); EntityTracker entTracker = user.getEntityTracker(Protocol1_11To1_10.class);
StoredEntityData entityData = entTracker.entityData(tracker.getEntityId()); StoredEntityData entityData = entTracker.entityData(tracker.getEntityId());
return entityData != null && entityData.type().is(EntityTypes1_11.EntityType.LIAMA); return entityData != null && entityData.type().is(EntityTypes1_11.EntityType.LIAMA);
} }
@ -334,7 +335,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
private Optional<ChestedHorseStorage> getChestedHorse(UserConnection user) { private Optional<ChestedHorseStorage> getChestedHorse(UserConnection user) {
WindowTracker tracker = user.get(WindowTracker.class); WindowTracker tracker = user.get(WindowTracker.class);
if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) { if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) {
EntityTracker entTracker = user.getEntityTracker(Protocol1_10To1_11.class); EntityTracker entTracker = user.getEntityTracker(Protocol1_11To1_10.class);
StoredEntityData entityData = entTracker.entityData(tracker.getEntityId()); StoredEntityData entityData = entTracker.entityData(tracker.getEntityId());
if (entityData != null) if (entityData != null)
return Optional.of(entityData.get(ChestedHorseStorage.class)); return Optional.of(entityData.get(ChestedHorseStorage.class));

View File

@ -16,68 +16,69 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets; package com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter;
import com.viaversion.viabackwards.api.entities.storage.EntityData; import com.viaversion.viabackwards.api.entities.storage.EntityData;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.data.PotionSplashHandler; import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.data.PotionSplashHandler;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; import com.viaversion.viabackwards.protocol.v1_11to1_10.storage.ChestedHorseStorage;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_9;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import java.util.List; import java.util.List;
public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_10To1_11> { public class EntityPacketRewriter1_11 extends LegacyEntityRewriter<ClientboundPackets1_9_3, Protocol1_11To1_10> {
public EntityPackets1_11(Protocol1_10To1_11 protocol) { public EntityPacketRewriter1_11(Protocol1_11To1_10 protocol) {
super(protocol); super(protocol);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.EFFECT, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_EVENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); map(Types.INT);
map(Type.POSITION1_8); map(Types.BLOCK_POSITION1_8);
map(Type.INT); map(Types.INT);
handler(wrapper -> { handler(wrapper -> {
int type = wrapper.get(Type.INT, 0); int type = wrapper.get(Types.INT, 0);
if (type == 2002 || type == 2007) { if (type == 2002 || type == 2007) {
// 2007 potion id doesn't exist in 1.10 // 2007 potion id doesn't exist in 1.10
if (type == 2007) { if (type == 2007) {
wrapper.set(Type.INT, 0, 2002); wrapper.set(Types.INT, 0, 2002);
} }
int mappedData = PotionSplashHandler.getOldData(wrapper.get(Type.INT, 1)); int mappedData = PotionSplashHandler.getOldData(wrapper.get(Types.INT, 1));
if (mappedData != -1) { if (mappedData != -1) {
wrapper.set(Type.INT, 1, mappedData); wrapper.set(Types.INT, 1, mappedData);
} }
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity id map(Types.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID map(Types.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type map(Types.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - x map(Types.DOUBLE); // 3 - x
map(Type.DOUBLE); // 4 - y map(Types.DOUBLE); // 4 - y
map(Type.DOUBLE); // 5 - z map(Types.DOUBLE); // 5 - z
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw map(Types.BYTE); // 7 - Yaw
map(Type.INT); // 8 - data map(Types.INT); // 8 - data
// Track Entity // Track Entity
handler(getObjectTrackerHandler()); handler(getObjectTrackerHandler());
@ -87,86 +88,86 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
} }
}); });
registerTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB); registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER); registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity id map(Types.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID map(Types.UUID); // 1 - UUID
map(Type.VAR_INT, Type.UNSIGNED_BYTE); // 2 - Entity Type map(Types.VAR_INT, Types.UNSIGNED_BYTE); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X map(Types.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Types.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Types.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw map(Types.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch map(Types.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch map(Types.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.METADATA_LIST); // 12 - Metadata map(Types1_9.ENTITY_DATA_LIST); // 12 - Metadata
// Track entity // Track entity
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0)); handler(getTrackerHandler(Types.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_9.METADATA_LIST)); handler(getMobSpawnRewriter(Types1_9.ENTITY_DATA_LIST));
// Sub 1.11 clients will error if the list is empty // Sub 1.11 clients will error if the list is empty
handler(wrapper -> { handler(wrapper -> {
List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0); List<EntityData> metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
if (metadata.isEmpty()) { if (metadata.isEmpty()) {
metadata.add(new Metadata(0, MetaType1_9.Byte, (byte) 0)); metadata.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0));
} }
}); });
} }
}); });
registerTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, EntityTypes1_11.EntityType.PAINTING); registerTracker(ClientboundPackets1_9_3.ADD_PAINTING, EntityTypes1_11.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, EntityTypes1_11.EntityType.PLAYER); registerJoinGame(ClientboundPackets1_9_3.LOGIN, EntityTypes1_11.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_9_3.RESPAWN); registerRespawn(ClientboundPackets1_9_3.RESPAWN);
protocol.registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.ADD_PLAYER, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID map(Types.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X map(Types.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y map(Types.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_9.METADATA_LIST); // 7 - Metadata list map(Types1_9.ENTITY_DATA_LIST); // 7 - Metadata list
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, EntityTypes1_11.EntityType.PLAYER)); handler(getTrackerAndMetaHandler(Types1_9.ENTITY_DATA_LIST, EntityTypes1_11.EntityType.PLAYER));
handler(wrapper -> { handler(wrapper -> {
// Sub 1.11 clients will cry if the list is empty // Sub 1.11 clients will cry if the list is empty
List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0); List<EntityData> metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
if (metadata.isEmpty()) { if (metadata.isEmpty()) {
metadata.add(new Metadata(0, MetaType1_9.Byte, (byte) 0)); metadata.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0));
} }
}); });
} }
}); });
registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES); registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST); registerSetEntityData(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.ENTITY_DATA_LIST);
protocol.registerClientbound(ClientboundPackets1_9_3.ENTITY_STATUS, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.ENTITY_EVENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Entity ID map(Types.INT); // 0 - Entity ID
map(Type.BYTE); // 1 - Entity Status map(Types.BYTE); // 1 - Entity Status
handler(wrapper -> { handler(wrapper -> {
byte b = wrapper.get(Type.BYTE, 0); byte b = wrapper.get(Types.BYTE, 0);
if (b == 35) { if (b == 35) {
wrapper.clearPacket(); wrapper.clearPacket();
wrapper.setPacketType(ClientboundPackets1_9_3.GAME_EVENT); wrapper.setPacketType(ClientboundPackets1_9_3.GAME_EVENT);
wrapper.write(Type.UNSIGNED_BYTE, (short) 10); // Play Elder Guardian animation wrapper.write(Types.UNSIGNED_BYTE, (short) 10); // Play Elder Guardian animation
wrapper.write(Type.FLOAT, 0F); wrapper.write(Types.FLOAT, 0F);
} }
}); });
} }
@ -193,9 +194,9 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_FANGS, EntityTypes1_11.EntityType.SHULKER); mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_FANGS, EntityTypes1_11.EntityType.SHULKER);
mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_ILLAGER, EntityTypes1_11.EntityType.VILLAGER).plainName(); mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_ILLAGER, EntityTypes1_11.EntityType.VILLAGER).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.VEX, EntityTypes1_11.EntityType.BAT).plainName(); mapEntityTypeWithData(EntityTypes1_11.EntityType.VEX, EntityTypes1_11.EntityType.BAT).plainName();
mapEntityTypeWithData(EntityTypes1_11.EntityType.VINDICATION_ILLAGER, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnMetadata(storage -> storage.add(new Metadata(13, MetaType1_9.VarInt, 4))); // Base Profession mapEntityTypeWithData(EntityTypes1_11.EntityType.VINDICATOR, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnMetadata(storage -> storage.add(new EntityData(13, EntityDataTypes1_9.VAR_INT, 4))); // Base Profession
mapEntityTypeWithData(EntityTypes1_11.EntityType.LIAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnMetadata(storage -> storage.add(getHorseMetaType(1))); mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnMetadata(storage -> storage.add(getHorseMetaType(1)));
mapEntityTypeWithData(EntityTypes1_11.EntityType.LIAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL); mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL);
mapObjectType(EntityTypes1_11.ObjectType.LIAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1); mapObjectType(EntityTypes1_11.ObjectType.LIAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1);
// Replace with endertorchthingies // Replace with endertorchthingies
@ -210,7 +211,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
bitmask |= 0x04; bitmask |= 0x04;
} }
meta.setTypeAndValue(MetaType1_9.Byte, (byte) bitmask); meta.setTypeAndValue(EntityDataTypes1_9.BYTE, (byte) bitmask);
}); });
// Handle skeleton swing // Handle skeleton swing
@ -235,7 +236,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
// Handle Evocation Illager // Handle Evocation Illager
filter().type(EntityTypes1_11.EntityType.EVOCATION_ILLAGER).index(12).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.EVOCATION_ILLAGER).index(12).handler((event, meta) -> {
event.setIndex(13); event.setIndex(13);
meta.setTypeAndValue(MetaType1_9.VarInt, ((Byte) meta.getValue()).intValue()); // Change the profession for the states meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) meta.getValue()).intValue()); // Change the profession for the states
}); });
// Handle Vex (Remove this field completely since the position is not updated correctly when idling for bats. Sad ): // Handle Vex (Remove this field completely since the position is not updated correctly when idling for bats. Sad ):
@ -246,7 +247,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
// Handle VindicationIllager // Handle VindicationIllager
filter().type(EntityTypes1_11.EntityType.VINDICATION_ILLAGER).index(12).handler((event, meta) -> { filter().type(EntityTypes1_11.EntityType.VINDICATION_ILLAGER).index(12).handler((event, meta) -> {
event.setIndex(13); event.setIndex(13);
meta.setTypeAndValue(MetaType1_9.VarInt, ((Number) meta.getValue()).intValue() == 1 ? 2 : 4); meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) meta.getValue()).intValue() == 1 ? 2 : 4);
}); });
/* /*
@ -326,8 +327,8 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
2 - Stray 2 - Stray
*/ */
private Metadata getSkeletonTypeMeta(int type) { private EntityData getSkeletonTypeMeta(int type) {
return new Metadata(12, MetaType1_9.VarInt, type); return new EntityData(12, EntityDataTypes1_9.VAR_INT, type);
} }
/* /*
@ -335,12 +336,12 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
1-5 - Villager with profession 1-5 - Villager with profession
6 - Husk 6 - Husk
*/ */
private Metadata getZombieTypeMeta(int type) { private EntityData getZombieTypeMeta(int type) {
return new Metadata(13, MetaType1_9.VarInt, type); return new EntityData(13, EntityDataTypes1_9.VAR_INT, type);
} }
private void handleZombieType(WrappedMetadata storage, int type) { private void handleZombieType(WrappedMetadata storage, int type) {
Metadata meta = storage.get(13); EntityData meta = storage.get(13);
if (meta == null) { if (meta == null) {
storage.add(getZombieTypeMeta(type)); storage.add(getZombieTypeMeta(type));
} }
@ -353,8 +354,8 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
Zombie horse 3 Zombie horse 3
Skeleton horse 4 Skeleton horse 4
*/ */
private Metadata getHorseMetaType(int type) { private EntityData getHorseMetaType(int type) {
return new Metadata(14, MetaType1_9.VarInt, type); return new EntityData(14, EntityDataTypes1_9.VAR_INT, type);
} }
@Override @Override

View File

@ -16,77 +16,78 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.packets; package com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter;
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
public class PlayerPackets1_11 { public class PlayerPacketRewriterRewriter1_11 {
private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<>(Type.FLOAT) { private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<>(Types.FLOAT) {
@Override @Override
public Float transform(PacketWrapper wrapper, Short inputValue) { public Float transform(PacketWrapper wrapper, Short inputValue) {
return inputValue / 16f; return inputValue / 16f;
} }
}; };
public static void register(Protocol1_10To1_11 protocol) { public static void register(Protocol1_11To1_10 protocol) {
protocol.registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.SET_TITLES, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Action map(Types.VAR_INT); // 0 - Action
handler(wrapper -> { handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0); int action = wrapper.get(Types.VAR_INT, 0);
if (action == 2) { // Handle the new ActionBar if (action == 2) { // Handle the new ActionBar
JsonElement message = wrapper.read(Type.COMPONENT); JsonElement message = wrapper.read(Types.COMPONENT);
wrapper.clearPacket(); wrapper.clearPacket();
wrapper.setPacketType(ClientboundPackets1_9_3.CHAT_MESSAGE); wrapper.setPacketType(ClientboundPackets1_9_3.CHAT);
// https://bugs.mojang.com/browse/MC-119145 // https://bugs.mojang.com/browse/MC-119145
String legacy = ComponentUtil.jsonToLegacy(message); String legacy = ComponentUtil.jsonToLegacy(message);
message = new JsonObject(); message = new JsonObject();
message.getAsJsonObject().addProperty("text", legacy); message.getAsJsonObject().addProperty("text", legacy);
wrapper.write(Type.COMPONENT, message); wrapper.write(Types.COMPONENT, message);
wrapper.write(Type.BYTE, (byte) 2); wrapper.write(Types.BYTE, (byte) 2);
} else if (action > 2) { } else if (action > 2) {
wrapper.set(Type.VAR_INT, 0, action - 1); // Move everything one position down wrapper.set(Types.VAR_INT, 0, action - 1); // Move everything one position down
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_9_3.TAKE_ITEM_ENTITY, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Collected entity id map(Types.VAR_INT); // 0 - Collected entity id
map(Type.VAR_INT); // 1 - Collector entity id map(Types.VAR_INT); // 1 - Collector entity id
handler(wrapper -> wrapper.read(Type.VAR_INT)); // Ignore item pickup count handler(wrapper -> wrapper.read(Types.VAR_INT)); // Ignore item pickup count
} }
}); });
protocol.registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9_3.USE_ITEM_ON, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // 0 - Location map(Types.BLOCK_POSITION1_8); // 0 - Location
map(Type.VAR_INT); // 1 - Face map(Types.VAR_INT); // 1 - Face
map(Type.VAR_INT); // 2 - Hand map(Types.VAR_INT); // 2 - Hand
map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); map(Types.UNSIGNED_BYTE, TO_NEW_FLOAT);
map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); map(Types.UNSIGNED_BYTE, TO_NEW_FLOAT);
map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); map(Types.UNSIGNED_BYTE, TO_NEW_FLOAT);
} }
}); });
} }

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage; package com.viaversion.viabackwards.protocol.v1_11to1_10.storage;
public class ChestedHorseStorage { public class ChestedHorseStorage {
private boolean chested; private boolean chested;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage; package com.viaversion.viabackwards.protocol.v1_11to1_10.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;

View File

@ -15,23 +15,23 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12to1_12_1; package com.viaversion.viabackwards.protocol.v1_12_1to1_12;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
public class Protocol1_12To1_12_1 extends BackwardsProtocol<ClientboundPackets1_12_1, ClientboundPackets1_12, ServerboundPackets1_12_1, ServerboundPackets1_12> { public class Protocol1_12_1To1_12 extends BackwardsProtocol<ClientboundPackets1_12_1, ClientboundPackets1_12, ServerboundPackets1_12_1, ServerboundPackets1_12> {
public Protocol1_12To1_12_1() { public Protocol1_12_1To1_12() {
super(ClientboundPackets1_12_1.class, ClientboundPackets1_12.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12.class); super(ClientboundPackets1_12_1.class, ClientboundPackets1_12.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12.class);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
cancelClientbound(ClientboundPackets1_12_1.CRAFT_RECIPE_RESPONSE); cancelClientbound(ClientboundPackets1_12_1.PLACE_GHOST_RECIPE);
cancelServerbound(ServerboundPackets1_12.PREPARE_CRAFTING_GRID); cancelServerbound(ServerboundPackets1_12.CRAFTING_RECIPE_PLACEMENT);
} }
} }

View File

@ -16,19 +16,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_1to1_12_2; package com.viaversion.viabackwards.protocol.v1_12_2to1_12_1;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.protocol.protocol1_12_1to1_12_2.storage.KeepAliveTracker; import com.viaversion.viabackwards.protocol.v1_12_2to1_12_1.storage.KeepAliveTracker;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
public class Protocol1_12_1To1_12_2 extends BackwardsProtocol<ClientboundPackets1_12_1, ClientboundPackets1_12_1, ServerboundPackets1_12_1, ServerboundPackets1_12_1> { public class Protocol1_12_2To1_12_1 extends BackwardsProtocol<ClientboundPackets1_12_1, ClientboundPackets1_12_1, ServerboundPackets1_12_1, ServerboundPackets1_12_1> {
public Protocol1_12_1To1_12_2() { public Protocol1_12_2To1_12_1() {
super(ClientboundPackets1_12_1.class, ClientboundPackets1_12_1.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12_1.class); super(ClientboundPackets1_12_1.class, ClientboundPackets1_12_1.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12_1.class);
} }
@ -38,9 +38,9 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol<ClientboundPackets
@Override @Override
public void register() { public void register() {
handler(packetWrapper -> { handler(packetWrapper -> {
Long keepAlive = packetWrapper.read(Type.LONG); Long keepAlive = packetWrapper.read(Types.LONG);
packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(keepAlive); packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(keepAlive);
packetWrapper.write(Type.VAR_INT, keepAlive.hashCode()); packetWrapper.write(Types.VAR_INT, keepAlive.hashCode());
}); });
} }
}); });
@ -49,13 +49,13 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol<ClientboundPackets
@Override @Override
public void register() { public void register() {
handler(packetWrapper -> { handler(packetWrapper -> {
int keepAlive = packetWrapper.read(Type.VAR_INT); int keepAlive = packetWrapper.read(Types.VAR_INT);
long realKeepAlive = packetWrapper.user().get(KeepAliveTracker.class).getKeepAlive(); long realKeepAlive = packetWrapper.user().get(KeepAliveTracker.class).getKeepAlive();
if (keepAlive != Long.hashCode(realKeepAlive)) { if (keepAlive != Long.hashCode(realKeepAlive)) {
packetWrapper.cancel(); // Wrong data, cancel packet packetWrapper.cancel(); // Wrong data, cancel packet
return; return;
} }
packetWrapper.write(Type.LONG, realKeepAlive); packetWrapper.write(Types.LONG, realKeepAlive);
// Reset KeepAliveTracker (to prevent sending same valid value in a row causing a timeout) // Reset KeepAliveTracker (to prevent sending same valid value in a row causing a timeout)
packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(Integer.MAX_VALUE); packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(Integer.MAX_VALUE);
}); });

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_1to1_12_2.storage; package com.viaversion.viabackwards.protocol.v1_12_2to1_12_1.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;

View File

@ -16,34 +16,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12; package com.viaversion.viabackwards.protocol.v1_12to1_11_1;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.ShoulderTracker;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.BlockItemPackets1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter.BlockItemPacketRewriter1_12;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.ChatPackets1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter.ChatPacketRewriter1_12;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.EntityPackets1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter.EntityPacketRewriter1_12;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets.SoundPackets1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter.SoundPacketRewriter1_12;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_12, ClientboundPackets1_9_3, ServerboundPackets1_12, ServerboundPackets1_9_3> { public class Protocol1_12To1_11_1 extends BackwardsProtocol<ClientboundPackets1_12, ClientboundPackets1_9_3, ServerboundPackets1_12, ServerboundPackets1_9_3> {
private static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.12", "1.11"); private static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.12", "1.11");
private final EntityPackets1_12 entityPackets = new EntityPackets1_12(this); private final EntityPacketRewriter1_12 entityPackets = new EntityPacketRewriter1_12(this);
private final BlockItemPackets1_12 blockItemPackets = new BlockItemPackets1_12(this); private final BlockItemPacketRewriter1_12 blockItemPackets = new BlockItemPacketRewriter1_12(this);
public Protocol1_11_1To1_12() { public Protocol1_12To1_11_1() {
super(ClientboundPackets1_12.class, ClientboundPackets1_9_3.class, ServerboundPackets1_12.class, ServerboundPackets1_9_3.class); super(ClientboundPackets1_12.class, ClientboundPackets1_9_3.class, ServerboundPackets1_12.class, ServerboundPackets1_9_3.class);
} }
@ -51,19 +51,19 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
protected void registerPackets() { protected void registerPackets() {
blockItemPackets.register(); blockItemPackets.register();
entityPackets.register(); entityPackets.register();
new SoundPackets1_12(this).register(); new SoundPacketRewriter1_12(this).register();
new ChatPackets1_12(this).register(); new ChatPacketRewriter1_12(this).register();
registerClientbound(ClientboundPackets1_12.TITLE, wrapper -> { registerClientbound(ClientboundPackets1_12.SET_TITLES, wrapper -> {
int action = wrapper.passthrough(Type.VAR_INT); int action = wrapper.passthrough(Types.VAR_INT);
if (action >= 0 && action <= 2) { if (action >= 0 && action <= 2) {
JsonElement component = wrapper.read(Type.COMPONENT); JsonElement component = wrapper.read(Types.COMPONENT);
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, component.toString())); wrapper.write(Types.COMPONENT, Protocol1_8To1_9.STRING_TO_JSON.transform(wrapper, component.toString()));
} }
}); });
cancelClientbound(ClientboundPackets1_12.ADVANCEMENTS); cancelClientbound(ClientboundPackets1_12.UPDATE_ADVANCEMENTS);
cancelClientbound(ClientboundPackets1_12.UNLOCK_RECIPES); cancelClientbound(ClientboundPackets1_12.RECIPE);
cancelClientbound(ClientboundPackets1_12.SELECT_ADVANCEMENTS_TAB); cancelClientbound(ClientboundPackets1_12.SELECT_ADVANCEMENTS_TAB);
} }
@ -79,17 +79,17 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
} }
@Override @Override
public BackwardsMappings getMappingData() { public BackwardsMappingData getMappingData() {
return MAPPINGS; return MAPPINGS;
} }
@Override @Override
public EntityPackets1_12 getEntityRewriter() { public EntityPacketRewriter1_12 getEntityRewriter() {
return entityPackets; return entityPackets;
} }
@Override @Override
public BlockItemPackets1_12 getItemRewriter() { public BlockItemPacketRewriter1_12 getItemRewriter() {
return blockItemPackets; return blockItemPackets;
} }

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.data;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.data;
public class BlockColors { public class BlockColors {
private static final String[] COLORS = new String[16]; private static final String[] COLORS = new String[16];

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.data;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.data;
public class ParrotStorage { public class ParrotStorage {
private boolean tamed = true; private boolean tamed = true;

View File

@ -16,16 +16,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.data;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.api.connection.StoredObject; import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.util.Locale; import java.util.Locale;
@ -39,17 +40,17 @@ public class ShoulderTracker extends StoredObject {
} }
public void update() { public void update() {
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12.CHAT_MESSAGE, null, getUser()); PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12.CHAT, null, getUser());
try { try {
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, generateString())); wrapper.write(Types.COMPONENT, Protocol1_8To1_9.STRING_TO_JSON.transform(wrapper, generateString()));
} catch (final Exception e) { } catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
wrapper.write(Type.BYTE, (byte) 2); wrapper.write(Types.BYTE, (byte) 2);
try { try {
wrapper.scheduleSend(Protocol1_11_1To1_12.class); wrapper.scheduleSend(Protocol1_12To1_11_1.class);
} catch (Exception e) { } catch (Exception e) {
ViaBackwards.getPlatform().getLogger().severe("Failed to send the shoulder indication"); ViaBackwards.getPlatform().getLogger().severe("Failed to send the shoulder indication");
e.printStackTrace(); e.printStackTrace();

View File

@ -16,11 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.MapColorMapping;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
@ -29,49 +29,50 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag; import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag; import com.viaversion.nbt.tag.LongArrayTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPackets1_12, ServerboundPackets1_9_3, Protocol1_11_1To1_12> { public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<ClientboundPackets1_12, ServerboundPackets1_9_3, Protocol1_12To1_11_1> {
public BlockItemPackets1_12(Protocol1_11_1To1_12 protocol) { public BlockItemPacketRewriter1_12(Protocol1_12To1_11_1 protocol) {
super(protocol, "1.12"); super(protocol, "1.12");
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
registerBlockChange(ClientboundPackets1_12.BLOCK_CHANGE); registerBlockChange(ClientboundPackets1_12.BLOCK_UPDATE);
registerMultiBlockChange(ClientboundPackets1_12.MULTI_BLOCK_CHANGE); registerMultiBlockChange(ClientboundPackets1_12.CHUNK_BLOCKS_UPDATE);
protocol.registerClientbound(ClientboundPackets1_12.MAP_DATA, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.MAP_ITEM_DATA, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.BYTE); map(Types.BYTE);
map(Type.BOOLEAN); map(Types.BOOLEAN);
handler(wrapper -> { handler(wrapper -> {
int count = wrapper.passthrough(Type.VAR_INT); int count = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < count * 3; i++) { for (int i = 0; i < count * 3; i++) {
wrapper.passthrough(Type.BYTE); wrapper.passthrough(Types.BYTE);
} }
}); });
handler(wrapper -> { handler(wrapper -> {
short columns = wrapper.passthrough(Type.UNSIGNED_BYTE); short columns = wrapper.passthrough(Types.UNSIGNED_BYTE);
if (columns <= 0) return; if (columns <= 0) return;
wrapper.passthrough(Type.UNSIGNED_BYTE); // Rows wrapper.passthrough(Types.UNSIGNED_BYTE); // Rows
wrapper.passthrough(Type.UNSIGNED_BYTE); // X wrapper.passthrough(Types.UNSIGNED_BYTE); // X
wrapper.passthrough(Type.UNSIGNED_BYTE); // Z wrapper.passthrough(Types.UNSIGNED_BYTE); // Z
byte[] data = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); byte[] data = wrapper.read(Types.BYTE_ARRAY_PRIMITIVE);
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
short color = (short) (data[i] & 0xFF); short color = (short) (data[i] & 0xFF);
if (color > 143) { if (color > 143) {
@ -79,82 +80,82 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
data[i] = (byte) color; data[i] = (byte) color;
} }
} }
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, data); wrapper.write(Types.BYTE_ARRAY_PRIMITIVE, data);
}); });
} }
}); });
registerSetSlot(ClientboundPackets1_12.SET_SLOT); registerSetSlot(ClientboundPackets1_12.CONTAINER_SET_SLOT);
registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS); registerSetContent(ClientboundPackets1_12.CONTAINER_SET_CONTENT);
registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT); registerSetEquippedItem(ClientboundPackets1_12.SET_EQUIPPED_ITEM);
// Plugin message Packet -> Trading // Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_12.PLUGIN_MESSAGE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.CUSTOM_PAYLOAD, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // 0 - Channel map(Types.STRING); // 0 - Channel
handler(wrapper -> { handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) { if (wrapper.get(Types.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID wrapper.passthrough(Types.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
if (secondItem) if (secondItem)
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item wrapper.write(Types.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_8))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Types.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses wrapper.passthrough(Types.INT); // Maximum number of trade uses
} }
} }
}); });
} }
}); });
protocol.registerServerbound(ServerboundPackets1_9_3.CLICK_WINDOW, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9_3.CONTAINER_CLICK, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot map(Types.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button map(Types.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number map(Types.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode map(Types.VAR_INT); // 4 - Mode
map(Type.ITEM1_8); // 5 - Clicked Item map(Types.ITEM1_8); // 5 - Clicked Item
handler(wrapper -> { handler(wrapper -> {
if (wrapper.get(Type.VAR_INT, 0) == 1) { // Shift click if (wrapper.get(Types.VAR_INT, 0) == 1) { // Shift click
// https://github.com/ViaVersion/ViaVersion/pull/754 // https://github.com/ViaVersion/ViaVersion/pull/754
// Previously clients grab the item from the clicked slot *before* it has // Previously clients grab the item from the clicked slot *before* it has
// been moved however now they grab the slot item *after* it has been moved // been moved however now they grab the slot item *after* it has been moved
// and send that in the packet. // and send that in the packet.
wrapper.set(Type.ITEM1_8, 0, null); // Set null item (probably will work) wrapper.set(Types.ITEM1_8, 0, null); // Set null item (probably will work)
// Apologize (may happen in some cases, maybe if inventory is full?) // Apologize (may happen in some cases, maybe if inventory is full?)
PacketWrapper confirm = wrapper.create(ServerboundPackets1_12.WINDOW_CONFIRMATION); PacketWrapper confirm = wrapper.create(ServerboundPackets1_12.CONTAINER_ACK);
confirm.write(Type.UNSIGNED_BYTE, wrapper.get(Type.UNSIGNED_BYTE, 0)); confirm.write(Types.UNSIGNED_BYTE, wrapper.get(Types.UNSIGNED_BYTE, 0));
confirm.write(Type.SHORT, wrapper.get(Type.SHORT, 1)); confirm.write(Types.SHORT, wrapper.get(Types.SHORT, 1));
confirm.write(Type.BOOLEAN, false); // Success - not used confirm.write(Types.BOOLEAN, false); // Success - not used
wrapper.sendToServer(Protocol1_11_1To1_12.class); wrapper.sendToServer(Protocol1_12To1_11_1.class);
wrapper.cancel(); wrapper.cancel();
confirm.sendToServer(Protocol1_11_1To1_12.class); confirm.sendToServer(Protocol1_12To1_11_1.class);
return; return;
} }
Item item = wrapper.get(Type.ITEM1_8, 0); Item item = wrapper.get(Types.ITEM1_8, 0);
handleItemToServer(wrapper.user(), item); handleItemToServer(wrapper.user(), item);
}); });
} }
}); });
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION); registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
protocol.registerClientbound(ClientboundPackets1_12.CHUNK_DATA, wrapper -> { protocol.registerClientbound(ClientboundPackets1_12.LEVEL_CHUNK, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed. ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed.
@ -166,31 +167,31 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
protocol.registerClientbound(ClientboundPackets1_12.BLOCK_ENTITY_DATA, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.BLOCK_ENTITY_DATA, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // 0 - Position map(Types.BLOCK_POSITION1_8); // 0 - Position
map(Type.UNSIGNED_BYTE); // 1 - Action map(Types.UNSIGNED_BYTE); // 1 - Action
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT map(Types.NAMED_COMPOUND_TAG); // 2 - NBT
handler(wrapper -> { handler(wrapper -> {
// Remove bed color // Remove bed color
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11) if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 11)
wrapper.cancel(); wrapper.cancel();
}); });
} }
}); });
protocol.getEntityRewriter().filter().handler((event, meta) -> { protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
}); });
protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_STATUS, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_COMMAND, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // Action ID map(Types.VAR_INT); // Action ID
handler(wrapper -> { handler(wrapper -> {
// Open Inventory // Open Inventory
if (wrapper.get(Type.VAR_INT, 0) == 2) { if (wrapper.get(Types.VAR_INT, 0) == 2) {
wrapper.cancel(); wrapper.cancel();
} }
}); });

View File

@ -16,19 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTranslations; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.AdvancementTranslations;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.rewriter.RewriterBase; import com.viaversion.viaversion.api.rewriter.RewriterBase;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
public class ChatPackets1_12 extends RewriterBase<Protocol1_11_1To1_12> { public class ChatPacketRewriter1_12 extends RewriterBase<Protocol1_12To1_11_1> {
public static final ComponentRewriter<ClientboundPackets1_12> COMPONENT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) { public static final ComponentRewriter<ClientboundPackets1_12> COMPONENT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) {
@Override @Override
@ -57,14 +58,14 @@ public class ChatPackets1_12 extends RewriterBase<Protocol1_11_1To1_12> {
} }
}; };
public ChatPackets1_12(Protocol1_11_1To1_12 protocol) { public ChatPacketRewriter1_12(Protocol1_12To1_11_1 protocol) {
super(protocol); super(protocol);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_12.CHAT_MESSAGE, wrapper -> { protocol.registerClientbound(ClientboundPackets1_12.CHAT, wrapper -> {
JsonElement element = wrapper.passthrough(Type.COMPONENT); JsonElement element = wrapper.passthrough(Types.COMPONENT);
COMPONENT_REWRITER.processText(wrapper.user(), element); COMPONENT_REWRITER.processText(wrapper.user(), element);
}); });
} }

View File

@ -16,46 +16,47 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.ParrotStorage;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.ShoulderTracker;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_12;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_12; import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.nbt.tag.CompoundTag;
public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_12, Protocol1_11_1To1_12> { public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPackets1_12, Protocol1_12To1_11_1> {
public EntityPackets1_12(Protocol1_11_1To1_12 protocol) { public EntityPacketRewriter1_12(Protocol1_12To1_11_1 protocol) {
super(protocol); super(protocol);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_12.SPAWN_ENTITY, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.ADD_ENTITY, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity id map(Types.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID map(Types.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type map(Types.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - x map(Types.DOUBLE); // 3 - x
map(Type.DOUBLE); // 4 - y map(Types.DOUBLE); // 4 - y
map(Type.DOUBLE); // 5 - z map(Types.DOUBLE); // 5 - z
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw map(Types.BYTE); // 7 - Yaw
map(Type.INT); // 8 - data map(Types.INT); // 8 - data
// Track Entity // Track Entity
handler(getObjectTrackerHandler()); handler(getObjectTrackerHandler());
@ -65,119 +66,119 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
} }
}); });
registerTracker(ClientboundPackets1_12.SPAWN_EXPERIENCE_ORB, EntityTypes1_12.EntityType.EXPERIENCE_ORB); registerTracker(ClientboundPackets1_12.ADD_EXPERIENCE_ORB, EntityTypes1_12.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_12.SPAWN_GLOBAL_ENTITY, EntityTypes1_12.EntityType.WEATHER); registerTracker(ClientboundPackets1_12.ADD_GLOBAL_ENTITY, EntityTypes1_12.EntityType.WEATHER);
protocol.registerClientbound(ClientboundPackets1_12.SPAWN_MOB, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.ADD_MOB, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity id map(Types.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID map(Types.UUID); // 1 - UUID
map(Type.VAR_INT); // 2 - Entity Type map(Types.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X map(Types.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Types.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Types.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw map(Types.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch map(Types.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch map(Types.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST); // 12 - Metadata map(Types1_12.ENTITY_DATA_LIST); // 12 - Metadata
// Track entity // Track entity
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(getMobSpawnRewriter1_11(Types1_12.METADATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST));
} }
}); });
registerTracker(ClientboundPackets1_12.SPAWN_PAINTING, EntityTypes1_12.EntityType.PAINTING); registerTracker(ClientboundPackets1_12.ADD_PAINTING, EntityTypes1_12.EntityType.PAINTING);
protocol.registerClientbound(ClientboundPackets1_12.SPAWN_PLAYER, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.ADD_PLAYER, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID map(Types.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X map(Types.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y map(Types.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_12.METADATA_LIST); // 7 - Metadata list map(Types1_12.ENTITY_DATA_LIST); // 7 - Metadata list
handler(getTrackerAndMetaHandler(Types1_12.METADATA_LIST, EntityTypes1_12.EntityType.PLAYER)); handler(getTrackerAndMetaHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_12.EntityType.PLAYER));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_12.JOIN_GAME, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.LOGIN, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Entity ID map(Types.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode map(Types.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension map(Types.INT); // 2 - Dimension
handler(getTrackerHandler(EntityTypes1_12.EntityType.PLAYER, Type.INT)); handler(getTrackerHandler(EntityTypes1_12.EntityType.PLAYER, Types.INT));
handler(getDimensionHandler(1)); handler(getDimensionHandler(1));
handler(wrapper -> { handler(wrapper -> {
ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class); ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class);
tracker.setEntityId(wrapper.get(Type.INT, 0)); tracker.setEntityId(wrapper.get(Types.INT, 0));
}); });
// Send fake inventory achievement // Send fake inventory achievement
handler(packetWrapper -> { handler(packetWrapper -> {
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.STATISTICS, packetWrapper.user()); PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.AWARD_STATS, packetWrapper.user());
wrapper.write(Type.VAR_INT, 1); wrapper.write(Types.VAR_INT, 1);
wrapper.write(Type.STRING, "achievement.openInventory"); wrapper.write(Types.STRING, "achievement.openInventory");
wrapper.write(Type.VAR_INT, 1); wrapper.write(Types.VAR_INT, 1);
wrapper.scheduleSend(Protocol1_11_1To1_12.class); wrapper.scheduleSend(Protocol1_12To1_11_1.class);
}); });
} }
}); });
registerRespawn(ClientboundPackets1_12.RESPAWN); registerRespawn(ClientboundPackets1_12.RESPAWN);
registerRemoveEntities(ClientboundPackets1_12.DESTROY_ENTITIES); registerRemoveEntities(ClientboundPackets1_12.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_12.ENTITY_METADATA, Types1_12.METADATA_LIST); registerSetEntityData(ClientboundPackets1_12.SET_ENTITY_DATA, Types1_12.ENTITY_DATA_LIST);
protocol.registerClientbound(ClientboundPackets1_12.ENTITY_PROPERTIES, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.UPDATE_ATTRIBUTES, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.INT); map(Types.INT);
handler(wrapper -> { handler(wrapper -> {
int size = wrapper.get(Type.INT, 0); int size = wrapper.get(Types.INT, 0);
int newSize = size; int newSize = size;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
String key = wrapper.read(Type.STRING); String key = wrapper.read(Types.STRING);
// Remove new attribute // Remove new attribute
if (key.equals("generic.flyingSpeed")) { if (key.equals("generic.flyingSpeed")) {
newSize--; newSize--;
wrapper.read(Type.DOUBLE); wrapper.read(Types.DOUBLE);
int modSize = wrapper.read(Type.VAR_INT); int modSize = wrapper.read(Types.VAR_INT);
for (int j = 0; j < modSize; j++) { for (int j = 0; j < modSize; j++) {
wrapper.read(Type.UUID); wrapper.read(Types.UUID);
wrapper.read(Type.DOUBLE); wrapper.read(Types.DOUBLE);
wrapper.read(Type.BYTE); wrapper.read(Types.BYTE);
} }
} else { } else {
wrapper.write(Type.STRING, key); wrapper.write(Types.STRING, key);
wrapper.passthrough(Type.DOUBLE); wrapper.passthrough(Types.DOUBLE);
int modSize = wrapper.passthrough(Type.VAR_INT); int modSize = wrapper.passthrough(Types.VAR_INT);
for (int j = 0; j < modSize; j++) { for (int j = 0; j < modSize; j++) {
wrapper.passthrough(Type.UUID); wrapper.passthrough(Types.UUID);
wrapper.passthrough(Type.DOUBLE); wrapper.passthrough(Types.DOUBLE);
wrapper.passthrough(Type.BYTE); wrapper.passthrough(Types.BYTE);
} }
} }
} }
if (newSize != size) { if (newSize != size) {
wrapper.set(Type.INT, 0, newSize); wrapper.set(Types.INT, 0, newSize);
} }
}); });
} }
@ -186,12 +187,12 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
mapEntityTypeWithData(EntityTypes1_12.EntityType.PARROT, EntityTypes1_12.EntityType.BAT).plainName().spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00))); mapEntityTypeWithData(EntityTypes1_12.EntityType.PARROT, EntityTypes1_12.EntityType.BAT).plainName().spawnMetadata(storage -> storage.add(new EntityData(12, EntityDataTypes1_12.BYTE, (byte) 0x00)));
mapEntityTypeWithData(EntityTypes1_12.EntityType.ILLUSION_ILLAGER, EntityTypes1_12.EntityType.EVOCATION_ILLAGER).plainName(); mapEntityTypeWithData(EntityTypes1_12.EntityType.ILLUSIONER, EntityTypes1_12.EntityType.EVOKER).plainName();
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
if (meta.metaType() == MetaType1_12.Chat) { if (meta.dataType() == EntityDataTypes1_12.COMPONENT) {
ChatPackets1_12.COMPONENT_REWRITER.processText(event.user(), (JsonElement) meta.getValue()); ComponentRewriter1_12.COMPONENT_REWRITER.processText(event.user(), (JsonElement) meta.getValue());
} }
}); });
@ -266,7 +267,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
// Right shoulder entity data // Right shoulder entity data
filter().type(EntityTypes1_12.EntityType.PLAYER).index(16).handler((event, meta) -> { filter().type(EntityTypes1_12.EntityType.PLAYER).index(16).handler((event, meta) -> {
CompoundTag tag = (CompoundTag) event.meta().getValue(); CompoundTag tag = (CompoundTag) event.data().getValue();
ShoulderTracker tracker = event.user().get(ShoulderTracker.class); ShoulderTracker tracker = event.user().get(ShoulderTracker.class);
if (tag.isEmpty() && tracker.getRightShoulder() != null) { if (tag.isEmpty() && tracker.getRightShoulder() != null) {

View File

@ -16,48 +16,49 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
import com.viaversion.viabackwards.api.rewriters.LegacySoundRewriter; import com.viaversion.viabackwards.api.rewriters.LegacySoundRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
public class SoundPackets1_12 extends LegacySoundRewriter<Protocol1_11_1To1_12> { public class SoundPacketRewriter1_12 extends LegacySoundRewriter<Protocol1_12To1_11_1> {
public SoundPackets1_12(Protocol1_11_1To1_12 protocol) { public SoundPacketRewriter1_12(Protocol1_12To1_11_1 protocol) {
super(protocol); super(protocol);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_12.NAMED_SOUND, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.CUSTOM_SOUND, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // 0 - Sound name map(Types.STRING); // 0 - Sound name
map(Type.VAR_INT); // 1 - Sound Category map(Types.VAR_INT); // 1 - Sound Category
map(Type.INT); // 2 - x map(Types.INT); // 2 - x
map(Type.INT); // 3 - y map(Types.INT); // 3 - y
map(Type.INT); // 4 - z map(Types.INT); // 4 - z
map(Type.FLOAT); // 5 - Volume map(Types.FLOAT); // 5 - Volume
map(Type.FLOAT); // 6 - Pitch map(Types.FLOAT); // 6 - Pitch
} }
}); });
protocol.registerClientbound(ClientboundPackets1_12.SOUND, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12.SOUND, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Sound name map(Types.VAR_INT); // 0 - Sound name
map(Type.VAR_INT); // 1 - Sound Category map(Types.VAR_INT); // 1 - Sound Category
map(Type.INT); // 2 - x map(Types.INT); // 2 - x
map(Type.INT); // 3 - y map(Types.INT); // 3 - y
map(Type.INT); // 4 - z map(Types.INT); // 4 - z
map(Type.FLOAT); // 5 - Volume map(Types.FLOAT); // 5 - Volume
map(Type.FLOAT); // 6 - Pitch map(Types.FLOAT); // 6 - Pitch
handler(wrapper -> { handler(wrapper -> {
int oldId = wrapper.get(Type.VAR_INT, 0); int oldId = wrapper.get(Types.VAR_INT, 0);
int newId = handleSounds(oldId); int newId = handleSounds(oldId);
if (newId == -1) { if (newId == -1) {
wrapper.cancel(); wrapper.cancel();
@ -65,9 +66,9 @@ public class SoundPackets1_12 extends LegacySoundRewriter<Protocol1_11_1To1_12>
} }
if (hasPitch(oldId)) { if (hasPitch(oldId)) {
wrapper.set(Type.FLOAT, 1, handlePitch(oldId)); wrapper.set(Types.FLOAT, 1, handlePitch(oldId));
} }
wrapper.set(Type.VAR_INT, 0, newId); wrapper.set(Types.VAR_INT, 0, newId);
}); });
} }
}); });

View File

@ -15,16 +15,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1; package com.viaversion.viabackwards.protocol.v1_13_1to1_13;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.data.CommandRewriter1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.data.CommandRewriter1_13_1;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter.EntityPacketRewriter1_13_1;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter.ItemPacketRewriter1_13_1;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter.WorldPacketRewriter1_13_1;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.api.minecraft.RegistryType;
@ -33,27 +33,27 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> { public class Protocol1_13_1To1_13 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.13.2", "1.13", Protocol1_13_1To1_13.class); public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.13.2", "1.13", Protocol1_13To1_13_1.class);
private final EntityPackets1_13_1 entityRewriter = new EntityPackets1_13_1(this); private final EntityPacketRewriter1_13_1 entityRewriter = new EntityPacketRewriter1_13_1(this);
private final InventoryPackets1_13_1 itemRewriter = new InventoryPackets1_13_1(this); private final ItemPacketRewriter1_13_1 itemRewriter = new ItemPacketRewriter1_13_1(this);
private final TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON);
private final TagRewriter<ClientboundPackets1_13> tagRewriter = new TagRewriter<>(this); private final TagRewriter<ClientboundPackets1_13> tagRewriter = new TagRewriter<>(this);
public Protocol1_13To1_13_1() { public Protocol1_13_1To1_13() {
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class); super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
} }
@ -61,22 +61,22 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
protected void registerPackets() { protected void registerPackets() {
super.registerPackets(); super.registerPackets();
WorldPackets1_13_1.register(this); WorldPacketRewriter1_13_1.register(this);
translatableRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT_MESSAGE); translatableRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT);
translatableRewriter.registerCombatEvent(ClientboundPackets1_13.COMBAT_EVENT); translatableRewriter.registerPlayerCombat(ClientboundPackets1_13.PLAYER_COMBAT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_13.DISCONNECT); translatableRewriter.registerComponentPacket(ClientboundPackets1_13.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST); translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE); translatableRewriter.registerTitle(ClientboundPackets1_13.SET_TITLES);
translatableRewriter.registerPing(); translatableRewriter.registerPing();
new CommandRewriter1_13_1(this).registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS); new CommandRewriter1_13_1(this).registerDeclareCommands(ClientboundPackets1_13.COMMANDS);
registerServerbound(ServerboundPackets1_13.TAB_COMPLETE, new PacketHandlers() { registerServerbound(ServerboundPackets1_13.COMMAND_SUGGESTION, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.STRING, new ValueTransformer<>(Type.STRING) { map(Types.STRING, new ValueTransformer<>(Types.STRING) {
@Override @Override
public String transform(PacketWrapper wrapper, String inputValue) { public String transform(PacketWrapper wrapper, String inputValue) {
// 1.13 starts sending slash at start, so we remove it for compatibility // 1.13 starts sending slash at start, so we remove it for compatibility
@ -89,22 +89,22 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketHandlers() { registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.ITEM1_13); map(Types.ITEM1_13);
map(Type.BOOLEAN); map(Types.BOOLEAN);
handler(wrapper -> { handler(wrapper -> {
itemRewriter.handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0)); itemRewriter.handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_13, 0));
wrapper.write(Type.VAR_INT, 0); wrapper.write(Types.VAR_INT, 0);
}); });
} }
}); });
registerClientbound(ClientboundPackets1_13.OPEN_WINDOW, new PacketHandlers() { registerClientbound(ClientboundPackets1_13.OPEN_SCREEN, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // Id map(Types.UNSIGNED_BYTE); // Id
map(Type.STRING); // Window Type map(Types.STRING); // Window Type
handler(wrapper -> { handler(wrapper -> {
JsonElement title = wrapper.passthrough(Type.COMPONENT); JsonElement title = wrapper.passthrough(Types.COMPONENT);
translatableRewriter.processText(wrapper.user(), title); translatableRewriter.processText(wrapper.user(), title);
if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) { if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) {
@ -117,87 +117,87 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
// https://bugs.mojang.com/browse/MC-124543 // https://bugs.mojang.com/browse/MC-124543
JsonObject legacyComponent = new JsonObject(); JsonObject legacyComponent = new JsonObject();
legacyComponent.addProperty("text", ComponentUtil.jsonToLegacy(title)); legacyComponent.addProperty("text", ComponentUtil.jsonToLegacy(title));
wrapper.set(Type.COMPONENT, 0, legacyComponent); wrapper.set(Types.COMPONENT, 0, legacyComponent);
} }
}); });
} }
}); });
registerClientbound(ClientboundPackets1_13.TAB_COMPLETE, new PacketHandlers() { registerClientbound(ClientboundPackets1_13.COMMAND_SUGGESTIONS, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // Transaction id map(Types.VAR_INT); // Transaction id
map(Type.VAR_INT); // Start map(Types.VAR_INT); // Start
map(Type.VAR_INT); // Length map(Types.VAR_INT); // Length
map(Type.VAR_INT); // Count map(Types.VAR_INT); // Count
handler(wrapper -> { handler(wrapper -> {
int start = wrapper.get(Type.VAR_INT, 1); int start = wrapper.get(Types.VAR_INT, 1);
wrapper.set(Type.VAR_INT, 1, start - 1); // Offset by +1 to take into account / at beginning wrapper.set(Types.VAR_INT, 1, start - 1); // Offset by +1 to take into account / at beginning
// Passthrough suggestions // Passthrough suggestions
int count = wrapper.get(Type.VAR_INT, 3); int count = wrapper.get(Types.VAR_INT, 3);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Types.STRING);
wrapper.passthrough(Type.OPTIONAL_COMPONENT); // Tooltip wrapper.passthrough(Types.OPTIONAL_COMPONENT); // Tooltip
} }
}); });
} }
}); });
registerClientbound(ClientboundPackets1_13.BOSSBAR, new PacketHandlers() { registerClientbound(ClientboundPackets1_13.BOSS_EVENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UUID); map(Types.UUID);
map(Type.VAR_INT); map(Types.VAR_INT);
handler(wrapper -> { handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0); int action = wrapper.get(Types.VAR_INT, 0);
if (action == 0 || action == 3) { if (action == 0 || action == 3) {
translatableRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)); translatableRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
if (action == 0) { if (action == 0) {
wrapper.passthrough(Type.FLOAT); wrapper.passthrough(Types.FLOAT);
wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Types.VAR_INT);
short flags = wrapper.read(Type.UNSIGNED_BYTE); short flags = wrapper.read(Types.UNSIGNED_BYTE);
if ((flags & 0x04) != 0) flags |= 0x02; if ((flags & 0x04) != 0) flags |= 0x02;
wrapper.write(Type.UNSIGNED_BYTE, flags); wrapper.write(Types.UNSIGNED_BYTE, flags);
} }
} }
}); });
} }
}); });
registerClientbound(ClientboundPackets1_13.ADVANCEMENTS, wrapper -> { registerClientbound(ClientboundPackets1_13.UPDATE_ADVANCEMENTS, wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear wrapper.passthrough(Types.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size int size = wrapper.passthrough(Types.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier wrapper.passthrough(Types.STRING); // Identifier
wrapper.passthrough(Type.OPTIONAL_STRING); // Parent wrapper.passthrough(Types.OPTIONAL_STRING); // Parent
// Display data // Display data
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Types.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title wrapper.passthrough(Types.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description wrapper.passthrough(Types.COMPONENT); // Description
Item icon = wrapper.passthrough(Type.ITEM1_13); Item icon = wrapper.passthrough(Types.ITEM1_13);
itemRewriter.handleItemToClient(wrapper.user(), icon); itemRewriter.handleItemToClient(wrapper.user(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Types.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Types.INT); // Flags
if ((flags & 1) != 0) if ((flags & 1) != 0)
wrapper.passthrough(Type.STRING); // Background texture wrapper.passthrough(Types.STRING); // Background texture
wrapper.passthrough(Type.FLOAT); // X wrapper.passthrough(Types.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y wrapper.passthrough(Types.FLOAT); // Y
} }
wrapper.passthrough(Type.STRING_ARRAY); // Criteria wrapper.passthrough(Types.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Type.VAR_INT); int arrayLength = wrapper.passthrough(Types.VAR_INT);
for (int array = 0; array < arrayLength; array++) { for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array wrapper.passthrough(Types.STRING_ARRAY); // String array
} }
} }
}); });
tagRewriter.register(ClientboundPackets1_13.TAGS, RegistryType.ITEM); tagRewriter.register(ClientboundPackets1_13.UPDATE_TAGS, RegistryType.ITEM);
new StatisticsRewriter<>(this).register(ClientboundPackets1_13.STATISTICS); new StatisticsRewriter<>(this).register(ClientboundPackets1_13.AWARD_STATS);
} }
@Override @Override
@ -210,17 +210,17 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
} }
@Override @Override
public BackwardsMappings getMappingData() { public BackwardsMappingData getMappingData() {
return MAPPINGS; return MAPPINGS;
} }
@Override @Override
public EntityPackets1_13_1 getEntityRewriter() { public EntityPacketRewriter1_13_1 getEntityRewriter() {
return entityRewriter; return entityRewriter;
} }
@Override @Override
public InventoryPackets1_13_1 getItemRewriter() { public ItemPacketRewriter1_13_1 getItemRewriter() {
return itemRewriter; return itemRewriter;
} }

View File

@ -15,20 +15,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.data; package com.viaversion.viabackwards.protocol.v1_13_1to1_13.data;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.CommandRewriter;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class CommandRewriter1_13_1 extends CommandRewriter<ClientboundPackets1_13> { public class CommandRewriter1_13_1 extends CommandRewriter<ClientboundPackets1_13> {
public CommandRewriter1_13_1(Protocol1_13To1_13_1 protocol) { public CommandRewriter1_13_1(Protocol1_13_1To1_13 protocol) {
super(protocol); super(protocol);
this.parserHandlers.put("minecraft:dimension", wrapper -> wrapper.write(Type.VAR_INT, 0)); // Single word this.parserHandlers.put("minecraft:dimension", wrapper -> wrapper.write(Types.VAR_INT, 0)); // Single word
} }
@Override @Override

View File

@ -15,47 +15,48 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets; package com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import java.util.List; import java.util.List;
public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets1_13, Protocol1_13To1_13_1> { public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter<ClientboundPackets1_13, Protocol1_13_1To1_13> {
public EntityPackets1_13_1(Protocol1_13To1_13_1 protocol) { public EntityPacketRewriter1_13_1(Protocol1_13_1To1_13 protocol) {
super(protocol); super(protocol);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_ENTITY, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_ENTITY, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity id map(Types.VAR_INT); // 0 - Entity id
map(Type.UUID); // 1 - UUID map(Types.UUID); // 1 - UUID
map(Type.BYTE); // 2 - Type map(Types.BYTE); // 2 - Type
map(Type.DOUBLE); // 3 - X map(Types.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Types.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Types.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Type.BYTE); // 7 - Yaw map(Types.BYTE); // 7 - Yaw
map(Type.INT); // 8 - Data map(Types.INT); // 8 - Data
handler(wrapper -> { handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Types.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0); byte type = wrapper.get(Types.BYTE, 0);
EntityTypes1_13.EntityType entType = EntityTypes1_13.getTypeFromId(type, true); EntityTypes1_13.EntityType entType = EntityTypes1_13.getTypeFromId(type, true);
if (entType == null) { if (entType == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type); ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
@ -64,8 +65,8 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
// Rewrite falling block // Rewrite falling block
if (entType.is(EntityTypes1_13.EntityType.FALLING_BLOCK)) { if (entType.is(EntityTypes1_13.EntityType.FALLING_BLOCK)) {
int data = wrapper.get(Type.INT, 0); int data = wrapper.get(Types.INT, 0);
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data)); wrapper.set(Types.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} }
// Track Entity // Track Entity
@ -74,73 +75,73 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
} }
}); });
registerTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, EntityTypes1_13.EntityType.EXPERIENCE_ORB); registerTracker(ClientboundPackets1_13.ADD_EXPERIENCE_ORB, EntityTypes1_13.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, EntityTypes1_13.EntityType.LIGHTNING_BOLT); registerTracker(ClientboundPackets1_13.ADD_GLOBAL_ENTITY, EntityTypes1_13.EntityType.LIGHTNING_BOLT);
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_MOB, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID map(Types.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type map(Types.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X map(Types.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Types.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Types.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw map(Types.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch map(Types.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch map(Types.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X map(Types.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y map(Types.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z map(Types.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST); // 12 - Metadata map(Types1_13.ENTITY_DATA_LIST); // 12 - Metadata
// Track Entity // Track Entity
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite Metadata // Rewrite Metadata
handler(wrapper -> { handler(wrapper -> {
List<Metadata> metadata = wrapper.get(Types1_13.METADATA_LIST, 0); List<EntityData> metadata = wrapper.get(Types1_13.ENTITY_DATA_LIST, 0);
handleMetadata(wrapper.get(Type.VAR_INT, 0), metadata, wrapper.user()); handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user());
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PLAYER, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_PLAYER, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); // 0 - Entity ID map(Types.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID map(Types.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X map(Types.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y map(Types.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z map(Types.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw map(Types.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch map(Types.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST); // 7 - Metadata map(Types1_13.ENTITY_DATA_LIST); // 7 - Metadata
handler(getTrackerAndMetaHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER)); handler(getTrackerAndMetaHandler(Types1_13.ENTITY_DATA_LIST, EntityTypes1_13.EntityType.PLAYER));
} }
}); });
registerTracker(ClientboundPackets1_13.SPAWN_PAINTING, EntityTypes1_13.EntityType.PAINTING); registerTracker(ClientboundPackets1_13.ADD_PAINTING, EntityTypes1_13.EntityType.PAINTING);
registerJoinGame(ClientboundPackets1_13.JOIN_GAME, EntityTypes1_13.EntityType.PLAYER); registerJoinGame(ClientboundPackets1_13.LOGIN, EntityTypes1_13.EntityType.PLAYER);
registerRespawn(ClientboundPackets1_13.RESPAWN); registerRespawn(ClientboundPackets1_13.RESPAWN);
registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES); registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST); registerSetEntityData(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13.ENTITY_DATA_LIST);
} }
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Rewrite items & blocks // Rewrite items & blocks
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
if (meta.metaType() == Types1_13.META_TYPES.itemType) { if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.itemType) {
protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue()); protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue());
} else if (meta.metaType() == Types1_13.META_TYPES.blockStateType) { } else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType) {
// Convert to new block id // Convert to new block id
int data = (int) meta.getValue(); int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (meta.metaType() == Types1_13.META_TYPES.particleType) { } else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.particleType) {
rewriteParticle(event.user(), (Particle) meta.getValue()); rewriteParticle(event.user(), (Particle) meta.getValue());
} else if (meta.metaType() == Types1_13.META_TYPES.optionalComponentType || meta.metaType() == Types1_13.META_TYPES.componentType) { } else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalComponentType || meta.dataType() == Types1_13.ENTITY_DATA_TYPES.componentType) {
JsonElement element = meta.value(); JsonElement element = meta.value();
protocol.translatableRewriter().processText(event.user(), element); protocol.translatableRewriter().processText(event.user(), element);
} }

View File

@ -0,0 +1,74 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter;
import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ItemRewriter;
public class ItemPacketRewriter1_13_1 extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13_1To1_13> {
public ItemPacketRewriter1_13_1(Protocol1_13_1To1_13 protocol) {
super(protocol, Types.ITEM1_13, Types.ITEM1_13_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerCooldown(ClientboundPackets1_13.COOLDOWN);
registerSetContent(ClientboundPackets1_13.CONTAINER_SET_CONTENT);
registerSetSlot(ClientboundPackets1_13.CONTAINER_SET_SLOT);
protocol.registerClientbound(ClientboundPackets1_13.CUSTOM_PAYLOAD, wrapper -> {
String channel = wrapper.passthrough(Types.STRING);
if (channel.equals("minecraft:trader_list")) {
wrapper.passthrough(Types.INT); //Passthrough Window ID
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.passthrough(Types.ITEM1_13);
handleItemToClient(wrapper.user(), input);
//Output Item
Item output = wrapper.passthrough(Types.ITEM1_13);
handleItemToClient(wrapper.user(), output);
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.passthrough(Types.ITEM1_13);
handleItemToClient(wrapper.user(), second);
}
wrapper.passthrough(Types.BOOLEAN); //Trade disabled
wrapper.passthrough(Types.INT); //Number of tools uses
wrapper.passthrough(Types.INT); //Maximum number of trade uses
}
}
});
registerSetEquippedItem(ClientboundPackets1_13.SET_EQUIPPED_ITEM);
registerContainerClick(ServerboundPackets1_13.CONTAINER_CLICK);
registerSetCreativeModeSlot(ServerboundPackets1_13.SET_CREATIVE_MODE_SLOT);
registerLevelParticles(ClientboundPackets1_13.LEVEL_PARTICLES, Types.FLOAT);
}
}

View File

@ -15,9 +15,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets; package com.viaversion.viabackwards.protocol.v1_13_1to1_13.rewriter;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.api.minecraft.BlockFace; import com.viaversion.viaversion.api.minecraft.BlockFace;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
@ -27,16 +27,17 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.BlockRewriter;
public class WorldPackets1_13_1 { public class WorldPacketRewriter1_13_1 {
public static void register(Protocol1_13To1_13_1 protocol) { public static void register(Protocol1_13_1To1_13 protocol) {
BlockRewriter<ClientboundPackets1_13> blockRewriter = BlockRewriter.legacy(protocol); BlockRewriter<ClientboundPackets1_13> blockRewriter = BlockRewriter.legacy(protocol);
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment())); Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
@ -53,34 +54,34 @@ public class WorldPackets1_13_1 {
} }
}); });
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION); blockRewriter.registerBlockEvent(ClientboundPackets1_13.BLOCK_EVENT);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE); blockRewriter.registerBlockUpdate(ClientboundPackets1_13.BLOCK_UPDATE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE); blockRewriter.registerChunkBlocksUpdate(ClientboundPackets1_13.CHUNK_BLOCKS_UPDATE);
protocol.registerClientbound(ClientboundPackets1_13.EFFECT, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.LEVEL_EVENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // Effect Id map(Types.INT); // Effect Id
map(Type.POSITION1_8); // Location map(Types.BLOCK_POSITION1_8); // Location
map(Type.INT); // Data map(Types.INT); // Data
handler(wrapper -> { handler(wrapper -> {
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Types.INT, 0);
int data = wrapper.get(Type.INT, 1); int data = wrapper.get(Types.INT, 1);
if (id == 1010) { // Play record if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data)); wrapper.set(Types.INT, 1, protocol.getMappingData().getNewItemId(data));
} else if (id == 2001) { // Block break + block break sound } else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(data)); wrapper.set(Types.INT, 1, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 2000) { // Smoke } else if (id == 2000) { // Smoke
switch (data) { // Down switch (data) { // Down
case 0, 1 -> { // Up case 0, 1 -> { // Up
Position pos = wrapper.get(Type.POSITION1_8, 0); Position pos = wrapper.get(Types.BLOCK_POSITION1_8, 0);
BlockFace relative = data == 0 ? BlockFace.BOTTOM : BlockFace.TOP; BlockFace relative = data == 0 ? BlockFace.BOTTOM : BlockFace.TOP;
wrapper.set(Type.POSITION1_8, 0, pos.getRelative(relative)); // Y Offset wrapper.set(Types.BLOCK_POSITION1_8, 0, pos.getRelative(relative)); // Y Offset
wrapper.set(Type.INT, 1, 4); // Self wrapper.set(Types.INT, 1, 4); // Self
} }
case 2 -> wrapper.set(Type.INT, 1, 1); // North case 2 -> wrapper.set(Types.INT, 1, 1); // North
case 3 -> wrapper.set(Type.INT, 1, 7); // South case 3 -> wrapper.set(Types.INT, 1, 7); // South
case 4 -> wrapper.set(Type.INT, 1, 3); // West case 4 -> wrapper.set(Types.INT, 1, 3); // West
case 5 -> wrapper.set(Type.INT, 1, 5); // East case 5 -> wrapper.set(Types.INT, 1, 5); // East
} }
} }
}); });

View File

@ -0,0 +1,81 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_13_2to1_13_1;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter.EntityPacketRewriter1_13_2;
import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter.ItemPacketRewriter1_13_2;
import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter.WorldPacketRewriter1_13_2;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
public class Protocol1_13_2To1_13_1 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
public Protocol1_13_2To1_13_1() {
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
}
@Override
protected void registerPackets() {
ItemPacketRewriter1_13_2.register(this);
WorldPacketRewriter1_13_2.register(this);
EntityPacketRewriter1_13_2.register(this);
registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketHandlers() {
@Override
public void register() {
map(Types.ITEM1_13, Types.ITEM1_13_2);
}
});
registerClientbound(ClientboundPackets1_13.UPDATE_ADVANCEMENTS, wrapper -> {
wrapper.passthrough(Types.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Types.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) {
wrapper.passthrough(Types.STRING); // Identifier
wrapper.passthrough(Types.OPTIONAL_STRING); // Parent
// Display data
if (wrapper.passthrough(Types.BOOLEAN)) {
wrapper.passthrough(Types.COMPONENT); // Title
wrapper.passthrough(Types.COMPONENT); // Description
Item icon = wrapper.read(Types.ITEM1_13_2);
wrapper.write(Types.ITEM1_13, icon);
wrapper.passthrough(Types.VAR_INT); // Frame type
int flags = wrapper.passthrough(Types.INT); // Flags
if ((flags & 1) != 0)
wrapper.passthrough(Types.STRING); // Background texture
wrapper.passthrough(Types.FLOAT); // X
wrapper.passthrough(Types.FLOAT); // Y
}
wrapper.passthrough(Types.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Types.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Types.STRING_ARRAY); // String array
}
}
});
}
}

View File

@ -0,0 +1,93 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter;
import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
public class EntityPacketRewriter1_13_2 {
public static void register(Protocol1_13_2To1_13_1 protocol) {
protocol.registerClientbound(ClientboundPackets1_13.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Entity UUID
map(Types.VAR_INT); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Metadata
handler(wrapper -> {
for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId()));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.ADD_PLAYER, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Player UUID
map(Types.DOUBLE); // 2 - X
map(Types.DOUBLE); // 3 - Y
map(Types.DOUBLE); // 4 - Z
map(Types.BYTE); // 5 - Yaw
map(Types.BYTE); // 6 - Pitch
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Metadata
handler(wrapper -> {
for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId()));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.SET_ENTITY_DATA, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Metadata list
handler(wrapper -> {
for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) {
metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId()));
}
});
}
});
}
}

View File

@ -0,0 +1,137 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter;
import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
public class ItemPacketRewriter1_13_2 {
public static void register(Protocol1_13_2To1_13_1 protocol) {
protocol.registerClientbound(ClientboundPackets1_13.CONTAINER_SET_SLOT, new PacketHandlers() {
@Override
public void register() {
map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Types.SHORT); // 1 - Slot ID
map(Types.ITEM1_13_2, Types.ITEM1_13); // 2 - Slot Value
}
});
protocol.registerClientbound(ClientboundPackets1_13.CONTAINER_SET_CONTENT, new PacketHandlers() {
@Override
public void register() {
map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Types.ITEM1_13_2_SHORT_ARRAY, Types.ITEM1_13_SHORT_ARRAY); // 1 - Window Values
}
});
protocol.registerClientbound(ClientboundPackets1_13.CUSTOM_PAYLOAD, new PacketHandlers() {
@Override
public void register() {
map(Types.STRING); // Channel
handler(wrapper -> {
String channel = wrapper.get(Types.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
wrapper.passthrough(Types.INT); // Passthrough Window ID
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
// Input Item
wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
// Output Item
wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
}
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Types.INT); // Number of tools uses
wrapper.passthrough(Types.INT); // Maximum number of trade uses
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.SET_EQUIPPED_ITEM, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.VAR_INT); // 1 - Slot ID
map(Types.ITEM1_13_2, Types.ITEM1_13); // 2 - Item
}
});
protocol.registerClientbound(ClientboundPackets1_13.UPDATE_RECIPES, wrapper -> {
int recipesNo = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < recipesNo; i++) {
wrapper.passthrough(Types.STRING); // Id
String type = wrapper.passthrough(Types.STRING);
if (type.equals("crafting_shapeless")) {
wrapper.passthrough(Types.STRING); // Group
int ingredientsNo = wrapper.passthrough(Types.VAR_INT);
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Types.ITEM1_13_ARRAY, wrapper.read(Types.ITEM1_13_2_ARRAY));
}
wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
} else if (type.equals("crafting_shaped")) {
int ingredientsNo = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.STRING); // Group
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Types.ITEM1_13_ARRAY, wrapper.read(Types.ITEM1_13_2_ARRAY));
}
wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
} else if (type.equals("smelting")) {
wrapper.passthrough(Types.STRING); // Group
// Ingredient start
wrapper.write(Types.ITEM1_13_ARRAY, wrapper.read(Types.ITEM1_13_2_ARRAY));
// Ingredient end
wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
wrapper.passthrough(Types.FLOAT); // EXP
wrapper.passthrough(Types.VAR_INT); // Cooking time
}
}
});
protocol.registerServerbound(ServerboundPackets1_13.CONTAINER_CLICK, new PacketHandlers() {
@Override
public void register() {
map(Types.UNSIGNED_BYTE); // 0 - Window ID
map(Types.SHORT); // 1 - Slot
map(Types.BYTE); // 2 - Button
map(Types.SHORT); // 3 - Action number
map(Types.VAR_INT); // 4 - Mode
map(Types.ITEM1_13, Types.ITEM1_13_2); // 5 - Clicked Item
}
});
protocol.registerServerbound(ServerboundPackets1_13.SET_CREATIVE_MODE_SLOT, new PacketHandlers() {
@Override
public void register() {
map(Types.SHORT); // 0 - Slot
map(Types.ITEM1_13, Types.ITEM1_13_2); // 1 - Clicked Item
}
});
}
}

View File

@ -15,34 +15,35 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.packets; package com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter;
import com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2; import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
public class WorldPackets1_13_2 { public class WorldPacketRewriter1_13_2 {
public static void register(Protocol1_13_1To1_13_2 protocol) { public static void register(Protocol1_13_2To1_13_1 protocol) {
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.LEVEL_PARTICLES, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Particle ID map(Types.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance map(Types.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X map(Types.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y map(Types.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z map(Types.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X map(Types.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y map(Types.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z map(Types.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data map(Types.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count map(Types.INT); // 9 - Particle Count
handler(wrapper -> { handler(wrapper -> {
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Types.INT, 0);
if (id == 27) { if (id == 27) {
wrapper.write(Type.ITEM1_13, wrapper.read(Type.ITEM1_13_2)); wrapper.write(Types.ITEM1_13, wrapper.read(Types.ITEM1_13_2));
} }
}); });
} }

View File

@ -16,22 +16,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13; package com.viaversion.viabackwards.protocol.v1_13to1_12_2;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.BackwardsMappingData1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.PaintingMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter.BlockItemPacketRewriter1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter.EntityPacketRewriter1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter.PlayerPacketRewriter1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter.SoundPacketRewriter1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.NoteBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.PlayerPositionStorage1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.TabCompleteStorage;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
@ -40,20 +40,20 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonParser; import com.viaversion.viaversion.libs.gson.JsonParser;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_12_1, ServerboundPackets1_13, ServerboundPackets1_12_1> { public class Protocol1_13To1_12_2 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_12_1, ServerboundPackets1_13, ServerboundPackets1_12_1> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings(); public static final BackwardsMappingData1_13 MAPPINGS = new BackwardsMappingData1_13();
private final EntityPackets1_13 entityRewriter = new EntityPackets1_13(this); private final EntityPacketRewriter1_13 entityRewriter = new EntityPacketRewriter1_13(this);
private final BlockItemPackets1_13 blockItemPackets = new BlockItemPackets1_13(this); private final BlockItemPacketRewriter1_13 blockItemPackets = new BlockItemPacketRewriter1_13(this);
private final TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON) { private final TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON) {
@Override @Override
protected void handleTranslate(JsonObject root, String translate) { protected void handleTranslate(JsonObject root, String translate) {
@ -68,46 +68,46 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
protected void handleTranslate(JsonObject root, String translate) { protected void handleTranslate(JsonObject root, String translate) {
String mappedKey = mappedTranslationKey(translate); String mappedKey = mappedTranslationKey(translate);
if (mappedKey != null || (mappedKey = getMappingData().getTranslateMappings().get(translate)) != null) { if (mappedKey != null || (mappedKey = getMappingData().getTranslateMappings().get(translate)) != null) {
root.addProperty("translate", Protocol1_13To1_12_2.MAPPINGS.getMojangTranslation().getOrDefault(mappedKey, mappedKey)); root.addProperty("translate", Protocol1_12_2To1_13.MAPPINGS.getMojangTranslation().getOrDefault(mappedKey, mappedKey));
} }
} }
}; };
public Protocol1_12_2To1_13() { public Protocol1_13To1_12_2() {
super(ClientboundPackets1_13.class, ClientboundPackets1_12_1.class, ServerboundPackets1_13.class, ServerboundPackets1_12_1.class); super(ClientboundPackets1_13.class, ClientboundPackets1_12_1.class, ServerboundPackets1_13.class, ServerboundPackets1_12_1.class);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_13To1_12_2.class, () -> { executeAsyncAfterLoaded(Protocol1_12_2To1_13.class, () -> {
MAPPINGS.load(); MAPPINGS.load();
PaintingMapping.init(); PaintingMapping.init();
Via.getManager().getProviders().register(BackwardsBlockEntityProvider.class, new BackwardsBlockEntityProvider()); Via.getManager().getProviders().register(BackwardsBlockEntityProvider.class, new BackwardsBlockEntityProvider());
}); });
translatableRewriter.registerPing(); translatableRewriter.registerPing();
translatableRewriter.registerBossBar(ClientboundPackets1_13.BOSSBAR); translatableRewriter.registerBossEvent(ClientboundPackets1_13.BOSS_EVENT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT_MESSAGE); translatableRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT);
translatableRewriter.registerLegacyOpenWindow(ClientboundPackets1_13.OPEN_WINDOW); translatableRewriter.registerLegacyOpenWindow(ClientboundPackets1_13.OPEN_SCREEN);
translatableRewriter.registerComponentPacket(ClientboundPackets1_13.DISCONNECT); translatableRewriter.registerComponentPacket(ClientboundPackets1_13.DISCONNECT);
translatableRewriter.registerCombatEvent(ClientboundPackets1_13.COMBAT_EVENT); translatableRewriter.registerPlayerCombat(ClientboundPackets1_13.PLAYER_COMBAT);
translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE); translatableRewriter.registerTitle(ClientboundPackets1_13.SET_TITLES);
translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST); translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST);
blockItemPackets.register(); blockItemPackets.register();
entityRewriter.register(); entityRewriter.register();
new PlayerPacket1_13(this).register(); new PlayerPacketRewriter1_13(this).register();
new SoundPackets1_13(this).register(); new SoundPacketRewriter1_13(this).register();
cancelClientbound(ClientboundPackets1_13.NBT_QUERY); cancelClientbound(ClientboundPackets1_13.TAG_QUERY);
cancelClientbound(ClientboundPackets1_13.CRAFT_RECIPE_RESPONSE); cancelClientbound(ClientboundPackets1_13.PLACE_GHOST_RECIPE);
cancelClientbound(ClientboundPackets1_13.UNLOCK_RECIPES); cancelClientbound(ClientboundPackets1_13.RECIPE);
cancelClientbound(ClientboundPackets1_13.ADVANCEMENTS); cancelClientbound(ClientboundPackets1_13.UPDATE_ADVANCEMENTS);
cancelClientbound(ClientboundPackets1_13.DECLARE_RECIPES); cancelClientbound(ClientboundPackets1_13.UPDATE_RECIPES);
cancelClientbound(ClientboundPackets1_13.TAGS); cancelClientbound(ClientboundPackets1_13.UPDATE_TAGS);
cancelServerbound(ServerboundPackets1_12_1.CRAFT_RECIPE_REQUEST); cancelServerbound(ServerboundPackets1_12_1.PLACE_RECIPE);
cancelServerbound(ServerboundPackets1_12_1.RECIPE_BOOK_DATA); cancelServerbound(ServerboundPackets1_12_1.RECIPE_BOOK_UPDATE);
} }
@Override @Override
@ -129,17 +129,17 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
} }
@Override @Override
public BackwardsMappings getMappingData() { public BackwardsMappingData1_13 getMappingData() {
return MAPPINGS; return MAPPINGS;
} }
@Override @Override
public EntityPackets1_13 getEntityRewriter() { public EntityPacketRewriter1_13 getEntityRewriter() {
return entityRewriter; return entityRewriter;
} }
@Override @Override
public BlockItemPackets1_13 getItemRewriter() { public BlockItemPacketRewriter1_13 getItemRewriter() {
return blockItemPackets; return blockItemPackets;
} }

View File

@ -16,14 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
public class BannerHandler implements BackwardsBlockEntityHandler { public class BannerHandler implements BackwardsBlockEntityHandler {
private static final int WALL_BANNER_START = 7110; // 4 each private static final int WALL_BANNER_START = 7110; // 4 each

View File

@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {

View File

@ -16,12 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.Pair;
public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {

View File

@ -15,19 +15,18 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers;
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import com.viaversion.viaversion.protocols.v1_12_2to1_13.blockconnections.ConnectionData;
import java.util.Map; import java.util.Map;
import java.util.StringJoiner; import java.util.StringJoiner;
@ -62,7 +61,7 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
// There doesn't seem to be a nicer way around it :( // There doesn't seem to be a nicer way around it :(
private void addEntries(String data, int id) { private void addEntries(String data, int id) {
id = Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(id); id = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(id);
pistonIds.put(data, id); pistonIds.put(data, id);
String substring = data.substring(10); String substring = data.substring(10);

View File

@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
public class SkullHandler implements BackwardsBlockEntityHandler { public class SkullHandler implements BackwardsBlockEntityHandler {
private static final int SKULL_START = 5447; private static final int SKULL_START = 5447;

View File

@ -16,12 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.EntityNameRewrites;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {

View File

@ -16,22 +16,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.data;
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.StatisticMappings; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.StatisticMappings;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class BackwardsMappings extends com.viaversion.viabackwards.api.data.BackwardsMappings { public class BackwardsMappingData1_13 extends BackwardsMappingData {
private final Int2ObjectMap<String> statisticMappings = new Int2ObjectOpenHashMap<>(); private final Int2ObjectMap<String> statisticMappings = new Int2ObjectOpenHashMap<>();
private final Map<String, String> translateMappings = new HashMap<>(); private final Map<String, String> translateMappings = new HashMap<>();
public BackwardsMappings() { public BackwardsMappingData1_13() {
super("1.13", "1.12", Protocol1_13To1_12_2.class); super("1.13", "1.12", Protocol1_12_2To1_13.class);
} }
@Override @Override
@ -41,7 +42,7 @@ public class BackwardsMappings extends com.viaversion.viabackwards.api.data.Back
for (Map.Entry<String, Integer> entry : StatisticMappings.CUSTOM_STATS.entrySet()) { for (Map.Entry<String, Integer> entry : StatisticMappings.CUSTOM_STATS.entrySet()) {
statisticMappings.put(entry.getValue().intValue(), entry.getKey()); statisticMappings.put(entry.getValue().intValue(), entry.getKey());
} }
for (Map.Entry<String, String> entry : Protocol1_13To1_12_2.MAPPINGS.getTranslateMapping().entrySet()) { for (Map.Entry<String, String> entry : Protocol1_12_2To1_13.MAPPINGS.getTranslateMapping().entrySet()) {
translateMappings.put(entry.getValue(), entry.getKey()); translateMappings.put(entry.getValue(), entry.getKey());
} }
} }

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.data;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.util.HashMap; import java.util.HashMap;

View File

@ -15,11 +15,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.data;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.EntityTypeRewriter;
public class EntityTypeMapping { public class EntityTypeMapping {
private static final Int2IntMap TYPES = new Int2IntOpenHashMap(); private static final Int2IntMap TYPES = new Int2IntOpenHashMap();

View File

@ -15,9 +15,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.data;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.NamedSoundRewriter;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.data;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;

View File

@ -16,13 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.data;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -32,17 +33,17 @@ public class ParticleMapping {
static { static {
ParticleHandler blockHandler = new ParticleHandler() { ParticleHandler blockHandler = new ParticleHandler() {
@Override @Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) { public int[] rewrite(Protocol1_13To1_12_2 protocol, PacketWrapper wrapper) {
return rewrite(wrapper.read(Type.VAR_INT)); return rewrite(wrapper.read(Types.VAR_INT));
} }
@Override @Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) { public int[] rewrite(Protocol1_13To1_12_2 protocol, List<Particle.ParticleData<?>> data) {
return rewrite((int) data.get(0).getValue()); return rewrite((int) data.get(0).getValue());
} }
private int[] rewrite(int newType) { private int[] rewrite(int newType) {
int blockType = Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(newType); int blockType = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(newType);
int type = blockType >> 4; int type = blockType >> 4;
int meta = blockType & 15; int meta = blockType & 15;
@ -70,23 +71,23 @@ public class ParticleMapping {
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
rewrite(30, new ParticleHandler() { rewrite(30, new ParticleHandler() {
@Override @Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) { public int[] rewrite(Protocol1_13To1_12_2 protocol, PacketWrapper wrapper) {
float r = wrapper.read(Type.FLOAT); float r = wrapper.read(Types.FLOAT);
float g = wrapper.read(Type.FLOAT); float g = wrapper.read(Types.FLOAT);
float b = wrapper.read(Type.FLOAT); float b = wrapper.read(Types.FLOAT);
float scale = wrapper.read(Type.FLOAT); float scale = wrapper.read(Types.FLOAT);
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3 wrapper.set(Types.FLOAT, 3, r); // 5 - Offset X index=3
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4 wrapper.set(Types.FLOAT, 4, g); // 6 - Offset Y index=4
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5 wrapper.set(Types.FLOAT, 5, b); // 7 - Offset Z index=5
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6 wrapper.set(Types.FLOAT, 6, scale); // 8 - Particle Data index=6
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle wrapper.set(Types.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
return null; return null;
} }
@Override @Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) { public int[] rewrite(Protocol1_13To1_12_2 protocol, List<Particle.ParticleData<?>> data) {
return null; return null;
} }
}), // (11->30) minecraft:dust -> reddust }), // (11->30) minecraft:dust -> reddust
@ -108,16 +109,16 @@ public class ParticleMapping {
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
rewrite(36, new ParticleHandler() { rewrite(36, new ParticleHandler() {
@Override @Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) { public int[] rewrite(Protocol1_13To1_12_2 protocol, PacketWrapper wrapper) {
return rewrite(protocol, wrapper.read(Type.ITEM1_13)); return rewrite(protocol, wrapper.read(Types.ITEM1_13));
} }
@Override @Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) { public int[] rewrite(Protocol1_13To1_12_2 protocol, List<Particle.ParticleData<?>> data) {
return rewrite(protocol, (Item) data.get(0).getValue()); return rewrite(protocol, (Item) data.get(0).getValue());
} }
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) { private int[] rewrite(Protocol1_13To1_12_2 protocol, Item newItem) {
Item item = protocol.getItemRewriter().handleItemToClient(null, newItem); Item item = protocol.getItemRewriter().handleItemToClient(null, newItem);
return new int[]{item.identifier(), item.data()}; return new int[]{item.identifier(), item.data()};
} }
@ -161,9 +162,9 @@ public class ParticleMapping {
public interface ParticleHandler { public interface ParticleHandler {
int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper); int[] rewrite(Protocol1_13To1_12_2 protocol, PacketWrapper wrapper);
int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data); int[] rewrite(Protocol1_13To1_12_2 protocol, List<Particle.ParticleData<?>> data);
default boolean isBlockHandler() { default boolean isBlockHandler() {
return false; return false;
@ -183,12 +184,12 @@ public class ParticleMapping {
this(historyId, null); this(historyId, null);
} }
public int @Nullable [] rewriteData(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) { public int @Nullable [] rewriteData(Protocol1_13To1_12_2 protocol, PacketWrapper wrapper) {
if (handler == null) return null; if (handler == null) return null;
return handler.rewrite(protocol, wrapper); return handler.rewrite(protocol, wrapper);
} }
public int @Nullable [] rewriteMeta(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) { public int @Nullable [] rewriteMeta(Protocol1_13To1_12_2 protocol, List<Particle.ParticleData<?>> data) {
if (handler == null) return null; if (handler == null) return null;
return handler.rewrite(protocol, data); return handler.rewrite(protocol, data);
} }

View File

@ -16,20 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BannerHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.BannerHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BedHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.BedHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.FlowerPotHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.PistonHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.PistonHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SkullHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.SkullHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SpawnerHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.SpawnerHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.platform.providers.Provider; import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -16,17 +16,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.block_entity_handlers.FlowerPotHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.providers.BackwardsBlockEntityProvider;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.NoteBlockStorage;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
@ -40,21 +40,22 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.nbt.tag.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.BlockIdData; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.BlockIdData;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.SpawnEggRewriter;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.IdAndData; import com.viaversion.viaversion.util.IdAndData;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
@ -66,12 +67,12 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPackets1_13, ServerboundPackets1_12_1, Protocol1_12_2To1_13> { public class BlockItemPacketRewriter1_13 extends BackwardsItemRewriter<ClientboundPackets1_13, ServerboundPackets1_12_1, Protocol1_13To1_12_2> {
private final Map<String, String> enchantmentMappings = new HashMap<>(); private final Map<String, String> enchantmentMappings = new HashMap<>();
private final String extraNbtTag; private final String extraNbtTag;
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) { public BlockItemPacketRewriter1_13(Protocol1_13To1_12_2 protocol) {
super(protocol, null, null); super(protocol, null, null);
extraNbtTag = nbtTagName("2"); extraNbtTag = nbtTagName("2");
} }
@ -93,7 +94,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_13.COOLDOWN, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.COOLDOWN, wrapper -> {
int itemId = wrapper.read(Type.VAR_INT); int itemId = wrapper.read(Types.VAR_INT);
int oldId = protocol.getMappingData().getItemMappings().getNewId(itemId); int oldId = protocol.getMappingData().getItemMappings().getNewId(itemId);
if (oldId == -1) { if (oldId == -1) {
wrapper.cancel(); wrapper.cancel();
@ -101,22 +102,22 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
} }
if (SpawnEggRewriter.getEntityId(oldId).isPresent()) { if (SpawnEggRewriter.getEntityId(oldId).isPresent()) {
wrapper.write(Type.VAR_INT, IdAndData.toRawData(383)); wrapper.write(Types.VAR_INT, IdAndData.toRawData(383));
return; return;
} }
wrapper.write(Type.VAR_INT, IdAndData.getId(oldId)); wrapper.write(Types.VAR_INT, IdAndData.getId(oldId));
}); });
protocol.registerClientbound(ClientboundPackets1_13.BLOCK_ACTION, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.BLOCK_EVENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // Location map(Types.BLOCK_POSITION1_8); // Location
map(Type.UNSIGNED_BYTE); // Action Id map(Types.UNSIGNED_BYTE); // Action Id
map(Type.UNSIGNED_BYTE); // Action param map(Types.UNSIGNED_BYTE); // Action param
map(Type.VAR_INT); // Block Id - /!\ NOT BLOCK STATE ID map(Types.VAR_INT); // Block Id - /!\ NOT BLOCK STATE ID
handler(wrapper -> { handler(wrapper -> {
int blockId = wrapper.get(Type.VAR_INT, 0); int blockId = wrapper.get(Types.VAR_INT, 0);
if (blockId == 73) if (blockId == 73)
blockId = 25; blockId = 25;
@ -142,15 +143,15 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
if (blockId == 25) { // Note block if (blockId == 25) { // Note block
final NoteBlockStorage noteBlockStorage = wrapper.user().get(NoteBlockStorage.class); final NoteBlockStorage noteBlockStorage = wrapper.user().get(NoteBlockStorage.class);
final Position position = wrapper.get(Type.POSITION1_8, 0); final Position position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
final Pair<Integer, Integer> update = noteBlockStorage.getNoteBlockUpdate(position); final Pair<Integer, Integer> update = noteBlockStorage.getNoteBlockUpdate(position);
if (update != null) { // Use values from block state update if (update != null) { // Use values from block state update
wrapper.set(Type.UNSIGNED_BYTE, 0, update.key().shortValue()); wrapper.set(Types.UNSIGNED_BYTE, 0, update.key().shortValue());
wrapper.set(Type.UNSIGNED_BYTE, 1, update.value().shortValue()); wrapper.set(Types.UNSIGNED_BYTE, 1, update.value().shortValue());
} }
} }
wrapper.set(Type.VAR_INT, 0, blockId); wrapper.set(Types.VAR_INT, 0, blockId);
}); });
} }
}); });
@ -158,31 +159,31 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
protocol.registerClientbound(ClientboundPackets1_13.BLOCK_ENTITY_DATA, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.BLOCK_ENTITY_DATA, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // 0 - Position map(Types.BLOCK_POSITION1_8); // 0 - Position
map(Type.UNSIGNED_BYTE); // 1 - Action map(Types.UNSIGNED_BYTE); // 1 - Action
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT Data map(Types.NAMED_COMPOUND_TAG); // 2 - NBT Data
handler(wrapper -> { handler(wrapper -> {
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
// TODO conduit handling // TODO conduit handling
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 5) { if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 5) {
wrapper.cancel(); wrapper.cancel();
} }
wrapper.set(Type.NAMED_COMPOUND_TAG, 0, wrapper.set(Types.NAMED_COMPOUND_TAG, 0,
provider.transform( provider.transform(
wrapper.user(), wrapper.user(),
wrapper.get(Type.POSITION1_8, 0), wrapper.get(Types.BLOCK_POSITION1_8, 0),
wrapper.get(Type.NAMED_COMPOUND_TAG, 0) wrapper.get(Types.NAMED_COMPOUND_TAG, 0)
)); ));
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.UNLOAD_CHUNK, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.FORGET_LEVEL_CHUNK, wrapper -> {
int chunkMinX = wrapper.passthrough(Type.INT) << 4; int chunkMinX = wrapper.passthrough(Types.INT) << 4;
int chunkMinZ = wrapper.passthrough(Type.INT) << 4; int chunkMinZ = wrapper.passthrough(Types.INT) << 4;
int chunkMaxX = chunkMinX + 15; int chunkMaxX = chunkMinX + 15;
int chunkMaxZ = chunkMinZ + 15; int chunkMaxZ = chunkMinZ + 15;
BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class); BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class);
@ -194,14 +195,14 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
}); });
// Block Change // Block Change
protocol.registerClientbound(ClientboundPackets1_13.BLOCK_CHANGE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.BLOCK_UPDATE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.POSITION1_8); // 0 - Position map(Types.BLOCK_POSITION1_8); // 0 - Position
handler(wrapper -> { handler(wrapper -> {
int blockState = wrapper.read(Type.VAR_INT); int blockState = wrapper.read(Types.VAR_INT);
Position position = wrapper.get(Type.POSITION1_8, 0); Position position = wrapper.get(Types.BLOCK_POSITION1_8, 0);
// Note block special treatment // Note block special treatment
if (blockState >= 249 && blockState <= 748) { // Note block states id range if (blockState >= 249 && blockState <= 748) { // Note block states id range
@ -212,7 +213,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
storage.checkAndStore(position, blockState); storage.checkAndStore(position, blockState);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockState)); wrapper.write(Types.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockState));
// Flower pot special treatment // Flower pot special treatment
flowerPotSpecialTreatment(wrapper.user(), blockState, position); flowerPotSpecialTreatment(wrapper.user(), blockState, position);
@ -221,18 +222,18 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
}); });
// Multi Block Change // Multi Block Change
protocol.registerClientbound(ClientboundPackets1_13.MULTI_BLOCK_CHANGE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.CHUNK_BLOCKS_UPDATE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Chunk X map(Types.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z map(Types.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY); map(Types.BLOCK_CHANGE_ARRAY);
handler(wrapper -> { handler(wrapper -> {
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { for (BlockChangeRecord record : wrapper.get(Types.BLOCK_CHANGE_ARRAY, 0)) {
int chunkX = wrapper.get(Type.INT, 0); int chunkX = wrapper.get(Types.INT, 0);
int chunkZ = wrapper.get(Type.INT, 1); int chunkZ = wrapper.get(Types.INT, 1);
int block = record.getBlockId(); int block = record.getBlockId();
Position position = new Position( Position position = new Position(
record.getSectionX() + (chunkX * 16), record.getSectionX() + (chunkX * 16),
@ -252,14 +253,14 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.WINDOW_ITEMS, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.CONTAINER_SET_CONTENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); map(Types.UNSIGNED_BYTE);
map(Type.ITEM1_13_SHORT_ARRAY, Type.ITEM1_8_SHORT_ARRAY); map(Types.ITEM1_13_SHORT_ARRAY, Types.ITEM1_8_SHORT_ARRAY);
handler(wrapper -> { handler(wrapper -> {
final Item[] items = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0); final Item[] items = wrapper.get(Types.ITEM1_8_SHORT_ARRAY, 0);
for (Item item : items) { for (Item item : items) {
handleItemToClient(wrapper.user(), item); handleItemToClient(wrapper.user(), item);
} }
@ -267,18 +268,18 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SET_SLOT, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.CONTAINER_SET_SLOT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); map(Types.UNSIGNED_BYTE);
map(Type.SHORT); map(Types.SHORT);
map(Type.ITEM1_13, Type.ITEM1_8); map(Types.ITEM1_13, Types.ITEM1_8);
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type_old = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); ChunkType1_9_3 type_old = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
@ -375,103 +376,103 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
wrapper.write(type_old, chunk); wrapper.write(type_old, chunk);
}); });
protocol.registerClientbound(ClientboundPackets1_13.EFFECT, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.LEVEL_EVENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // Effect Id map(Types.INT); // Effect Id
map(Type.POSITION1_8); // Location map(Types.BLOCK_POSITION1_8); // Location
map(Type.INT); // Data map(Types.INT); // Data
handler(wrapper -> { handler(wrapper -> {
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Types.INT, 0);
int data = wrapper.get(Type.INT, 1); int data = wrapper.get(Types.INT, 1);
if (id == 1010) { // Play record if (id == 1010) { // Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getItemMappings().getNewId(data) >> 4); wrapper.set(Types.INT, 1, protocol.getMappingData().getItemMappings().getNewId(data) >> 4);
} else if (id == 2001) { // Block break + block break sound } else if (id == 2001) { // Block break + block break sound
data = protocol.getMappingData().getNewBlockStateId(data); data = protocol.getMappingData().getNewBlockStateId(data);
int blockId = data >> 4; int blockId = data >> 4;
int blockData = data & 0xF; int blockData = data & 0xF;
wrapper.set(Type.INT, 1, (blockId & 0xFFF) | (blockData << 12)); wrapper.set(Types.INT, 1, (blockId & 0xFFF) | (blockData << 12));
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.MAP_DATA, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.MAP_ITEM_DATA, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.BYTE); map(Types.BYTE);
map(Type.BOOLEAN); map(Types.BOOLEAN);
handler(wrapper -> { handler(wrapper -> {
int iconCount = wrapper.passthrough(Type.VAR_INT); int iconCount = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < iconCount; i++) { for (int i = 0; i < iconCount; i++) {
int type = wrapper.read(Type.VAR_INT); int type = wrapper.read(Types.VAR_INT);
byte x = wrapper.read(Type.BYTE); byte x = wrapper.read(Types.BYTE);
byte z = wrapper.read(Type.BYTE); byte z = wrapper.read(Types.BYTE);
byte direction = wrapper.read(Type.BYTE); byte direction = wrapper.read(Types.BYTE);
wrapper.read(Type.OPTIONAL_COMPONENT); wrapper.read(Types.OPTIONAL_COMPONENT);
if (type > 9) { if (type > 9) {
wrapper.set(Type.VAR_INT, 1, wrapper.get(Type.VAR_INT, 1) - 1); wrapper.set(Types.VAR_INT, 1, wrapper.get(Types.VAR_INT, 1) - 1);
continue; continue;
} }
wrapper.write(Type.BYTE, (byte) ((type << 4) | (direction & 0x0F))); wrapper.write(Types.BYTE, (byte) ((type << 4) | (direction & 0x0F)));
wrapper.write(Type.BYTE, x); wrapper.write(Types.BYTE, x);
wrapper.write(Type.BYTE, z); wrapper.write(Types.BYTE, z);
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.ENTITY_EQUIPMENT, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.SET_EQUIPPED_ITEM, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.ITEM1_13, Type.ITEM1_8); map(Types.ITEM1_13, Types.ITEM1_8);
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0))); handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Types.ITEM1_8, 0)));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.WINDOW_PROPERTY, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.CONTAINER_SET_DATA, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); // Window Id map(Types.UNSIGNED_BYTE); // Window Id
map(Type.SHORT); // Property map(Types.SHORT); // Property
map(Type.SHORT); // Value map(Types.SHORT); // Value
handler(wrapper -> { handler(wrapper -> {
short property = wrapper.get(Type.SHORT, 0); short property = wrapper.get(Types.SHORT, 0);
// Enchantment table // Enchantment table
if (property >= 4 && property <= 6) { if (property >= 4 && property <= 6) {
short oldId = wrapper.get(Type.SHORT, 1); short oldId = wrapper.get(Types.SHORT, 1);
wrapper.set(Type.SHORT, 1, (short) protocol.getMappingData().getEnchantmentMappings().getNewId(oldId)); wrapper.set(Types.SHORT, 1, (short) protocol.getMappingData().getEnchantmentMappings().getNewId(oldId));
} }
}); });
} }
}); });
protocol.registerServerbound(ServerboundPackets1_12_1.CREATIVE_INVENTORY_ACTION, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_12_1.SET_CREATIVE_MODE_SLOT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.SHORT); map(Types.SHORT);
map(Type.ITEM1_8, Type.ITEM1_13); map(Types.ITEM1_8, Types.ITEM1_13);
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0))); handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_13, 0)));
} }
}); });
protocol.registerServerbound(ServerboundPackets1_12_1.CLICK_WINDOW, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_12_1.CONTAINER_CLICK, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.UNSIGNED_BYTE); map(Types.UNSIGNED_BYTE);
map(Type.SHORT); map(Types.SHORT);
map(Type.BYTE); map(Types.BYTE);
map(Type.SHORT); map(Types.SHORT);
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.ITEM1_8, Type.ITEM1_13); map(Types.ITEM1_8, Types.ITEM1_13);
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0))); handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Types.ITEM1_13, 0)));
} }
}); });
} }
@ -639,7 +640,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
lore.add(new StringTag(mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level))); lore.add(new StringTag(mappedEnchantmentId + " " + EnchantmentRewriter.getRomanNumber(level)));
noMapped.add(enchantmentEntry); noMapped.add(enchantmentEntry);
} else if (!newId.isEmpty()) { } else if (!newId.isEmpty()) {
Short oldId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().inverse().get(Key.stripMinecraftNamespace(newId)); Short oldId = Protocol1_12_2To1_13.MAPPINGS.getOldEnchantmentsIds().inverse().get(Key.stripMinecraftNamespace(newId));
if (oldId == null) { if (oldId == null) {
if (!newId.startsWith("viaversion:legacy/")) { if (!newId.startsWith("viaversion:legacy/")) {
// Custom enchant (?) // Custom enchant (?)
@ -682,7 +683,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
NumberTag hideFlags = tag.getNumberTag("HideFlags"); NumberTag hideFlags = tag.getNumberTag("HideFlags");
if (hideFlags == null) { if (hideFlags == null) {
hideFlags = new IntTag(); hideFlags = new IntTag();
tag.put(extraNbtTag + "|DummyEnchant", new ByteTag()); tag.put(extraNbtTag + "|DummyEnchant", new ByteTag(false));
} else { } else {
tag.putInt(extraNbtTag + "|OldHideFlags", hideFlags.asByte()); tag.putInt(extraNbtTag + "|OldHideFlags", hideFlags.asByte());
} }
@ -710,7 +711,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
ListTag<StringTag> loreTag = display.getListTag("Lore", StringTag.class); ListTag<StringTag> loreTag = display.getListTag("Lore", StringTag.class);
if (loreTag == null) { if (loreTag == null) {
display.put("Lore", loreTag = new ListTag<>(StringTag.class)); display.put("Lore", loreTag = new ListTag<>(StringTag.class));
tag.put(extraNbtTag + "|DummyLore", new ByteTag()); tag.put(extraNbtTag + "|DummyLore", new ByteTag(false));
} else if (!loreTag.isEmpty()) { } else if (!loreTag.isEmpty()) {
ListTag<StringTag> oldLore = new ListTag<>(StringTag.class); ListTag<StringTag> oldLore = new ListTag<>(StringTag.class);
for (StringTag value : loreTag) { for (StringTag value : loreTag) {
@ -841,8 +842,9 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) { private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) {
if (tag.getListTag(tagName) == null) return; if (tag.getListTag(tagName) == null) return;
ListTag<?> blockTag = tag.remove(extraNbtTag + "|" + tagName); ListTag<?> blockTag = tag.getListTag(extraNbtTag + "|" + tagName);
if (blockTag != null) { if (blockTag != null) {
tag.remove(extraNbtTag + "|" + tagName);
tag.put(tagName, blockTag.copy()); tag.put(tagName, blockTag.copy());
} else if ((blockTag = tag.getListTag(tagName)) != null) { } else if ((blockTag = tag.getListTag(tagName)) != null) {
ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class); ListTag<StringTag> newCanPlaceOn = new ListTag<>(StringTag.class);
@ -897,7 +899,7 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
continue; // Skip dummy enchatment continue; // Skip dummy enchatment
} }
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId); String newId = Protocol1_12_2To1_13.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) { if (newId == null) {
newId = "viaversion:legacy/" + oldId; newId = "viaversion:legacy/" + oldId;
} }
@ -970,23 +972,23 @@ public class BlockItemPackets1_13 extends BackwardsItemRewriter<ClientboundPacke
CompoundTag nbt = beProvider.transform(user, position, "minecraft:flower_pot"); CompoundTag nbt = beProvider.transform(user, position, "minecraft:flower_pot");
// Remove the flowerpot // Remove the flowerpot
PacketWrapper blockUpdateRemove = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_CHANGE, user); PacketWrapper blockUpdateRemove = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_UPDATE, user);
blockUpdateRemove.write(Type.POSITION1_8, position); blockUpdateRemove.write(Types.BLOCK_POSITION1_8, position);
blockUpdateRemove.write(Type.VAR_INT, 0); blockUpdateRemove.write(Types.VAR_INT, 0);
blockUpdateRemove.scheduleSend(Protocol1_12_2To1_13.class); blockUpdateRemove.scheduleSend(Protocol1_13To1_12_2.class);
// Create the flowerpot // Create the flowerpot
PacketWrapper blockCreate = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_CHANGE, user); PacketWrapper blockCreate = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_UPDATE, user);
blockCreate.write(Type.POSITION1_8, position); blockCreate.write(Types.BLOCK_POSITION1_8, position);
blockCreate.write(Type.VAR_INT, Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(blockState)); blockCreate.write(Types.VAR_INT, Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(blockState));
blockCreate.scheduleSend(Protocol1_12_2To1_13.class); blockCreate.scheduleSend(Protocol1_13To1_12_2.class);
// Send a block entity update // Send a block entity update
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_ENTITY_DATA, user); PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_ENTITY_DATA, user);
wrapper.write(Type.POSITION1_8, position); wrapper.write(Types.BLOCK_POSITION1_8, position);
wrapper.write(Type.UNSIGNED_BYTE, (short) 5); wrapper.write(Types.UNSIGNED_BYTE, (short) 5);
wrapper.write(Type.NAMED_COMPOUND_TAG, nbt); wrapper.write(Types.NAMED_COMPOUND_TAG, nbt);
wrapper.scheduleSend(Protocol1_12_2To1_13.class); wrapper.scheduleSend(Protocol1_13To1_12_2.class);
} }
} }

View File

@ -15,38 +15,39 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler; import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.EntityTypeMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.PaintingMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.ParticleMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.NoteBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.PlayerPositionStorage1_13;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_12;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_12; import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_13, Protocol1_12_2To1_13> { public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPackets1_13, Protocol1_13To1_12_2> {
public EntityPackets1_13(Protocol1_12_2To1_13 protocol) { public EntityPacketRewriter1_13(Protocol1_13To1_12_2 protocol) {
super(protocol); super(protocol);
} }
@ -55,89 +56,89 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
protocol.registerClientbound(ClientboundPackets1_13.PLAYER_POSITION, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.PLAYER_POSITION, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.FLOAT); map(Types.FLOAT);
map(Type.FLOAT); map(Types.FLOAT);
map(Type.BYTE); map(Types.BYTE);
handler(wrapper -> { handler(wrapper -> {
if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return; if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return;
PlayerPositionStorage1_13 playerStorage = wrapper.user().get(PlayerPositionStorage1_13.class); PlayerPositionStorage1_13 playerStorage = wrapper.user().get(PlayerPositionStorage1_13.class);
byte bitField = wrapper.get(Type.BYTE, 0); byte bitField = wrapper.get(Types.BYTE, 0);
playerStorage.setX(toSet(bitField, 0, playerStorage.x(), wrapper.get(Type.DOUBLE, 0))); playerStorage.setX(toSet(bitField, 0, playerStorage.x(), wrapper.get(Types.DOUBLE, 0)));
playerStorage.setY(toSet(bitField, 1, playerStorage.y(), wrapper.get(Type.DOUBLE, 1))); playerStorage.setY(toSet(bitField, 1, playerStorage.y(), wrapper.get(Types.DOUBLE, 1)));
playerStorage.setZ(toSet(bitField, 2, playerStorage.z(), wrapper.get(Type.DOUBLE, 2))); playerStorage.setZ(toSet(bitField, 2, playerStorage.z(), wrapper.get(Types.DOUBLE, 2)));
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_ENTITY, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_ENTITY, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.UUID); map(Types.UUID);
map(Type.BYTE); map(Types.BYTE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.BYTE); map(Types.BYTE);
map(Type.BYTE); map(Types.BYTE);
map(Type.INT); map(Types.INT);
handler(getObjectTrackerHandler()); handler(getObjectTrackerHandler());
handler(wrapper -> { handler(wrapper -> {
Optional<EntityTypes1_13.ObjectType> optionalType = EntityTypes1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0)); Optional<EntityTypes1_13.ObjectType> optionalType = EntityTypes1_13.ObjectType.findById(wrapper.get(Types.BYTE, 0));
if (optionalType.isEmpty()) return; if (optionalType.isEmpty()) return;
EntityTypes1_13.ObjectType type = optionalType.get(); EntityTypes1_13.ObjectType type = optionalType.get();
if (type == EntityTypes1_13.ObjectType.FALLING_BLOCK) { if (type == EntityTypes1_13.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Types.INT, 0);
int combined = Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(blockState); int combined = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(blockState);
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12); combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
wrapper.set(Type.INT, 0, combined); wrapper.set(Types.INT, 0, combined);
} else if (type == EntityTypes1_13.ObjectType.ITEM_FRAME) { } else if (type == EntityTypes1_13.ObjectType.ITEM_FRAME) {
int data = wrapper.get(Type.INT, 0); int data = wrapper.get(Types.INT, 0);
data = switch (data) { data = switch (data) {
case 3 -> 0; case 3 -> 0;
case 4 -> 1; case 4 -> 1;
case 5 -> 3; case 5 -> 3;
default -> data; default -> data;
}; };
wrapper.set(Type.INT, 0, data); wrapper.set(Types.INT, 0, data);
} else if (type == EntityTypes1_13.ObjectType.TRIDENT) { } else if (type == EntityTypes1_13.ObjectType.TRIDENT) {
wrapper.set(Type.BYTE, 0, (byte) EntityTypes1_13.ObjectType.TIPPED_ARROW.getId()); wrapper.set(Types.BYTE, 0, (byte) EntityTypes1_13.ObjectType.TIPPED_ARROW.getId());
} }
}); });
} }
}); });
registerTracker(ClientboundPackets1_13.SPAWN_EXPERIENCE_ORB, EntityTypes1_13.EntityType.EXPERIENCE_ORB); registerTracker(ClientboundPackets1_13.ADD_EXPERIENCE_ORB, EntityTypes1_13.EntityType.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_13.SPAWN_GLOBAL_ENTITY, EntityTypes1_13.EntityType.LIGHTNING_BOLT); registerTracker(ClientboundPackets1_13.ADD_GLOBAL_ENTITY, EntityTypes1_13.EntityType.LIGHTNING_BOLT);
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_MOB, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.UUID); map(Types.UUID);
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.BYTE); map(Types.BYTE);
map(Type.BYTE); map(Types.BYTE);
map(Type.BYTE); map(Types.BYTE);
map(Type.SHORT); map(Types.SHORT);
map(Type.SHORT); map(Types.SHORT);
map(Type.SHORT); map(Types.SHORT);
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); map(Types1_13.ENTITY_DATA_LIST, Types1_12.ENTITY_DATA_LIST);
handler(wrapper -> { handler(wrapper -> {
int type = wrapper.get(Type.VAR_INT, 1); int type = wrapper.get(Types.VAR_INT, 1);
EntityType entityType = EntityTypes1_13.getTypeFromId(type, false); EntityType entityType = EntityTypes1_13.getTypeFromId(type, false);
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), entityType); tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
int oldId = EntityTypeMapping.getOldId(type); int oldId = EntityTypeMapping.getOldId(type);
if (oldId == -1) { if (oldId == -1) {
@ -145,52 +146,52 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType); ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType);
} }
} else { } else {
wrapper.set(Type.VAR_INT, 1, oldId); wrapper.set(Types.VAR_INT, 1, oldId);
} }
}); });
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(getMobSpawnRewriter1_11(Types1_12.METADATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PLAYER, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_PLAYER, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.UUID); map(Types.UUID);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.BYTE); map(Types.BYTE);
map(Type.BYTE); map(Types.BYTE);
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); map(Types1_13.ENTITY_DATA_LIST, Types1_12.ENTITY_DATA_LIST);
handler(getTrackerAndMetaHandler(Types1_12.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER)); handler(getTrackerAndMetaHandler(Types1_12.ENTITY_DATA_LIST, EntityTypes1_13.EntityType.PLAYER));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PAINTING, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.ADD_PAINTING, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
map(Type.UUID); map(Types.UUID);
handler(getTrackerHandler(EntityTypes1_13.EntityType.PAINTING, Type.VAR_INT)); handler(getTrackerHandler(EntityTypes1_13.EntityType.PAINTING, Types.VAR_INT));
handler(wrapper -> { handler(wrapper -> {
int motive = wrapper.read(Type.VAR_INT); int motive = wrapper.read(Types.VAR_INT);
String title = PaintingMapping.getStringId(motive); String title = PaintingMapping.getStringId(motive);
wrapper.write(Type.STRING, title); wrapper.write(Types.STRING, title);
}); });
} }
}); });
registerJoinGame(ClientboundPackets1_13.JOIN_GAME, EntityTypes1_13.EntityType.PLAYER); registerJoinGame(ClientboundPackets1_13.LOGIN, EntityTypes1_13.EntityType.PLAYER);
protocol.registerClientbound(ClientboundPackets1_13.RESPAWN, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.RESPAWN, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Dimension ID map(Types.INT); // 0 - Dimension ID
handler(getDimensionHandler(0)); handler(getDimensionHandler(0));
handler(wrapper -> { handler(wrapper -> {
@ -200,53 +201,53 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
} }
}); });
registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES); registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); registerSetEntityData(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13.ENTITY_DATA_LIST, Types1_12.ENTITY_DATA_LIST);
// Face Player (new packet) // Face Player (new packet)
protocol.registerClientbound(ClientboundPackets1_13.FACE_PLAYER, null, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.PLAYER_LOOK_AT, null, wrapper -> {
wrapper.cancel(); wrapper.cancel();
if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return; if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) return;
// We will just accept a possible, very minor mismatch between server and client position, // We will just accept a possible, very minor mismatch between server and client position,
// and will take the server's one in both cases, else we would have to cache all entities' positions. // and will take the server's one in both cases, else we would have to cache all entities' positions.
final int anchor = wrapper.read(Type.VAR_INT); // feet/eyes enum final int anchor = wrapper.read(Types.VAR_INT); // feet/eyes enum
final double x = wrapper.read(Type.DOUBLE); final double x = wrapper.read(Types.DOUBLE);
final double y = wrapper.read(Type.DOUBLE); final double y = wrapper.read(Types.DOUBLE);
final double z = wrapper.read(Type.DOUBLE); final double z = wrapper.read(Types.DOUBLE);
PlayerPositionStorage1_13 positionStorage = wrapper.user().get(PlayerPositionStorage1_13.class); PlayerPositionStorage1_13 positionStorage = wrapper.user().get(PlayerPositionStorage1_13.class);
// Send teleport packet to client // Send teleport packet to client
PacketWrapper positionAndLook = wrapper.create(ClientboundPackets1_12_1.PLAYER_POSITION); PacketWrapper positionAndLook = wrapper.create(ClientboundPackets1_12_1.PLAYER_POSITION);
positionAndLook.write(Type.DOUBLE, 0D); positionAndLook.write(Types.DOUBLE, 0D);
positionAndLook.write(Type.DOUBLE, 0D); positionAndLook.write(Types.DOUBLE, 0D);
positionAndLook.write(Type.DOUBLE, 0D); positionAndLook.write(Types.DOUBLE, 0D);
//TODO properly cache and calculate head position? //TODO properly cache and calculate head position?
EntityPositionHandler.writeFacingDegrees(positionAndLook, positionStorage.x(), EntityPositionHandler.writeFacingDegrees(positionAndLook, positionStorage.x(),
anchor == 1 ? positionStorage.y() + 1.62 : positionStorage.y(), anchor == 1 ? positionStorage.y() + 1.62 : positionStorage.y(),
positionStorage.z(), x, y, z); positionStorage.z(), x, y, z);
positionAndLook.write(Type.BYTE, (byte) 7); // bitfield, 0=absolute, 1=relative - x,y,z relative, yaw,pitch absolute positionAndLook.write(Types.BYTE, (byte) 7); // bitfield, 0=absolute, 1=relative - x,y,z relative, yaw,pitch absolute
positionAndLook.write(Type.VAR_INT, -1); positionAndLook.write(Types.VAR_INT, -1);
positionAndLook.send(Protocol1_12_2To1_13.class); positionAndLook.send(Protocol1_13To1_12_2.class);
}); });
if (ViaBackwards.getConfig().isFix1_13FacePlayer()) { if (ViaBackwards.getConfig().isFix1_13FacePlayer()) {
PacketHandlers movementRemapper = new PacketHandlers() { PacketHandlers movementRemapper = new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
map(Type.DOUBLE); map(Types.DOUBLE);
handler(wrapper -> wrapper.user().get(PlayerPositionStorage1_13.class).setCoordinates(wrapper, false)); handler(wrapper -> wrapper.user().get(PlayerPositionStorage1_13.class).setCoordinates(wrapper, false));
} }
}; };
protocol.registerServerbound(ServerboundPackets1_12_1.PLAYER_POSITION, movementRemapper); // Player Position protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS, movementRemapper); // Player Position
protocol.registerServerbound(ServerboundPackets1_12_1.PLAYER_POSITION_AND_ROTATION, movementRemapper); // Player Position And Look (serverbound) protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS_ROT, movementRemapper); // Player Position And Look (serverbound)
protocol.registerServerbound(ServerboundPackets1_12_1.VEHICLE_MOVE, movementRemapper); // Vehicle Move (serverbound) protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_VEHICLE, movementRemapper); // Vehicle Move (serverbound)
} }
} }
@ -264,7 +265,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
// Phantom // Phantom
mapEntityTypeWithData(EntityTypes1_13.EntityType.PHANTOM, EntityTypes1_13.EntityType.PARROT).plainName().spawnMetadata(storage -> { mapEntityTypeWithData(EntityTypes1_13.EntityType.PHANTOM, EntityTypes1_13.EntityType.PARROT).plainName().spawnMetadata(storage -> {
// The phantom is grey/blue so let's do yellow/blue // The phantom is grey/blue so let's do yellow/blue
storage.add(new Metadata(15, MetaType1_12.VarInt, 3)); storage.add(new EntityData(15, EntityDataTypes1_12.VAR_INT, 3));
}); });
// Dolphin // Dolphin
@ -275,23 +276,23 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
// Rewrite Meta types // Rewrite Meta types
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
int typeId = meta.metaType().typeId(); int typeId = meta.dataType().typeId();
if (typeId == 4) { if (typeId == 4) {
JsonElement element = meta.value(); JsonElement element = meta.value();
protocol.translatableRewriter().processText(event.user(), element); protocol.translatableRewriter().processText(event.user(), element);
meta.setMetaType(MetaType1_12.Chat); meta.setDataType(EntityDataTypes1_12.COMPONENT);
} else if (typeId == 5) { } else if (typeId == 5) {
// Rewrite optional chat to string // Rewrite optional chat to string
JsonElement element = meta.value(); JsonElement element = meta.value();
meta.setTypeAndValue(MetaType1_12.String, protocol.jsonToLegacy(event.user(), element)); meta.setTypeAndValue(EntityDataTypes1_12.STRING, protocol.jsonToLegacy(event.user(), element));
} else if (typeId == 6) { } else if (typeId == 6) {
Item item = (Item) meta.getValue(); Item item = (Item) meta.getValue();
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(event.user(), item)); meta.setTypeAndValue(EntityDataTypes1_12.ITEM, protocol.getItemRewriter().handleItemToClient(event.user(), item));
} else if (typeId == 15) { } else if (typeId == 15) {
// Discontinue particles // Discontinue particles
event.cancel(); event.cancel();
} else { } else {
meta.setMetaType(MetaType1_12.byId(typeId > 5 ? typeId - 1 : typeId)); meta.setDataType(EntityDataTypes1_12.byId(typeId > 5 ? typeId - 1 : typeId));
} }
}); });
@ -343,9 +344,9 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
secondArg = particleArgs.length == 2 ? particleArgs[1] : 0; secondArg = particleArgs.length == 2 ? particleArgs[1] : 0;
} }
event.createExtraMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId())); event.createExtraData(new EntityData(9, EntityDataTypes1_12.VAR_INT, data.getHistoryId()));
event.createExtraMeta(new Metadata(10, MetaType1_12.VarInt, firstArg)); event.createExtraData(new EntityData(10, EntityDataTypes1_12.VAR_INT, firstArg));
event.createExtraMeta(new Metadata(11, MetaType1_12.VarInt, secondArg)); event.createExtraData(new EntityData(11, EntityDataTypes1_12.VAR_INT, secondArg));
event.cancel(); event.cancel();
}); });

View File

@ -15,13 +15,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.ParticleMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.TabCompleteStorage;
import com.viaversion.viabackwards.utils.ChatUtil; import com.viaversion.viabackwards.utils.ChatUtil;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
@ -31,14 +31,15 @@ import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.rewriter.RewriterBase; import com.viaversion.viaversion.api.rewriter.RewriterBase;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ItemPacketRewriter1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -48,11 +49,11 @@ import java.util.Locale;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> { public class PlayerPacketRewriter1_13 extends RewriterBase<Protocol1_13To1_12_2> {
private final CommandRewriter<ClientboundPackets1_13> commandRewriter = new CommandRewriter<>(protocol); private final CommandRewriter<ClientboundPackets1_13> commandRewriter = new CommandRewriter<>(protocol);
public PlayerPacket1_13(Protocol1_12_2To1_13 protocol) { public PlayerPacketRewriter1_13(Protocol1_13To1_12_2 protocol) {
super(protocol); super(protocol);
} }
@ -66,41 +67,41 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
packetWrapper.cancel(); packetWrapper.cancel();
// Plugin response // Plugin response
packetWrapper.create(ServerboundLoginPackets.CUSTOM_QUERY_ANSWER.getId(), wrapper -> { packetWrapper.create(ServerboundLoginPackets.CUSTOM_QUERY_ANSWER.getId(), wrapper -> {
wrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id wrapper.write(Types.VAR_INT, packetWrapper.read(Types.VAR_INT)); // Packet id
wrapper.write(Type.BOOLEAN, false); // Success wrapper.write(Types.BOOLEAN, false); // Success
}).sendToServer(Protocol1_12_2To1_13.class); }).sendToServer(Protocol1_13To1_12_2.class);
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.CUSTOM_PAYLOAD, wrapper -> {
String channel = wrapper.read(Type.STRING); String channel = wrapper.read(Types.STRING);
if (channel.equals("minecraft:trader_list")) { if (channel.equals("minecraft:trader_list")) {
wrapper.write(Type.STRING, "MC|TrList"); wrapper.write(Types.STRING, "MC|TrList");
wrapper.passthrough(Type.INT); //Passthrough Window ID wrapper.passthrough(Types.INT); //Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
//Input Item //Input Item
Item input = wrapper.read(Type.ITEM1_13); Item input = wrapper.read(Types.ITEM1_13);
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), input)); wrapper.write(Types.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), input));
//Output Item //Output Item
Item output = wrapper.read(Type.ITEM1_13); Item output = wrapper.read(Types.ITEM1_13);
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), output)); wrapper.write(Types.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), output));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item boolean secondItem = wrapper.passthrough(Types.BOOLEAN); //Has second item
if (secondItem) { if (secondItem) {
//Second Item //Second Item
Item second = wrapper.read(Type.ITEM1_13); Item second = wrapper.read(Types.ITEM1_13);
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), second)); wrapper.write(Types.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), second));
} }
wrapper.passthrough(Type.BOOLEAN); //Trade disabled wrapper.passthrough(Types.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses wrapper.passthrough(Types.INT); //Number of tools uses
wrapper.passthrough(Type.INT); //Maximum number of trade uses wrapper.passthrough(Types.INT); //Maximum number of trade uses
} }
} else { } else {
String oldChannel = InventoryPackets.getOldPluginChannelId(channel); String oldChannel = ItemPacketRewriter1_13.getOldPluginChannelId(channel);
if (oldChannel == null) { if (oldChannel == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("Ignoring clientbound plugin message with channel: " + channel); ViaBackwards.getPlatform().getLogger().warning("Ignoring clientbound plugin message with channel: " + channel);
@ -108,40 +109,40 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
wrapper.cancel(); wrapper.cancel();
return; return;
} }
wrapper.write(Type.STRING, oldChannel); wrapper.write(Types.STRING, oldChannel);
if (oldChannel.equals("REGISTER") || oldChannel.equals("UNREGISTER")) { if (oldChannel.equals("REGISTER") || oldChannel.equals("UNREGISTER")) {
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); String[] channels = new String(wrapper.read(Types.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
List<String> rewrittenChannels = new ArrayList<>(); List<String> rewrittenChannels = new ArrayList<>();
for (String s : channels) { for (String s : channels) {
String rewritten = InventoryPackets.getOldPluginChannelId(s); String rewritten = ItemPacketRewriter1_13.getOldPluginChannelId(s);
if (rewritten != null) { if (rewritten != null) {
rewrittenChannels.add(rewritten); rewrittenChannels.add(rewritten);
} else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { } else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("Ignoring plugin channel in clientbound " + oldChannel + ": " + s); ViaBackwards.getPlatform().getLogger().warning("Ignoring plugin channel in clientbound " + oldChannel + ": " + s);
} }
} }
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); wrapper.write(Types.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
} }
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.LEVEL_PARTICLES, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // 0 - Particle ID map(Types.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance map(Types.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X map(Types.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y map(Types.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z map(Types.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X map(Types.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y map(Types.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z map(Types.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data map(Types.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count map(Types.INT); // 9 - Particle Count
handler(wrapper -> { handler(wrapper -> {
ParticleMapping.ParticleData old = ParticleMapping.getMapping(wrapper.get(Type.INT, 0)); ParticleMapping.ParticleData old = ParticleMapping.getMapping(wrapper.get(Types.INT, 0));
wrapper.set(Type.INT, 0, old.getHistoryId()); wrapper.set(Types.INT, 0, old.getHistoryId());
int[] data = old.rewriteData(protocol, wrapper); int[] data = old.rewriteData(protocol, wrapper);
if (data != null) { if (data != null) {
@ -152,7 +153,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
for (int i : data) { for (int i : data) {
wrapper.write(Type.VAR_INT, i); wrapper.write(Types.VAR_INT, i);
} }
} }
}); });
@ -164,28 +165,28 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
public void register() { public void register() {
handler(packetWrapper -> { handler(packetWrapper -> {
TabCompleteStorage storage = packetWrapper.user().get(TabCompleteStorage.class); TabCompleteStorage storage = packetWrapper.user().get(TabCompleteStorage.class);
int action = packetWrapper.passthrough(Type.VAR_INT); int action = packetWrapper.passthrough(Types.VAR_INT);
int nPlayers = packetWrapper.passthrough(Type.VAR_INT); int nPlayers = packetWrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < nPlayers; i++) { for (int i = 0; i < nPlayers; i++) {
UUID uuid = packetWrapper.passthrough(Type.UUID); UUID uuid = packetWrapper.passthrough(Types.UUID);
if (action == 0) { // Add if (action == 0) { // Add
String name = packetWrapper.passthrough(Type.STRING); String name = packetWrapper.passthrough(Types.STRING);
storage.usernames().put(uuid, name); storage.usernames().put(uuid, name);
int nProperties = packetWrapper.passthrough(Type.VAR_INT); int nProperties = packetWrapper.passthrough(Types.VAR_INT);
for (int j = 0; j < nProperties; j++) { for (int j = 0; j < nProperties; j++) {
packetWrapper.passthrough(Type.STRING); packetWrapper.passthrough(Types.STRING);
packetWrapper.passthrough(Type.STRING); packetWrapper.passthrough(Types.STRING);
packetWrapper.passthrough(Type.OPTIONAL_STRING); packetWrapper.passthrough(Types.OPTIONAL_STRING);
} }
packetWrapper.passthrough(Type.VAR_INT); packetWrapper.passthrough(Types.VAR_INT);
packetWrapper.passthrough(Type.VAR_INT); packetWrapper.passthrough(Types.VAR_INT);
packetWrapper.passthrough(Type.OPTIONAL_COMPONENT); packetWrapper.passthrough(Types.OPTIONAL_COMPONENT);
} else if (action == 1) { // Update Game Mode } else if (action == 1) { // Update Game Mode
packetWrapper.passthrough(Type.VAR_INT); packetWrapper.passthrough(Types.VAR_INT);
} else if (action == 2) { // Update Ping } else if (action == 2) { // Update Ping
packetWrapper.passthrough(Type.VAR_INT); packetWrapper.passthrough(Types.VAR_INT);
} else if (action == 3) { // Update Display Name } else if (action == 3) { // Update Display Name
packetWrapper.passthrough(Type.OPTIONAL_COMPONENT); packetWrapper.passthrough(Types.OPTIONAL_COMPONENT);
} else if (action == 4) { // Remove Player } else if (action == 4) { // Remove Player
storage.usernames().remove(uuid); storage.usernames().remove(uuid);
} }
@ -194,47 +195,47 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.SCOREBOARD_OBJECTIVE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.SET_OBJECTIVE, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); map(Types.STRING);
map(Type.BYTE); map(Types.BYTE);
handler(wrapper -> { handler(wrapper -> {
byte mode = wrapper.get(Type.BYTE, 0); byte mode = wrapper.get(Types.BYTE, 0);
if (mode == 0 || mode == 2) { if (mode == 0 || mode == 2) {
JsonElement value = wrapper.read(Type.COMPONENT); JsonElement value = wrapper.read(Types.COMPONENT);
String legacyValue = protocol.jsonToLegacy(wrapper.user(), value); String legacyValue = protocol.jsonToLegacy(wrapper.user(), value);
wrapper.write(Type.STRING, ChatUtil.fromLegacy(legacyValue, 'f', 32)); wrapper.write(Types.STRING, ChatUtil.fromLegacy(legacyValue, 'f', 32));
int type = wrapper.read(Type.VAR_INT); int type = wrapper.read(Types.VAR_INT);
wrapper.write(Type.STRING, type == 1 ? "hearts" : "integer"); wrapper.write(Types.STRING, type == 1 ? "hearts" : "integer");
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.TEAMS, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.SET_PLAYER_TEAM, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.STRING); // Name map(Types.STRING); // Name
map(Type.BYTE); // Action map(Types.BYTE); // Action
handler(wrapper -> { handler(wrapper -> {
byte action = wrapper.get(Type.BYTE, 0); byte action = wrapper.get(Types.BYTE, 0);
if (action == 0 || action == 2) { if (action == 0 || action == 2) {
JsonElement displayName = wrapper.read(Type.COMPONENT); JsonElement displayName = wrapper.read(Types.COMPONENT);
String legacyTextDisplayName = protocol.jsonToLegacy(wrapper.user(), displayName); String legacyTextDisplayName = protocol.jsonToLegacy(wrapper.user(), displayName);
wrapper.write(Type.STRING, ChatUtil.fromLegacy(legacyTextDisplayName, 'f', 32)); wrapper.write(Types.STRING, ChatUtil.fromLegacy(legacyTextDisplayName, 'f', 32));
byte flags = wrapper.read(Type.BYTE); byte flags = wrapper.read(Types.BYTE);
String nameTagVisibility = wrapper.read(Type.STRING); String nameTagVisibility = wrapper.read(Types.STRING);
String collisionRule = wrapper.read(Type.STRING); String collisionRule = wrapper.read(Types.STRING);
int colour = wrapper.read(Type.VAR_INT); int colour = wrapper.read(Types.VAR_INT);
if (colour == 21) { if (colour == 21) {
colour = -1; colour = -1;
} }
JsonElement prefixComponent = wrapper.read(Type.COMPONENT); JsonElement prefixComponent = wrapper.read(Types.COMPONENT);
JsonElement suffixComponent = wrapper.read(Type.COMPONENT); JsonElement suffixComponent = wrapper.read(Types.COMPONENT);
String prefix = protocol.jsonToLegacy(wrapper.user(), prefixComponent); String prefix = protocol.jsonToLegacy(wrapper.user(), prefixComponent);
if (ViaBackwards.getConfig().addTeamColorTo1_13Prefix()) { if (ViaBackwards.getConfig().addTeamColorTo1_13Prefix()) {
@ -242,24 +243,24 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
String suffix = protocol.jsonToLegacy(wrapper.user(), suffixComponent); String suffix = protocol.jsonToLegacy(wrapper.user(), suffixComponent);
wrapper.write(Type.STRING, ChatUtil.fromLegacyPrefix(prefix, 'f', 16)); wrapper.write(Types.STRING, ChatUtil.fromLegacyPrefix(prefix, 'f', 16));
wrapper.write(Type.STRING, ChatUtil.fromLegacy(suffix, '\0', 16)); wrapper.write(Types.STRING, ChatUtil.fromLegacy(suffix, '\0', 16));
wrapper.write(Type.BYTE, flags); wrapper.write(Types.BYTE, flags);
wrapper.write(Type.STRING, nameTagVisibility); wrapper.write(Types.STRING, nameTagVisibility);
wrapper.write(Type.STRING, collisionRule); wrapper.write(Types.STRING, collisionRule);
wrapper.write(Type.BYTE, (byte) colour); wrapper.write(Types.BYTE, (byte) colour);
} }
if (action == 0 || action == 3 || action == 4) { if (action == 0 || action == 3 || action == 4) {
wrapper.passthrough(Type.STRING_ARRAY); //Entities wrapper.passthrough(Types.STRING_ARRAY); //Entities
} }
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_COMMANDS, null, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.COMMANDS, null, wrapper -> {
wrapper.cancel(); wrapper.cancel();
TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class); TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class);
@ -268,13 +269,13 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
storage.commands().clear(); storage.commands().clear();
} }
int size = wrapper.read(Type.VAR_INT); int size = wrapper.read(Types.VAR_INT);
boolean initialNodes = true; boolean initialNodes = true;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
byte flags = wrapper.read(Type.BYTE); byte flags = wrapper.read(Types.BYTE);
wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE); // Children indices wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE); // Children indices
if ((flags & 0x08) != 0) { if ((flags & 0x08) != 0) {
wrapper.read(Type.VAR_INT); // Redirect node index wrapper.read(Types.VAR_INT); // Redirect node index
} }
byte nodeType = (byte) (flags & 0x03); byte nodeType = (byte) (flags & 0x03);
@ -283,31 +284,31 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
if (nodeType == 1 || nodeType == 2) { // Literal/argument node if (nodeType == 1 || nodeType == 2) { // Literal/argument node
String name = wrapper.read(Type.STRING); String name = wrapper.read(Types.STRING);
if (nodeType == 1 && initialNodes) { if (nodeType == 1 && initialNodes) {
storage.commands().add('/' + name); storage.commands().add('/' + name);
} }
} }
if (nodeType == 2) { // Argument node if (nodeType == 2) { // Argument node
commandRewriter.handleArgument(wrapper, wrapper.read(Type.STRING)); commandRewriter.handleArgument(wrapper, wrapper.read(Types.STRING));
} }
if ((flags & 0x10) != 0) { if ((flags & 0x10) != 0) {
wrapper.read(Type.STRING); // Suggestion type wrapper.read(Types.STRING); // Suggestion type
} }
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.TAB_COMPLETE, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.COMMAND_SUGGESTIONS, wrapper -> {
TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class); TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class);
if (storage.lastRequest() == null) { if (storage.lastRequest() == null) {
wrapper.cancel(); wrapper.cancel();
return; return;
} }
if (storage.lastId() != wrapper.read(Type.VAR_INT)) wrapper.cancel(); if (storage.lastId() != wrapper.read(Types.VAR_INT)) wrapper.cancel();
int start = wrapper.read(Type.VAR_INT); int start = wrapper.read(Types.VAR_INT);
int length = wrapper.read(Type.VAR_INT); int length = wrapper.read(Types.VAR_INT);
int lastRequestPartIndex = storage.lastRequest().lastIndexOf(' ') + 1; int lastRequestPartIndex = storage.lastRequest().lastIndexOf(' ') + 1;
if (lastRequestPartIndex != start) wrapper.cancel(); // Client only replaces after space if (lastRequestPartIndex != start) wrapper.cancel(); // Client only replaces after space
@ -316,21 +317,21 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
wrapper.cancel(); // We can't set the length in previous versions wrapper.cancel(); // We can't set the length in previous versions
} }
int count = wrapper.passthrough(Type.VAR_INT); int count = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String match = wrapper.read(Type.STRING); String match = wrapper.read(Types.STRING);
wrapper.write(Type.STRING, (start == 0 && !storage.isLastAssumeCommand() ? "/" : "") + match); wrapper.write(Types.STRING, (start == 0 && !storage.isLastAssumeCommand() ? "/" : "") + match);
wrapper.read(Type.OPTIONAL_COMPONENT); // Remove tooltip wrapper.read(Types.OPTIONAL_COMPONENT); // Remove tooltip
} }
}); });
protocol.registerServerbound(ServerboundPackets1_12_1.TAB_COMPLETE, wrapper -> { protocol.registerServerbound(ServerboundPackets1_12_1.COMMAND_SUGGESTION, wrapper -> {
TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class); TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class);
List<String> suggestions = new ArrayList<>(); List<String> suggestions = new ArrayList<>();
String command = wrapper.read(Type.STRING); String command = wrapper.read(Types.STRING);
boolean assumeCommand = wrapper.read(Type.BOOLEAN); boolean assumeCommand = wrapper.read(Types.BOOLEAN);
wrapper.read(Type.OPTIONAL_POSITION1_8); wrapper.read(Types.OPTIONAL_POSITION1_8);
if (!assumeCommand && !command.startsWith("/")) { if (!assumeCommand && !command.startsWith("/")) {
// Complete usernames for non-commands // Complete usernames for non-commands
@ -351,12 +352,12 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
if (!suggestions.isEmpty()) { if (!suggestions.isEmpty()) {
wrapper.cancel(); wrapper.cancel();
PacketWrapper response = wrapper.create(ClientboundPackets1_12_1.TAB_COMPLETE); PacketWrapper response = wrapper.create(ClientboundPackets1_12_1.COMMAND_SUGGESTIONS);
response.write(Type.VAR_INT, suggestions.size()); response.write(Types.VAR_INT, suggestions.size());
for (String value : suggestions) { for (String value : suggestions) {
response.write(Type.STRING, value); response.write(Types.STRING, value);
} }
response.scheduleSend(Protocol1_12_2To1_13.class); response.scheduleSend(Protocol1_13To1_12_2.class);
storage.setLastRequest(null); storage.setLastRequest(null);
return; return;
} }
@ -366,120 +367,120 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
int id = ThreadLocalRandom.current().nextInt(); int id = ThreadLocalRandom.current().nextInt();
wrapper.write(Type.VAR_INT, id); wrapper.write(Types.VAR_INT, id);
wrapper.write(Type.STRING, command); wrapper.write(Types.STRING, command);
storage.setLastId(id); storage.setLastId(id);
storage.setLastAssumeCommand(assumeCommand); storage.setLastAssumeCommand(assumeCommand);
storage.setLastRequest(command); storage.setLastRequest(command);
}); });
protocol.registerServerbound(ServerboundPackets1_12_1.PLUGIN_MESSAGE, wrapper -> { protocol.registerServerbound(ServerboundPackets1_12_1.CUSTOM_PAYLOAD, wrapper -> {
String channel = wrapper.read(Type.STRING); String channel = wrapper.read(Types.STRING);
switch (channel) { switch (channel) {
case "MC|BSign", "MC|BEdit" -> { case "MC|BSign", "MC|BEdit" -> {
wrapper.setPacketType(ServerboundPackets1_13.EDIT_BOOK); wrapper.setPacketType(ServerboundPackets1_13.EDIT_BOOK);
Item book = wrapper.read(Type.ITEM1_8); Item book = wrapper.read(Types.ITEM1_8);
wrapper.write(Type.ITEM1_13, protocol.getItemRewriter().handleItemToServer(wrapper.user(), book)); wrapper.write(Types.ITEM1_13, protocol.getItemRewriter().handleItemToServer(wrapper.user(), book));
boolean signing = channel.equals("MC|BSign"); boolean signing = channel.equals("MC|BSign");
wrapper.write(Type.BOOLEAN, signing); wrapper.write(Types.BOOLEAN, signing);
} }
case "MC|ItemName" -> wrapper.setPacketType(ServerboundPackets1_13.RENAME_ITEM); case "MC|ItemName" -> wrapper.setPacketType(ServerboundPackets1_13.RENAME_ITEM);
case "MC|AdvCmd" -> { case "MC|AdvCmd" -> {
byte type = wrapper.read(Type.BYTE); byte type = wrapper.read(Types.BYTE);
if (type == 0) { if (type == 0) {
//Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089 //Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089
//The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either. //The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either.
//Maybe older versions used this and we need to implement this? The issue is that we would have to save the command block types //Maybe older versions used this and we need to implement this? The issue is that we would have to save the command block types
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK); wrapper.setPacketType(ServerboundPackets1_13.SET_COMMAND_BLOCK);
wrapper.cancel(); wrapper.cancel();
ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!"); ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!");
} else if (type == 1) { } else if (type == 1) {
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART); wrapper.setPacketType(ServerboundPackets1_13.SET_COMMAND_MINECART);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Entity Id wrapper.write(Types.VAR_INT, wrapper.read(Types.INT)); //Entity Id
wrapper.passthrough(Type.STRING); //Command wrapper.passthrough(Types.STRING); //Command
wrapper.passthrough(Type.BOOLEAN); //Track Output wrapper.passthrough(Types.BOOLEAN); //Track Output
} else { } else {
wrapper.cancel(); wrapper.cancel();
} }
} }
case "MC|AutoCmd" -> { case "MC|AutoCmd" -> {
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK); wrapper.setPacketType(ServerboundPackets1_13.SET_COMMAND_BLOCK);
int x = wrapper.read(Type.INT); int x = wrapper.read(Types.INT);
int y = wrapper.read(Type.INT); int y = wrapper.read(Types.INT);
int z = wrapper.read(Type.INT); int z = wrapper.read(Types.INT);
wrapper.write(Type.POSITION1_8, new Position(x, (short) y, z)); wrapper.write(Types.BLOCK_POSITION1_8, new Position(x, (short) y, z));
wrapper.passthrough(Type.STRING); //Command wrapper.passthrough(Types.STRING); //Command
byte flags = 0; byte flags = 0;
if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Track Output if (wrapper.read(Types.BOOLEAN)) flags |= 0x01; //Track Output
String mode = wrapper.read(Type.STRING); String mode = wrapper.read(Types.STRING);
int modeId = mode.equals("SEQUENCE") ? 0 : mode.equals("AUTO") ? 1 : 2; int modeId = mode.equals("SEQUENCE") ? 0 : mode.equals("AUTO") ? 1 : 2;
wrapper.write(Type.VAR_INT, modeId); wrapper.write(Types.VAR_INT, modeId);
if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Is conditional if (wrapper.read(Types.BOOLEAN)) flags |= 0x02; //Is conditional
if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Automatic if (wrapper.read(Types.BOOLEAN)) flags |= 0x04; //Automatic
wrapper.write(Type.BYTE, flags); wrapper.write(Types.BYTE, flags);
} }
case "MC|Struct" -> { case "MC|Struct" -> {
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK); wrapper.setPacketType(ServerboundPackets1_13.SET_STRUCTURE_BLOCK);
int x = wrapper.read(Type.INT); int x = wrapper.read(Types.INT);
int y = wrapper.read(Type.INT); int y = wrapper.read(Types.INT);
int z = wrapper.read(Type.INT); int z = wrapper.read(Types.INT);
wrapper.write(Type.POSITION1_8, new Position(x, (short) y, z)); wrapper.write(Types.BLOCK_POSITION1_8, new Position(x, (short) y, z));
wrapper.write(Type.VAR_INT, wrapper.read(Type.BYTE) - 1); wrapper.write(Types.VAR_INT, wrapper.read(Types.BYTE) - 1);
String mode = wrapper.read(Type.STRING); String mode = wrapper.read(Types.STRING);
int modeId = mode.equals("SAVE") ? 0 : mode.equals("LOAD") ? 1 : mode.equals("CORNER") ? 2 : 3; int modeId = mode.equals("SAVE") ? 0 : mode.equals("LOAD") ? 1 : mode.equals("CORNER") ? 2 : 3;
wrapper.write(Type.VAR_INT, modeId); wrapper.write(Types.VAR_INT, modeId);
wrapper.passthrough(Type.STRING); //Name wrapper.passthrough(Types.STRING); //Name
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset X wrapper.write(Types.BYTE, wrapper.read(Types.INT).byteValue()); //Offset X
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Y wrapper.write(Types.BYTE, wrapper.read(Types.INT).byteValue()); //Offset Y
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Z wrapper.write(Types.BYTE, wrapper.read(Types.INT).byteValue()); //Offset Z
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size X wrapper.write(Types.BYTE, wrapper.read(Types.INT).byteValue()); //Size X
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Y wrapper.write(Types.BYTE, wrapper.read(Types.INT).byteValue()); //Size Y
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Z wrapper.write(Types.BYTE, wrapper.read(Types.INT).byteValue()); //Size Z
String mirror = wrapper.read(Type.STRING); String mirror = wrapper.read(Types.STRING);
int mirrorId = mode.equals("NONE") ? 0 : mode.equals("LEFT_RIGHT") ? 1 : 2; int mirrorId = mode.equals("NONE") ? 0 : mode.equals("LEFT_RIGHT") ? 1 : 2;
String rotation = wrapper.read(Type.STRING); String rotation = wrapper.read(Types.STRING);
int rotationId = mode.equals("NONE") ? 0 : mode.equals("CLOCKWISE_90") ? 1 : mode.equals("CLOCKWISE_180") ? 2 : 3; int rotationId = mode.equals("NONE") ? 0 : mode.equals("CLOCKWISE_90") ? 1 : mode.equals("CLOCKWISE_180") ? 2 : 3;
wrapper.passthrough(Type.STRING); //Metadata wrapper.passthrough(Types.STRING); //Metadata
byte flags = 0; byte flags = 0;
if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Ignore entities if (wrapper.read(Types.BOOLEAN)) flags |= 0x01; //Ignore entities
if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Show air if (wrapper.read(Types.BOOLEAN)) flags |= 0x02; //Show air
if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Show bounding box if (wrapper.read(Types.BOOLEAN)) flags |= 0x04; //Show bounding box
wrapper.passthrough(Type.FLOAT); //Integrity wrapper.passthrough(Types.FLOAT); //Integrity
wrapper.passthrough(Type.VAR_LONG); //Seed wrapper.passthrough(Types.VAR_LONG); //Seed
wrapper.write(Type.BYTE, flags); wrapper.write(Types.BYTE, flags);
} }
case "MC|Beacon" -> { case "MC|Beacon" -> {
wrapper.setPacketType(ServerboundPackets1_13.SET_BEACON_EFFECT); wrapper.setPacketType(ServerboundPackets1_13.SET_BEACON);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Primary Effect wrapper.write(Types.VAR_INT, wrapper.read(Types.INT)); //Primary Effect
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Secondary Effect wrapper.write(Types.VAR_INT, wrapper.read(Types.INT)); //Secondary Effect
} }
case "MC|TrSel" -> { case "MC|TrSel" -> {
wrapper.setPacketType(ServerboundPackets1_13.SELECT_TRADE); wrapper.setPacketType(ServerboundPackets1_13.SELECT_TRADE);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Slot wrapper.write(Types.VAR_INT, wrapper.read(Types.INT)); //Slot
} }
case "MC|PickItem" -> wrapper.setPacketType(ServerboundPackets1_13.PICK_ITEM); case "MC|PickItem" -> wrapper.setPacketType(ServerboundPackets1_13.PICK_ITEM);
default -> { default -> {
String newChannel = InventoryPackets.getNewPluginChannelId(channel); String newChannel = ItemPacketRewriter1_13.getNewPluginChannelId(channel);
if (newChannel == null) { if (newChannel == null) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("Ignoring serverbound plugin message with channel: " + channel); ViaBackwards.getPlatform().getLogger().warning("Ignoring serverbound plugin message with channel: " + channel);
@ -487,13 +488,13 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
wrapper.cancel(); wrapper.cancel();
return; return;
} }
wrapper.write(Type.STRING, newChannel); wrapper.write(Types.STRING, newChannel);
if (newChannel.equals("minecraft:register") || newChannel.equals("minecraft:unregister")) { if (newChannel.equals("minecraft:register") || newChannel.equals("minecraft:unregister")) {
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); String[] channels = new String(wrapper.read(Types.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
List<String> rewrittenChannels = new ArrayList<>(); List<String> rewrittenChannels = new ArrayList<>();
for (String s : channels) { for (String s : channels) {
String rewritten = InventoryPackets.getNewPluginChannelId(s); String rewritten = ItemPacketRewriter1_13.getNewPluginChannelId(s);
if (rewritten != null) { if (rewritten != null) {
rewrittenChannels.add(rewritten); rewrittenChannels.add(rewritten);
} else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { } else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
@ -501,7 +502,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
} }
if (!rewrittenChannels.isEmpty()) { if (!rewrittenChannels.isEmpty()) {
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); wrapper.write(Types.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
} else { } else {
wrapper.cancel(); wrapper.cancel();
} }
@ -510,41 +511,41 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
} }
}); });
protocol.registerClientbound(ClientboundPackets1_13.STATISTICS, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.AWARD_STATS, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
handler(wrapper -> { handler(wrapper -> {
int size = wrapper.get(Type.VAR_INT, 0); int size = wrapper.get(Types.VAR_INT, 0);
int newSize = size; int newSize = size;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int categoryId = wrapper.read(Type.VAR_INT); int categoryId = wrapper.read(Types.VAR_INT);
int statisticId = wrapper.read(Type.VAR_INT); int statisticId = wrapper.read(Types.VAR_INT);
String name = ""; String name = "";
// categories 0-7 (items, blocks, entities) - probably not feasible // categories 0-7 (items, blocks, entities) - probably not feasible
switch (categoryId) { switch (categoryId) {
case 0, 1, 2, 3, 4, 5, 6, 7 -> { case 0, 1, 2, 3, 4, 5, 6, 7 -> {
wrapper.read(Type.VAR_INT); // remove value wrapper.read(Types.VAR_INT); // remove value
newSize--; newSize--;
continue; continue;
} }
case 8 -> { case 8 -> {
name = protocol.getMappingData().getStatisticMappings().get(statisticId); name = protocol.getMappingData().getStatisticMappings().get(statisticId);
if (name == null) { if (name == null) {
wrapper.read(Type.VAR_INT); wrapper.read(Types.VAR_INT);
newSize--; newSize--;
continue; continue;
} }
} }
} }
wrapper.write(Type.STRING, name); // string id wrapper.write(Types.STRING, name); // string id
wrapper.passthrough(Type.VAR_INT); // value wrapper.passthrough(Types.VAR_INT); // value
} }
if (newSize != size) { if (newSize != size) {
wrapper.set(Type.VAR_INT, 0, newSize); wrapper.set(Types.VAR_INT, 0, newSize);
} }
}); });
} }

View File

@ -15,49 +15,50 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.rewriter;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.NamedSoundMapping;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.rewriter.RewriterBase; import com.viaversion.viaversion.api.rewriter.RewriterBase;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
public class SoundPackets1_13 extends RewriterBase<Protocol1_12_2To1_13> { public class SoundPacketRewriter1_13 extends RewriterBase<Protocol1_13To1_12_2> {
private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}; private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"};
public SoundPackets1_13(Protocol1_12_2To1_13 protocol) { public SoundPacketRewriter1_13(Protocol1_13To1_12_2 protocol) {
super(protocol); super(protocol);
} }
@Override @Override
protected void registerPackets() { protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_13.NAMED_SOUND, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.CUSTOM_SOUND, wrapper -> {
String sound = wrapper.read(Type.STRING); String sound = wrapper.read(Types.STRING);
String mappedSound = NamedSoundMapping.getOldId(sound); String mappedSound = NamedSoundMapping.getOldId(sound);
if (mappedSound != null || (mappedSound = protocol.getMappingData().getMappedNamedSound(sound)) != null) { if (mappedSound != null || (mappedSound = protocol.getMappingData().getMappedNamedSound(sound)) != null) {
wrapper.write(Type.STRING, mappedSound); wrapper.write(Types.STRING, mappedSound);
} else { } else {
wrapper.write(Type.STRING, sound); wrapper.write(Types.STRING, sound);
} }
}); });
// Stop Sound -> Plugin Message // Stop Sound -> Plugin Message
protocol.registerClientbound(ClientboundPackets1_13.STOP_SOUND, ClientboundPackets1_12_1.PLUGIN_MESSAGE, wrapper -> { protocol.registerClientbound(ClientboundPackets1_13.STOP_SOUND, ClientboundPackets1_12_1.CUSTOM_PAYLOAD, wrapper -> {
wrapper.write(Type.STRING, "MC|StopSound"); wrapper.write(Types.STRING, "MC|StopSound");
byte flags = wrapper.read(Type.BYTE); byte flags = wrapper.read(Types.BYTE);
String source; String source;
if ((flags & 0x01) != 0) { if ((flags & 0x01) != 0) {
source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)]; source = SOUND_SOURCES[wrapper.read(Types.VAR_INT)];
} else { } else {
source = ""; source = "";
} }
String sound; String sound;
if ((flags & 0x02) != 0) { if ((flags & 0x02) != 0) {
String newSound = wrapper.read(Type.STRING); String newSound = wrapper.read(Types.STRING);
sound = protocol.getMappingData().getMappedNamedSound(newSound); sound = protocol.getMappingData().getMappedNamedSound(newSound);
if (sound == null) { if (sound == null) {
sound = ""; sound = "";
@ -66,21 +67,21 @@ public class SoundPackets1_13 extends RewriterBase<Protocol1_12_2To1_13> {
sound = ""; sound = "";
} }
wrapper.write(Type.STRING, source); wrapper.write(Types.STRING, source);
wrapper.write(Type.STRING, sound); wrapper.write(Types.STRING, sound);
}); });
protocol.registerClientbound(ClientboundPackets1_13.SOUND, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_13.SOUND, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.VAR_INT); map(Types.VAR_INT);
handler(wrapper -> { handler(wrapper -> {
int newSound = wrapper.get(Type.VAR_INT, 0); int newSound = wrapper.get(Types.VAR_INT, 0);
int oldSound = protocol.getMappingData().getSoundMappings().getNewId(newSound); int oldSound = protocol.getMappingData().getSoundMappings().getNewId(newSound);
if (oldSound == -1) { if (oldSound == -1) {
wrapper.cancel(); wrapper.cancel();
} else { } else {
wrapper.set(Type.VAR_INT, 0, oldSound); wrapper.set(Types.VAR_INT, 0, oldSound);
} }
}); });
} }

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage; package com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage;
import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage; import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage;

Some files were not shown because too many files have changed in this diff Show More