From 5ff776735312c79cccdac6c6c2a9c27ffdc69fac Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sat, 6 Jun 2020 16:15:28 +0200 Subject: [PATCH] Use packet type constants for automated channel mapping --- .../viabackwards/api/BackwardsProtocol.java | 37 +-- .../api/data/MappedLegacyBlockItem.java | 6 +- .../api/data/VBSoundMappings.java | 2 + .../api/entities/meta/MetaHandlerEvent.java | 2 + .../entities/meta/MetaHandlerSettings.java | 4 +- .../api/entities/storage/EntityData.java | 3 + .../api/entities/storage/EntityTracker.java | 5 + .../api/entities/storage/MetaStorage.java | 2 + .../api/rewriters/EntityRewriter.java | 18 +- .../api/rewriters/EntityRewriterBase.java | 36 +-- .../api/rewriters/ItemRewriter.java | 8 +- .../api/rewriters/ItemRewriterBase.java | 5 +- .../rewriters/LegacyBlockItemRewriter.java | 5 +- .../rewriters/LegacyEnchantmentRewriter.java | 2 +- .../api/rewriters/LegacyEntityRewriter.java | 12 +- .../api/rewriters/RecipeRewriter.java | 8 +- .../api/rewriters/SoundRewriter.java | 10 +- .../api/rewriters/TranslatableRewriter.java | 35 +-- .../Protocol1_10To1_11.java | 18 +- .../packets/BlockItemPackets1_11.java | 191 ++++++------- .../packets/EntityPackets1_11.java | 41 +-- .../packets/PlayerPackets1_11.java | 35 +-- .../packets/SoundPackets1_11.java | 8 +- .../Protocol1_11_1To1_12.java | 27 +- .../packets/BlockItemPackets1_12.java | 109 ++++---- .../packets/ChangedPacketIds1_12.java | 99 ------- .../packets/ChatPackets1_12.java | 9 +- .../packets/EntityPackets1_12.java | 41 +-- .../packets/SoundPackets1_12.java | 20 +- .../Protocol1_11To1_11_1.java | 15 +- .../packets/EntityPackets1_11_1.java | 36 +-- .../packets/ItemPackets1_11_1.java | 29 +- .../Protocol1_12_1To1_12_2.java | 18 +- .../Protocol1_12_2To1_13.java | 128 +++------ .../packets/BlockItemPackets1_13.java | 256 ++++++++---------- .../packets/EntityPackets1_13.java | 52 ++-- .../packets/PlayerPacket1_13.java | 156 ++++++----- .../packets/SoundPackets1_13.java | 13 +- .../Protocol1_12To1_12_1.java | 87 +----- .../Protocol1_13_1To1_13_2.java | 21 +- .../packets/EntityPackets1_13_2.java | 15 +- .../packets/InventoryPackets1_13_2.java | 70 ++--- .../packets/WorldPackets1_13_2.java | 9 +- .../Protocol1_13_2To1_14.java | 132 ++------- .../data/RecipeRewriter1_14.java | 2 +- .../packets/BlockItemPackets1_14.java | 91 +++---- .../packets/EntityPackets1_14.java | 46 ++-- .../packets/PlayerPackets1_14.java | 54 ++-- .../packets/SoundPackets1_14.java | 10 +- .../Protocol1_13To1_13_1.java | 40 ++- .../packets/EntityPackets1_13_1.java | 37 +-- .../packets/InventoryPackets1_13_1.java | 28 +- .../packets/WorldPackets1_13_1.java | 24 +- .../Protocol1_14_1To1_14_2.java | 13 +- .../Protocol1_14_2To1_14_3.java | 85 +++--- .../Protocol1_14_3To1_14_4.java | 23 +- .../Protocol1_14_4To1_15.java | 91 ++----- .../data/RecipeRewriter1_15.java | 2 +- .../packets/BlockItemPackets1_15.java | 58 ++-- .../packets/EntityPackets1_15.java | 43 +-- .../Protocol1_14To1_14_1.java | 12 +- .../packets/EntityPackets1_14_1.java | 22 +- .../Protocol1_15_1To1_15_2.java | 12 +- .../Protocol1_15_2To1_16.java | 124 ++------- .../data/RecipeRewriter1_16.java | 6 +- .../packets/BlockItemPackets1_16.java | 65 ++--- .../packets/EntityPackets1_16.java | 38 +-- .../Protocol1_15To1_15_1.java | 12 +- .../Protocol1_9_4To1_10.java | 27 +- .../packets/BlockItemPackets1_10.java | 113 ++++---- .../packets/ChangedPackets1_10.java | 32 --- .../packets/EntityPackets1_10.java | 36 +-- .../packets/SoundPackets1_10.java | 20 +- pom.xml | 8 + 74 files changed, 1167 insertions(+), 1842 deletions(-) delete mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChangedPacketIds1_12.java delete mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/ChangedPackets1_10.java diff --git a/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java b/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java index 46140d09..82a341b0 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java @@ -1,43 +1,30 @@ -/* - * Copyright (c) 2016 Matsv - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package nl.matsv.viabackwards.api; +import org.jetbrains.annotations.Nullable; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion.api.remapper.PacketRemapper; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; -public abstract class BackwardsProtocol extends Protocol { +public abstract class BackwardsProtocol + extends Protocol { protected BackwardsProtocol() { + super(); } protected BackwardsProtocol(boolean hasMappingDataToLoad) { super(hasMappingDataToLoad); } - public void out(State state, int oldPacketID, int newPacketID) { - this.registerOutgoing(state, oldPacketID, newPacketID, null); + protected BackwardsProtocol(@Nullable Class oldClientboundPacketEnum, @Nullable Class clientboundPacketEnum, + @Nullable Class oldServerboundPacketEnum, @Nullable Class serverboundPacketEnum) { + super(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum, false); } - public void out(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { - this.registerOutgoing(state, oldPacketID, newPacketID, packetRemapper); - } - - public void in(State state, int oldPacketID, int newPacketID) { - this.registerIncoming(state, oldPacketID, newPacketID, null); - } - - public void in(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { - this.registerIncoming(state, oldPacketID, newPacketID, packetRemapper); + protected BackwardsProtocol(@Nullable Class oldClientboundPacketEnum, @Nullable Class clientboundPacketEnum, + @Nullable Class oldServerboundPacketEnum, @Nullable Class serverboundPacketEnum, boolean hasMappingDatatToLoad) { + super(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum, hasMappingDatatToLoad); } /** diff --git a/core/src/main/java/nl/matsv/viabackwards/api/data/MappedLegacyBlockItem.java b/core/src/main/java/nl/matsv/viabackwards/api/data/MappedLegacyBlockItem.java index 75e90842..f9f563af 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/data/MappedLegacyBlockItem.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/data/MappedLegacyBlockItem.java @@ -2,6 +2,7 @@ package nl.matsv.viabackwards.api.data; import net.md_5.bungee.api.ChatColor; import nl.matsv.viabackwards.utils.Block; +import org.jetbrains.annotations.Nullable; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; public class MappedLegacyBlockItem { @@ -12,7 +13,7 @@ public class MappedLegacyBlockItem { private final Block block; private BlockEntityHandler blockEntityHandler; - public MappedLegacyBlockItem(int id, short data, String name, boolean block) { + public MappedLegacyBlockItem(int id, short data, @Nullable String name, boolean block) { this.id = id; this.data = data; this.name = name != null ? ChatColor.RESET + name : null; @@ -43,11 +44,12 @@ public class MappedLegacyBlockItem { return blockEntityHandler != null; } + @Nullable public BlockEntityHandler getBlockEntityHandler() { return blockEntityHandler; } - public void setBlockEntityHandler(BlockEntityHandler blockEntityHandler) { + public void setBlockEntityHandler(@Nullable BlockEntityHandler blockEntityHandler) { this.blockEntityHandler = blockEntityHandler; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/data/VBSoundMappings.java b/core/src/main/java/nl/matsv/viabackwards/api/data/VBSoundMappings.java index 6a482f7d..130f2a05 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/data/VBSoundMappings.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/data/VBSoundMappings.java @@ -1,5 +1,6 @@ package nl.matsv.viabackwards.api.data; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.data.Mappings; import us.myles.viaversion.libs.gson.JsonArray; import us.myles.viaversion.libs.gson.JsonElement; @@ -31,6 +32,7 @@ public class VBSoundMappings { } } + @Nullable public String getNewId(String oldId) { return namedSoundMappings.get(oldId); } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java index c9feecbb..97a18fc8 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java @@ -12,6 +12,7 @@ package nl.matsv.viabackwards.api.entities.meta; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -78,6 +79,7 @@ public class MetaHandlerEvent { /** * May be null, use {@link #createMeta(Metadata)} for adding metadata. */ + @Nullable public List getExtraData() { return extraData; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerSettings.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerSettings.java index 58370083..58da30bc 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerSettings.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerSettings.java @@ -11,6 +11,7 @@ package nl.matsv.viabackwards.api.entities.meta; import nl.matsv.viabackwards.api.exceptions.RemovedValueException; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -43,7 +44,7 @@ public class MetaHandlerSettings { return this; } - public void handle(MetaHandler handler) { + public void handle(@Nullable MetaHandler handler) { this.handler = handler; } @@ -100,6 +101,7 @@ public class MetaHandlerSettings { return filterIndex; } + @Nullable public MetaHandler getHandler() { return handler; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java index c5c0db8e..bece05a7 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityData.java @@ -10,6 +10,7 @@ package nl.matsv.viabackwards.api.entities.storage; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; public class EntityData { @@ -46,6 +47,7 @@ public class EntityData { return id; } + @Nullable public String getMobName() { return mobName; } @@ -54,6 +56,7 @@ public class EntityData { return replacementId; } + @Nullable public MetaCreator getDefaultMeta() { return defaultMeta; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityTracker.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityTracker.java index 92e0086b..4a967832 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityTracker.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/EntityTracker.java @@ -11,6 +11,7 @@ package nl.matsv.viabackwards.api.entities.storage; import nl.matsv.viabackwards.api.BackwardsProtocol; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.EntityType; @@ -29,6 +30,7 @@ public class EntityTracker extends StoredObject { trackers.put(protocol, new ProtocolEntityTracker()); } + @Nullable public ProtocolEntityTracker get(BackwardsProtocol protocol) { return trackers.get(protocol); } @@ -44,11 +46,13 @@ public class EntityTracker extends StoredObject { entityMap.remove(id); } + @Nullable public EntityType getEntityType(int id) { StoredEntity storedEntity = entityMap.get(id); return storedEntity != null ? storedEntity.getType() : null; } + @Nullable public StoredEntity getEntity(int id) { return entityMap.get(id); } @@ -71,6 +75,7 @@ public class EntityTracker extends StoredObject { * @param The type of the class you want to get. * @return The requested object */ + @Nullable public T get(Class objectClass) { return (T) storedObjects.get(objectClass); } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java index b1239710..e6b5164a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java @@ -10,6 +10,7 @@ package nl.matsv.viabackwards.api.entities.storage; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import java.util.List; @@ -37,6 +38,7 @@ public class MetaStorage { this.metaDataList.add(data); } + @Nullable public Metadata get(int index) { for (Metadata meta : this.metaDataList) { if (index == meta.getId()) { diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java index ce0f9cac..b35cbf49 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java @@ -8,10 +8,10 @@ import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import java.util.List; @@ -25,8 +25,8 @@ public abstract class EntityRewriter extends Entity super(protocol, displayType, 2); } - public void registerSpawnTrackerWithData(int oldPacketId, int newPacketId, EntityType fallingBlockType, IdRewriteFunction blockStateRewriter) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType, IdRewriteFunction blockStateRewriter) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -49,8 +49,8 @@ public abstract class EntityRewriter extends Entity }); } - public void registerSpawnTracker(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerSpawnTracker(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -77,8 +77,8 @@ public abstract class EntityRewriter extends Entity /** * Helper method to handle a metadata list packet and its full initial meta rewrite. */ - protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type> oldMetaType, Type> newMetaType) { - getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + protected void registerMetadataRewriter(ClientboundPacketType packetType, Type> oldMetaType, Type> newMetaType) { + getProtocol().registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -108,7 +108,7 @@ public abstract class EntityRewriter extends Entity }); } - protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type> metaType) { - registerMetadataRewriter(oldPacketId, newPacketId, null, metaType); + protected void registerMetadataRewriter(ClientboundPacketType packetType, Type> metaType) { + registerMetadataRewriter(packetType, null, metaType); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java index 12ede7fe..49cbaab9 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriterBase.java @@ -9,6 +9,7 @@ import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.exceptions.RemovedValueException; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -16,11 +17,11 @@ import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.CancelException; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.ArrayList; @@ -66,6 +67,7 @@ public abstract class EntityRewriterBase extends Re return entityTypes.containsKey(type); } + @Nullable protected EntityData getEntityData(EntityType type) { return entityTypes.get(type); } @@ -192,8 +194,8 @@ public abstract class EntityRewriterBase extends Re return storage; } - public void registerRespawn(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerRespawn(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); @@ -205,8 +207,8 @@ public abstract class EntityRewriterBase extends Re }); } - public void registerJoinGame(int oldPacketId, int newPacketId, EntityType playerType) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerJoinGame(ClientboundPacketType packetType, EntityType playerType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -224,8 +226,8 @@ public abstract class EntityRewriterBase extends Re /** * Helper method to handle player, painting, or xp orb trackers without meta changes. */ - protected void registerExtraTracker(int oldId, int newId, EntityType entityType, Type intType) { - getProtocol().registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + protected void registerExtraTracker(ClientboundPacketType packetType, EntityType entityType, Type intType) { + getProtocol().registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(intType); // 0 - Entity id @@ -234,20 +236,12 @@ public abstract class EntityRewriterBase extends Re }); } - protected void registerExtraTracker(int packetId, EntityType entityType, Type intType) { - registerExtraTracker(packetId, packetId, entityType, intType); + protected void registerExtraTracker(ClientboundPacketType packetType, EntityType entityType) { + registerExtraTracker(packetType, entityType, Type.VAR_INT); } - protected void registerExtraTracker(int oldId, int newId, EntityType entityType) { - registerExtraTracker(oldId, newId, entityType, Type.VAR_INT); - } - - protected void registerExtraTracker(int packetId, EntityType entityType) { - registerExtraTracker(packetId, entityType, Type.VAR_INT); - } - - protected void registerEntityDestroy(int oldPacketId, int newPacketId) { - getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + protected void registerEntityDestroy(ClientboundPacketType packetType) { + getProtocol().registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT_ARRAY_PRIMITIVE); // 0 - Entity ids @@ -261,10 +255,6 @@ public abstract class EntityRewriterBase extends Re }); } - protected void registerEntityDestroy(int packetId) { - registerEntityDestroy(packetId, packetId); - } - // ONLY TRACKS, DOESN'T REWRITE IDS protected PacketHandler getTrackerHandler(Type intType, int typeIndex) { return wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java index 56091804..32aac011 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriter.java @@ -2,6 +2,7 @@ package nl.matsv.viabackwards.api.rewriters; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.data.MappedItem; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -14,19 +15,21 @@ public abstract class ItemRewriter extends ItemRewr private final MappedItemFunction mappedItemFunction; private final TranslatableRewriter translatableRewriter; - protected ItemRewriter(T protocol, TranslatableRewriter translatableRewriter, IdRewriteFunction oldRewriter, IdRewriteFunction newRewriter, MappedItemFunction mappedItemFunction) { + protected ItemRewriter(T protocol, @Nullable TranslatableRewriter translatableRewriter, + @Nullable IdRewriteFunction oldRewriter, @Nullable IdRewriteFunction newRewriter, MappedItemFunction mappedItemFunction) { super(protocol, oldRewriter, newRewriter, true); this.translatableRewriter = translatableRewriter; this.mappedItemFunction = mappedItemFunction; } - protected ItemRewriter(T protocol, TranslatableRewriter translatableRewriter, MappedItemFunction mappedItemFunction) { + protected ItemRewriter(T protocol, @Nullable TranslatableRewriter translatableRewriter, MappedItemFunction mappedItemFunction) { super(protocol, true); this.translatableRewriter = translatableRewriter; this.mappedItemFunction = mappedItemFunction; } @Override + @Nullable public Item handleItemToClient(Item item) { if (item == null) return null; @@ -94,6 +97,7 @@ public abstract class ItemRewriter extends ItemRewr @FunctionalInterface public interface MappedItemFunction { + @Nullable MappedItem get(int id); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java index 3fc673c9..bfe4f444 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/ItemRewriterBase.java @@ -1,6 +1,7 @@ package nl.matsv.viabackwards.api.rewriters; import nl.matsv.viabackwards.api.BackwardsProtocol; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.viaversion.libs.opennbt.conversion.builtin.CompoundTagConverter; @@ -17,7 +18,7 @@ public abstract class ItemRewriterBase extends Rewr protected final String nbtTagName; protected final boolean jsonNameFormat; - protected ItemRewriterBase(T protocol, IdRewriteFunction toClientRewriter, IdRewriteFunction toServerRewriter, boolean jsonNameFormat) { + protected ItemRewriterBase(T protocol, @Nullable IdRewriteFunction toClientRewriter, @Nullable IdRewriteFunction toServerRewriter, boolean jsonNameFormat) { super(protocol); this.toClientRewriter = toClientRewriter; this.toServerRewriter = toServerRewriter; @@ -29,6 +30,7 @@ public abstract class ItemRewriterBase extends Rewr this(protocol, null, null, jsonNameFormat); } + @Nullable public Item handleItemToClient(Item item) { if (item == null) return null; if (toClientRewriter != null) { @@ -37,6 +39,7 @@ public abstract class ItemRewriterBase extends Rewr return item; } + @Nullable public Item handleItemToServer(Item item) { if (item == null) return null; diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index f9790544..fb71eabd 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -16,6 +16,7 @@ import nl.matsv.viabackwards.api.data.MappedLegacyBlockItem; import nl.matsv.viabackwards.api.data.VBMappingDataLoader; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors; import nl.matsv.viabackwards.utils.Block; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -75,7 +76,7 @@ public abstract class LegacyBlockItemRewriter exten } } - protected LegacyBlockItemRewriter(T protocol, IdRewriteFunction oldRewriter, IdRewriteFunction newRewriter) { + protected LegacyBlockItemRewriter(T protocol, @Nullable IdRewriteFunction oldRewriter, @Nullable IdRewriteFunction newRewriter) { super(protocol, oldRewriter, newRewriter, false); replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", ".")); } @@ -85,6 +86,7 @@ public abstract class LegacyBlockItemRewriter exten } @Override + @Nullable public Item handleItemToClient(Item item) { if (item == null) return null; @@ -138,6 +140,7 @@ public abstract class LegacyBlockItemRewriter exten return (b.getId() << 4 | (b.getData() & 15)); } + @Nullable public Block handleBlock(int blockId, int data) { MappedLegacyBlockItem settings = replacementData.get(blockId); if (settings == null || !settings.isBlock()) return null; diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java index adda696e..c7297cac 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java @@ -10,7 +10,7 @@ public class LegacyEnchantmentRewriter { private final String nbtTagName; private Set hideLevelForEnchants; - public LegacyEnchantmentRewriter(final String nbtTagName) { + public LegacyEnchantmentRewriter(String nbtTagName) { this.nbtTagName = nbtTagName; } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEntityRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEntityRewriter.java index c556a7b8..756f740d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEntityRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEntityRewriter.java @@ -5,14 +5,15 @@ import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityObjectData; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.entities.ObjectType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import java.util.HashMap; import java.util.List; @@ -36,12 +37,13 @@ public abstract class LegacyEntityRewriter extends return entData; } + @Nullable protected EntityData getObjectData(ObjectType type) { return objectTypes.get(type); } - protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type> oldMetaType, Type> newMetaType) { - getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + protected void registerMetadataRewriter(ClientboundPacketType packetType, Type> oldMetaType, Type> newMetaType) { + getProtocol().registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -59,8 +61,8 @@ public abstract class LegacyEntityRewriter extends }); } - protected void registerMetadataRewriter(int oldPacketId, int newPacketId, Type> metaType) { - registerMetadataRewriter(oldPacketId, newPacketId, null, metaType); + protected void registerMetadataRewriter(ClientboundPacketType packetType, Type> metaType) { + registerMetadataRewriter(packetType, null, metaType); } protected PacketHandler getMobSpawnRewriter(Type> metaType) { diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java index 585ad88a..300897ef 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/RecipeRewriter.java @@ -1,22 +1,22 @@ package nl.matsv.viabackwards.api.rewriters; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; public abstract class RecipeRewriter { protected final ItemRewriterBase rewriter; - protected RecipeRewriter(final ItemRewriterBase rewriter) { + protected RecipeRewriter(ItemRewriterBase rewriter) { this.rewriter = rewriter; } public abstract void handle(PacketWrapper wrapper, String type) throws Exception; - public void registerDefaultHandler(int oldId, int newId) { - rewriter.getProtocol().registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerDefaultHandler(ClientboundPacketType packetType) { + rewriter.getProtocol().registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java index 06bb4720..092d54fc 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/SoundRewriter.java @@ -1,10 +1,10 @@ package nl.matsv.viabackwards.api.rewriters; import nl.matsv.viabackwards.api.BackwardsProtocol; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import java.util.function.Function; @@ -21,8 +21,8 @@ public class SoundRewriter extends us.myles.ViaVersion.api.rewriters.SoundRewrit this(protocol, idRewriter, null); } - public void registerNamedSound(int oldId, int newId) { - protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerNamedSound(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // Sound identifier @@ -40,8 +40,8 @@ public class SoundRewriter extends us.myles.ViaVersion.api.rewriters.SoundRewrit }); } - public void registerStopSound(int oldId, int newId) { - protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerStopSound(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java index 11bfc425..fda2e5f0 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/TranslatableRewriter.java @@ -3,6 +3,7 @@ package nl.matsv.viabackwards.api.rewriters; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.data.VBMappingDataLoader; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; @@ -46,7 +47,7 @@ public class TranslatableRewriter { } public void registerPing() { - protocol.out(State.LOGIN, 0x00, 0x00, new PacketRemapper() { + protocol.registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> wrapper.write(Type.STRING, processText(wrapper.read(Type.STRING)))); @@ -54,8 +55,8 @@ public class TranslatableRewriter { }); } - public void registerDisconnect(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerDisconnect(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> wrapper.write(Type.STRING, processText(wrapper.read(Type.STRING)))); @@ -63,8 +64,8 @@ public class TranslatableRewriter { }); } - public void registerChatMessage(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerChatMessage(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> wrapper.write(Type.STRING, processText(wrapper.read(Type.STRING)))); @@ -72,8 +73,8 @@ public class TranslatableRewriter { }); } - public void registerBossBar(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerBossBar(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.UUID); @@ -88,8 +89,8 @@ public class TranslatableRewriter { }); } - public void registerLegacyOpenWindow(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerLegacyOpenWindow(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Id @@ -99,8 +100,8 @@ public class TranslatableRewriter { }); } - public void registerOpenWindow(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerOpenWindow(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Id @@ -110,8 +111,8 @@ public class TranslatableRewriter { }); } - public void registerCombatEvent(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerCombatEvent(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -125,8 +126,8 @@ public class TranslatableRewriter { }); } - public void registerTitle(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerTitle(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -139,8 +140,8 @@ public class TranslatableRewriter { }); } - public void registerPlayerList(int oldId, int newId) { - protocol.out(State.PLAY, oldId, newId, new PacketRemapper() { + public void registerTabList(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java index f4d1646e..673dfe2e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java @@ -18,12 +18,19 @@ import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.PlayerPackets1_ import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.SoundPackets1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_10To1_11 extends BackwardsProtocol { +public class Protocol1_10To1_11 extends BackwardsProtocol { + private EntityPackets1_11 entityPackets; // Required for the item rewriter private BlockItemPackets1_11 blockItemPackets; + public Protocol1_10To1_11() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); + } + @Override protected void registerPackets() { (entityPackets = new EntityPackets1_11(this)).register(); @@ -35,15 +42,18 @@ public class Protocol1_10To1_11 extends BackwardsProtocol { @Override public void init(UserConnection user) { // Register ClientWorld - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } - if (!user.has(WindowTracker.class)) + if (!user.has(WindowTracker.class)) { user.put(new WindowTracker(user)); + } // Init protocol in EntityTracker user.get(EntityTracker.class).initProtocol(this); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 7d5cb54f..bcd0426d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -29,9 +29,10 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_11to1_10.EntityIdRewriter; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; @@ -53,8 +54,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter Trading - protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel @@ -134,8 +132,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter horse = getChestedHorse(wrapper.user()); + if (!horse.isPresent()) + return; + ChestedHorseStorage storage = horse.get(); + int clickSlot = wrapper.get(Type.SHORT, 0); + int correctSlot = getOldSlotId(storage, clickSlot); - handler(itemRewriter.itemToServerHandler(Type.ITEM)); - - // Llama slot - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - if (isLlama(wrapper.user())) { - Optional horse = getChestedHorse(wrapper.user()); - if (!horse.isPresent()) - return; - ChestedHorseStorage storage = horse.get(); - int clickSlot = wrapper.get(Type.SHORT, 0); - int correctSlot = getOldSlotId(storage, clickSlot); - - wrapper.set(Type.SHORT, 0, ((Integer) correctSlot).shortValue()); - } - } - }); + wrapper.set(Type.SHORT, 0, ((Integer) correctSlot).shortValue()); + } } - } - ); + }); + } + }); - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x18); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM); - /* Block packets */ - // Chunk packet - protocol.registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed. - Chunk chunk = wrapper.passthrough(type); + Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed. + Chunk chunk = wrapper.passthrough(type); - handleChunk(chunk); + handleChunk(chunk); - // only patch it for signs for now, TODO-> Find all the block entities old/new to replace ids and implement in ViaVersion - for (CompoundTag tag : chunk.getBlockEntities()) { - Tag idTag = tag.get("id"); - if (!(idTag instanceof StringTag)) continue; + // only patch it for signs for now, TODO-> Find all the block entities old/new to replace ids and implement in ViaVersion + for (CompoundTag tag : chunk.getBlockEntities()) { + Tag idTag = tag.get("id"); + if (!(idTag instanceof StringTag)) continue; - String id = (String) idTag.getValue(); - if (id.equals("minecraft:sign")) { - ((StringTag) idTag).setValue("Sign"); - } - } + String id = (String) idTag.getValue(); + if (id.equals("minecraft:sign")) { + ((StringTag) idTag).setValue("Sign"); } - }); + } } - } - ); + }); + } + }); - // Block Change Packet - protocol.registerOutgoing(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.BLOCK_CHANGE, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION); // 0 - Block Position + map(Type.VAR_INT); // 1 - Block + + handler(new PacketHandler() { @Override - public void registerMap() { - map(Type.POSITION); // 0 - Block Position - map(Type.VAR_INT); // 1 - Block - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int idx = wrapper.get(Type.VAR_INT, 0); - wrapper.set(Type.VAR_INT, 0, handleBlockID(idx)); - } - }); + public void handle(PacketWrapper wrapper) throws Exception { + int idx = wrapper.get(Type.VAR_INT, 0); + wrapper.set(Type.VAR_INT, 0, handleBlockID(idx)); } - } - ); + }); + } + }); - // Multi Block Change Packet - protocol.registerOutgoing(State.PLAY, 0x10, 0x10, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.MULTI_BLOCK_CHANGE, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Chunk X + map(Type.INT); // 1 - Chunk Z + map(Type.BLOCK_CHANGE_RECORD_ARRAY); + + handler(new PacketHandler() { @Override - public void registerMap() { - map(Type.INT); // 0 - Chunk X - map(Type.INT); // 1 - Chunk Z - map(Type.BLOCK_CHANGE_RECORD_ARRAY); - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { - record.setBlockId(handleBlockID(record.getBlockId())); - } - } - }); + public void handle(PacketWrapper wrapper) throws Exception { + for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { + record.setBlockId(handleBlockID(record.getBlockId())); + } } - } - ); + }); + } + }); - // Update Block Entity - protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Position @@ -277,8 +265,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter @Override protected void registerPackets() { - protocol.registerOutgoing(State.PLAY, 0x21, 0x21, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); @@ -63,8 +63,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter } }); - // Spawn Object - protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -102,14 +101,10 @@ public class EntityPackets1_11 extends LegacyEntityRewriter } }); - // Spawn Experience Orb - registerExtraTracker(0x01, Entity1_11Types.EntityType.EXPERIENCE_ORB); + registerExtraTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB); + registerExtraTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER); - // Spawn Global Entity - registerExtraTracker(0x02, Entity1_11Types.EntityType.WEATHER); - - // Spawn Mob - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -162,17 +157,11 @@ public class EntityPackets1_11 extends LegacyEntityRewriter } }); - // Spawn Painting - registerExtraTracker(0x04, Entity1_11Types.EntityType.PAINTING); + registerExtraTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING); + registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_11Types.EntityType.PLAYER); + registerRespawn(ClientboundPackets1_9_3.RESPAWN); - // Join game - registerJoinGame(0x23, 0x23, Entity1_11Types.EntityType.PLAYER); - - // Respawn Packet - registerRespawn(0x33, 0x33); - - // Spawn Player - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -188,14 +177,10 @@ public class EntityPackets1_11 extends LegacyEntityRewriter } }); - // Destroy entities - registerEntityDestroy(0x30); + registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST); - // Metadata packet - registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST); - - // Entity Status - protocol.registerOutgoing(State.PLAY, 0x1B, 0x1B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.ENTITY_STATUS, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java index bde99336..54d94b1a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/PlayerPackets1_11.java @@ -16,11 +16,12 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; public class PlayerPackets1_11 { - private static final ValueTransformer toNewFloat = new ValueTransformer(Type.FLOAT) { + private static final ValueTransformer TO_NEW_FLOAT = new ValueTransformer(Type.FLOAT) { @Override public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception { return inputValue / 15f; @@ -28,10 +29,7 @@ public class PlayerPackets1_11 { }; public void register(Protocol1_10To1_11 protocol) { - /* Outgoing packets */ - - // Title packet - protocol.registerOutgoing(State.PLAY, 0x45, 0x45, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.TITLE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Action @@ -57,44 +55,35 @@ public class PlayerPackets1_11 { return; } - if (action > 2) + if (action > 2) { wrapper.set(Type.VAR_INT, 0, action - 1); // Move everything one position down + } } }); - - } }); - // Collect item packet - protocol.registerOutgoing(State.PLAY, 0x48, 0x48, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Collected entity id map(Type.VAR_INT); // 1 - Collector entity id - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper packetWrapper) throws Exception { - packetWrapper.read(Type.VAR_INT); // Ignore pickup item count - } - }); + handler(wrapper -> wrapper.read(Type.VAR_INT)); // Ignore item pickup count } }); - /* Incoming packets */ - // Block placement packet - protocol.registerIncoming(State.PLAY, 0x1C, 0x1C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Location map(Type.VAR_INT); // 1 - Face map(Type.VAR_INT); // 2 - Hand - map(Type.UNSIGNED_BYTE, toNewFloat); - map(Type.UNSIGNED_BYTE, toNewFloat); - map(Type.UNSIGNED_BYTE, toNewFloat); + map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); + map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); + map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT); } }); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/SoundPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/SoundPackets1_11.java index 83051cdc..54b51c78 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/SoundPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/SoundPackets1_11.java @@ -16,7 +16,7 @@ import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; public class SoundPackets1_11 extends LegacySoundRewriter { @@ -26,8 +26,7 @@ public class SoundPackets1_11 extends LegacySoundRewriter { @Override protected void registerPackets() { - // Named sound effect - protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Sound name @@ -40,8 +39,7 @@ public class SoundPackets1_11 extends LegacySoundRewriter { } }); - // Sound effect - protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound name diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/Protocol1_11_1To1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/Protocol1_11_1To1_12.java index c6ce4f43..6863ea52 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/Protocol1_11_1To1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/Protocol1_11_1To1_12.java @@ -13,32 +13,49 @@ package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker; -import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.*; +import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.BlockItemPackets1_12; +import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.ChatPackets1_12; +import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.EntityPackets1_12; +import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.SoundPackets1_12; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_11_1To1_12 extends BackwardsProtocol { +public class Protocol1_11_1To1_12 extends BackwardsProtocol { + private EntityPackets1_12 entityPackets; private BlockItemPackets1_12 blockItemPackets; + public Protocol1_11_1To1_12() { + super(ClientboundPackets1_12.class, ClientboundPackets1_9_3.class, ServerboundPackets1_12.class, ServerboundPackets1_9_3.class); + } + @Override protected void registerPackets() { - new ChangedPacketIds1_12(this).register(); (entityPackets = new EntityPackets1_12(this)).register(); (blockItemPackets = new BlockItemPackets1_12(this)).register(); new SoundPackets1_12(this).register(); new ChatPackets1_12(this).register(); + + cancelOutgoing(ClientboundPackets1_12.ADVANCEMENTS); + cancelOutgoing(ClientboundPackets1_12.UNLOCK_RECIPES); + cancelOutgoing(ClientboundPackets1_12.SELECT_ADVANCEMENTS_TAB); } @Override public void init(UserConnection user) { // Register ClientWorld - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } user.put(new ShoulderTracker(user)); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java index eea134e8..a751c328 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java @@ -22,8 +22,9 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class BlockItemPackets1_12 extends LegacyBlockItemRewriter { @@ -34,7 +35,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter Trading - protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel @@ -113,53 +110,48 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter { - - public ChangedPacketIds1_12(Protocol1_11_1To1_12 protocol) { - super(protocol); - } - - @Override - protected void registerPackets() { - protocol.registerOutgoing(State.PLAY, 0x25, 0x28); // Entity - protocol.registerOutgoing(State.PLAY, 0x26, 0x25); // Entity Relative Move - protocol.registerOutgoing(State.PLAY, 0x27, 0x26); // Entity Look and Relative Move - protocol.registerOutgoing(State.PLAY, 0x28, 0x27); // Entity Look - - protocol.cancelOutgoing(State.PLAY, 0x30); // Unlock Recipes - - // 0x31 -> 0x30 Destroy Entities handled in EntityPackets1_12.java - protocol.registerOutgoing(State.PLAY, 0x32, 0x31); // Remove Entity Effect - protocol.registerOutgoing(State.PLAY, 0x33, 0x32); // Resource Pack Send - // 0x34 -> 0x33 Respawn handled in EntityPackets1_12.java - protocol.registerOutgoing(State.PLAY, 0x35, 0x34); // Entity Head Look - - protocol.cancelOutgoing(State.PLAY, 0x36); // Advancement Progress - - protocol.registerOutgoing(State.PLAY, 0x37, 0x35); // World Border - protocol.registerOutgoing(State.PLAY, 0x38, 0x36); //Camera - protocol.registerOutgoing(State.PLAY, 0x39, 0x37); // Held Item Change (ClientBound) - protocol.registerOutgoing(State.PLAY, 0x3A, 0x38); // Display Scoreboard - // 0x3B -> 0x39 Entity Metadata handled in EntityPackets1_12.java - protocol.registerOutgoing(State.PLAY, 0x3C, 0x3A); // Attach Entity - protocol.registerOutgoing(State.PLAY, 0x3D, 0x3B); // Entity Velocity - // 0x3E -> 0x3C Entity Equipment handled in BlockItemPackets1_12.java - protocol.registerOutgoing(State.PLAY, 0x3F, 0x3D); // Set Experience - protocol.registerOutgoing(State.PLAY, 0x40, 0x3E); // Update Health - protocol.registerOutgoing(State.PLAY, 0x41, 0x3F); // ScoreBoard Objective - protocol.registerOutgoing(State.PLAY, 0x42, 0x40); // Set Passengers - protocol.registerOutgoing(State.PLAY, 0x43, 0x41); // Teams - protocol.registerOutgoing(State.PLAY, 0x44, 0x42); // Update Score - protocol.registerOutgoing(State.PLAY, 0x45, 0x43); // Spawn Position - protocol.registerOutgoing(State.PLAY, 0x46, 0x44); // Time Update - protocol.registerOutgoing(State.PLAY, 0x47, 0x45); // Title - // 0x48 -> 0x46 Sound Effect handled in SoundPackets1_12.java - protocol.registerOutgoing(State.PLAY, 0x49, 0x47); // Player List Header And Footer - protocol.registerOutgoing(State.PLAY, 0x4A, 0x48); // Collect Item - protocol.registerOutgoing(State.PLAY, 0x4B, 0x49); // Entity Teleport - - protocol.cancelOutgoing(State.PLAY, 0x4C); // Advancements - - protocol.registerOutgoing(State.PLAY, 0x4E, 0x4B); // Entity Effect - - // New incoming packet 0x01 - Prepare Crafting Grid - protocol.registerIncoming(State.PLAY, 0x02, 0x01); // Tab-Complete (Serverbound) - protocol.registerIncoming(State.PLAY, 0x03, 0x02); // Chat Message (Serverbound) - // 0x04->0x03 Client Status handled in BlockItemPackets1_12.java - protocol.registerIncoming(State.PLAY, 0x05, 0x04); // Client Settings - protocol.registerIncoming(State.PLAY, 0x06, 0x05); // Confirm Transaction (Serverbound) - protocol.registerIncoming(State.PLAY, 0x07, 0x06); // Enchant Item - // 0x08 -> 0x07 Click Window handled in BlockItemPackets1_12.java - protocol.registerIncoming(State.PLAY, 0x09, 0x08); // Close Window (Serverbound) - protocol.registerIncoming(State.PLAY, 0x0A, 0x09); // Plugin message (Serverbound) - protocol.registerIncoming(State.PLAY, 0x0B, 0x0A); // Use Entity - protocol.registerIncoming(State.PLAY, 0x0C, 0x0B); // Keep Alive (Serverbound) - protocol.registerIncoming(State.PLAY, 0x0D, 0x0F); // Player - protocol.registerIncoming(State.PLAY, 0x0E, 0x0C); // Player Position - protocol.registerIncoming(State.PLAY, 0x0F, 0x0D); // Player Position And Look (ServerBound) - protocol.registerIncoming(State.PLAY, 0x10, 0x0E); // Player Look - protocol.registerIncoming(State.PLAY, 0x11, 0x10); // Vehicle Move - protocol.registerIncoming(State.PLAY, 0x12, 0x11); // Steer Boat - protocol.registerIncoming(State.PLAY, 0x13, 0x12); // Player Abilities (Serverbound) - protocol.registerIncoming(State.PLAY, 0x14, 0x13); // Player Digging - protocol.registerIncoming(State.PLAY, 0x15, 0x14); // Entity Action - protocol.registerIncoming(State.PLAY, 0x16, 0x15); // Steer Vehicle - // New incoming packet 0x17 - Crafting Book Data - protocol.registerIncoming(State.PLAY, 0x18, 0x16); // Resource Pack Status - // New incoming packet 0x19 - Advancement Tab - protocol.registerIncoming(State.PLAY, 0x1A, 0x17); // Held Item Change (Serverbound) - // 0x1B -> 0x18 Creative Inventory Action handled in BlockItemPackets.java - protocol.registerIncoming(State.PLAY, 0x1C, 0x19); // Update Sign - protocol.registerIncoming(State.PLAY, 0x1D, 0x1A); // Animatin (Serverbound) - protocol.registerIncoming(State.PLAY, 0x1E, 0x1B); // Spectate - protocol.registerIncoming(State.PLAY, 0x1F, 0x1C); // Player Block Placement - protocol.registerIncoming(State.PLAY, 0x20, 0x1D); // Use Item - } -} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java index 3de6fb83..344242e3 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatPackets1_12.java @@ -17,7 +17,7 @@ import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.AdvancementTrans import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import us.myles.ViaVersion.util.GsonUtil; import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonObject; @@ -32,8 +32,7 @@ public class ChatPackets1_12 extends Rewriter { @Override protected void registerPackets() { - // Chat Message (ClientBound) - protocol.registerOutgoing(State.PLAY, 0x0F, 0x0F, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Json Data @@ -42,10 +41,10 @@ public class ChatPackets1_12 extends Rewriter { handler(wrapper -> { try { JsonObject object = GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0)).getAsJsonObject(); - // Skip if the root doesn't contain translate - if (object.has("translate")) + if (object.has("translate")) { handleTranslations(object); + } ChatItemRewriter.toClient(object, wrapper.user()); wrapper.set(Type.STRING, 0, object.toString()); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java index 9da368f7..492c81d3 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java @@ -25,7 +25,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_12; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import java.util.Optional; @@ -38,8 +38,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter> 12 & 15; Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data); - if (block == null) + if (block == null) { return; + } wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12); } @@ -77,14 +77,10 @@ public class EntityPackets1_12 extends LegacyEntityRewriter { @@ -26,8 +26,7 @@ public class SoundPackets1_12 extends LegacySoundRewriter @Override protected void registerPackets() { - // Named sound effect - protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Sound name @@ -40,8 +39,7 @@ public class SoundPackets1_12 extends LegacySoundRewriter } }); - // Sound effect - protocol.registerOutgoing(State.PLAY, 0x48, 0x46, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound name @@ -57,13 +55,15 @@ public class SoundPackets1_12 extends LegacySoundRewriter public void handle(PacketWrapper wrapper) throws Exception { int oldId = wrapper.get(Type.VAR_INT, 0); int newId = handleSounds(oldId); - if (newId == -1) + if (newId == -1) { wrapper.cancel(); - else { - if (hasPitch(oldId)) - wrapper.set(Type.FLOAT, 1, handlePitch(oldId)); - wrapper.set(Type.VAR_INT, 0, newId); + return; } + + if (hasPitch(oldId)) { + wrapper.set(Type.FLOAT, 1, handlePitch(oldId)); + } + wrapper.set(Type.VAR_INT, 0, newId); } }); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java index 15c9852e..4e6278f8 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java @@ -15,11 +15,18 @@ import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets.EntityPackets1_11_1; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets.ItemPackets1_11_1; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_11To1_11_1 extends BackwardsProtocol { +public class Protocol1_11To1_11_1 extends BackwardsProtocol { + private EntityPackets1_11_1 entityPackets; + public Protocol1_11To1_11_1() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); + } + @Override protected void registerPackets() { (entityPackets = new EntityPackets1_11_1(this)).register(); @@ -29,12 +36,14 @@ public class Protocol1_11To1_11_1 extends BackwardsProtocol { @Override public void init(UserConnection user) { // Register ClientWorld - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } // Init protocol in EntityTracker user.get(EntityTracker.class).initProtocol(this); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java index cb413ac2..cfcd1f79 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java @@ -17,7 +17,7 @@ import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_9; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; public class EntityPackets1_11_1 extends LegacyEntityRewriter { @@ -27,8 +27,7 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter Trading - protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel @@ -63,8 +59,9 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter { Metadata data = e.getData(); - if (data.getMetaType().getType().equals(Type.ITEM)) // Is Item + if (data.getMetaType().getType().equals(Type.ITEM)) { // Is Item data.setValue(handleItemToClient((Item) data.getValue())); + } return data; }); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java index fb398902..de5dd7e0 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java @@ -16,14 +16,18 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; + +public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { + + public Protocol1_12_1To1_12_2() { + super(ClientboundPackets1_12_1.class, ClientboundPackets1_12_1.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12_1.class); + } -public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { @Override protected void registerPackets() { - // Outgoing - // 0x1f - Keep alive - registerOutgoing(State.PLAY, 0x1f, 0x1f, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -37,9 +41,7 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { } }); - // Incoming - // 0xb - Keep alive - registerIncoming(State.PLAY, 0xb, 0xb, new PacketRemapper() { + registerIncoming(ServerboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index 291e7bcf..041f03fd 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -1,11 +1,11 @@ /* * Copyright (c) 2016 Matsv * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software withregisterOutgoing restriction, including withregisterOutgoing limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHregisterOutgoing WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, registerOutgoing OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13; @@ -24,19 +24,24 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBl import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage; -import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.remapper.PacketRemapper; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.viaversion.libs.gson.JsonObject; -public class Protocol1_12_2To1_13 extends BackwardsProtocol { +public class Protocol1_12_2To1_13 extends BackwardsProtocol { private BlockItemPackets1_13 blockItemPackets; + public Protocol1_12_2To1_13() { + super(ClientboundPackets1_13.class, ClientboundPackets1_12_1.class, ServerboundPackets1_13.class, ServerboundPackets1_12_1.class); + } + @Override protected void registerPackets() { executeAsyncAfterLoaded(Protocol1_13To1_12_2.class, () -> { @@ -55,123 +60,60 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol { } }; translatableRewriter.registerPing(); - translatableRewriter.registerBossBar(0x0C, 0x0C); - translatableRewriter.registerChatMessage(0x0E, 0x0F); - translatableRewriter.registerLegacyOpenWindow(0x14, 0x13); - translatableRewriter.registerDisconnect(0x1B, 0x1A); - translatableRewriter.registerCombatEvent(0x2F, 0x2D); - translatableRewriter.registerTitle(0x4B, 0x48); - translatableRewriter.registerPlayerList(0x4E, 0x4A); + translatableRewriter.registerBossBar(ClientboundPackets1_13.BOSSBAR); + translatableRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE); + translatableRewriter.registerLegacyOpenWindow(ClientboundPackets1_13.OPEN_WINDOW); + translatableRewriter.registerDisconnect(ClientboundPackets1_13.DISCONNECT); + translatableRewriter.registerCombatEvent(ClientboundPackets1_13.COMBAT_EVENT); + translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE); + translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST); (blockItemPackets = new BlockItemPackets1_13(this)).register(); new EntityPackets1_13(this).register(); new PlayerPacket1_13(this).register(); new SoundPackets1_13(this).register(); - // Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150 + cancelOutgoing(ClientboundPackets1_13.DECLARE_COMMANDS); //TODO + cancelOutgoing(ClientboundPackets1_13.NBT_QUERY); + cancelOutgoing(ClientboundPackets1_13.CRAFT_RECIPE_RESPONSE); + cancelOutgoing(ClientboundPackets1_13.UNLOCK_RECIPES); + cancelOutgoing(ClientboundPackets1_13.ADVANCEMENTS); + cancelOutgoing(ClientboundPackets1_13.DECLARE_RECIPES); //TODO ? + cancelOutgoing(ClientboundPackets1_13.TAGS); - out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW - out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound) - out(State.PLAY, 0x13, 0x12); // Close Window (clientbound) - out(State.PLAY, 0x1C, 0x1B); // Entity Status - out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer) - out(State.PLAY, 0x1E, 0x1C); // Explosion - out(State.PLAY, 0x20, 0x1E); // Change Game State - out(State.PLAY, 0x21, 0x1F); // Keep Alive (clientbound) - out(State.PLAY, 0x27, 0x25); // Entity - out(State.PLAY, 0x28, 0x26); // Entity Relative Move - out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move - out(State.PLAY, 0x2A, 0x28); // Entity Look - out(State.PLAY, 0x2B, 0x29); // Vehicle Move (clientbound) - out(State.PLAY, 0x2C, 0x2A); // Open Sign Editor - out(State.PLAY, 0x2D, 0x2B, cancel()); // Craft Recipe Response TODO MODIFIED - out(State.PLAY, 0x2E, 0x2C); // Player Abilities (clientbound) - out(State.PLAY, 0x33, 0x30); // Use Bed - out(State.PLAY, 0x34, 0x31, cancel()); // Unlock Recipes TODO MODIFIED - out(State.PLAY, 0x36, 0x33); // Remove Entity Effect - out(State.PLAY, 0x37, 0x34); // Resource Pack Send - out(State.PLAY, 0x39, 0x36); // Entity Head Look - out(State.PLAY, 0x3A, 0x37); // Select Advancement Tab - out(State.PLAY, 0x3B, 0x38); // World Border - out(State.PLAY, 0x3C, 0x39); // Camera - out(State.PLAY, 0x3D, 0x3A); // Held Item Change (clientbound) - out(State.PLAY, 0x3E, 0x3B); // Display Scoreboard - out(State.PLAY, 0x40, 0x3D); // Attach Entity - out(State.PLAY, 0x41, 0x3E); // Entity Velocity - out(State.PLAY, 0x43, 0x40); // Set Experience - out(State.PLAY, 0x44, 0x41); // Update Health - out(State.PLAY, 0x46, 0x43); // Set Passengers - out(State.PLAY, 0x48, 0x45); // Update Score - out(State.PLAY, 0x49, 0x46); // Spawn Position - out(State.PLAY, 0x4A, 0x47); // Time Update - out(State.PLAY, 0x4F, 0x4B); // Collect Item - out(State.PLAY, 0x50, 0x4C); // Entity Teleport - out(State.PLAY, 0x51, 0x4D, cancel()); // Advancements - out(State.PLAY, 0x52, 0x4E); // Entity Properties - out(State.PLAY, 0x53, 0x4F); // Entity Effect - out(State.PLAY, 0x54, -1, cancel()); // Declare Recipes TODO NEW - out(State.PLAY, 0x55, -1, cancel()); // Tags (the client won't need this) - - in(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound) - in(State.PLAY, 0x07, 0x06); // Enchant Item - in(State.PLAY, 0x09, 0x08); // Close Window (serverbound) - in(State.PLAY, 0x0D, 0x0A); // Use Entity - in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound) - in(State.PLAY, 0x0F, 0x0C); // Player - in(State.PLAY, 0x12, 0x0F); // Player Look - in(State.PLAY, 0x14, 0x11); // Steer Boat - in(State.PLAY, 0x16, 0x12, cancel()); // Craft Recipe Request TODO MODIFIED - in(State.PLAY, 0x17, 0x13); // Player Abilities (serverbound) - in(State.PLAY, 0x18, 0x14); // Player Digging - in(State.PLAY, 0x19, 0x15); // Entity Action - in(State.PLAY, 0x1A, 0x16); // Steer Vehicle - in(State.PLAY, 0x1B, 0x17, cancel()); // Recipe Book Data TODO MODIFIED - in(State.PLAY, 0x1D, 0x18); // Resource Pack Status - in(State.PLAY, 0x1E, 0x19); // Advancement Tab - //in(State.PLAY, 0x1F, -1); // Select Trade (the client won't send this) - //in(State.PLAY, 0x20, -1); // Set Beacon Effect (the client won't send this) - in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound) - in(State.PLAY, 0x26, 0x1C); // Update Sign - in(State.PLAY, 0x27, 0x1D); // Animation (serverbound) - in(State.PLAY, 0x28, 0x1E); // Spectate - in(State.PLAY, 0x29, 0x1F); // Player Block Placement - in(State.PLAY, 0x2A, 0x20); // Use Item + cancelIncoming(ServerboundPackets1_12_1.CRAFT_RECIPE_REQUEST); + cancelIncoming(ServerboundPackets1_12_1.RECIPE_BOOK_DATA); } @Override public void init(UserConnection user) { // Register ClientWorld - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } // Init protocol in EntityTracker user.get(EntityTracker.class).initProtocol(this); // Register Block Storage - if (!user.has(BackwardsBlockStorage.class)) + if (!user.has(BackwardsBlockStorage.class)) { user.put(new BackwardsBlockStorage(user)); + } // Register Block Storage - if (!user.has(TabCompleteStorage.class)) + if (!user.has(TabCompleteStorage.class)) { user.put(new TabCompleteStorage(user)); + } if (ViaBackwards.getConfig().isFix1_13FacePlayer() && !user.has(PlayerPositionStorage1_13.class)) { user.put(new PlayerPositionStorage1_13(user)); } } - public PacketRemapper cancel() { - return new PacketRemapper() { - @Override - public void registerMap() { - handler(PacketWrapper::cancel); - } - }; - } - public BlockItemPackets1_13 getBlockItemPackets() { return blockItemPackets; } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index d4d7e288..db8e054e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -30,8 +30,9 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter; @@ -93,8 +94,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It @Override protected void registerPackets() { - // Set Cooldown - protocol.out(State.PLAY, 0x18, 0x17, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.COOLDOWN, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -116,8 +116,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Block Action - protocol.out(State.PLAY, 0x0A, 0x0A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // Location @@ -156,8 +155,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Update Block Entity - protocol.out(State.PLAY, 0x09, 0x09, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Position @@ -185,8 +183,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Unload chunk - protocol.registerOutgoing(State.PLAY, 0x1F, 0x1D, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.UNLOAD_CHUNK, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -208,7 +205,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It }); // Block Change - protocol.out(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Position @@ -233,7 +230,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It }); // Multi Block Change - protocol.out(State.PLAY, 0x0F, 0x10, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.MULTI_BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Chunk X @@ -269,8 +266,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); - // Windows Items - protocol.out(State.PLAY, 0x15, 0x14, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.WINDOW_ITEMS, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); @@ -280,8 +276,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Set Slot - protocol.out(State.PLAY, 0x17, 0x16, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SET_SLOT, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); @@ -292,127 +287,121 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Chunk packet - protocol.out(State.PLAY, 0x22, 0x20, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk1_9_3_4Type type_old = new Chunk1_9_3_4Type(clientWorld); - Chunk1_13Type type = new Chunk1_13Type(clientWorld); - Chunk chunk = wrapper.read(type); + Chunk1_9_3_4Type type_old = new Chunk1_9_3_4Type(clientWorld); + Chunk1_13Type type = new Chunk1_13Type(clientWorld); + Chunk chunk = wrapper.read(type); - // Handle Block Entities before block rewrite - BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); - BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); - for (CompoundTag tag : chunk.getBlockEntities()) { - Tag idTag = tag.get("id"); - if (idTag == null) continue; + // Handle Block Entities before block rewrite + BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); + BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); + for (CompoundTag tag : chunk.getBlockEntities()) { + Tag idTag = tag.get("id"); + if (idTag == null) continue; - String id = (String) idTag.getValue(); + String id = (String) idTag.getValue(); - // Ignore if we don't handle it - if (!provider.isHandled(id)) continue; + // Ignore if we don't handle it + if (!provider.isHandled(id)) continue; - int sectionIndex = ((int) tag.get("y").getValue()) >> 4; - ChunkSection section = chunk.getSections()[sectionIndex]; + int sectionIndex = ((int) tag.get("y").getValue()) >> 4; + ChunkSection section = chunk.getSections()[sectionIndex]; - int x = (int) tag.get("x").getValue(); - int y = (int) tag.get("y").getValue(); - int z = (int) tag.get("z").getValue(); - Position position = new Position(x, (short) y, z); + int x = (int) tag.get("x").getValue(); + int y = (int) tag.get("y").getValue(); + int z = (int) tag.get("z").getValue(); + Position position = new Position(x, (short) y, z); - int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF); - storage.checkAndStore(position, block); + int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF); + storage.checkAndStore(position, block); - provider.transform(wrapper.user(), position, tag); - } - - // Rewrite new blocks to old blocks - for (int i = 0; i < chunk.getSections().length; i++) { - ChunkSection section = chunk.getSections()[i]; - if (section == null) { - continue; - } - - // Flower pots require a special treatment, they are no longer block entities :( - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - for (int x = 0; x < 16; x++) { - int block = section.getFlatBlock(x, y, z); - - // Check if the block is a flower - if (FlowerPotHandler.isFlowah(block)) { - Position pos = new Position( - (x + (chunk.getX() << 4)), - (short) (y + (i << 4)), - (z + (chunk.getZ() << 4)) - ); - // Store block - storage.checkAndStore(pos, block); - - CompoundTag nbt = provider.transform(wrapper.user(), pos, "minecraft:flower_pot"); - - chunk.getBlockEntities().add(nbt); - } - } - } - } - - for (int p = 0; p < section.getPaletteSize(); p++) { - int old = section.getPaletteEntry(p); - if (old != 0) { - int oldId = toOldId(old); - section.setPaletteEntry(p, oldId); - } - } - } - - - if (chunk.isBiomeData()) { - for (int i = 0; i < 256; i++) { - int biome = chunk.getBiomeData()[i]; - int newId = -1; - switch (biome) { - case 40: // end biomes - case 41: - case 42: - case 43: - newId = 9; - break; - case 47: // deep ocean biomes - case 48: - case 49: - newId = 24; - break; - case 50: // deep frozen... let's just pick the frozen variant - newId = 10; - break; - case 44: // the other new ocean biomes - case 45: - case 46: - newId = 0; - break; - } - - if (newId != -1) { - chunk.getBiomeData()[i] = newId; - } - } - } - - wrapper.write(type_old, chunk); - } - }); + provider.transform(wrapper.user(), position, tag); } - } - ); - // Effect - protocol.out(State.PLAY, 0x23, 0x21, new PacketRemapper() { + // Rewrite new blocks to old blocks + for (int i = 0; i < chunk.getSections().length; i++) { + ChunkSection section = chunk.getSections()[i]; + if (section == null) { + continue; + } + + // Flower pots require a special treatment, they are no longer block entities :( + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + for (int x = 0; x < 16; x++) { + int block = section.getFlatBlock(x, y, z); + + // Check if the block is a flower + if (FlowerPotHandler.isFlowah(block)) { + Position pos = new Position( + (x + (chunk.getX() << 4)), + (short) (y + (i << 4)), + (z + (chunk.getZ() << 4)) + ); + // Store block + storage.checkAndStore(pos, block); + + CompoundTag nbt = provider.transform(wrapper.user(), pos, "minecraft:flower_pot"); + + chunk.getBlockEntities().add(nbt); + } + } + } + } + + for (int p = 0; p < section.getPaletteSize(); p++) { + int old = section.getPaletteEntry(p); + if (old != 0) { + int oldId = toOldId(old); + section.setPaletteEntry(p, oldId); + } + } + } + + + if (chunk.isBiomeData()) { + for (int i = 0; i < 256; i++) { + int biome = chunk.getBiomeData()[i]; + int newId = -1; + switch (biome) { + case 40: // end biomes + case 41: + case 42: + case 43: + newId = 9; + break; + case 47: // deep ocean biomes + case 48: + case 49: + newId = 24; + break; + case 50: // deep frozen... let's just pick the frozen variant + newId = 10; + break; + case 44: // the other new ocean biomes + case 45: + case 46: + newId = 0; + break; + } + + if (newId != -1) { + chunk.getBiomeData()[i] = newId; + } + } + } + + wrapper.write(type_old, chunk); + }); + } + }); + + protocol.registerOutgoing(ClientboundPackets1_13.EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id @@ -436,8 +425,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Map - protocol.out(State.PLAY, 0x26, 0x24, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.MAP_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -468,8 +456,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Entity Equipment - protocol.out(State.PLAY, 0x42, 0x3F, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.ENTITY_EQUIPMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -480,8 +467,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Window Property - protocol.out(State.PLAY, 0x16, 0x15, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.WINDOW_PROPERTY, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Window Id @@ -499,8 +485,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It }); - // Set Creative Slot - protocol.in(State.PLAY, 0x24, 0x1B, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_12_1.CREATIVE_INVENTORY_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.SHORT); @@ -510,8 +495,7 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Click Window - protocol.in(State.PLAY, 0x08, 0x07, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_12_1.CLICK_WINDOW, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index ac3c547b..6e415edb 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -22,8 +22,9 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.api.type.types.version.Types1_13; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import java.util.Optional; @@ -35,8 +36,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter wrapper.user().get(PlayerPositionStorage1_13.class).setCoordinates(wrapper, false)); } }; - protocol.in(State.PLAY, 0x10, 0x0D, movementRemapper); // Player Position - protocol.in(State.PLAY, 0x11, 0x0E, movementRemapper); // Player Position And Look (serverbound) - protocol.in(State.PLAY, 0x13, 0x10, movementRemapper); // Vehicle Move (serverbound) - } else { - protocol.in(State.PLAY, 0x10, 0x0D); // Player Position - protocol.in(State.PLAY, 0x11, 0x0E); // Player Position And Look (serverbound) - protocol.in(State.PLAY, 0x13, 0x10); // Vehicle Move (serverbound) + protocol.registerIncoming(ServerboundPackets1_12_1.PLAYER_POSITION, movementRemapper); // Player Position + protocol.registerIncoming(ServerboundPackets1_12_1.PLAYER_POSITION_AND_ROTATION, movementRemapper); // Player Position And Look (serverbound) + protocol.registerIncoming(ServerboundPackets1_12_1.VEHICLE_MOVE, movementRemapper); // Vehicle Move (serverbound) } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index f86e72a6..970c576b 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -17,7 +17,9 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import java.nio.charset.StandardCharsets; @@ -35,7 +37,7 @@ public class PlayerPacket1_13 extends Rewriter { @Override protected void registerPackets() { // Login Plugin Request - protocol.out(State.LOGIN, 0x04, -1, new PacketRemapper() { + protocol.registerOutgoing(State.LOGIN, 0x04, -1, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -54,8 +56,7 @@ public class PlayerPacket1_13 extends Rewriter { } }); - //Plugin Message - protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -100,12 +101,12 @@ public class PlayerPacket1_13 extends Rewriter { if (oldChannel.equals("REGISTER") || oldChannel.equals("UNREGISTER")) { String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); List rewrittenChannels = new ArrayList<>(); - for (int i = 0; i < channels.length; i++) { - String rewritten = InventoryPackets.getOldPluginChannelId(channels[i]); + for (String s : channels) { + String rewritten = InventoryPackets.getOldPluginChannelId(s); if (rewritten != null) { rewrittenChannels.add(rewritten); } else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { - ViaBackwards.getPlatform().getLogger().warning("Ignoring plugin channel in outgoing REGISTER: " + channels[i]); + ViaBackwards.getPlatform().getLogger().warning("Ignoring plugin channel in outgoing REGISTER: " + s); } } wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); @@ -116,8 +117,7 @@ public class PlayerPacket1_13 extends Rewriter { } }); - // Spawn Particle - protocol.out(State.PLAY, 0x24, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID @@ -130,7 +130,6 @@ public class PlayerPacket1_13 extends Rewriter { map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count - handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -147,8 +146,7 @@ public class PlayerPacket1_13 extends Rewriter { } }); - // Player List Item - protocol.out(State.PLAY, 0x30, 0x2E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.PLAYER_INFO, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -192,8 +190,7 @@ public class PlayerPacket1_13 extends Rewriter { } }); - //Scoreboard Objective - protocol.out(State.PLAY, 0x45, 0x42, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SCOREBOARD_OBJECTIVE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -215,8 +212,7 @@ public class PlayerPacket1_13 extends Rewriter { } }); - //Teams - protocol.out(State.PLAY, 0x47, 0x44, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.TEAMS, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -274,8 +270,7 @@ public class PlayerPacket1_13 extends Rewriter { } }); - // Tab-Complete (clientbound) - protocol.out(State.PLAY, 0x10, 0x0E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -311,67 +306,64 @@ public class PlayerPacket1_13 extends Rewriter { } }); - // Tab-Complete (serverbound) - protocol.in(State.PLAY, 0x05, 0x01, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_12_1.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class); - int id = ThreadLocalRandom.current().nextInt(); - wrapper.write(Type.VAR_INT, id); + handler(wrapper -> { + TabCompleteStorage storage = wrapper.user().get(TabCompleteStorage.class); + int id = ThreadLocalRandom.current().nextInt(); + wrapper.write(Type.VAR_INT, id); - String command = wrapper.read(Type.STRING); - boolean assumeCommand = wrapper.read(Type.BOOLEAN); - wrapper.read(Type.OPTIONAL_POSITION); + String command = wrapper.read(Type.STRING); + boolean assumeCommand = wrapper.read(Type.BOOLEAN); + wrapper.read(Type.OPTIONAL_POSITION); - if (!assumeCommand) { - if (command.startsWith("/")) { - command = command.substring(1); - } else { - wrapper.cancel(); - PacketWrapper response = wrapper.create(0xE); - List usernames = new ArrayList<>(); - for (String value : storage.usernames.values()) { - if (value.toLowerCase().startsWith(command.substring(command.lastIndexOf(' ') + 1).toLowerCase())) { - usernames.add(value); - } + if (!assumeCommand) { + if (command.startsWith("/")) { + command = command.substring(1); + } else { + wrapper.cancel(); + PacketWrapper response = wrapper.create(0xE); + List usernames = new ArrayList<>(); + for (String value : storage.usernames.values()) { + if (value.toLowerCase().startsWith(command.substring(command.lastIndexOf(' ') + 1).toLowerCase())) { + usernames.add(value); } - response.write(Type.VAR_INT, usernames.size()); - for (String value : usernames) { - response.write(Type.STRING, value); - } - response.send(protocol.getClass()); } + response.write(Type.VAR_INT, usernames.size()); + for (String value : usernames) { + response.write(Type.STRING, value); + } + response.send(protocol.getClass()); } - - wrapper.write(Type.STRING, command); - storage.lastId = id; - storage.lastAssumeCommand = assumeCommand; - storage.lastRequest = command; } + + wrapper.write(Type.STRING, command); + storage.lastId = id; + storage.lastAssumeCommand = assumeCommand; + storage.lastRequest = command; }); } }); - //Plugin Message - protocol.in(State.PLAY, 0x0A, 0x09, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - String channel = wrapper.read(Type.STRING); - if (channel.equals("MC|BSign") || channel.equals("MC|BEdit")) { + handler(wrapper -> { + String channel = wrapper.read(Type.STRING); + switch (channel) { + case "MC|BSign": + case "MC|BEdit": wrapper.setId(0x0B); Item book = wrapper.read(Type.ITEM); wrapper.write(Type.FLAT_ITEM, getProtocol().getBlockItemPackets().handleItemToServer(book)); boolean signing = channel.equals("MC|BSign"); wrapper.write(Type.BOOLEAN, signing); - } else if (channel.equals("MC|ItemName")) { + break; + case "MC|ItemName": wrapper.setId(0x1C); - } else if (channel.equals("MC|AdvCmd")) { + break; + case "MC|AdvCmd": byte type = wrapper.read(Type.BYTE); if (type == 0) { //Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089 @@ -389,7 +381,8 @@ public class PlayerPacket1_13 extends Rewriter { } else { wrapper.cancel(); } - } else if (channel.equals("MC|AutoCmd")) { + break; + case "MC|AutoCmd": { wrapper.setId(0x22); int x = wrapper.read(Type.INT); @@ -400,6 +393,7 @@ public class PlayerPacket1_13 extends Rewriter { wrapper.passthrough(Type.STRING); //Command + byte flags = 0; if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Track Output @@ -412,7 +406,9 @@ public class PlayerPacket1_13 extends Rewriter { if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Automatic wrapper.write(Type.BYTE, flags); - } else if (channel.equals("MC|Struct")) { + break; + } + case "MC|Struct": { wrapper.setId(0x25); int x = wrapper.read(Type.INT); int y = wrapper.read(Type.INT); @@ -423,34 +419,52 @@ public class PlayerPacket1_13 extends Rewriter { int modeId = mode.equals("SAVE") ? 0 : mode.equals("LOAD") ? 1 : mode.equals("CORNER") ? 2 : 3; wrapper.write(Type.VAR_INT, modeId); wrapper.passthrough(Type.STRING); //Name + wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset X + wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Y + wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Z + wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size X + wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Y + wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Z + String mirror = wrapper.read(Type.STRING); int mirrorId = mode.equals("NONE") ? 0 : mode.equals("LEFT_RIGHT") ? 1 : 2; String rotation = wrapper.read(Type.STRING); int rotationId = mode.equals("NONE") ? 0 : mode.equals("CLOCKWISE_90") ? 1 : mode.equals("CLOCKWISE_180") ? 2 : 3; wrapper.passthrough(Type.STRING); //Metadata + byte flags = 0; if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Ignore entities if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Show air if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Show bounding box wrapper.passthrough(Type.FLOAT); //Integrity + wrapper.passthrough(Type.VAR_LONG); //Seed + wrapper.write(Type.BYTE, flags); - } else if (channel.equals("MC|Beacon")) { + break; + } + case "MC|Beacon": wrapper.setId(0x20); wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Primary Effect + wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Secondary Effect - } else if (channel.equals("MC|TrSel")) { + + break; + case "MC|TrSel": wrapper.setId(0x1F); wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Slot - } else if (channel.equals("MC|PickItem")) { + + break; + case "MC|PickItem": wrapper.setId(0x15); - } else { + break; + default: String newChannel = InventoryPackets.getNewPluginChannelId(channel); if (newChannel == null) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { @@ -464,12 +478,12 @@ public class PlayerPacket1_13 extends Rewriter { if (newChannel.equals("minecraft:register") || newChannel.equals("minecraft:unregister")) { String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); List rewrittenChannels = new ArrayList<>(); - for (int i = 0; i < channels.length; i++) { - String rewritten = InventoryPackets.getNewPluginChannelId(channels[i]); + for (String s : channels) { + String rewritten = InventoryPackets.getNewPluginChannelId(s); if (rewritten != null) { rewrittenChannels.add(rewritten); } else if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { - ViaBackwards.getPlatform().getLogger().warning("Ignoring plugin channel in incoming REGISTER: " + channels[i]); + ViaBackwards.getPlatform().getLogger().warning("Ignoring plugin channel in incoming REGISTER: " + s); } } if (!rewrittenChannels.isEmpty()) { @@ -479,14 +493,13 @@ public class PlayerPacket1_13 extends Rewriter { return; } } - } + break; } }); } }); - // Statistics - protocol.out(State.PLAY, 0x07, 0x07, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.STATISTICS, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -527,8 +540,9 @@ public class PlayerPacket1_13 extends Rewriter { wrapper.passthrough(Type.VAR_INT); // value } - if (newSize != size) + if (newSize != size) { wrapper.set(Type.VAR_INT, 0, newSize); + } } }); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java index 5a1a8893..ac5a0154 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java @@ -8,7 +8,8 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMappin import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; public class SoundPackets1_13 extends Rewriter { private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}; @@ -19,8 +20,7 @@ public class SoundPackets1_13 extends Rewriter { @Override protected void registerPackets() { - // Named Sound Event - protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -36,8 +36,8 @@ public class SoundPackets1_13 extends Rewriter { } }); - // Stop Sound - protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() { + // Stop Sound -> Plugin Message + protocol.registerOutgoing(ClientboundPackets1_13.STOP_SOUND, ClientboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -66,8 +66,7 @@ public class SoundPackets1_13 extends Rewriter { } }); - // Sound Effect - protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/Protocol1_12To1_12_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/Protocol1_12To1_12_1.java index 8ecc75c9..32a8df36 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/Protocol1_12To1_12_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/Protocol1_12To1_12_1.java @@ -1,83 +1,20 @@ -/* - * Copyright (c) 2016 Matsv - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package nl.matsv.viabackwards.protocol.protocol1_12to1_12_1; import nl.matsv.viabackwards.api.BackwardsProtocol; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; + +public class Protocol1_12To1_12_1 extends BackwardsProtocol { + + public Protocol1_12To1_12_1() { + super(ClientboundPackets1_12_1.class, ClientboundPackets1_12.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12.class); + } -public class Protocol1_12To1_12_1 extends BackwardsProtocol { @Override protected void registerPackets() { - cancelOutgoing(State.PLAY, 0x2B); //TODO - registerOutgoing(State.PLAY, 0x2c, 0x2b); - registerOutgoing(State.PLAY, 0x2d, 0x2c); - registerOutgoing(State.PLAY, 0x2e, 0x2d); - registerOutgoing(State.PLAY, 0x2f, 0x2e); - registerOutgoing(State.PLAY, 0x30, 0x2f); - registerOutgoing(State.PLAY, 0x31, 0x30); - registerOutgoing(State.PLAY, 0x32, 0x31); - registerOutgoing(State.PLAY, 0x33, 0x32); - registerOutgoing(State.PLAY, 0x34, 0x33); - registerOutgoing(State.PLAY, 0x35, 0x34); - registerOutgoing(State.PLAY, 0x36, 0x35); - registerOutgoing(State.PLAY, 0x37, 0x36); - registerOutgoing(State.PLAY, 0x38, 0x37); - registerOutgoing(State.PLAY, 0x39, 0x38); - registerOutgoing(State.PLAY, 0x3a, 0x39); - registerOutgoing(State.PLAY, 0x3b, 0x3a); - registerOutgoing(State.PLAY, 0x3c, 0x3b); - registerOutgoing(State.PLAY, 0x3d, 0x3c); - registerOutgoing(State.PLAY, 0x3e, 0x3d); - registerOutgoing(State.PLAY, 0x3f, 0x3e); - registerOutgoing(State.PLAY, 0x40, 0x3f); - registerOutgoing(State.PLAY, 0x41, 0x40); - registerOutgoing(State.PLAY, 0x42, 0x41); - registerOutgoing(State.PLAY, 0x43, 0x42); - registerOutgoing(State.PLAY, 0x44, 0x43); - registerOutgoing(State.PLAY, 0x45, 0x44); - registerOutgoing(State.PLAY, 0x46, 0x45); - registerOutgoing(State.PLAY, 0x47, 0x46); - registerOutgoing(State.PLAY, 0x48, 0x47); - registerOutgoing(State.PLAY, 0x49, 0x48); - registerOutgoing(State.PLAY, 0x4a, 0x49); - registerOutgoing(State.PLAY, 0x4b, 0x4a); - registerOutgoing(State.PLAY, 0x4c, 0x4b); - registerOutgoing(State.PLAY, 0x4d, 0x4c); - registerOutgoing(State.PLAY, 0x4e, 0x4d); - registerOutgoing(State.PLAY, 0x4f, 0x4e); - - cancelIncoming(State.PLAY, 0x01); //TODO - registerIncoming(State.PLAY, 0x1, 0x2); - registerIncoming(State.PLAY, 0x2, 0x3); - registerIncoming(State.PLAY, 0x3, 0x4); - registerIncoming(State.PLAY, 0x4, 0x5); - registerIncoming(State.PLAY, 0x5, 0x6); - registerIncoming(State.PLAY, 0x6, 0x7); - registerIncoming(State.PLAY, 0x7, 0x8); - registerIncoming(State.PLAY, 0x8, 0x9); - registerIncoming(State.PLAY, 0x9, 0xa); - registerIncoming(State.PLAY, 0xa, 0xb); - registerIncoming(State.PLAY, 0xb, 0xc); - registerIncoming(State.PLAY, 0xc, 0xd); - registerIncoming(State.PLAY, 0xd, 0xe); - registerIncoming(State.PLAY, 0xe, 0xf); - registerIncoming(State.PLAY, 0xf, 0x10); - registerIncoming(State.PLAY, 0x10, 0x11); - registerIncoming(State.PLAY, 0x11, 0x12); - // New incoming 0x12 - No sent by client, sad :( - } - - @Override - public void init(UserConnection userConnection) { - + cancelOutgoing(ClientboundPackets1_12_1.CRAFT_RECIPE_RESPONSE); + cancelIncoming(ServerboundPackets1_12.PREPARE_CRAFTING_GRID); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java index 33f7af9e..cae0d384 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java @@ -5,14 +5,18 @@ import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPacke import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets1_13_2; import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets1_13_2; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; -public class Protocol1_13_1To1_13_2 extends BackwardsProtocol { +public class Protocol1_13_1To1_13_2 extends BackwardsProtocol { + + public Protocol1_13_1To1_13_2() { + super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class); + } @Override protected void registerPackets() { @@ -20,16 +24,14 @@ public class Protocol1_13_1To1_13_2 extends BackwardsProtocol { WorldPackets1_13_2.register(this); EntityPackets1_13_2.register(this); - //Edit Book - registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); } }); - // Advancements - registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -71,9 +73,4 @@ public class Protocol1_13_1To1_13_2 extends BackwardsProtocol { } }); } - - @Override - public void init(UserConnection userConnection) { - - } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java index 945d9a61..84e64b0a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java @@ -1,23 +1,22 @@ package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets; +import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2; -import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13_2; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; public class EntityPackets1_13_2 { - public static void register(Protocol protocol) { - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + public static void register(Protocol1_13_1To1_13_2 protocol) { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -47,8 +46,7 @@ public class EntityPackets1_13_2 { } }); - // Spawn player packet - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -73,8 +71,7 @@ public class EntityPackets1_13_2 { } }); - // Metadata packet - protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.ENTITY_METADATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java index 0c2b6370..5ab28782 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java @@ -1,21 +1,17 @@ package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets; +import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; public class InventoryPackets1_13_2 { - public static void register(Protocol protocol) { - /* - Outgoing packets - */ - - // Set slot packet - protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { + public static void register(Protocol1_13_1To1_13_2 protocol) { + protocol.registerOutgoing(ClientboundPackets1_13.SET_SLOT, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); // 0 - Window ID @@ -24,8 +20,7 @@ public class InventoryPackets1_13_2 { } }); - // Window items packet - protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.WINDOW_ITEMS, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID @@ -33,8 +28,7 @@ public class InventoryPackets1_13_2 { } }); - // Plugin message - protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // Channel @@ -67,8 +61,7 @@ public class InventoryPackets1_13_2 { } }); - // Entity Equipment Packet - protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.ENTITY_EQUIPMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -77,8 +70,7 @@ public class InventoryPackets1_13_2 { } }); - // Declare Recipes - protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.DECLARE_RECIPES, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -117,32 +109,24 @@ public class InventoryPackets1_13_2 { } }); - /* - Incoming packets - */ + protocol.registerIncoming(ServerboundPackets1_13.CLICK_WINDOW, new PacketRemapper() { + @Override + public void registerMap() { + 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.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 5 - Clicked Item + } + }); - // Click window packet - protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() { - @Override - public void registerMap() { - 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.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 5 - Clicked Item - } - } - ); - - // Creative Inventory Action - protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.SHORT); // 0 - Slot - map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 1 - Clicked Item - } - } - ); + protocol.registerIncoming(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.SHORT); // 0 - Slot + map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 1 - Clicked Item + } + }); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java index 92d31a2e..f8d9317f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java @@ -1,17 +1,16 @@ package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets; +import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; public class WorldPackets1_13_2 { - public static void register(Protocol protocol) { - //spawn particle - protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { + public static void register(Protocol1_13_1To1_13_2 protocol) { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java index d662312f..37f8cce4 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java @@ -15,27 +15,34 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_13_2To1_14 extends BackwardsProtocol { +public class Protocol1_13_2To1_14 extends BackwardsProtocol { private BlockItemPackets1_14 blockItemPackets; private EntityPackets1_14 entityPackets; + public Protocol1_13_2To1_14() { + super(ClientboundPackets1_14.class, ClientboundPackets1_13.class, ServerboundPackets1_14.class, ServerboundPackets1_13.class); + } + @Override protected void registerPackets() { executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, BackwardsMappings::init); TranslatableRewriter translatableRewriter = new TranslatableRewriter(this); - translatableRewriter.registerBossBar(0x0C, 0x0C); - translatableRewriter.registerChatMessage(0x0E, 0x0E); - translatableRewriter.registerCombatEvent(0x32, 0x2F); - translatableRewriter.registerDisconnect(0x1A, 0x1B); - translatableRewriter.registerPlayerList(0x53, 0x4E); - translatableRewriter.registerTitle(0x4F, 0x4B); + translatableRewriter.registerBossBar(ClientboundPackets1_14.BOSSBAR); + translatableRewriter.registerChatMessage(ClientboundPackets1_14.CHAT_MESSAGE); + translatableRewriter.registerCombatEvent(ClientboundPackets1_14.COMBAT_EVENT); + translatableRewriter.registerDisconnect(ClientboundPackets1_14.DISCONNECT); + translatableRewriter.registerTabList(ClientboundPackets1_14.TAB_LIST); + translatableRewriter.registerTitle(ClientboundPackets1_14.TITLE); translatableRewriter.registerPing(); blockItemPackets = new BlockItemPackets1_14(this, translatableRewriter); @@ -45,45 +52,11 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { new PlayerPackets1_14(this).register(); new SoundPackets1_14(this).register(); - registerOutgoing(State.PLAY, 0x15, 0x16); - registerOutgoing(State.PLAY, 0x18, 0x19); - registerOutgoing(State.PLAY, 0x54, 0x1D); - registerOutgoing(State.PLAY, 0x1E, 0x20); - registerOutgoing(State.PLAY, 0x20, 0x21); - registerOutgoing(State.PLAY, 0x2B, 0x27); - registerOutgoing(State.PLAY, 0x2C, 0x2B); - registerOutgoing(State.PLAY, 0x30, 0x2D); - registerOutgoing(State.PLAY, 0x31, 0x2E); - registerOutgoing(State.PLAY, 0x33, 0x30); - registerOutgoing(State.PLAY, 0x34, 0x31); - registerOutgoing(State.PLAY, 0x35, 0x32); - registerOutgoing(State.PLAY, 0x36, 0x34); - registerOutgoing(State.PLAY, 0x38, 0x36); - registerOutgoing(State.PLAY, 0x39, 0x37); - registerOutgoing(State.PLAY, 0x3B, 0x39); - registerOutgoing(State.PLAY, 0x3C, 0x3A); - registerOutgoing(State.PLAY, 0x3D, 0x3B); - registerOutgoing(State.PLAY, 0x3E, 0x3C); - registerOutgoing(State.PLAY, 0x3F, 0x3D); - registerOutgoing(State.PLAY, 0x42, 0x3E); - registerOutgoing(State.PLAY, 0x44, 0x40); - registerOutgoing(State.PLAY, 0x45, 0x41); - registerOutgoing(State.PLAY, 0x47, 0x43); - registerOutgoing(State.PLAY, 0x48, 0x44); - registerOutgoing(State.PLAY, 0x49, 0x45); - registerOutgoing(State.PLAY, 0x4A, 0x46); - registerOutgoing(State.PLAY, 0x4B, 0x47); - registerOutgoing(State.PLAY, 0x4C, 0x48); - registerOutgoing(State.PLAY, 0x4E, 0x4A); - registerOutgoing(State.PLAY, 0x55, 0x4F); + cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_POSITION); + cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE); + cancelOutgoing(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING); - // Update View Position - cancelOutgoing(State.PLAY, 0x40); - - // Update View Distance - cancelOutgoing(State.PLAY, 0x41); - - registerOutgoing(State.PLAY, 0x57, 0x51, new PacketRemapper() { // c + registerOutgoing(ClientboundPackets1_14.ADVANCEMENTS, new PacketRemapper() { // c @Override public void registerMap() { handler(new PacketHandler() { @@ -124,13 +97,9 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { } }); - registerOutgoing(State.PLAY, 0x58, 0x52); // c - registerOutgoing(State.PLAY, 0x59, 0x53); // c - - // Tags - registerOutgoing(State.PLAY, 0x5B, 0x55, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.TAGS, new PacketRemapper() { @Override - public void registerMap() { // c + public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -175,9 +144,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { } }); - - // Light update - out(State.PLAY, 0x24, -1, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.UPDATE_LIGHT, null, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -231,51 +198,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { }); } }); - - - //Incomming - - //Unknown packet added in 19w11a - 0x02 - registerIncoming(State.PLAY, 0x03, 0x02); // r - registerIncoming(State.PLAY, 0x04, 0x03); // r - registerIncoming(State.PLAY, 0x05, 0x04); // r - registerIncoming(State.PLAY, 0x06, 0x05); // r - registerIncoming(State.PLAY, 0x07, 0x06); // r - registerIncoming(State.PLAY, 0x08, 0x07); // r - - registerIncoming(State.PLAY, 0x0A, 0x09); // r - registerIncoming(State.PLAY, 0x0B, 0x0A); // r - - registerIncoming(State.PLAY, 0x0D, 0x0C); // r - registerIncoming(State.PLAY, 0x0E, 0x0D); // r - //Unknown packet added in 19w11a - 0x0F - registerIncoming(State.PLAY, 0x0F, 0x0E); // r - registerIncoming(State.PLAY, 0x11, 0x10); // r - registerIncoming(State.PLAY, 0x12, 0x11); // r - registerIncoming(State.PLAY, 0x13, 0x12); // r - registerIncoming(State.PLAY, 0x14, 0x0F); // r - registerIncoming(State.PLAY, 0x15, 0x13); // r - registerIncoming(State.PLAY, 0x16, 0x14); // r - registerIncoming(State.PLAY, 0x17, 0x15); // r - registerIncoming(State.PLAY, 0x18, 0x16); // r - registerIncoming(State.PLAY, 0x19, 0x17); // r - - registerIncoming(State.PLAY, 0x1B, 0x19); // r - registerIncoming(State.PLAY, 0x1C, 0x1A); // r - - registerIncoming(State.PLAY, 0x1E, 0x1C); // r - registerIncoming(State.PLAY, 0x1F, 0x1D); // r - registerIncoming(State.PLAY, 0x20, 0x1E); // r - registerIncoming(State.PLAY, 0x21, 0x1F); // r - registerIncoming(State.PLAY, 0x22, 0x20); // r - registerIncoming(State.PLAY, 0x23, 0x21); // r - - registerIncoming(State.PLAY, 0x25, 0x23); // r - -// registerIncoming(State.PLAY, 0x29, 0x27); // r - registerIncoming(State.PLAY, 0x2A, 0x27); // r - registerIncoming(State.PLAY, 0x2B, 0x28); // r - registerIncoming(State.PLAY, 0x2D, 0x2A); // r } public static int getNewBlockStateId(int id) { @@ -297,22 +219,24 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { return newId; } - @Override public void init(UserConnection user) { // Register ClientWorld - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } // Init protocol in EntityTracker user.get(EntityTracker.class).initProtocol(this); - if (!user.has(ChunkLightStorage.class)) + if (!user.has(ChunkLightStorage.class)) { user.put(new ChunkLightStorage(user)); + } } public BlockItemPackets1_14 getBlockItemPackets() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/data/RecipeRewriter1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/data/RecipeRewriter1_14.java index 1c009b1e..b466a464 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/data/RecipeRewriter1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/data/RecipeRewriter1_14.java @@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.type.Type; public class RecipeRewriter1_14 extends RecipeRewriter { - public RecipeRewriter1_14(final ItemRewriterBase rewriter) { + public RecipeRewriter1_14(ItemRewriterBase rewriter) { super(rewriter); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index 72a99f95..708fd46f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -26,9 +26,11 @@ import us.myles.ViaVersion.api.rewriters.BlockRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_13; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -54,18 +56,16 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It @Override protected void registerPackets() { - // Edit Book - protocol.registerIncoming(State.PLAY, 0x0C, 0x0B, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); } }); - // Open window - protocol.registerOutgoing(State.PLAY, 0x2E, 0x14, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.OPEN_WINDOW, new PacketRemapper() { @Override - public void registerMap() { // c + public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -156,10 +156,10 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Horse window - protocol.registerOutgoing(State.PLAY, 0x1F, 0x14, new PacketRemapper() { + // Horse window -> Open Window + protocol.registerOutgoing(ClientboundPackets1_14.OPEN_HORSE_WINDOW, ClientboundPackets1_13.OPEN_WINDOW, new PacketRemapper() { @Override - public void registerMap() { // c + public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -176,17 +176,12 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13_2To1_14::getNewBlockStateId, Protocol1_13_2To1_14::getNewBlockId); - // Set cooldown - itemRewriter.registerSetCooldown(0x17, 0x18, BlockItemPackets1_14::getOldItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN, BlockItemPackets1_14::getOldItemId); + itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); + itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x14, 0x15); - - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x16, 0x17); - - // Trade list - protocol.out(State.PLAY, 0x27, 0x19, new PacketRemapper() { + // Trade List -> Plugin Message + protocol.registerOutgoing(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -234,8 +229,8 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Book open - protocol.registerOutgoing(State.PLAY, 0x2D, 0x19, new PacketRemapper() { + // Open Book -> Plugin Message + protocol.registerOutgoing(ClientboundPackets1_14.OPEN_BOOK, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -248,8 +243,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Entity Equipment Packet - protocol.registerOutgoing(State.PLAY, 0x46, 0x42, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.ENTITY_EQUIPMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -286,8 +280,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Declare Recipes - protocol.registerOutgoing(State.PLAY, 0x5A, 0x54, new PacketRemapper() { // c + protocol.registerOutgoing(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() { // c @Override public void registerMap() { handler(new PacketHandler() { @@ -334,18 +327,11 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - /* - Incoming packets - */ - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x08); + itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x26, 0x24); - - // Block break animation - protocol.registerOutgoing(State.PLAY, 0x08, 0x08, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.BLOCK_BREAK_ANIMATION, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -354,16 +340,14 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Update block entity - protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION1_14, Type.POSITION); } }); - // Block Action - protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.BLOCK_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION1_14, Type.POSITION); // Location @@ -379,8 +363,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Block Change - protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION1_14, Type.POSITION); @@ -396,11 +379,9 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Multi Block Change - blockRewriter.registerMultiBlockChange(0xF, 0xF); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_14.MULTI_BLOCK_CHANGE); - //Explosion - protocol.registerOutgoing(State.PLAY, 0x1C, 0x1E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.EXPLOSION, new PacketRemapper() { @Override public void registerMap() { map(Type.FLOAT); // X @@ -423,8 +404,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - //Chunk - protocol.registerOutgoing(State.PLAY, 0x21, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -477,8 +457,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Unload chunk - protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.UNLOAD_CHUNK, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -492,8 +471,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Effect packet - protocol.registerOutgoing(State.PLAY, 0x22, 0x23, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id @@ -514,12 +492,10 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Spawn particle - blockRewriter.registerSpawnParticle(Type.FLOAT, 0x23, 0x24, 3, 23, 32, - EntityPackets1_14::getOldParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM); + blockRewriter.registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, 3, 23, 32, + EntityPackets1_14::getOldParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM, Type.FLOAT); - //Map Data - protocol.registerOutgoing(State.PLAY, 0x26, 0x26, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.MAP_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -529,8 +505,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Spawn position - protocol.registerOutgoing(State.PLAY, 0x4D, 0x49, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_POSITION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION1_14, Type.POSITION); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index beac0b65..a213b2dd 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -27,7 +27,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.version.Types1_13_2; import us.myles.ViaVersion.api.type.types.version.Types1_14; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class EntityPackets1_14 extends LegacyEntityRewriter { @@ -55,8 +55,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter { @@ -81,8 +80,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter { @@ -17,8 +18,7 @@ public class PlayerPackets1_14 extends Rewriter { @Override protected void registerPackets() { - // Server Difficulty - protocol.registerOutgoing(State.PLAY, 0x0D, 0x0D, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.SERVER_DIFFICULTY, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); @@ -26,25 +26,20 @@ public class PlayerPackets1_14 extends Rewriter { } }); - // Open Sign Editor - protocol.registerOutgoing(State.PLAY, 0x2F, 0x2C, new PacketRemapper() { // c + protocol.registerOutgoing(ClientboundPackets1_14.OPEN_SIGN_EDITOR, new PacketRemapper() { // c @Override public void registerMap() { map(Type.POSITION1_14, Type.POSITION); } }); - - // Query Block NBT - protocol.registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.QUERY_BLOCK_NBT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); map(Type.POSITION, Type.POSITION1_14); } }); - - // Player Digging - protocol.registerIncoming(State.PLAY, 0x1A, 0x18, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.PLAYER_DIGGING, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -53,8 +48,7 @@ public class PlayerPackets1_14 extends Rewriter { } }); - // Recipe Book Data - protocol.registerIncoming(State.PLAY, 0x1D, 0x1B, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.RECIPE_BOOK_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -81,32 +75,26 @@ public class PlayerPackets1_14 extends Rewriter { } }); - // Update Command Block - protocol.registerIncoming(State.PLAY, 0x24, 0x22, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION, Type.POSITION1_14); + } + }); + protocol.registerIncoming(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION, Type.POSITION1_14); + } + }); + protocol.registerIncoming(ServerboundPackets1_13.UPDATE_SIGN, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION, Type.POSITION1_14); } }); - // Update Structure Block - protocol.registerIncoming(State.PLAY, 0x28, 0x25, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.POSITION, Type.POSITION1_14); - } - }); - - // Update Sign - protocol.registerIncoming(State.PLAY, 0x29, 0x26, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.POSITION, Type.POSITION1_14); - } - }); - - // Player Block Placement - protocol.registerIncoming(State.PLAY, 0x2C, 0x29, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java index 16b1642a..3d4ed4c1 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/SoundPackets1_14.java @@ -10,7 +10,7 @@ import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositio import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; public class SoundPackets1_14 extends Rewriter { @@ -22,12 +22,12 @@ public class SoundPackets1_14 extends Rewriter { protected void registerPackets() { SoundRewriter soundRewriter = new SoundRewriter(protocol, id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId)); - soundRewriter.registerSound(0x51, 0x4D); - soundRewriter.registerNamedSound(0x19, 0x1A); - soundRewriter.registerStopSound(0x52, 0x4C); + soundRewriter.registerSound(ClientboundPackets1_14.SOUND); + soundRewriter.registerNamedSound(ClientboundPackets1_14.NAMED_SOUND); + soundRewriter.registerStopSound(ClientboundPackets1_14.STOP_SOUND); // Entity Sound Effect - protocol.registerOutgoing(State.PLAY, 0x50, -1, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.ENTITY_SOUND, null, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index e41950b2..7b9a6d99 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -13,10 +13,15 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_13To1_13_1 extends BackwardsProtocol { +public class Protocol1_13To1_13_1 extends BackwardsProtocol { + + public Protocol1_13To1_13_1() { + super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class); + } @Override protected void registerPackets() { @@ -25,16 +30,15 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { WorldPackets1_13_1.register(this); TranslatableRewriter translatableRewriter = new TranslatableRewriter(this); - translatableRewriter.registerChatMessage(0x0E, 0x0E); - translatableRewriter.registerLegacyOpenWindow(0x14, 0x14); - translatableRewriter.registerCombatEvent(0x2F, 0x2F); - translatableRewriter.registerDisconnect(0x1B, 0x1B); - translatableRewriter.registerPlayerList(0x4E, 0x4E); - translatableRewriter.registerTitle(0x4B, 0x4B); + translatableRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE); + translatableRewriter.registerLegacyOpenWindow(ClientboundPackets1_13.OPEN_WINDOW); + translatableRewriter.registerCombatEvent(ClientboundPackets1_13.COMBAT_EVENT); + translatableRewriter.registerDisconnect(ClientboundPackets1_13.DISCONNECT); + translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST); + translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE); translatableRewriter.registerPing(); - //Tab complete - registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -48,8 +52,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); - //Edit Book - registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { map(Type.FLAT_ITEM); @@ -64,8 +67,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); - // Tab complete - registerOutgoing(State.PLAY, 0x10, 0x10, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Transaction id @@ -91,8 +93,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); - // Boss bar - registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.BOSSBAR, new PacketRemapper() { @Override public void registerMap() { map(Type.UUID); @@ -117,9 +118,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); - - // Advancements - registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -161,8 +160,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } }); - // Tags - registerOutgoing(State.PLAY, 0x55, 0x55, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.TAGS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java index 797840ad..4143f423 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java @@ -14,7 +14,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_13; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; public class EntityPackets1_13_1 extends LegacyEntityRewriter { @@ -24,8 +24,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter { - @Override - protected void registerPackets() { - } - - @Override - public void init(UserConnection userConnection) { + public Protocol1_14_1To1_14_2() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java index e442d84b..94863436 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java @@ -2,18 +2,21 @@ package nl.matsv.viabackwards.protocol.protocol1_14_2to1_14_3; import nl.matsv.viabackwards.api.BackwardsProtocol; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -public class Protocol1_14_2To1_14_3 extends BackwardsProtocol { +public class Protocol1_14_2To1_14_3 extends BackwardsProtocol { + + public Protocol1_14_2To1_14_3() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); + } @Override protected void registerPackets() { - // Trade list - registerOutgoing(State.PLAY, 0x27, 0x27, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -44,8 +47,7 @@ public class Protocol1_14_2To1_14_3 extends BackwardsProtocol { } }); - // Declare recipes - registerOutgoing(State.PLAY, 0x5A, 0x5A, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -66,30 +68,51 @@ public class Protocol1_14_2To1_14_3 extends BackwardsProtocol { wrapper.write(Type.STRING, fullType); wrapper.write(Type.STRING, id); - if (type.equals("crafting_shapeless")) { - wrapper.passthrough(Type.STRING); // Group - int ingredientsNo = wrapper.passthrough(Type.VAR_INT); - for (int j = 0; j < ingredientsNo; j++) { - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + switch (type) { + case "crafting_shapeless": { + wrapper.passthrough(Type.STRING); // Group + + int ingredientsNo = wrapper.passthrough(Type.VAR_INT); + for (int j = 0; j < ingredientsNo; j++) { + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + } + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);// Result + + break; } - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);// Result - } 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 j = 0; j < ingredientsNo; j++) { - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + case "crafting_shaped": { + int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); + wrapper.passthrough(Type.STRING); // Group + + for (int j = 0; j < ingredientsNo; j++) { + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + } + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);// Result + + break; } - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);// Result - } else if (type.equals("stonecutting")) { - wrapper.passthrough(Type.STRING); // Group? - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); // Result - } else if (type.equals("smelting") || type.equals("blasting") || type.equals("campfire_cooking") || type.equals("smoking")) { - wrapper.passthrough(Type.STRING); // Group - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients - wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); - wrapper.passthrough(Type.FLOAT); // EXP - wrapper.passthrough(Type.VAR_INT); // Cooking time + case "stonecutting": + wrapper.passthrough(Type.STRING); // Group? + + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); // Result + + break; + case "smelting": + case "blasting": + case "campfire_cooking": + case "smoking": + wrapper.passthrough(Type.STRING); // Group + + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients + + wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); + wrapper.passthrough(Type.FLOAT); // EXP + + wrapper.passthrough(Type.VAR_INT); // Cooking time + + break; } } @@ -99,8 +122,4 @@ public class Protocol1_14_2To1_14_3 extends BackwardsProtocol { } }); } - - @Override - public void init(UserConnection userConnection) { - } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_3to1_14_4/Protocol1_14_3To1_14_4.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_3to1_14_4/Protocol1_14_3To1_14_4.java index dc2a050c..f00c20f6 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_3to1_14_4/Protocol1_14_3To1_14_4.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_3to1_14_4/Protocol1_14_3To1_14_4.java @@ -2,18 +2,22 @@ package nl.matsv.viabackwards.protocol.protocol1_14_3to1_14_4; import nl.matsv.viabackwards.api.BackwardsProtocol; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -public class Protocol1_14_3To1_14_4 extends BackwardsProtocol { +public class Protocol1_14_3To1_14_4 extends BackwardsProtocol { + + public Protocol1_14_3To1_14_4() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); + } @Override protected void registerPackets() { // Acknowledge Player Digging - added in pre4 - registerOutgoing(State.PLAY, 0x5C, 0x0B, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION1_14); @@ -21,13 +25,14 @@ public class Protocol1_14_3To1_14_4 extends BackwardsProtocol { handler(wrapper -> { int status = wrapper.read(Type.VAR_INT); boolean allGood = wrapper.read(Type.BOOLEAN); - if (allGood && status == 0) wrapper.cancel(); + if (allGood && status == 0) { + wrapper.cancel(); + } }); } }); - // Trade list - registerOutgoing(State.PLAY, 0x27, 0x27, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -54,8 +59,4 @@ public class Protocol1_14_3To1_14_4 extends BackwardsProtocol { } }); } - - @Override - public void init(UserConnection userConnection) { - } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java index cfe7fd23..9ea9473d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/Protocol1_14_4To1_15.java @@ -16,26 +16,33 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_14_4To1_15 extends BackwardsProtocol { +public class Protocol1_14_4To1_15 extends BackwardsProtocol { private BlockItemPackets1_15 blockItemPackets; + public Protocol1_14_4To1_15() { + super(ClientboundPackets1_15.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); + } + @Override protected void registerPackets() { executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, BackwardsMappings::init); TranslatableRewriter translatableRewriter = new TranslatableRewriter(this); - translatableRewriter.registerBossBar(0x0D, 0x0C); - translatableRewriter.registerChatMessage(0x0F, 0x0E); - translatableRewriter.registerCombatEvent(0x33, 0x32); - translatableRewriter.registerDisconnect(0x1B, 0x1A); - translatableRewriter.registerOpenWindow(0x2F, 0x2E); - translatableRewriter.registerPlayerList(0x54, 0x53); - translatableRewriter.registerTitle(0x50, 0x4F); + translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR); + translatableRewriter.registerChatMessage(ClientboundPackets1_15.CHAT_MESSAGE); + translatableRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT); + translatableRewriter.registerDisconnect(ClientboundPackets1_15.DISCONNECT); + translatableRewriter.registerOpenWindow(ClientboundPackets1_15.OPEN_WINDOW); + translatableRewriter.registerTabList(ClientboundPackets1_15.TAB_LIST); + translatableRewriter.registerTitle(ClientboundPackets1_15.TITLE); translatableRewriter.registerPing(); (blockItemPackets = new BlockItemPackets1_15(this, translatableRewriter)).register(); @@ -43,13 +50,13 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol { SoundRewriter soundRewriter = new SoundRewriter(this, id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId)); - soundRewriter.registerSound(0x52, 0x51); - soundRewriter.registerSound(0x51, 0x50); - soundRewriter.registerNamedSound(0x1A, 0x19); - soundRewriter.registerStopSound(0x53, 0x52); + soundRewriter.registerSound(ClientboundPackets1_15.SOUND); + soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND); + soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND); + soundRewriter.registerStopSound(ClientboundPackets1_15.STOP_SOUND); // Explosion - manually send an explosion sound - registerOutgoing(State.PLAY, 0x1D, 0x1C, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_15.EXPLOSION, new PacketRemapper() { @Override public void registerMap() { map(Type.FLOAT); // x @@ -73,8 +80,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol { } }); - // Advancements - registerOutgoing(State.PLAY, 0x58, 0x57, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_15.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -113,8 +119,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol { } }); - // Tags - registerOutgoing(State.PLAY, 0x5C, 0x5B, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_15.TAGS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -158,58 +163,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol { }); } }); - - registerOutgoing(State.PLAY, 0x09, 0x08); - registerOutgoing(State.PLAY, 0x0A, 0x09); - registerOutgoing(State.PLAY, 0x0E, 0x0D); - registerOutgoing(State.PLAY, 0x11, 0x10); - registerOutgoing(State.PLAY, 0x12, 0x11); - registerOutgoing(State.PLAY, 0x13, 0x12); - registerOutgoing(State.PLAY, 0x14, 0x13); - registerOutgoing(State.PLAY, 0x16, 0x15); - registerOutgoing(State.PLAY, 0x19, 0x18); - registerOutgoing(State.PLAY, 0x1C, 0x1B); - registerOutgoing(State.PLAY, 0x1E, 0x1D); - registerOutgoing(State.PLAY, 0x20, 0x1F); - registerOutgoing(State.PLAY, 0x21, 0x20); - registerOutgoing(State.PLAY, 0x25, 0x24); - registerOutgoing(State.PLAY, 0x27, 0x26); - registerOutgoing(State.PLAY, 0x29, 0x28); - registerOutgoing(State.PLAY, 0x2A, 0x29); - registerOutgoing(State.PLAY, 0x2B, 0x2A); - registerOutgoing(State.PLAY, 0x2C, 0x2B); - registerOutgoing(State.PLAY, 0x2D, 0x2C); - registerOutgoing(State.PLAY, 0x2E, 0x2D); - registerOutgoing(State.PLAY, 0x30, 0x2F); - registerOutgoing(State.PLAY, 0x31, 0x30); - registerOutgoing(State.PLAY, 0x32, 0x31); - registerOutgoing(State.PLAY, 0x34, 0x33); - registerOutgoing(State.PLAY, 0x35, 0x34); - registerOutgoing(State.PLAY, 0x36, 0x35); - registerOutgoing(State.PLAY, 0x37, 0x36); - registerOutgoing(State.PLAY, 0x39, 0x38); - registerOutgoing(State.PLAY, 0x3A, 0x39); - registerOutgoing(State.PLAY, 0x3C, 0x3B); - registerOutgoing(State.PLAY, 0x3D, 0x3C); - registerOutgoing(State.PLAY, 0x3E, 0x3D); - registerOutgoing(State.PLAY, 0x3F, 0x3E); - registerOutgoing(State.PLAY, 0x40, 0x3F); - registerOutgoing(State.PLAY, 0x41, 0x40); - registerOutgoing(State.PLAY, 0x42, 0x41); - registerOutgoing(State.PLAY, 0x43, 0x42); - registerOutgoing(State.PLAY, 0x45, 0x44); - registerOutgoing(State.PLAY, 0x46, 0x45); - registerOutgoing(State.PLAY, 0x48, 0x47); - registerOutgoing(State.PLAY, 0x4A, 0x49); - registerOutgoing(State.PLAY, 0x4B, 0x4A); - registerOutgoing(State.PLAY, 0x4C, 0x4B); - registerOutgoing(State.PLAY, 0x4D, 0x4C); - registerOutgoing(State.PLAY, 0x4E, 0x4D); - registerOutgoing(State.PLAY, 0x4F, 0x4E); - registerOutgoing(State.PLAY, 0x55, 0x54); - registerOutgoing(State.PLAY, 0x56, 0x55); - registerOutgoing(State.PLAY, 0x57, 0x56); - registerOutgoing(State.PLAY, 0x5A, 0x59); } public static int getNewBlockStateId(int id) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java index fc72f998..793644fa 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/data/RecipeRewriter1_15.java @@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.type.Type; public class RecipeRewriter1_15 extends RecipeRewriter1_14 { - public RecipeRewriter1_15(final ItemRewriterBase rewriter) { + public RecipeRewriter1_15(ItemRewriterBase rewriter) { super(rewriter); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java index ea57d162..fbc7b61f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java @@ -15,8 +15,9 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.BlockRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -32,28 +33,20 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_14_4To1_15::getNewBlockStateId, Protocol1_14_4To1_15::getNewBlockId); - // Declare Recipes - new RecipeRewriter1_15(this).registerDefaultHandler(0x5B, 0x5A); + new RecipeRewriter1_15(this).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES); - // Edit Book - protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); } }); - // Set cooldown - itemRewriter.registerSetCooldown(0x18, 0x17, BlockItemPackets1_15::getOldItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN, BlockItemPackets1_15::getOldItemId); + itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); + itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x15, 0x14); - - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x17, 0x16); - - // Trade list - protocol.out(State.PLAY, 0x28, 0x27, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -92,29 +85,16 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x46); + itemRewriter.registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09); + blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING); + blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE); - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x26, 0x26); - - // Acknowledge player digging - blockRewriter.registerAcknowledgePlayerDigging(0x08, 0x5C); - - // Block Action - blockRewriter.registerBlockAction(0x0B, 0x0A); - - // Block Change - blockRewriter.registerBlockChange(0x0C, 0x0B); - - // Multi Block Change - blockRewriter.registerMultiBlockChange(0x10, 0x0F); - - // Chunk - protocol.registerOutgoing(State.PLAY, 0x22, 0x21, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -161,11 +141,9 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Effect packet - blockRewriter.registerEffect(0x23, 0x22, 1010, 2001, BlockItemPackets1_15::getOldItemId); + blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, BlockItemPackets1_15::getOldItemId); - // Spawn particle - protocol.registerOutgoing(State.PLAY, 0x24, 0x23, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/EntityPackets1_15.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/EntityPackets1_15.java index ad4360f5..efca8b06 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/EntityPackets1_15.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14_4to1_15/packets/EntityPackets1_15.java @@ -17,7 +17,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.version.Types1_14; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import java.util.ArrayList; @@ -29,8 +29,7 @@ public class EntityPackets1_15 extends EntityRewriter { @Override protected void registerPackets() { - // Update health - protocol.registerOutgoing(State.PLAY, 0x49, 0x48, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.UPDATE_HEALTH, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -46,8 +45,7 @@ public class EntityPackets1_15 extends EntityRewriter { } }); - // Change game state - protocol.registerOutgoing(State.PLAY, 0x1F, 0x1E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.GAME_EVENT, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); @@ -60,11 +58,9 @@ public class EntityPackets1_15 extends EntityRewriter { } }); - // Spawn Object - registerSpawnTrackerWithData(0x00, 0x00, Entity1_15Types.EntityType.FALLING_BLOCK, Protocol1_14_4To1_15::getNewBlockStateId); + registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_15Types.EntityType.FALLING_BLOCK, Protocol1_14_4To1_15::getNewBlockStateId); - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -90,8 +86,7 @@ public class EntityPackets1_15 extends EntityRewriter { } }); - // Respawn - protocol.registerOutgoing(State.PLAY, 0x3B, 0x3A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); @@ -100,8 +95,7 @@ public class EntityPackets1_15 extends EntityRewriter { } }); - // Join Game - protocol.registerOutgoing(State.PLAY, 0x26, 0x25, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -122,17 +116,11 @@ public class EntityPackets1_15 extends EntityRewriter { } }); - // Spawn Experience Orb - registerExtraTracker(0x01, Entity1_15Types.EntityType.EXPERIENCE_ORB); + registerExtraTracker(ClientboundPackets1_15.SPAWN_EXPERIENCE_ORB, Entity1_15Types.EntityType.EXPERIENCE_ORB); + registerExtraTracker(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, Entity1_15Types.EntityType.LIGHTNING_BOLT); + registerExtraTracker(ClientboundPackets1_15.SPAWN_PAINTING, Entity1_15Types.EntityType.PAINTING); - // Spawn Global Object - registerExtraTracker(0x02, Entity1_15Types.EntityType.LIGHTNING_BOLT); - - // Spawn painting - registerExtraTracker(0x04, Entity1_15Types.EntityType.PAINTING); - - // Spawn player packet - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -148,14 +136,11 @@ public class EntityPackets1_15 extends EntityRewriter { } }); - // Destroy entities - registerEntityDestroy(0x38, 0x37); - - // Entity Metadata packet - registerMetadataRewriter(0x44, 0x43, Types1_14.METADATA_LIST); + registerEntityDestroy(ClientboundPackets1_15.DESTROY_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST); // Attributes (get rid of generic.flyingSpeed for the Bee remap) - protocol.registerOutgoing(State.PLAY, 0x59, 0x58, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/Protocol1_14To1_14_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/Protocol1_14To1_14_1.java index 955963ef..d5a3b716 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/Protocol1_14To1_14_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/Protocol1_14To1_14_1.java @@ -4,8 +4,15 @@ import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_14to1_14_1.packets.EntityPackets1_14_1; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; -public class Protocol1_14To1_14_1 extends BackwardsProtocol { +public class Protocol1_14To1_14_1 extends BackwardsProtocol { + + public Protocol1_14To1_14_1() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); + } @Override protected void registerPackets() { @@ -15,8 +22,9 @@ public class Protocol1_14To1_14_1 extends BackwardsProtocol { @Override public void init(UserConnection user) { // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } // Init protocol in EntityTracker user.get(EntityTracker.class).initProtocol(this); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/packets/EntityPackets1_14_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/packets/EntityPackets1_14_1.java index af9ad5e0..b9a24c70 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/packets/EntityPackets1_14_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_14to1_14_1/packets/EntityPackets1_14_1.java @@ -10,7 +10,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_14; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; public class EntityPackets1_14_1 extends LegacyEntityRewriter { @@ -20,15 +20,14 @@ public class EntityPackets1_14_1 extends LegacyEntityRewriter { - @Override - protected void registerPackets() { - } - - @Override - public void init(UserConnection userConnection) { + public Protocol1_15_1To1_15_2() { + super(ClientboundPackets1_15.class, ClientboundPackets1_15.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java index 10b7b363..f020f432 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/Protocol1_15_2To1_16.java @@ -14,35 +14,42 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.TagRewriter; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.UUID; -public class Protocol1_15_2To1_16 extends BackwardsProtocol { +public class Protocol1_15_2To1_16 extends BackwardsProtocol { private BlockItemPackets1_16 blockItemPackets; private TranslatableRewriter translatableRewriter; + public Protocol1_15_2To1_16() { + super(ClientboundPackets1_16.class, ClientboundPackets1_15.class, ServerboundPackets1_16.class, ServerboundPackets1_14.class); + } + @Override protected void registerPackets() { executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, BackwardsMappings::init); translatableRewriter = new TranslatableRewriter1_16(this); - translatableRewriter.registerBossBar(0x0C, 0x0D); - translatableRewriter.registerCombatEvent(0x32, 0x33); - translatableRewriter.registerDisconnect(0x1A, 0x1B); - translatableRewriter.registerPlayerList(0x53, 0x54); - translatableRewriter.registerTitle(0x4F, 0x50); + translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR); + translatableRewriter.registerCombatEvent(ClientboundPackets1_16.COMBAT_EVENT); + translatableRewriter.registerDisconnect(ClientboundPackets1_16.DISCONNECT); + translatableRewriter.registerTabList(ClientboundPackets1_16.TAB_LIST); + translatableRewriter.registerTitle(ClientboundPackets1_16.TITLE); translatableRewriter.registerPing(); (blockItemPackets = new BlockItemPackets1_16(this, translatableRewriter)).register(); EntityPackets1_16 entityPackets = new EntityPackets1_16(this); entityPackets.register(); - // Chat Message - registerOutgoing(State.PLAY, 0x0E, 0x0F, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_16.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> wrapper.write(Type.STRING, translatableRewriter.processText(wrapper.read(Type.STRING)))); @@ -51,8 +58,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { } }); - // Open Window - registerOutgoing(State.PLAY, 0x2E, 0x2F, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_16.OPEN_WINDOW, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Window Id @@ -71,10 +77,10 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { SoundRewriter soundRewriter = new SoundRewriter(this, id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId)); - soundRewriter.registerSound(0x50, 0x51); - soundRewriter.registerSound(0x51, 0x52); - soundRewriter.registerNamedSound(0x10, 0x1A); - soundRewriter.registerStopSound(0x52, 0x53); + soundRewriter.registerSound(ClientboundPackets1_16.SOUND); + soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND); + soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND); + soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_SOUND); // Login success registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() { @@ -88,8 +94,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { } }); - // Advancements - registerOutgoing(State.PLAY, 0x57, 0x58, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_16.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -125,89 +130,12 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { } }); - // Tags new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> { Integer oldId = MappingData.oldToNewItems.inverse().get(id); return oldId != null ? oldId : -1; - }, entityPackets::getOldEntityId).register(0x5B, 0x5C); + }, entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS); - registerOutgoing(State.PLAY, 0x05, 0x06); - registerOutgoing(State.PLAY, 0x06, 0x07); - registerOutgoing(State.PLAY, 0x08, 0x09); - registerOutgoing(State.PLAY, 0x09, 0x0A); - registerOutgoing(State.PLAY, 0x0D, 0x0E); - registerOutgoing(State.PLAY, 0x11, 0x12); - registerOutgoing(State.PLAY, 0x12, 0x13); - registerOutgoing(State.PLAY, 0x13, 0x14); - registerOutgoing(State.PLAY, 0x18, 0x19); - registerOutgoing(State.PLAY, 0x19, 0x1A); - registerOutgoing(State.PLAY, 0x1B, 0x1C); - registerOutgoing(State.PLAY, 0x1C, 0x1D); - registerOutgoing(State.PLAY, 0x1D, 0x1E); - registerOutgoing(State.PLAY, 0x1E, 0x1F); - registerOutgoing(State.PLAY, 0x1F, 0x20); - registerOutgoing(State.PLAY, 0x20, 0x21); - registerOutgoing(State.PLAY, 0x24, 0x25); - registerOutgoing(State.PLAY, 0x26, 0x27); - registerOutgoing(State.PLAY, 0x28, 0x29); - registerOutgoing(State.PLAY, 0x29, 0x2A); - registerOutgoing(State.PLAY, 0x2A, 0x2B); - registerOutgoing(State.PLAY, 0x2B, 0x2C); - registerOutgoing(State.PLAY, 0x2C, 0x2D); - registerOutgoing(State.PLAY, 0x2D, 0x2E); - registerOutgoing(State.PLAY, 0x2F, 0x30); - registerOutgoing(State.PLAY, 0x30, 0x31); - registerOutgoing(State.PLAY, 0x31, 0x32); - registerOutgoing(State.PLAY, 0x33, 0x34); - registerOutgoing(State.PLAY, 0x34, 0x35); - registerOutgoing(State.PLAY, 0x35, 0x36); - registerOutgoing(State.PLAY, 0x36, 0x37); - registerOutgoing(State.PLAY, 0x38, 0x39); - registerOutgoing(State.PLAY, 0x39, 0x3A); - registerOutgoing(State.PLAY, 0x3B, 0x3C); - registerOutgoing(State.PLAY, 0x3C, 0x3D); - registerOutgoing(State.PLAY, 0x3D, 0x3E); - registerOutgoing(State.PLAY, 0x3E, 0x3F); - registerOutgoing(State.PLAY, 0x3F, 0x40); - registerOutgoing(State.PLAY, 0x40, 0x41); - registerOutgoing(State.PLAY, 0x41, 0x42); - registerOutgoing(State.PLAY, 0x42, 0x4E); - registerOutgoing(State.PLAY, 0x4E, 0x4F); - registerOutgoing(State.PLAY, 0x54, 0x55); - registerOutgoing(State.PLAY, 0x55, 0x56); - registerOutgoing(State.PLAY, 0x56, 0x57); - registerOutgoing(State.PLAY, 0x59, 0x5A); - - cancelIncoming(State.PLAY, 0x27); // Set jigsaw - registerIncoming(State.PLAY, 0x10, 0x0F); - registerIncoming(State.PLAY, 0x11, 0x10); - registerIncoming(State.PLAY, 0x12, 0x11); - registerIncoming(State.PLAY, 0x13, 0x12); - registerIncoming(State.PLAY, 0x14, 0x13); - registerIncoming(State.PLAY, 0x15, 0x14); - registerIncoming(State.PLAY, 0x16, 0x15); - registerIncoming(State.PLAY, 0x17, 0x16); - registerIncoming(State.PLAY, 0x18, 0x17); - registerIncoming(State.PLAY, 0x19, 0x18); - registerIncoming(State.PLAY, 0x1A, 0x19); - registerIncoming(State.PLAY, 0x1B, 0x1A); - registerIncoming(State.PLAY, 0x1C, 0x1B); - registerIncoming(State.PLAY, 0x1D, 0x1C); - registerIncoming(State.PLAY, 0x1E, 0x1D); - registerIncoming(State.PLAY, 0x1F, 0x1E); - registerIncoming(State.PLAY, 0x20, 0x1F); - registerIncoming(State.PLAY, 0x21, 0x20); - registerIncoming(State.PLAY, 0x22, 0x21); - registerIncoming(State.PLAY, 0x23, 0x22); - registerIncoming(State.PLAY, 0x24, 0x23); - registerIncoming(State.PLAY, 0x25, 0x24); - registerIncoming(State.PLAY, 0x26, 0x25); - registerIncoming(State.PLAY, 0x29, 0x28); - registerIncoming(State.PLAY, 0x2A, 0x29); - registerIncoming(State.PLAY, 0x2B, 0x2A); - registerIncoming(State.PLAY, 0x2C, 0x2B); - registerIncoming(State.PLAY, 0x2D, 0x2C); - registerIncoming(State.PLAY, 0x2E, 0x2D); + cancelIncoming(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK); } public static int getNewBlockStateId(int id) { @@ -230,10 +158,12 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol { @Override public void init(UserConnection user) { - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); - if (!user.has(EntityTracker.class)) + } + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } user.get(EntityTracker.class).initProtocol(this); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java index 8858954b..d1795761 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/data/RecipeRewriter1_16.java @@ -4,9 +4,9 @@ import nl.matsv.viabackwards.api.rewriters.ItemRewriterBase; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; public class RecipeRewriter1_16 extends RecipeRewriter1_15 { @@ -14,9 +14,9 @@ public class RecipeRewriter1_16 extends RecipeRewriter1_15 { super(rewriter); } - public void register(int oldId, int newId) { + public void register(ClientboundPacketType packetType) { // Remove new smithing type, only in this handler - rewriter.getProtocol().registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + rewriter.getProtocol().registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index cda75099..80d495fb 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -3,7 +3,6 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; -import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.RecipeRewriter1_16; @@ -15,8 +14,9 @@ import us.myles.ViaVersion.api.rewriters.BlockRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.UUIDIntArrayType; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -43,20 +43,13 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15_2To1_16::getNewBlockStateId, Protocol1_15_2To1_16::getNewBlockId); - // Declare Recipes - new RecipeRewriter1_16(this).register(0x5A, 0x5B); + new RecipeRewriter1_16(this).register(ClientboundPackets1_16.DECLARE_RECIPES); - // Set cooldown - itemRewriter.registerSetCooldown(0x17, 0x18, BlockItemPackets1_16::getOldItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, BlockItemPackets1_16::getOldItemId); + itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); + itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x14, 0x15); - - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x16, 0x17); - - // Trade list - protocol.out(State.PLAY, 0x27, 0x28, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_16.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -92,23 +85,13 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x47); + itemRewriter.registerEntityEquipment(ClientboundPackets1_16.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); + blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING); + blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_16.MULTI_BLOCK_CHANGE); - // Acknowledge player digging - blockRewriter.registerAcknowledgePlayerDigging(0x07, 0x08); - - // Block Action - blockRewriter.registerBlockAction(0x0A, 0x0B); - - // Block Change - blockRewriter.registerBlockChange(0x0B, 0x0C); - - // Multi Block Change - blockRewriter.registerMultiBlockChange(0x0F, 0x10); - - // Chunk - protocol.registerOutgoing(State.PLAY, 0x21, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -177,15 +160,11 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Effect packet - blockRewriter.registerEffect(0x22, 0x23, 1010, 2001, BlockItemPackets1_16::getOldItemId); + blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001, BlockItemPackets1_16::getOldItemId); + blockRewriter.registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, 3, 23, 32, + BlockItemPackets1_16::getNewParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); - // Spawn particle - blockRewriter.registerSpawnParticle(Type.DOUBLE, 0x23, 0x24, 3, 23, 32, - BlockItemPackets1_16::getNewParticleId, this::handleItemToClient, Type.FLAT_VAR_INT_ITEM); - - // Window Property - protocol.registerOutgoing(State.PLAY, 0x15, 0x16, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_16.WINDOW_PROPERTY, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Window id @@ -205,14 +184,10 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It } }); - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09); + itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x27, 0x26); - - // Edit Book - protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java index 3df5793d..c6409dbc 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java @@ -17,7 +17,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.version.Types1_14; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class EntityPackets1_16 extends EntityRewriter { @@ -43,14 +43,10 @@ public class EntityPackets1_16 extends EntityRewriter { @Override protected void registerPackets() { - // Spawn Object - registerSpawnTrackerWithData(0x00, 0x00, Entity1_16Types.EntityType.FALLING_BLOCK, Protocol1_15_2To1_16::getNewBlockStateId); + registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK, Protocol1_15_2To1_16::getNewBlockStateId); + registerSpawnTracker(ClientboundPackets1_16.SPAWN_MOB); - // Spawn mob packet - registerSpawnTracker(0x02, 0x03); - - // Respawn - protocol.registerOutgoing(State.PLAY, 0x3A, 0x3B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_16.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(dimensionTransformer); // Dimension Type @@ -71,8 +67,7 @@ public class EntityPackets1_16 extends EntityRewriter { } }); - // Join Game - protocol.registerOutgoing(State.PLAY, 0x25, 0x26, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_16.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Entity ID @@ -102,25 +97,14 @@ public class EntityPackets1_16 extends EntityRewriter { } }); - // Spawn Experience Orb - registerExtraTracker(0x01, Entity1_16Types.EntityType.EXPERIENCE_ORB); - + registerExtraTracker(ClientboundPackets1_16.SPAWN_EXPERIENCE_ORB, Entity1_16Types.EntityType.EXPERIENCE_ORB); // F Spawn Global Object, it is no longer with us :( + registerExtraTracker(ClientboundPackets1_16.SPAWN_PAINTING, Entity1_16Types.EntityType.PAINTING); + registerExtraTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16Types.EntityType.PLAYER); + registerEntityDestroy(ClientboundPackets1_16.DESTROY_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_14.METADATA_LIST); - // Spawn painting - registerExtraTracker(0x03, 0x04, Entity1_16Types.EntityType.PAINTING); - - // Spawn player packet - registerExtraTracker(0x04, 0x05, Entity1_16Types.EntityType.PLAYER); - - // Destroy entities - registerEntityDestroy(0x37, 0x38); - - // Entity Metadata packet - registerMetadataRewriter(0x44, 0x44, Types1_14.METADATA_LIST); - - // Entity Properties - protocol.out(State.PLAY, 0x58, 0x59, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_16.ENTITY_PROPERTIES, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15to1_15_1/Protocol1_15To1_15_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15to1_15_1/Protocol1_15To1_15_1.java index e7851775..8a9e7005 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15to1_15_1/Protocol1_15To1_15_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_15to1_15_1/Protocol1_15To1_15_1.java @@ -2,14 +2,12 @@ package nl.matsv.viabackwards.protocol.protocol1_15to1_15_1; import nl.matsv.viabackwards.api.BackwardsProtocol; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; -public class Protocol1_15To1_15_1 extends BackwardsProtocol { +public class Protocol1_15To1_15_1 extends BackwardsProtocol { - @Override - protected void registerPackets() { - } - - @Override - public void init(UserConnection userConnection) { + public Protocol1_15To1_15_1() { + super(ClientboundPackets1_15.class, ClientboundPackets1_15.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java index d851dd06..16ab0481 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java @@ -13,31 +13,48 @@ package nl.matsv.viabackwards.protocol.protocol1_9_4to1_10; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.BlockItemPackets1_10; -import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.ChangedPackets1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.EntityPackets1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.SoundPackets1_10; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_9_4To1_10 extends BackwardsProtocol { +public class Protocol1_9_4To1_10 extends BackwardsProtocol { + private EntityPackets1_10 entityPackets; // Required for the item rewriter private BlockItemPackets1_10 blockItemPackets; + public Protocol1_9_4To1_10() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); + } + protected void registerPackets() { - new ChangedPackets1_10().register(this); new SoundPackets1_10(this).register(); (entityPackets = new EntityPackets1_10(this)).register(); (blockItemPackets = new BlockItemPackets1_10(this)).register(); + + registerIncoming(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING, Type.NOTHING); // 0 - Hash + map(Type.VAR_INT); // 1 - Result + } + }); } public void init(UserConnection user) { // Register ClientWorld - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } // Register EntityTracker if it doesn't exist yet. - if (!user.has(EntityTracker.class)) + if (!user.has(EntityTracker.class)) { user.put(new EntityTracker(user)); + } // Init protocol in EntityTracker user.get(EntityTracker.class).initProtocol(this); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/BlockItemPackets1_10.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/BlockItemPackets1_10.java index 29c9dc01..2da4b636 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/BlockItemPackets1_10.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/BlockItemPackets1_10.java @@ -21,8 +21,9 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class BlockItemPackets1_10 extends LegacyBlockItemRewriter { @@ -35,17 +36,13 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter Trading - protocol.registerOutgoing(State.PLAY, 0x18, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel @@ -62,8 +59,9 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter { @@ -151,7 +140,7 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter @Override protected void registerPackets() { - // Spawn Object - protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -78,14 +77,10 @@ public class EntityPackets1_10 extends LegacyEntityRewriter } }); - // Spawn Experience Orb - registerExtraTracker(0x01, Entity1_10Types.EntityType.EXPERIENCE_ORB); + registerExtraTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_10Types.EntityType.EXPERIENCE_ORB); + registerExtraTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_10Types.EntityType.WEATHER); - // Spawn Global Entity - registerExtraTracker(0x02, Entity1_10Types.EntityType.WEATHER); - - // Spawn Mob - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -138,17 +133,11 @@ public class EntityPackets1_10 extends LegacyEntityRewriter } }); - // Spawn Painting - registerExtraTracker(0x04, Entity1_10Types.EntityType.PAINTING); + registerExtraTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_10Types.EntityType.PAINTING); + registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_10Types.EntityType.PLAYER); + registerRespawn(ClientboundPackets1_9_3.RESPAWN); - // Join game - registerJoinGame(0x23, 0x23, Entity1_10Types.EntityType.PLAYER); - - // Respawn Packet - registerRespawn(0x33, 0x33); - - // Spawn Player - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -164,11 +153,8 @@ public class EntityPackets1_10 extends LegacyEntityRewriter } }); - // Destroy entities - registerEntityDestroy(0x30); - - // Metadata packet - registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST); + registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST); } @Override diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/SoundPackets1_10.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/SoundPackets1_10.java index 875bd82f..bd63f6f7 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/SoundPackets1_10.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/SoundPackets1_10.java @@ -17,7 +17,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; public class SoundPackets1_10 extends LegacySoundRewriter { protected static ValueTransformer toOldPitch = new ValueTransformer(Type.UNSIGNED_BYTE) { @@ -32,8 +32,7 @@ public class SoundPackets1_10 extends LegacySoundRewriter { @Override protected void registerPackets() { - // Named sound effect - protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Sound name @@ -46,8 +45,7 @@ public class SoundPackets1_10 extends LegacySoundRewriter { } }); - // Sound effect - protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_9_3.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound name @@ -63,13 +61,15 @@ public class SoundPackets1_10 extends LegacySoundRewriter { public void handle(PacketWrapper wrapper) throws Exception { int oldId = wrapper.get(Type.VAR_INT, 0); int newId = handleSounds(oldId); - if (newId == -1) + if (newId == -1) { wrapper.cancel(); - else { - if (hasPitch(oldId)) - wrapper.set(Type.UNSIGNED_BYTE, 0, (short) Math.round(handlePitch(oldId) * 63.5F)); - wrapper.set(Type.VAR_INT, 0, newId); + return; } + + if (hasPitch(oldId)) { + wrapper.set(Type.UNSIGNED_BYTE, 0, (short) Math.round(handlePitch(oldId) * 63.5F)); + } + wrapper.set(Type.VAR_INT, 0, newId); } }); } diff --git a/pom.xml b/pom.xml index a05fffba..1c07067d 100644 --- a/pom.xml +++ b/pom.xml @@ -57,5 +57,13 @@ 3.0.0-SNAPSHOT provided + + + + org.jetbrains + annotations + 19.0.0 + provided +