diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManager.java b/common/src/main/java/us/myles/ViaVersion/ViaManager.java index 81bb0743b..8be60ad18 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManager.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManager.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.platform.TaskId; @@ -207,6 +208,7 @@ public class ViaManager { /** * @see ViaConnectionManager#getConnectedClient(UUID) */ + @Nullable public UserConnection getConnection(UUID playerUUID) { return platform.getConnectionManager().getConnectedClient(playerUUID); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 961c55b71..df813e6bf 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -16,7 +16,11 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.util.PipelineUtil; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.NoSuchElementException; public class PacketWrapper { public static final int PASSTHROUGH_ID = 1000; @@ -249,8 +253,9 @@ public class PacketWrapper { * Clear the input buffer / readable objects */ public void clearInputBuffer() { - if (inputBuffer != null) + if (inputBuffer != null) { inputBuffer.clear(); + } readableObjects.clear(); // :( } diff --git a/common/src/main/java/us/myles/ViaVersion/api/Pair.java b/common/src/main/java/us/myles/ViaVersion/api/Pair.java index efb87619b..2f5e451f8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/Pair.java +++ b/common/src/main/java/us/myles/ViaVersion/api/Pair.java @@ -1,12 +1,14 @@ package us.myles.ViaVersion.api; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; public class Pair { private final X key; private Y value; - public Pair(X key, Y value) { + public Pair(@Nullable X key, @Nullable Y value) { this.key = key; this.value = value; } @@ -19,7 +21,7 @@ public class Pair { return value; } - public void setValue(Y value) { + public void setValue(@Nullable Y value) { this.value = value; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/Triple.java b/common/src/main/java/us/myles/ViaVersion/api/Triple.java index 02600957e..3c7d5996a 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/Triple.java +++ b/common/src/main/java/us/myles/ViaVersion/api/Triple.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.api; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; public class Triple { @@ -7,20 +9,23 @@ public class Triple { private final B second; private final C third; - public Triple(A first, B second, C third) { + public Triple(@Nullable A first, @Nullable B second, @Nullable C third) { this.first = first; this.second = second; this.third = third; } + @Nullable public A getFirst() { return first; } + @Nullable public B getSecond() { return second; } + @Nullable public C getThird() { return third; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java index a87aa1026..149db8083 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.api; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.protocols.base.ProtocolInfo; @@ -20,6 +21,7 @@ public abstract class ViaListener { * @param uuid UUID object * @return The UserConnection */ + @Nullable protected UserConnection getUserConnection(UUID uuid) { return Via.getManager().getConnection(uuid); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java b/common/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java index 802f93b3a..9f4a10fb0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java +++ b/common/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.api.boss; public enum BossColor { + PINK(0), BLUE(1), RED(2), diff --git a/common/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java b/common/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java index 5b72fd69a..f849332f3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java +++ b/common/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.api.boss; public enum BossFlag { + DARKEN_SKY(1), PLAY_BOSS_MUSIC(2); diff --git a/common/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java b/common/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java index 60dd209ea..e1a080a36 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java +++ b/common/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.api.boss; public enum BossStyle { + SOLID(0), SEGMENTED_6(1), SEGMENTED_10(2), diff --git a/common/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java b/common/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java index c60037af0..03c931450 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java +++ b/common/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.api.command; +import org.jetbrains.annotations.Nullable; + import java.util.List; public interface ViaVersionCommand { @@ -25,6 +27,7 @@ public interface ViaVersionCommand { * @param name subcommand name * @return ViaSubCommand instance */ + @Nullable ViaSubCommand getSubCommand(String name); /** diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/ExternalJoinGameListener.java b/common/src/main/java/us/myles/ViaVersion/api/data/ExternalJoinGameListener.java index 02e71cc8c..f5ec6c126 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/ExternalJoinGameListener.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/ExternalJoinGameListener.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.api.data; public interface ExternalJoinGameListener { + void onExternalJoinGame(int playerEntityId); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java b/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java index e2371aebf..448d6c066 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.util.GsonUtil; @@ -127,6 +128,7 @@ public class MappingDataLoader { } } + @Nullable private static Map.Entry mapIdentifierEntry(Map.Entry entry, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers) { Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { @@ -181,6 +183,7 @@ public class MappingDataLoader { } } + @Nullable public static Map.Entry findValue(JsonObject object, String needle) { for (Map.Entry entry : object.entrySet()) { String value = entry.getValue().getAsString(); @@ -191,6 +194,7 @@ public class MappingDataLoader { return null; } + @Nullable public static Integer findIndex(JsonArray array, String value) { for (int i = 0; i < array.size(); i++) { JsonElement v = array.get(i); diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java b/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java index 0221bd197..5369fc4ed 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java @@ -6,6 +6,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.ViaVersionConfig; @@ -36,7 +37,7 @@ public class UserConnection { private int secondsObserved; private int warnings; - public UserConnection(Channel channel) { + public UserConnection(@Nullable Channel channel) { this.channel = channel; } @@ -47,6 +48,7 @@ public class UserConnection { * @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); } @@ -84,8 +86,8 @@ public class UserConnection { * @param packet The raw packet to send * @param currentThread Should it run in the same thread */ - public void sendRawPacket(final ByteBuf packet, boolean currentThread) { - final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); + public void sendRawPacket(ByteBuf packet, boolean currentThread) { + ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); if (currentThread) { channel.pipeline().context(handler).writeAndFlush(packet); } else { @@ -99,8 +101,8 @@ public class UserConnection { * @param packet The raw packet to send * @return ChannelFuture of the packet being sent */ - public ChannelFuture sendRawPacketFuture(final ByteBuf packet) { - final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); + public ChannelFuture sendRawPacketFuture(ByteBuf packet) { + ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); return channel.pipeline().context(handler).writeAndFlush(packet); } @@ -109,7 +111,7 @@ public class UserConnection { * * @param packet The packet to send */ - public void sendRawPacket(final ByteBuf packet) { + public void sendRawPacket(ByteBuf packet) { sendRawPacket(packet, false); } @@ -177,12 +179,12 @@ public class UserConnection { * * @param reason The reason to use, not used if player is not active. */ - public void disconnect(final String reason) { + public void disconnect(String reason) { if (!channel.isOpen()) return; if (pendingDisconnect) return; pendingDisconnect = true; if (get(ProtocolInfo.class).getUuid() != null) { - final UUID uuid = get(ProtocolInfo.class).getUuid(); + UUID uuid = get(ProtocolInfo.class).getUuid(); Via.getPlatform().runSync(() -> { if (!Via.getPlatform().kickPlayer(uuid, ChatColor.translateAlternateColorCodes('&', reason))) { channel.close(); // =) @@ -197,8 +199,8 @@ public class UserConnection { * @param packet Raw packet to be sent * @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop */ - public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) { - final ByteBuf buf = packet.alloc().buffer(); + public void sendRawPacketToServer(ByteBuf packet, boolean currentThread) { + ByteBuf buf = packet.alloc().buffer(); try { try { Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID); @@ -207,7 +209,7 @@ public class UserConnection { Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e); } buf.writeBytes(packet); - final ChannelHandlerContext context = PipelineUtil + ChannelHandlerContext context = PipelineUtil .getPreviousContext(Via.getManager().getInjector().getDecoderName(), channel.pipeline()); if (currentThread) { if (context != null) { @@ -248,6 +250,7 @@ public class UserConnection { return id; } + @Nullable public Channel getChannel() { return channel; } @@ -272,11 +275,12 @@ public class UserConnection { this.pendingDisconnect = pendingDisconnect; } + @Nullable public Object getLastPacket() { return lastPacket; } - public void setLastPacket(Object lastPacket) { + public void setLastPacket(@Nullable Object lastPacket) { this.lastPacket = lastPacket; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java b/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java index 7c8de1eeb..8a615f1ad 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java @@ -1,9 +1,12 @@ package us.myles.ViaVersion.api.entities; +import org.jetbrains.annotations.Nullable; + public interface EntityType { int getId(); + @Nullable EntityType getParent(); String name(); diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index 74d9803a1..595496c26 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.api.minecraft.chunks; import io.netty.buffer.ByteBuf; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -145,7 +146,7 @@ public class ChunkSection { * * @param data The value to set the block light to */ - public void setBlockLight(byte[] data) { + public void setBlockLight(@Nullable byte[] data) { if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH); if (this.blockLight == null) { this.blockLight = new NibbleArray(data); @@ -159,7 +160,7 @@ public class ChunkSection { * * @param data The value to set the sky light to */ - public void setSkyLight(byte[] data) { + public void setSkyLight(@Nullable byte[] data) { if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH); if (this.skyLight == null) { this.skyLight = new NibbleArray(data); @@ -168,18 +169,22 @@ public class ChunkSection { } } + @Nullable public byte[] getBlockLight() { return blockLight == null ? null : blockLight.getHandle(); } + @Nullable public NibbleArray getBlockLightNibbleArray() { return blockLight; } + @Nullable public byte[] getSkyLight() { return skyLight == null ? null : skyLight.getHandle(); } + @Nullable public NibbleArray getSkyLightNibbleArray() { return skyLight; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java index 0ea2c766b..c478938bb 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java @@ -2,6 +2,9 @@ package us.myles.ViaVersion.api.minecraft.item; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.google.gson.annotations.SerializedName; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; public class Item { @SerializedName(value = "identifier", alternate = "id") @@ -13,7 +16,7 @@ public class Item { public Item() { } - public Item(int identifier, byte amount, short data, CompoundTag tag) { + public Item(int identifier, byte amount, short data, @Nullable CompoundTag tag) { this.identifier = identifier; this.amount = amount; this.data = data; @@ -48,11 +51,12 @@ public class Item { this.data = data; } + @Nullable public CompoundTag getTag() { return tag; } - public void setTag(CompoundTag tag) { + public void setTag(@Nullable CompoundTag tag) { this.tag = tag; } @@ -64,7 +68,7 @@ public class Item { if (identifier != item.identifier) return false; if (amount != item.amount) return false; if (data != item.data) return false; - return tag != null ? tag.equals(item.tag) : item.tag == null; + return Objects.equals(tag, item.tag); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java index c73eb0e15..82649612e 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java +++ b/common/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.api.platform; import io.netty.channel.ChannelFutureListener; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.base.ProtocolInfo; @@ -51,6 +52,7 @@ public class ViaConnectionManager { * Note that connections are removed as soon as their channel is closed, * so avoid using this method during player quits for example. */ + @Nullable public UserConnection getConnectedClient(UUID clientIdentifier) { return clients.get(clientIdentifier); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java b/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java index 9aa602423..204c4066f 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java +++ b/common/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.api.platform.providers; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -22,6 +24,7 @@ public class ViaProviders { providers.put(provider, value); } + @Nullable public T get(Class provider) { Provider rawProvider = providers.get(provider); if (rawProvider != null) { diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ClientboundPacketType.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ClientboundPacketType.java new file mode 100644 index 000000000..ffda1facd --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ClientboundPacketType.java @@ -0,0 +1,18 @@ +package us.myles.ViaVersion.api.protocol; + +/** + * Interface to be implemented by server outgoing packet type enums, + * representing PLAY state packets, ordered by their packet id. + */ +public interface ClientboundPacketType { + + /** + * @return name of the packet, to be consistent over multiple versions + */ + String name(); + + /** + * @return ordinal, being the packet id for the implemented protocol + */ + int ordinal(); +} diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index c244ff1b0..c6de1c300 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -1,5 +1,7 @@ package us.myles.ViaVersion.api.protocol; +import com.google.common.base.Preconditions; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -9,24 +11,119 @@ import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.State; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; -public abstract class Protocol { +/** + * Abstract protocol class handling packet transformation between two protocol versions. + * Clientbound and serverbount packet types can be set to enforce correct usage of them. + * + * @param old clientbound packet types + * @param new clientbound packet types + * @param old serverbound packet types + * @param new serverbound packet types + * @see SimpleProtocol for a helper class if you do not want to define any of the types above + */ +public abstract class Protocol { private final Map incoming = new HashMap<>(); private final Map outgoing = new HashMap<>(); private final Map storedObjects = new HashMap<>(); // currently only used for MetadataRewriters - private final boolean hasMappingDataToLoad; + protected final Class oldClientboundPacketEnum; + protected final Class newClientboundPacketEnum; + protected final Class oldServerboundPacketEnum; + protected final Class newServerboundPacketEnum; + protected final boolean hasMappingDataToLoad; - public Protocol() { - this(false); + protected Protocol() { + this(null, null, null, null, false); } - public Protocol(boolean hasMappingDataToLoad) { + protected Protocol(boolean hasMappingDataToLoad) { + this(null, null, null, null, hasMappingDataToLoad); + } + + /** + * Creates a protocol with automated id mapping if the respective enums are not null. + */ + protected Protocol(@Nullable Class oldClientboundPacketEnum, @Nullable Class clientboundPacketEnum, + @Nullable Class oldServerboundPacketEnum, @Nullable Class serverboundPacketEnum) { + this(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum, false); + } + + /** + * Creates a protocol with automated id mapping if the respective enums are not null. + * + * @param hasMappingDataToLoad whether an async executor should call the {@Link #loadMappingData} method + */ + protected Protocol(@Nullable Class oldClientboundPacketEnum, @Nullable Class clientboundPacketEnum, + @Nullable Class oldServerboundPacketEnum, @Nullable Class serverboundPacketEnum, boolean hasMappingDataToLoad) { + this.oldClientboundPacketEnum = oldClientboundPacketEnum; + this.newClientboundPacketEnum = clientboundPacketEnum; + this.oldServerboundPacketEnum = oldServerboundPacketEnum; + this.newServerboundPacketEnum = serverboundPacketEnum; this.hasMappingDataToLoad = hasMappingDataToLoad; registerPackets(); + + // Register the rest of the ids with no handlers if necessary + if (oldClientboundPacketEnum != null && clientboundPacketEnum != null + && oldClientboundPacketEnum != clientboundPacketEnum) { + registerOutgoingChannelIdChanges(); + } + if (oldServerboundPacketEnum != null && serverboundPacketEnum != null + && oldServerboundPacketEnum != serverboundPacketEnum) { + registerIncomingChannelIdChanges(); + } + } + + protected void registerOutgoingChannelIdChanges() { + ClientboundPacketType[] newConstants = newClientboundPacketEnum.getEnumConstants(); + Map newClientboundPackets = new HashMap<>(newConstants.length); + for (ClientboundPacketType newConstant : newConstants) { + newClientboundPackets.put(newConstant.name(), newConstant); + } + + for (ClientboundPacketType packet : oldClientboundPacketEnum.getEnumConstants()) { + ClientboundPacketType mappedPacket = newClientboundPackets.get(packet.name()); + int oldId = packet.ordinal(); + if (mappedPacket == null) { + // Packet doesn't exist on new client + Preconditions.checkArgument(hasRegisteredOutgoing(State.PLAY, oldId), + "Packet " + mappedPacket + " in " + getClass().getSimpleName() + " has no mapping - it needs to be manually cancelled or remapped!"); + continue; + } + + int newId = mappedPacket.ordinal(); + if (!hasRegisteredOutgoing(State.PLAY, oldId)) { + registerOutgoing(State.PLAY, oldId, newId); + } + } + } + + protected void registerIncomingChannelIdChanges() { + ServerboundPacketType[] oldConstants = oldServerboundPacketEnum.getEnumConstants(); + Map oldServerboundConstants = new HashMap<>(oldConstants.length); + for (ServerboundPacketType oldConstant : oldConstants) { + oldServerboundConstants.put(oldConstant.name(), oldConstant); + } + + for (ServerboundPacketType packet : newServerboundPacketEnum.getEnumConstants()) { + ServerboundPacketType mappedPacket = oldServerboundConstants.get(packet.name()); + int newId = packet.ordinal(); + if (mappedPacket == null) { + // Packet doesn't exist on old server + Preconditions.checkArgument(hasRegisteredIncoming(State.PLAY, newId), + "Packet " + mappedPacket + " in " + getClass().getSimpleName() + " has no mapping - it needs to be manually cancelled or remapped!"); + continue; + } + + int oldId = mappedPacket.ordinal(); + if (!hasRegisteredIncoming(State.PLAY, newId)) { + registerIncoming(State.PLAY, oldId, newId); + } + } } /** @@ -53,9 +150,10 @@ public abstract class Protocol { } /** - * Register the packets for this protocol. + * Register the packets for this protocol. To be overriden. */ - protected abstract void registerPackets(); + protected void registerPackets() { + } /** * Load mapping data for the protocol. @@ -155,16 +253,6 @@ public abstract class Protocol { registerOutgoing(state, oldPacketID, newPacketID, packetRemapper, false); } - public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) { - ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); - Packet packet = new Packet(state, oldPacketID); - if (!override && outgoing.containsKey(packet)) { - Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" + - " If override is intentional, set override to true. Stacktrace: ", new Exception()); - } - outgoing.put(packet, protocolPacket); - } - public void cancelOutgoing(State state, int oldPacketID, int newPacketID) { registerOutgoing(state, oldPacketID, newPacketID, new PacketRemapper() { @Override @@ -178,6 +266,118 @@ public abstract class Protocol { cancelOutgoing(state, oldPacketID, -1); } + public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) { + ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); + Packet packet = new Packet(state, oldPacketID); + if (!override && outgoing.containsKey(packet)) { + Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" + + " If override is intentional, set override to true. Stacktrace: ", new Exception()); + } + outgoing.put(packet, protocolPacket); + } + + + /** + * Registers an outgoing protocol and automatically maps it to the new id. + * + * @param packetType clientbound packet type the server sends + * @param packetRemapper remapper + */ + public void registerOutgoing(C1 packetType, @Nullable PacketRemapper packetRemapper) { + ClientboundPacketType mappedPacket = oldClientboundPacketEnum == newClientboundPacketEnum ? packetType + : Arrays.stream(newClientboundPacketEnum.getEnumConstants()).filter(en -> en.name().equals(packetType.name())).findAny().orElse(null); + Preconditions.checkNotNull(mappedPacket, "Packet type " + packetType + " in " + packetType.getClass().getSimpleName() + " could not be automatically mapped!"); + + int oldId = packetType.ordinal(); + int newId = mappedPacket.ordinal(); + registerOutgoing(State.PLAY, oldId, newId, packetRemapper); + } + + /** + * Registers an outgoing protocol. + * + * @param packetType clientbound packet type the server initially sends + * @param mappedPacketType clientbound packet type after transforming for the client + * @param packetRemapper remapper + */ + public void registerOutgoing(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper) { + registerOutgoing(State.PLAY, packetType.ordinal(), mappedPacketType != null ? mappedPacketType.ordinal() : -1, packetRemapper); + } + + /** + * Maps a packet type to another packet type without a packet handler. + * Note that this should not be called for simple channel mappings of the same packet; this is already done automatically. + * + * @param packetType clientbound packet type the server initially sends + * @param mappedPacketType clientbound packet type after transforming for the client + */ + public void registerOutgoing(C1 packetType, @Nullable C2 mappedPacketType) { + registerOutgoing(packetType, mappedPacketType, null); + } + + public void cancelOutgoing(C1 packetType) { + cancelOutgoing(State.PLAY, packetType.ordinal(), packetType.ordinal()); + } + + /** + * Registers an incoming protocol and automatically maps it to the server's id. + * + * @param packetType serverbound packet type the client sends + * @param packetRemapper remapper + */ + public void registerIncoming(S2 packetType, @Nullable PacketRemapper packetRemapper) { + Preconditions.checkArgument(packetType.getClass() == newServerboundPacketEnum); + + ServerboundPacketType mappedPacket = oldServerboundPacketEnum == newServerboundPacketEnum ? packetType + : Arrays.stream(oldServerboundPacketEnum.getEnumConstants()).filter(en -> en.name().equals(packetType.name())).findAny().orElse(null); + Preconditions.checkNotNull(mappedPacket, "Packet type " + packetType + " in " + packetType.getClass().getSimpleName() + " could not be automatically mapped!"); + + int oldId = mappedPacket.ordinal(); + int newId = packetType.ordinal(); + registerIncoming(State.PLAY, oldId, newId, packetRemapper); + } + + /** + * Registers an incoming protocol. + * + * @param packetType serverbound packet type initially sent by the client + * @param mappedPacketType serverbound packet type after transforming for the server + * @param packetRemapper remapper + */ + public void registerIncoming(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper) { + registerIncoming(State.PLAY, mappedPacketType != null ? mappedPacketType.ordinal() : -1, packetType.ordinal(), packetRemapper); + } + + public void cancelIncoming(S2 packetType) { + Preconditions.checkArgument(packetType.getClass() == newServerboundPacketEnum); + cancelIncoming(State.PLAY, -1, packetType.ordinal()); + } + + + /** + * Checks if an outgoing packet has already been registered. + * + * @param state state which the packet is sent in + * @param oldPacketID old packet ID + * @return true if already registered + */ + public boolean hasRegisteredOutgoing(State state, int oldPacketID) { + Packet packet = new Packet(state, oldPacketID); + return outgoing.containsKey(packet); + } + + /** + * Checks if an incoming packet has already been registered. + * + * @param state state which the packet is sent in + * @param newPacketId packet ID + * @return true if already registered + */ + public boolean hasRegisteredIncoming(State state, int newPacketId) { + Packet packet = new Packet(state, newPacketId); + return incoming.containsKey(packet); + } + public boolean hasMappingDataToLoad() { return hasMappingDataToLoad; } @@ -210,7 +410,7 @@ public abstract class Protocol { } } - public T get(Class objectClass) { + public @Nullable T get(Class objectClass) { return (T) storedObjects.get(objectClass); } @@ -267,7 +467,7 @@ public abstract class Protocol { private final int newID; private final PacketRemapper remapper; - public ProtocolPacket(State state, int oldID, int newID, PacketRemapper remapper) { + public ProtocolPacket(State state, int oldID, int newID, @Nullable PacketRemapper remapper) { this.state = state; this.oldID = oldID; this.newID = newID; @@ -286,6 +486,7 @@ public abstract class Protocol { return newID; } + @Nullable public PacketRemapper getRemapper() { return remapper; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java index 25f5b1048..381f71328 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java @@ -14,7 +14,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; -public class ProtocolPipeline extends Protocol { +public class ProtocolPipeline extends SimpleProtocol { private List protocolList; private UserConnection userConnection; diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 3ae565322..8ef9a3276 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.collect.Lists; import com.google.common.collect.Range; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; @@ -224,6 +225,7 @@ public class ProtocolRegistry { * @param serverVersion The desired output version * @return The path which has been generated, null if failed. */ + @Nullable private static List> getProtocolPath(List> current, int clientVersion, int serverVersion) { if (clientVersion == serverVersion) return null; // We're already there if (current.size() > 50) return null; // Fail safe, protocol too complicated. @@ -273,6 +275,7 @@ public class ProtocolRegistry { * @param serverVersion The desired output server version * @return The path it generated, null if it failed. */ + @Nullable public static List> getProtocolPath(int clientVersion, int serverVersion) { Pair protocolKey = new Pair<>(clientVersion, serverVersion); // Check cache @@ -367,6 +370,7 @@ public class ProtocolRegistry { } } + @Nullable public static CompletableFuture getMappingLoaderFuture(Class protocolClass) { synchronized (MAPPING_LOADER_LOCK) { if (mappingsLoaded) return null; diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ServerboundPacketType.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ServerboundPacketType.java new file mode 100644 index 000000000..c6dbd3b4c --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ServerboundPacketType.java @@ -0,0 +1,18 @@ +package us.myles.ViaVersion.api.protocol; + +/** + * Interface to be implemented by server incoming packet type enums, + * representing PLAY state packets, ordered by their packet id. + */ +public interface ServerboundPacketType { + + /** + * @return name of the packet, to be consistent over multiple versions + */ + String name(); + + /** + * @return ordinal, being the packet id for the implemented protocol + */ + int ordinal(); +} diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/SimpleProtocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/SimpleProtocol.java new file mode 100644 index 000000000..e27d598ca --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/SimpleProtocol.java @@ -0,0 +1,20 @@ +package us.myles.ViaVersion.api.protocol; + +/** + * Dummy protocol class for when you do not need any of the + * existing packet type enums or automated channel mappings. + * + * @see Protocol + */ +public abstract class SimpleProtocol extends Protocol { + + protected SimpleProtocol() { + } + + protected SimpleProtocol(boolean hasMappingDataToLoad) { + super(hasMappingDataToLoad); + } + + public enum DummyPacketTypes implements ClientboundPacketType, ServerboundPacketType { + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java b/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java index 0c7a2fda6..05ea97569 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java +++ b/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.api.remapper; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.InformativeException; @@ -8,7 +9,7 @@ public abstract class ValueTransformer implements ValueWriter { private final Type inputType; private final Type outputType; - public ValueTransformer(Type inputType, Type outputType) { + public ValueTransformer(@Nullable Type inputType, Type outputType) { this.inputType = inputType; this.outputType = outputType; } @@ -37,6 +38,7 @@ public abstract class ValueTransformer implements ValueWriter { } } + @Nullable public Type getInputType() { return inputType; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/BlockRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/BlockRewriter.java index 3b628d5d3..e6f9cb040 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/BlockRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/BlockRewriter.java @@ -1,12 +1,13 @@ package us.myles.ViaVersion.api.rewriters; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; // If any of these methods become outdated, just create a new rewriter overriding the methods public class BlockRewriter { @@ -22,8 +23,8 @@ public class BlockRewriter { this.blockRewriter = blockRewriter; } - public void registerBlockAction(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerBlockAction(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(positionType); // Location @@ -35,8 +36,8 @@ public class BlockRewriter { }); } - public void registerBlockChange(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerBlockChange(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(positionType); @@ -46,8 +47,8 @@ public class BlockRewriter { }); } - public void registerMultiBlockChange(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerMultiBlockChange(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Chunk X @@ -62,13 +63,13 @@ public class BlockRewriter { }); } - public void registerAcknowledgePlayerDigging(int oldPacketId, int newPacketId) { + public void registerAcknowledgePlayerDigging(ClientboundPacketType packetType) { // Same exact handler - registerBlockChange(oldPacketId, newPacketId); + registerBlockChange(packetType); } - public void registerEffect(int oldPacketId, int newPacketId, int playRecordId, int blockBreakId, IdRewriteFunction itemIdRewriteFunction) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerEffect(ClientboundPacketType packetType, int playRecordId, int blockBreakId, IdRewriteFunction itemIdRewriteFunction) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id @@ -87,14 +88,14 @@ public class BlockRewriter { }); } - public void registerSpawnParticle(Type coordType, int oldPacketId, int newPacketId, int blockId, int fallingDustId, int itemId, - ItemRewriter.RewriteFunction itemRewriteFunction, Type itemType) { - registerSpawnParticle(coordType, oldPacketId, newPacketId, blockId, fallingDustId, itemId, null, itemRewriteFunction, itemType); + public void registerSpawnParticle(ClientboundPacketType packetType, int blockId, int fallingDustId, int itemId, + ItemRewriter.RewriteFunction itemRewriteFunction, Type itemType, Type coordType) { + registerSpawnParticle(packetType, blockId, fallingDustId, itemId, null, itemRewriteFunction, itemType, coordType); } - public void registerSpawnParticle(Type coordType, int oldPacketId, int newPacketId, int blockId, int fallingDustId, int itemId, - IdRewriteFunction particleRewriteFunction, ItemRewriter.RewriteFunction itemRewriteFunction, Type itemType) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerSpawnParticle(ClientboundPacketType packetType, int blockId, int fallingDustId, int itemId, + @Nullable IdRewriteFunction particleRewriteFunction, ItemRewriter.RewriteFunction itemRewriteFunction, Type itemType, Type coordType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java index 32be6c86f..4495feca8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java @@ -1,11 +1,12 @@ package us.myles.ViaVersion.api.rewriters; import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; 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; // If any of these methods become outdated, just create a new rewriter overriding the methods public class ItemRewriter { @@ -19,8 +20,8 @@ public class ItemRewriter { this.toServer = toServer; } - public void registerWindowItems(Type type, int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerWindowItems(ClientboundPacketType packetType, Type type) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID @@ -31,8 +32,8 @@ public class ItemRewriter { }); } - public void registerSetSlot(Type type, int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerSetSlot(ClientboundPacketType packetType, Type type) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); // 0 - Window ID @@ -44,8 +45,8 @@ public class ItemRewriter { }); } - public void registerEntityEquipment(Type type, int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerEntityEquipment(ClientboundPacketType packetType, Type type) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -57,8 +58,8 @@ public class ItemRewriter { }); } - public void registerCreativeInvAction(Type type, int oldPacketId, int newPacketId) { - protocol.registerIncoming(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerCreativeInvAction(ServerboundPacketType packetType, Type type) { + protocol.registerIncoming(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.SHORT); // 0 - Slot @@ -69,8 +70,8 @@ public class ItemRewriter { }); } - public void registerClickWindow(Type type, int oldPacketId, int newPacketId) { - protocol.registerIncoming(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerClickWindow(ServerboundPacketType packetType, Type type) { + protocol.registerIncoming(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID @@ -85,8 +86,8 @@ public class ItemRewriter { }); } - public void registerSetCooldown(int oldPacketId, int newPacketId, IdRewriteFunction itemIDRewriteFunction) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerSetCooldown(ClientboundPacketType packetType, IdRewriteFunction itemIDRewriteFunction) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index da77ff67c..de6db2ebd 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -1,18 +1,23 @@ package us.myles.ViaVersion.api.rewriters; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.EntityType; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; 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.storage.EntityTracker; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.logging.Logger; public abstract class MetadataRewriter { @@ -54,8 +59,8 @@ public abstract class MetadataRewriter { } } - public void registerJoinGame(int oldPacketId, int newPacketId, EntityType playerType) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerJoinGame(ClientboundPacketType packetType, @Nullable EntityType playerType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -74,8 +79,8 @@ public abstract class MetadataRewriter { }); } - 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); @@ -88,8 +93,8 @@ public abstract class MetadataRewriter { }); } - public void registerTracker(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerTracker(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -100,8 +105,8 @@ public abstract class MetadataRewriter { }); } - public void registerSpawnTrackerWithData(int oldPacketId, int newPacketId, EntityType fallingBlockType, IdRewriteFunction itemRewriter) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerSpawnTrackerWithData(ClientboundPacketType packetType, EntityType fallingBlockType, IdRewriteFunction itemRewriter) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -125,8 +130,8 @@ public abstract class MetadataRewriter { }); } - public void registerTracker(int oldPacketId, int newPacketId, EntityType entityType) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerTracker(ClientboundPacketType packetType, EntityType entityType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -138,8 +143,8 @@ public abstract class MetadataRewriter { }); } - public void registerEntityDestroy(int oldPacketId, int newPacketId) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerEntityDestroy(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT_ARRAY_PRIMITIVE); // 0 - Entity ids @@ -153,8 +158,8 @@ public abstract class MetadataRewriter { }); } - public void registerMetadataRewriter(int oldPacketId, int newPacketId, Type> oldMetaType, Type> newMetaType) { - protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + public void registerMetadataRewriter(ClientboundPacketType packetType, @Nullable Type> oldMetaType, Type> newMetaType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -172,8 +177,8 @@ public abstract class MetadataRewriter { }); } - public void registerMetadataRewriter(int oldPacketId, int newPacketId, Type> metaType) { - registerMetadataRewriter(oldPacketId, newPacketId, null, metaType); + public void registerMetadataRewriter(ClientboundPacketType packetType, Type> metaType) { + registerMetadataRewriter(packetType, null, metaType); } public & EntityType> void mapTypes(EntityType[] oldTypes, Class newTypeClass) { @@ -185,7 +190,7 @@ public abstract class MetadataRewriter { } catch (IllegalArgumentException notFound) { if (!typeMapping.containsKey(oldType.getId())) { Via.getPlatform().getLogger().warning("Could not find new entity type for " + oldType + "! " + - "Old type: " + oldType.getClass().getSimpleName() + " New type: " + newTypeClass.getSimpleName()); + "Old type: " + oldType.getClass().getSimpleName() + " New type: " + newTypeClass.getSimpleName()); } } } @@ -209,7 +214,7 @@ public abstract class MetadataRewriter { * @param metaType type of the metadata list * @return handler for tracking and rewriting entities */ - public PacketHandler getTrackerAndRewriter(Type> metaType) { + public PacketHandler getTrackerAndRewriter(@Nullable Type> metaType) { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); @@ -229,7 +234,7 @@ public abstract class MetadataRewriter { }; } - public PacketHandler getTrackerAndRewriter(Type> metaType, EntityType entityType) { + public PacketHandler getTrackerAndRewriter(@Nullable Type> metaType, EntityType entityType) { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); // Register Type ID diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java index 740ba84e2..831bab655 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/SoundRewriter.java @@ -1,9 +1,9 @@ package us.myles.ViaVersion.api.rewriters; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; public class SoundRewriter { protected final Protocol protocol; @@ -15,9 +15,9 @@ public class SoundRewriter { this.idRewriter = idRewriter; } - // The same for entity sound effect - public void registerSound(int oldId, int newId) { - protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + // The same for entity sound + public void registerSound(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Sound Id diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java index 9de13e59e..5b2edd47e 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java @@ -1,10 +1,10 @@ package us.myles.ViaVersion.api.rewriters; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import java.util.ArrayList; import java.util.List; @@ -40,8 +40,8 @@ public class TagRewriter { newTags.add(new TagData(id, oldIds)); } - public void register(int oldId, int newId) { - protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() { + public void register(ClientboundPacketType packetType) { + protocol.registerOutgoing(packetType, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java index fcafa91fe..bc49bf297 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.api.storage; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.data.ExternalJoinGameListener; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; @@ -30,6 +31,7 @@ public abstract class EntityTracker extends StoredObject implements ExternalJoin return clientEntityTypes.containsKey(entityId); } + @Nullable public EntityType getEntity(int entityId) { return clientEntityTypes.get(entityId); } diff --git a/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java b/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java index afc97ddec..201d39f63 100644 --- a/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java +++ b/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java @@ -247,6 +247,7 @@ public abstract class CommonBoss extends BossBar { } private enum UpdateAction { + ADD(0), REMOVE(1), UPDATE_HEALTH(2), diff --git a/common/src/main/java/us/myles/ViaVersion/packets/Direction.java b/common/src/main/java/us/myles/ViaVersion/packets/Direction.java index 93e5a567d..443be814b 100644 --- a/common/src/main/java/us/myles/ViaVersion/packets/Direction.java +++ b/common/src/main/java/us/myles/ViaVersion/packets/Direction.java @@ -1,6 +1,13 @@ package us.myles.ViaVersion.packets; public enum Direction { + + /** + * Outgoing server packets sent to the client. + */ OUTGOING, + /** + * Incoming server packets send by the client to the server. + */ INCOMING } diff --git a/common/src/main/java/us/myles/ViaVersion/packets/State.java b/common/src/main/java/us/myles/ViaVersion/packets/State.java index 60a17f8f6..c5ff5f355 100644 --- a/common/src/main/java/us/myles/ViaVersion/packets/State.java +++ b/common/src/main/java/us/myles/ViaVersion/packets/State.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.packets; public enum State { + HANDSHAKE, STATUS, LOGIN, diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java index cdd36664c..35afc80d8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java @@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.api.protocol.SimpleProtocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; @@ -16,7 +17,7 @@ import us.myles.ViaVersion.packets.State; import java.util.List; -public class BaseProtocol extends Protocol { +public class BaseProtocol extends SimpleProtocol { @Override protected void registerPackets() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java index 8ccd9f60a..7e20f0f2b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java @@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; +import us.myles.ViaVersion.api.protocol.SimpleProtocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; @@ -23,7 +24,7 @@ import java.util.List; import java.util.UUID; import java.util.logging.Level; -public class BaseProtocol1_7 extends Protocol { +public class BaseProtocol1_7 extends SimpleProtocol { @Override protected void registerPackets() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java index 7d05cadc6..2646513d4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java @@ -8,28 +8,24 @@ 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.api.type.types.version.Metadata1_9Type; -import us.myles.ViaVersion.api.type.types.version.MetadataList1_9Type; import us.myles.ViaVersion.api.type.types.version.Types1_9; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker; +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 java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -public class Protocol1_10To1_9_3_4 extends Protocol { - @Deprecated - public static final Type> METADATA_LIST = new MetadataList1_9Type(); - @Deprecated - public static final Type METADATA = new Metadata1_9Type(); +public class Protocol1_10To1_9_3_4 extends Protocol { - public static final ValueTransformer toNewPitch = new ValueTransformer(Type.FLOAT) { + public static final ValueTransformer TO_NEW_PITCH = new ValueTransformer(Type.FLOAT) { @Override public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception { return inputValue / 63.5F; } }; - public static final ValueTransformer, List> transformMetadata = new ValueTransformer, List>(Types1_9.METADATA_LIST) { + public static final ValueTransformer, List> TRANSFORM_METADATA = new ValueTransformer, List>(Types1_9.METADATA_LIST) { @Override public List transform(PacketWrapper wrapper, List inputValue) throws Exception { List metaList = new CopyOnWriteArrayList<>(inputValue); @@ -41,6 +37,10 @@ public class Protocol1_10To1_9_3_4 extends Protocol { } }; + public Protocol1_10To1_9_3_4() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); + } + @Override protected void registerPackets() { // Named sound effect @@ -53,7 +53,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.INT); // 3 - y map(Type.INT); // 4 - z map(Type.FLOAT); // 5 - Volume - map(Type.UNSIGNED_BYTE, toNewPitch); // 6 - Pitch + map(Type.UNSIGNED_BYTE, TO_NEW_PITCH); // 6 - Pitch } }); @@ -67,7 +67,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.INT); // 3 - y map(Type.INT); // 4 - z map(Type.FLOAT); // 5 - Volume - map(Type.UNSIGNED_BYTE, toNewPitch); // 6 - Pitch + map(Type.UNSIGNED_BYTE, TO_NEW_PITCH); // 6 - Pitch handler(new PacketHandler() { @Override @@ -84,7 +84,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID - map(Types1_9.METADATA_LIST, transformMetadata); // 1 - Metadata list + map(Types1_9.METADATA_LIST, TRANSFORM_METADATA); // 1 - Metadata list } }); @@ -104,7 +104,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z - map(Types1_9.METADATA_LIST, transformMetadata); // 12 - Metadata + map(Types1_9.METADATA_LIST, TRANSFORM_METADATA); // 12 - Metadata } }); @@ -119,7 +119,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.DOUBLE); // 4 - Z map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 6 - Pitch - map(Types1_9.METADATA_LIST, transformMetadata); // 7 - Metadata list + map(Types1_9.METADATA_LIST, TRANSFORM_METADATA); // 7 - Metadata list } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/Protocol1_11_1To1_11.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/Protocol1_11_1To1_11.java index cbedf97c9..9d16e420f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/Protocol1_11_1To1_11.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/Protocol1_11_1To1_11.java @@ -1,10 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_11_1to1_11; import us.myles.ViaVersion.api.protocol.Protocol; +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 Protocol1_11_1To1_11 extends Protocol { - @Override - protected void registerPackets() { - // Only had metadata changes, see wiki.vg for full info. - } +public class Protocol1_11_1To1_11 extends Protocol { } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java index c482ad5ec..6dd4c4eb4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java @@ -15,14 +15,15 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.rewriters.SoundRewriter; 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; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata.MetadataRewriter1_11To1_10; import us.myles.ViaVersion.protocols.protocol1_11to1_10.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_11; 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.storage.ClientWorld; -public class Protocol1_11To1_10 extends Protocol { +public class Protocol1_11To1_10 extends Protocol { private static final ValueTransformer toOldByte = new ValueTransformer(Type.UNSIGNED_BYTE) { @Override public Short transform(PacketWrapper wrapper, Float inputValue) throws Exception { @@ -30,14 +31,17 @@ public class Protocol1_11To1_10 extends Protocol { } }; + public Protocol1_11To1_10() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class); + } + @Override protected void registerPackets() { MetadataRewriter1_11To1_10 metadataRewriter = new MetadataRewriter1_11To1_10(this); InventoryPackets.register(this); - // Spawn Object - registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -49,8 +53,7 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Spawn mob packet - registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -87,10 +90,9 @@ public class Protocol1_11To1_10 extends Protocol { } }); - new SoundRewriter(this, this::getNewSoundId).registerSound(0x46, 0x46); + new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND); - // Collect item packet - registerOutgoing(State.PLAY, 0x48, 0x48, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Collected entity id @@ -105,11 +107,9 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Metadata packet - metadataRewriter.registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST); - // Entity teleport - registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.ENTITY_TELEPORT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -137,11 +137,9 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Destroy entities - metadataRewriter.registerEntityDestroy(0x30, 0x30); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES); - // Title packet - registerOutgoing(State.PLAY, 0x45, 0x45, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.TITLE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Action @@ -161,8 +159,7 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Block action packet - registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.BLOCK_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Position @@ -185,8 +182,7 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Update Block Entity - registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Position @@ -209,8 +205,7 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Chunk Data - registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -240,18 +235,15 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Join (save dimension id) - metadataRewriter.registerJoinGame(0x23, 0x23, null); + metadataRewriter.registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, null); - // Respawn (save dimension id) - metadataRewriter.registerRespawn(0x33, 0x33); + metadataRewriter.registerRespawn(ClientboundPackets1_9_3.RESPAWN); /* INCOMING PACKETS - */ + */ - // Block placement - registerIncoming(State.PLAY, 0x1C, 0x1C, new PacketRemapper() { + registerIncoming(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Location @@ -264,8 +256,7 @@ public class Protocol1_11To1_10 extends Protocol { } }); - // Chat Message Incoming - registerIncoming(State.PLAY, 0x02, 0x02, new PacketRemapper() { + registerIncoming(ServerboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Message diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java index 4c731116f..fa87fc5db 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java @@ -5,7 +5,8 @@ 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_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_11to1_10.EntityIdRewriter; import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10; @@ -14,17 +15,12 @@ public class InventoryPackets { public static void register(Protocol1_11To1_10 protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, EntityIdRewriter::toClientItem, EntityIdRewriter::toServerItem); - // Set slot packet - itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16); - - // Window items packet - itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14); - - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3C); + itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM); + itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY); + itemRewriter.registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM); // Plugin message Packet -> 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 @@ -54,11 +50,7 @@ public class InventoryPackets { } }); - - // Click window packet - itemRewriter.registerClickWindow(Type.ITEM, 0x07, 0x07); - - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x18); + itemRewriter.registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/ClientboundPackets1_12_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/ClientboundPackets1_12_1.java new file mode 100644 index 000000000..85baecbf4 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/ClientboundPackets1_12_1.java @@ -0,0 +1,87 @@ +package us.myles.ViaVersion.protocols.protocol1_12_1to1_12; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_12_1 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + TAB_COMPLETE, // 0x0E + CHAT_MESSAGE, // 0x0F + MULTI_BLOCK_CHANGE, // 0x10 + WINDOW_CONFIRMATION, // 0x11 + CLOSE_WINDOW, // 0x12 + OPEN_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + PLUGIN_MESSAGE, // 0x18 + NAMED_SOUND, // 0x19 + DISCONNECT, // 0x1A + ENTITY_STATUS, // 0x1B + EXPLOSION, // 0x1C + UNLOAD_CHUNK, // 0x1D + GAME_EVENT, // 0x1E + KEEP_ALIVE, // 0x1F + CHUNK_DATA, // 0x20 + EFFECT, // 0x21 + SPAWN_PARTICLE, // 0x22 + JOIN_GAME, // 0x23 + MAP_DATA, // 0x24 + ENTITY_MOVEMENT, // 0x25 + ENTITY_POSITION, // 0x26 + ENTITY_POSITION_AND_ROTATION, // 0x27 + ENTITY_ROTATION, // 0x28 + VEHICLE_MOVE, // 0x29 + OPEN_SIGN_EDITOR, // 0x2A + CRAFT_RECIPE_RESPONSE, // 0x2B + PLAYER_ABILITIES, // 0x2C + COMBAT_EVENT, // 0x2D + PLAYER_INFO, // 0x2E + PLAYER_POSITION, // 0x2F + USE_BED, // 0x30 + UNLOCK_RECIPES, // 0x31 + DESTROY_ENTITIES, // 0x32 + REMOVE_ENTITY_EFFECT, // 0x33 + RESOURCE_PACK, // 0x34 + RESPAWN, // 0x35 + ENTITY_HEAD_LOOK, // 0x36 + SELECT_ADVANCEMENTS_TAB, // 0x37 + WORLD_BORDER, // 0x38 + CAMERA, // 0x39 + HELD_ITEM_CHANGE, // 0x3A + DISPLAY_SCOREBOARD, // 0x3B + ENTITY_METADATA, // 0x3C + ATTACH_ENTITY, // 0x3D + ENTITY_VELOCITY, // 0x3E + ENTITY_EQUIPMENT, // 0x3F + SET_EXPERIENCE, // 0x40 + UPDATE_HEALTH, // 0x41 + SCOREBOARD_OBJECTIVE, // 0x42 + SET_PASSENGERS, // 0x43 + TEAMS, // 0x44 + UPDATE_SCORE, // 0x45 + SPAWN_POSITION, // 0x46 + TIME_UPDATE, // 0x47 + TITLE, // 0x48 + SOUND, // 0x49 + TAB_LIST, // 0x4A + COLLECT_ITEM, // 0x4B + ENTITY_TELEPORT, // 0x4C + ADVANCEMENTS, // 0x4D + ENTITY_PROPERTIES, // 0x4E + ENTITY_EFFECT, // 0x4F +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1To1_12.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1To1_12.java index d4d26efdf..09c4d67f5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1To1_12.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/Protocol1_12_1To1_12.java @@ -1,89 +1,17 @@ package us.myles.ViaVersion.protocols.protocol1_12_1to1_12; -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_12to1_11_1.ClientboundPackets1_12; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; + +public class Protocol1_12_1To1_12 extends Protocol { + + public Protocol1_12_1To1_12() { + super(ClientboundPackets1_12.class, ClientboundPackets1_12_1.class, ServerboundPackets1_12.class, ServerboundPackets1_12_1.class); + } -public class Protocol1_12_1To1_12 extends Protocol { @Override protected void registerPackets() { - registerOutgoing(State.PLAY, -1, 0x2B); // TODO new packet? - registerOutgoing(State.PLAY, 0x2b, 0x2c); // Player Abilities (clientbound) - registerOutgoing(State.PLAY, 0x2c, 0x2d); // Combat Event - registerOutgoing(State.PLAY, 0x2d, 0x2e); // Player List Item - registerOutgoing(State.PLAY, 0x2e, 0x2f); // Player Position And Look (clientbound) - registerOutgoing(State.PLAY, 0x2f, 0x30); // Use Bed - registerOutgoing(State.PLAY, 0x30, 0x31); // Unlock Recipes - registerOutgoing(State.PLAY, 0x31, 0x32); // Destroy Entities - registerOutgoing(State.PLAY, 0x32, 0x33); // Remove Entity Effect - registerOutgoing(State.PLAY, 0x33, 0x34); // Resource Pack Send - registerOutgoing(State.PLAY, 0x34, 0x35); // Respawn - registerOutgoing(State.PLAY, 0x35, 0x36); // Entity Head Look - registerOutgoing(State.PLAY, 0x36, 0x37); // Select Advancement Tab - registerOutgoing(State.PLAY, 0x37, 0x38); // World Border - registerOutgoing(State.PLAY, 0x38, 0x39); // Camera - registerOutgoing(State.PLAY, 0x39, 0x3a); // Held Item Change (clientbound) - registerOutgoing(State.PLAY, 0x3a, 0x3b); // Display Scoreboard - registerOutgoing(State.PLAY, 0x3b, 0x3c); // Entity Metadata - registerOutgoing(State.PLAY, 0x3c, 0x3d); // Attach Entity - registerOutgoing(State.PLAY, 0x3d, 0x3e); // Entity Velocity - registerOutgoing(State.PLAY, 0x3e, 0x3f); // Entity Equipment - registerOutgoing(State.PLAY, 0x3f, 0x40); // Set Experience - registerOutgoing(State.PLAY, 0x40, 0x41); // Update Health - registerOutgoing(State.PLAY, 0x41, 0x42); // Scoreboard Objective - registerOutgoing(State.PLAY, 0x42, 0x43); // Set Passengers - registerOutgoing(State.PLAY, 0x43, 0x44); // Teams - registerOutgoing(State.PLAY, 0x44, 0x45); // Update Sc - registerOutgoing(State.PLAY, 0x45, 0x46); // Spawn Position - registerOutgoing(State.PLAY, 0x46, 0x47); // Time Update - registerOutgoing(State.PLAY, 0x47, 0x48); // Title - registerOutgoing(State.PLAY, 0x48, 0x49); // Sound Effect - registerOutgoing(State.PLAY, 0x49, 0x4a); // Player List Header And Footer - registerOutgoing(State.PLAY, 0x4a, 0x4b); // Collect Item - registerOutgoing(State.PLAY, 0x4b, 0x4c); // Entity Teleport - registerOutgoing(State.PLAY, 0x4c, 0x4d); // Advancements - registerOutgoing(State.PLAY, 0x4d, 0x4e); // Entity Properties - registerOutgoing(State.PLAY, 0x4e, 0x4f); // Entity Effect - - // TODO Where did the Prepare Crafting Grid packet go to? - registerIncoming(State.PLAY, 0x01, -1); // Prepare Crafting Grid (removed) - - registerIncoming(State.PLAY, 0x02, 0x01); // Tab-Complete (serverbound) - registerIncoming(State.PLAY, 0x03, 0x02); // Chat Message (serverbound) - registerIncoming(State.PLAY, 0x04, 0x03); // Client Status - registerIncoming(State.PLAY, 0x05, 0x04); // Client Settings - registerIncoming(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound) - registerIncoming(State.PLAY, 0x07, 0x06); // Enchant Item - registerIncoming(State.PLAY, 0x08, 0x07); // Click Window - registerIncoming(State.PLAY, 0x09, 0x08); // Close Window (serverbound) - registerIncoming(State.PLAY, 0x0a, 0x09); // Plugin Message (serverbound) - registerIncoming(State.PLAY, 0x0b, 0x0a); // Use Entity - registerIncoming(State.PLAY, 0x0c, 0x0b); // Keep Alive (serverbound) - registerIncoming(State.PLAY, 0x0d, 0x0c); // Player - registerIncoming(State.PLAY, 0x0e, 0x0d); // Player Position - registerIncoming(State.PLAY, 0x0f, 0x0e); // Player Position And Look (serverbound) - registerIncoming(State.PLAY, 0x10, 0x0f); // Player Look - registerIncoming(State.PLAY, 0x11, 0x10); // Vehicle Move (serverbound) - registerIncoming(State.PLAY, 0x12, 0x11); // Steer Boat - - // TODO hello new packet - registerIncoming(State.PLAY, -1, 0x12, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.BYTE); // 0 - Unknown - map(Type.VAR_INT); // 1 - Unknown - map(Type.BOOLEAN); // 2 - Unknown - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(ServerboundPackets1_12_1.CRAFT_RECIPE_REQUEST); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/ServerboundPackets1_12_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/ServerboundPackets1_12_1.java new file mode 100644 index 000000000..1dd24b7fa --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_1to1_12/ServerboundPackets1_12_1.java @@ -0,0 +1,40 @@ +package us.myles.ViaVersion.protocols.protocol1_12_1to1_12; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_12_1 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + TAB_COMPLETE, // 0x01 + CHAT_MESSAGE, // 0x02 + CLIENT_STATUS, // 0x03 + CLIENT_SETTINGS, // 0x04 + WINDOW_CONFIRMATION, // 0x05 + CLICK_WINDOW_BUTTON, // 0x06 + CLICK_WINDOW, // 0x07 + CLOSE_WINDOW, // 0x08 + PLUGIN_MESSAGE, // 0x09 + INTERACT_ENTITY, // 0x0A + KEEP_ALIVE, // 0x0B + PLAYER_MOVEMENT, // 0x0C + PLAYER_POSITION, // 0x0D + PLAYER_POSITION_AND_ROTATION, // 0x0E + PLAYER_ROTATION, // 0x0F + VEHICLE_MOVE, // 0x10 + STEER_BOAT, // 0x11 + CRAFT_RECIPE_REQUEST, // 0x12 + PLAYER_ABILITIES, // 0x13 + PLAYER_DIGGING, // 0x14 + ENTITY_ACTION, // 0x15 + STEER_VEHICLE, // 0x16 + RECIPE_BOOK_DATA, // 0x17 + RESOURCE_PACK_STATUS, // 0x18 + ADVANCEMENT_TAB, // 0x19 + HELD_ITEM_CHANGE, // 0x1A + CREATIVE_INVENTORY_ACTION, // 0x1B + UPDATE_SIGN, // 0x1C + ANIMATION, // 0x1D + SPECTATE, // 0x1E + PLAYER_BLOCK_PLACEMENT, // 0x1F + USE_ITEM, // 0x20 +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_2to1_12_1/Protocol1_12_2To1_12_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_2to1_12_1/Protocol1_12_2To1_12_1.java index 263d6008f..450092bfa 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_2to1_12_1/Protocol1_12_2To1_12_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12_2to1_12_1/Protocol1_12_2To1_12_1.java @@ -3,22 +3,25 @@ package us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1; import us.myles.ViaVersion.api.protocol.Protocol; 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_2To1_12_1 extends Protocol { + + public Protocol1_12_2To1_12_1() { + super(ClientboundPackets1_12_1.class, ClientboundPackets1_12_1.class, ServerboundPackets1_12_1.class, ServerboundPackets1_12_1.class); + } + @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() { map(Type.VAR_INT, Type.LONG); } - }); // Keep alive - // Incoming - // 0xb - Keep alive - registerIncoming(State.PLAY, 0xb, 0xb, new PacketRemapper() { + }); + + registerIncoming(ServerboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() { @Override public void registerMap() { map(Type.LONG, Type.VAR_INT); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/ClientboundPackets1_12.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/ClientboundPackets1_12.java new file mode 100644 index 000000000..a3499e252 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/ClientboundPackets1_12.java @@ -0,0 +1,86 @@ +package us.myles.ViaVersion.protocols.protocol1_12to1_11_1; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_12 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + TAB_COMPLETE, // 0x0E + CHAT_MESSAGE, // 0x0F + MULTI_BLOCK_CHANGE, // 0x10 + WINDOW_CONFIRMATION, // 0x11 + CLOSE_WINDOW, // 0x12 + OPEN_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + PLUGIN_MESSAGE, // 0x18 + NAMED_SOUND, // 0x19 + DISCONNECT, // 0x1A + ENTITY_STATUS, // 0x1B + EXPLOSION, // 0x1C + UNLOAD_CHUNK, // 0x1D + GAME_EVENT, // 0x1E + KEEP_ALIVE, // 0x1F + CHUNK_DATA, // 0x20 + EFFECT, // 0x21 + SPAWN_PARTICLE, // 0x22 + JOIN_GAME, // 0x23 + MAP_DATA, // 0x24 + ENTITY_MOVEMENT, // 0x25 + ENTITY_POSITION, // 0x26 + ENTITY_POSITION_AND_ROTATION, // 0x27 + ENTITY_ROTATION, // 0x28 + VEHICLE_MOVE, // 0x29 + OPEN_SIGN_EDITOR, // 0x2A + PLAYER_ABILITIES, // 0x2B + COMBAT_EVENT, // 0x2C + PLAYER_INFO, // 0x2D + PLAYER_POSITION, // 0x2E + USE_BED, // 0x2F + UNLOCK_RECIPES, // 0x30 + DESTROY_ENTITIES, // 0x31 + REMOVE_ENTITY_EFFECT, // 0x32 + RESOURCE_PACK, // 0x33 + RESPAWN, // 0x34 + ENTITY_HEAD_LOOK, // 0x35 + SELECT_ADVANCEMENTS_TAB, // 0x36 + WORLD_BORDER, // 0x37 + CAMERA, // 0x38 + HELD_ITEM_CHANGE, // 0x39 + DISPLAY_SCOREBOARD, // 0x3A + ENTITY_METADATA, // 0x3B + ATTACH_ENTITY, // 0x3C + ENTITY_VELOCITY, // 0x3D + ENTITY_EQUIPMENT, // 0x3E + SET_EXPERIENCE, // 0x3F + UPDATE_HEALTH, // 0x40 + SCOREBOARD_OBJECTIVE, // 0x41 + SET_PASSENGERS, // 0x42 + TEAMS, // 0x43 + UPDATE_SCORE, // 0x44 + SPAWN_POSITION, // 0x45 + TIME_UPDATE, // 0x46 + TITLE, // 0x47 + SOUND, // 0x48 + TAB_LIST, // 0x49 + COLLECT_ITEM, // 0x4A + ENTITY_TELEPORT, // 0x4B + ADVANCEMENTS, // 0x4C + ENTITY_PROPERTIES, // 0x4D + ENTITY_EFFECT, // 0x4E +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index b657f6eb4..2a3eec570 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -16,7 +16,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.SoundRewriter; 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_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_12to1_11_1.metadata.MetadataRewriter1_12To1_11_1; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; @@ -26,16 +27,19 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.util.GsonUtil; -public class Protocol1_12To1_11_1 extends Protocol { +public class Protocol1_12To1_11_1 extends Protocol { + + public Protocol1_12To1_11_1() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_12.class, ServerboundPackets1_9_3.class, ServerboundPackets1_12.class); + } @Override protected void registerPackets() { MetadataRewriter1_12To1_11_1 metadataRewriter = new MetadataRewriter1_12To1_11_1(this); InventoryPackets.register(this); - // Outgoing - // Spawn Object - registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -47,8 +51,7 @@ public class Protocol1_12To1_11_1 extends Protocol { } }); - // Spawn mob packet - registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -70,8 +73,7 @@ public class Protocol1_12To1_11_1 extends Protocol { } }); - // Chat message packet - registerOutgoing(State.PLAY, 0x0F, 0x0F, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Chat Message (json) @@ -97,8 +99,7 @@ public class Protocol1_12To1_11_1 extends Protocol { } }); - // Chunk Data - registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -141,66 +142,19 @@ public class Protocol1_12To1_11_1 extends Protocol { } }); - // Join Packet - metadataRewriter.registerJoinGame(0x23, 0x23, null); + metadataRewriter.registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, null); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES); + metadataRewriter.registerRespawn(ClientboundPackets1_9_3.RESPAWN); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_12.METADATA_LIST); - // 0x28 moved to 0x25 - registerOutgoing(State.PLAY, 0x28, 0x25); - registerOutgoing(State.PLAY, 0x25, 0x26); - registerOutgoing(State.PLAY, 0x26, 0x27); - registerOutgoing(State.PLAY, 0x27, 0x28); + new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND); - // New packet at 0x30 - // Destroy entities - metadataRewriter.registerEntityDestroy(0x30, 0x31); - registerOutgoing(State.PLAY, 0x31, 0x32); - registerOutgoing(State.PLAY, 0x32, 0x33); - - // Respawn Packet - metadataRewriter.registerRespawn(0x33, 0x34); - - registerOutgoing(State.PLAY, 0x34, 0x35); - // New packet at 0x36 - registerOutgoing(State.PLAY, 0x35, 0x37); - registerOutgoing(State.PLAY, 0x36, 0x38); - registerOutgoing(State.PLAY, 0x37, 0x39); - registerOutgoing(State.PLAY, 0x38, 0x3a); - - // Metadata packet - metadataRewriter.registerMetadataRewriter(0x39, 0x3b, Types1_12.METADATA_LIST); - - registerOutgoing(State.PLAY, 0x3a, 0x3c); - registerOutgoing(State.PLAY, 0x3b, 0x3d); - // registerOutgoing(State.PLAY, 0x3c, 0x3e); - Handled in InventoryPackets - registerOutgoing(State.PLAY, 0x3d, 0x3f); - registerOutgoing(State.PLAY, 0x3e, 0x40); - registerOutgoing(State.PLAY, 0x3f, 0x41); - registerOutgoing(State.PLAY, 0x40, 0x42); - registerOutgoing(State.PLAY, 0x41, 0x43); - registerOutgoing(State.PLAY, 0x42, 0x44); - registerOutgoing(State.PLAY, 0x43, 0x45); - registerOutgoing(State.PLAY, 0x44, 0x46); - registerOutgoing(State.PLAY, 0x45, 0x47); - - new SoundRewriter(this, this::getNewSoundId).registerSound(0x46, 0x48); - - registerOutgoing(State.PLAY, 0x47, 0x49); - registerOutgoing(State.PLAY, 0x48, 0x4a); - registerOutgoing(State.PLAY, 0x49, 0x4b); - // New packet at 0x4c - registerOutgoing(State.PLAY, 0x4a, 0x4d); - registerOutgoing(State.PLAY, 0x4b, 0x4e); - - // Incoming // New packet at 0x01 - cancelIncoming(State.PLAY, 0x01, 0x01); + cancelIncoming(ServerboundPackets1_12.PREPARE_CRAFTING_GRID); - registerIncoming(State.PLAY, 0x01, 0x02); - registerIncoming(State.PLAY, 0x02, 0x03); - registerIncoming(State.PLAY, 0x03, 0x04); // Client Settings (max length changed) - registerIncoming(State.PLAY, 0x04, 0x05, new PacketRemapper() { + registerIncoming(ServerboundPackets1_12.CLIENT_SETTINGS, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Locale @@ -229,41 +183,12 @@ public class Protocol1_12To1_11_1 extends Protocol { }); } }); - registerIncoming(State.PLAY, 0x05, 0x06); - registerIncoming(State.PLAY, 0x06, 0x07); - // registerIncoming(State.PLAY, 0x07, 0x08); - Handled in InventoryPackets - registerIncoming(State.PLAY, 0x08, 0x09); - registerIncoming(State.PLAY, 0x09, 0x0a); - registerIncoming(State.PLAY, 0x0a, 0x0b); - registerIncoming(State.PLAY, 0x0b, 0x0c); - // Mojang swapped 0x0F to 0x0D - registerIncoming(State.PLAY, 0x0f, 0x0d); - registerIncoming(State.PLAY, 0x0c, 0x0e); - // Mojang swapped 0x0F to 0x0D - registerIncoming(State.PLAY, 0x0d, 0x0f); - registerIncoming(State.PLAY, 0x0e, 0x10); - registerIncoming(State.PLAY, 0x10, 0x11); - registerIncoming(State.PLAY, 0x11, 0x12); - registerIncoming(State.PLAY, 0x12, 0x13); - registerIncoming(State.PLAY, 0x13, 0x14); - registerIncoming(State.PLAY, 0x14, 0x15); - registerIncoming(State.PLAY, 0x15, 0x16); // New packet at 0x17 - cancelIncoming(State.PLAY, 0x17, 0x17); - - registerIncoming(State.PLAY, 0x16, 0x18); + cancelIncoming(ServerboundPackets1_12.RECIPE_BOOK_DATA); // New packet 0x19 - cancelIncoming(State.PLAY, 0x19, 0x19); - - registerIncoming(State.PLAY, 0x17, 0x1a); - // registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets - registerIncoming(State.PLAY, 0x19, 0x1c); - registerIncoming(State.PLAY, 0x1a, 0x1d); - registerIncoming(State.PLAY, 0x1b, 0x1e); - registerIncoming(State.PLAY, 0x1c, 0x1f); - registerIncoming(State.PLAY, 0x1d, 0x20); + cancelIncoming(ServerboundPackets1_12.ADVANCEMENT_TAB); } private int getNewSoundId(int id) { //TODO Make it better, suggestions are welcome. It's ugly and hardcoded now. diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/ServerboundPackets1_12.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/ServerboundPackets1_12.java new file mode 100644 index 000000000..5c10d99f0 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/ServerboundPackets1_12.java @@ -0,0 +1,40 @@ +package us.myles.ViaVersion.protocols.protocol1_12to1_11_1; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_12 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + PREPARE_CRAFTING_GRID, // 0x01 + TAB_COMPLETE, // 0x02 + CHAT_MESSAGE, // 0x03 + CLIENT_STATUS, // 0x04 + CLIENT_SETTINGS, // 0x05 + WINDOW_CONFIRMATION, // 0x06 + CLICK_WINDOW_BUTTON, // 0x07 + CLICK_WINDOW, // 0x08 + CLOSE_WINDOW, // 0x09 + PLUGIN_MESSAGE, // 0x0A + INTERACT_ENTITY, // 0x0B + KEEP_ALIVE, // 0x0C + PLAYER_MOVEMENT, // 0x0D + PLAYER_POSITION, // 0x0E + PLAYER_POSITION_AND_ROTATION, // 0x0F + PLAYER_ROTATION, // 0x10 + VEHICLE_MOVE, // 0x11 + STEER_BOAT, // 0x12 + PLAYER_ABILITIES, // 0x13 + PLAYER_DIGGING, // 0x14 + ENTITY_ACTION, // 0x15 + STEER_VEHICLE, // 0x16 + RECIPE_BOOK_DATA, // 0x17 + RESOURCE_PACK_STATUS, // 0x18 + ADVANCEMENT_TAB, // 0x19 + HELD_ITEM_CHANGE, // 0x1A + CREATIVE_INVENTORY_ACTION, // 0x1B + UPDATE_SIGN, // 0x1C + ANIMATION, // 0x1D + SPECTATE, // 0x1E + PLAYER_BLOCK_PLACEMENT, // 0x1F + USE_ITEM, // 0x20 +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java index 982cb39b7..2018b998b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/TranslateRewriter.java @@ -5,13 +5,13 @@ import com.google.gson.JsonObject; import us.myles.ViaVersion.api.data.UserConnection; public class TranslateRewriter { + public static boolean toClient(JsonElement element, UserConnection user) { if (element instanceof JsonObject) { JsonObject obj = (JsonObject) element; - if (obj.has("translate")) { - if (obj.get("translate").getAsString().equals("chat.type.achievement")) { - return false; - } + JsonElement translate = obj.get("translate"); + if (translate != null) { + return !translate.getAsString().equals("chat.type.achievement"); } } return true; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java index 907770a17..a18c36980 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java @@ -7,9 +7,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_9_3to1_9_1_2.ClientboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; +import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; public class InventoryPackets { @@ -17,17 +18,12 @@ public class InventoryPackets { public static void register(Protocol1_12To1_11_1 protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, BedRewriter::toClientItem, BedRewriter::toServerItem); - // Set slot packet - itemRewriter.registerSetSlot(Type.ITEM, 0x16, 0x16); - - // Window items packet - itemRewriter.registerWindowItems(Type.ITEM_ARRAY, 0x14, 0x14); - - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.ITEM, 0x3C, 0x3E); + itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM); + itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY); + itemRewriter.registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM); // Plugin message Packet -> 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 @@ -44,8 +40,9 @@ public class InventoryPackets { BedRewriter.toClientItem(wrapper.passthrough(Type.ITEM)); // Output Item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item - if (secondItem) + if (secondItem) { BedRewriter.toClientItem(wrapper.passthrough(Type.ITEM)); // Second Item + } wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.INT); // Number of tools uses @@ -58,8 +55,7 @@ public class InventoryPackets { }); - // Click window packet - protocol.registerIncoming(State.PLAY, 0x07, 0x08, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_12.CLICK_WINDOW, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID @@ -100,6 +96,6 @@ public class InventoryPackets { ); // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.ITEM, 0x18, 0x1b); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_12.CREATIVE_INVENTORY_ACTION, Type.ITEM); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java index 69f57e38b..06787674b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java @@ -8,15 +8,20 @@ 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_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.WorldPackets; +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.storage.EntityTracker1_13; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_13_1To1_13 extends Protocol { +public class Protocol1_13_1To1_13 extends Protocol { + + public Protocol1_13_1To1_13() { + super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class); + } @Override protected void registerPackets() { @@ -26,8 +31,7 @@ public class Protocol1_13_1To1_13 extends Protocol { InventoryPackets.register(this); WorldPackets.register(this); - //Tab complete - registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -41,8 +45,7 @@ public class Protocol1_13_1To1_13 extends Protocol { } }); - //Edit Book - registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { map(Type.FLAT_ITEM); @@ -66,8 +69,7 @@ public class Protocol1_13_1To1_13 extends Protocol { } }); - // 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 @@ -93,8 +95,7 @@ public class Protocol1_13_1To1_13 extends Protocol { } }); - // Boss bar - registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.BOSSBAR, new PacketRemapper() { @Override public void registerMap() { map(Type.UUID); @@ -117,8 +118,7 @@ public class Protocol1_13_1To1_13 extends Protocol { } }); - // Advancements - registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -160,9 +160,7 @@ public class Protocol1_13_1To1_13 extends Protocol { } }); - - //Tags - registerOutgoing(State.PLAY, 0x55, 0x55, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.TAGS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -193,8 +191,9 @@ public class Protocol1_13_1To1_13 extends Protocol { @Override public void init(UserConnection userConnection) { userConnection.put(new EntityTracker1_13(userConnection)); - if (!userConnection.has(ClientWorld.class)) + if (!userConnection.has(ClientWorld.class)) { userConnection.put(new ClientWorld(userConnection)); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/EntityPackets.java index 9ebab3466..01282ba56 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/EntityPackets.java @@ -2,23 +2,21 @@ package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_13Types; -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.packets.State; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; public class EntityPackets { - public static void register(final Protocol protocol) { + public static void register(Protocol1_13_1To1_13 protocol) { MetadataRewriter1_13_1To1_13 metadataRewriter = protocol.get(MetadataRewriter1_13_1To1_13.class); - //spawn entity - protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -52,8 +50,7 @@ public class EntityPackets { } }); - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -74,8 +71,7 @@ public class EntityPackets { } }); - // 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 @@ -91,10 +87,7 @@ public class EntityPackets { } }); - // Destroy entities - metadataRewriter.registerEntityDestroy(0x35, 0x35); - - // Metadata packet - metadataRewriter.registerMetadataRewriter(0x3F, 0x3F, Types1_13.METADATA_LIST); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13.METADATA_LIST); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java index 17815507f..1dff09681 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java @@ -7,24 +7,19 @@ 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_13to1_12_2.ClientboundPackets1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; public class InventoryPackets { public static void register(Protocol protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer); - // Set cooldown - itemRewriter.registerSetCooldown(0x18, 0x18, InventoryPackets::getNewItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN, InventoryPackets::getNewItemId); + itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_ITEM); + itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_ITEM_ARRAY); - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_ITEM, 0x17, 0x17); - - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_ITEM_ARRAY, 0x15, 0x15); - - // 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 @@ -58,11 +53,9 @@ public class InventoryPackets { } }); - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.FLAT_ITEM, 0x42, 0x42); + itemRewriter.registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM); - // 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() { @@ -77,8 +70,8 @@ public class InventoryPackets { int ingredientsNo = wrapper.passthrough(Type.VAR_INT); for (int i1 = 0; i1 < ingredientsNo; i1++) { Item[] items = wrapper.passthrough(Type.FLAT_ITEM_ARRAY_VAR_INT); - for (int i2 = 0; i2 < items.length; i2++) { - InventoryPackets.toClient(items[i2]); + for (Item item : items) { + InventoryPackets.toClient(item); } } InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Result @@ -87,8 +80,8 @@ public class InventoryPackets { wrapper.passthrough(Type.STRING); // Group for (int i1 = 0; i1 < ingredientsNo; i1++) { Item[] items = wrapper.passthrough(Type.FLAT_ITEM_ARRAY_VAR_INT); - for (int i2 = 0; i2 < items.length; i2++) { - InventoryPackets.toClient(items[i2]); + for (Item item : items) { + InventoryPackets.toClient(item); } } InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); // Result @@ -96,8 +89,8 @@ public class InventoryPackets { wrapper.passthrough(Type.STRING); // Group // Ingredient start Item[] items = wrapper.passthrough(Type.FLAT_ITEM_ARRAY_VAR_INT); - for (int i2 = 0; i2 < items.length; i2++) { - InventoryPackets.toClient(items[i2]); + for (Item item : items) { + InventoryPackets.toClient(item); } // Ingredient end InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); @@ -110,12 +103,8 @@ public class InventoryPackets { } }); - - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_ITEM, 0x08, 0x08); - - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_ITEM, 0x24, 0x24); + itemRewriter.registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.FLAT_ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.FLAT_ITEM); } public static void toClient(Item item) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/WorldPackets.java index 1540f235f..13dd7ae20 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_1to1_13/packets/WorldPackets.java @@ -8,8 +8,8 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.BlockRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @@ -18,8 +18,7 @@ public class WorldPackets { public static void register(Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13_1To1_13::getNewBlockStateId, Protocol1_13_1To1_13::getNewBlockId); - //Chunk - protocol.registerOutgoing(State.PLAY, 0x22, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -39,20 +38,12 @@ public class WorldPackets { } }); - // Block action - blockRewriter.registerBlockAction(0x0A, 0x0A); + blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE); + blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001, InventoryPackets::getNewItemId); - // Block Change - blockRewriter.registerBlockChange(0xB, 0xB); - - // Multi Block Change - blockRewriter.registerMultiBlockChange(0xF, 0xF); - - // Effect packet - blockRewriter.registerEffect(0x23, 0x23, 1010, 2001, InventoryPackets::getNewItemId); - - //join game - protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -71,8 +62,7 @@ public class WorldPackets { } }); - //respawn - protocol.registerOutgoing(State.PLAY, 0x38, 0x38, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension ID @@ -87,7 +77,6 @@ public class WorldPackets { } }); - //spawn particle - blockRewriter.registerSpawnParticle(Type.FLOAT, 0x24, 0x24, 3, 20, 27, InventoryPackets::toClient, Type.FLAT_ITEM); + blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, InventoryPackets::toClient, Type.FLAT_ITEM, Type.FLOAT); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java index f5dd2533d..e897165d6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/Protocol1_13_2To1_13_1.java @@ -6,12 +6,17 @@ 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_13_2to1_13_1.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.WorldPackets; +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_2To1_13_1 extends Protocol { +public class Protocol1_13_2To1_13_1 extends Protocol { + + public Protocol1_13_2To1_13_1() { + super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class); + } @Override protected void registerPackets() { @@ -19,16 +24,14 @@ public class Protocol1_13_2To1_13_1 extends Protocol { WorldPackets.register(this); EntityPackets.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_VAR_INT_ITEM, Type.FLAT_ITEM); } }); - // Advancements - registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java index aa6556d18..ea5511460 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java @@ -1,6 +1,5 @@ package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets; -import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2; import us.myles.ViaVersion.api.protocol.Protocol; @@ -9,22 +8,18 @@ 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 EntityPackets { public static void register(Protocol protocol) { - final PacketHandler metaTypeHandler = new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { - metadata.setMetaType(MetaType1_13_2.byId(metadata.getMetaType().getTypeID())); - } + final PacketHandler metaTypeHandler = wrapper -> { + for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { + metadata.setMetaType(MetaType1_13_2.byId(metadata.getMetaType().getTypeID())); } }; - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -45,8 +40,7 @@ public class EntityPackets { } }); - // 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 @@ -62,9 +56,7 @@ public class EntityPackets { } }); - - // 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 @@ -74,5 +66,4 @@ public class EntityPackets { } }); } - } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java index 65382aab6..62017c3d3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/InventoryPackets.java @@ -5,13 +5,13 @@ 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 InventoryPackets { public static void register(Protocol protocol) { - // Set slot packet - protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SET_SLOT, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); // 0 - Window ID @@ -19,9 +19,7 @@ public class InventoryPackets { map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value } }); - - // 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 @@ -29,8 +27,7 @@ public class InventoryPackets { } }); - // 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 @@ -63,8 +60,7 @@ public class InventoryPackets { } }); - // 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 @@ -73,8 +69,7 @@ public class InventoryPackets { } }); - // 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() { @@ -113,28 +108,23 @@ public class InventoryPackets { } }); - // 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_VAR_INT_ITEM, Type.FLAT_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_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item - } - } - ); + 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_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item + } + }); + protocol.registerIncoming(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.SHORT); // 0 - Slot + map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item + } + }); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java index cdbe42151..d97e6d5f5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13_2to1_13_1/packets/WorldPackets.java @@ -5,13 +5,12 @@ 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 WorldPackets { public static void register(Protocol protocol) { - //spawn particle - protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ClientboundPackets1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ClientboundPackets1_13.java new file mode 100644 index 000000000..05ccd9f6b --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ClientboundPackets1_13.java @@ -0,0 +1,93 @@ +package us.myles.ViaVersion.protocols.protocol1_13to1_12_2; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_13 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + CHAT_MESSAGE, // 0x0E + MULTI_BLOCK_CHANGE, // 0x0F + TAB_COMPLETE, // 0x10 + DECLARE_COMMANDS, // 0x11 + WINDOW_CONFIRMATION, // 0x12 + CLOSE_WINDOW, // 0x13 + OPEN_WINDOW, // 0x14 + WINDOW_ITEMS, // 0x15 + WINDOW_PROPERTY, // 0x16 + SET_SLOT, // 0x17 + COOLDOWN, // 0x18 + PLUGIN_MESSAGE, // 0x19 + NAMED_SOUND, // 0x1A + DISCONNECT, // 0x1B + ENTITY_STATUS, // 0x1C + NBT_QUERY, // 0x1D + EXPLOSION, // 0x1E + UNLOAD_CHUNK, // 0x1F + GAME_EVENT, // 0x20 + KEEP_ALIVE, // 0x21 + CHUNK_DATA, // 0x22 + EFFECT, // 0x23 + SPAWN_PARTICLE, // 0x24 + JOIN_GAME, // 0x25 + MAP_DATA, // 0x26 + ENTITY_MOVEMENT, // 0x27 + ENTITY_POSITION, // 0x28 + ENTITY_POSITION_AND_ROTATION, // 0x29 + ENTITY_ROTATION, // 0x2A + VEHICLE_MOVE, // 0x2B + OPEN_SIGN_EDITOR, // 0x2C + CRAFT_RECIPE_RESPONSE, // 0x2D + PLAYER_ABILITIES, // 0x2E + COMBAT_EVENT, // 0x2F + PLAYER_INFO, // 0x30 + FACE_PLAYER, // 0x31 + PLAYER_POSITION, // 0x32 + USE_BED, // 0x33 + UNLOCK_RECIPES, // 0x34 + DESTROY_ENTITIES, // 0x35 + REMOVE_ENTITY_EFFECT, // 0x36 + RESOURCE_PACK, // 0x37 + RESPAWN, // 0x38 + ENTITY_HEAD_LOOK, // 0x39 + SELECT_ADVANCEMENTS_TAB, // 0x3A + WORLD_BORDER, // 0x3B + CAMERA, // 0x3C + HELD_ITEM_CHANGE, // 0x3D + DISPLAY_SCOREBOARD, // 0x3E + ENTITY_METADATA, // 0x3F + ATTACH_ENTITY, // 0x40 + ENTITY_VELOCITY, // 0x41 + ENTITY_EQUIPMENT, // 0x42 + SET_EXPERIENCE, // 0x43 + UPDATE_HEALTH, // 0x44 + SCOREBOARD_OBJECTIVE, // 0x45 + SET_PASSENGERS, // 0x46 + TEAMS, // 0x47 + UPDATE_SCORE, // 0x48 + SPAWN_POSITION, // 0x49 + TIME_UPDATE, // 0x4A + TITLE, // 0x4B + STOP_SOUND, // 0x4D + SOUND, // 0x4C + TAB_LIST, // 0x4E + COLLECT_ITEM, // 0x4F + ENTITY_TELEPORT, // 0x50 + ADVANCEMENTS, // 0x51 + ENTITY_PROPERTIES, // 0x52 + ENTITY_EFFECT, // 0x53 + DECLARE_RECIPES, // 0x54 + TAGS, // 0x55 +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index d319436cc..feb9cef5f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -18,6 +18,8 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.rewriters.SoundRewriter; 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; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; @@ -41,10 +43,10 @@ import us.myles.ViaVersion.util.GsonUtil; import java.util.EnumMap; import java.util.Map; -public class Protocol1_13To1_12_2 extends Protocol { +public class Protocol1_13To1_12_2 extends Protocol { public Protocol1_13To1_12_2() { - super(true); + super(ClientboundPackets1_12_1.class, ClientboundPackets1_13.class, ServerboundPackets1_12_1.class, ServerboundPackets1_13.class, true); } public static final PacketHandler POS_TO_3_INT = wrapper -> { @@ -145,8 +147,6 @@ public class Protocol1_13To1_12_2 extends Protocol { WorldPackets.register(this); InventoryPackets.register(this); - // Outgoing packets - registerOutgoing(State.LOGIN, 0x0, 0x0, new PacketRemapper() { @Override public void registerMap() { @@ -185,7 +185,7 @@ public class Protocol1_13To1_12_2 extends Protocol { // New packet 0x04 - Login Plugin Message // Statistics - registerOutgoing(State.PLAY, 0x07, 0x07, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.STATISTICS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -244,8 +244,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - // Boss bar - registerOutgoing(State.PLAY, 0xC, 0xC, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.BOSSBAR, new PacketRemapper() { @Override public void registerMap() { map(Type.UUID); @@ -261,8 +260,7 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - // Chat message - registerOutgoing(State.PLAY, 0xF, 0xE, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -274,10 +272,7 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - // WorldPackets 0x10 -> 0x0F - - // Tab-Complete - registerOutgoing(State.PLAY, 0xE, 0x10, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { create(new ValueCreator() { @@ -318,31 +313,17 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - // New packet 0x11, declare commands - registerOutgoing(State.PLAY, 0x11, 0x12); - registerOutgoing(State.PLAY, 0x12, 0x13); - // Open window - registerOutgoing(State.PLAY, 0x13, 0x14, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.OPEN_WINDOW, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Id map(Type.STRING); // Window type map(Type.STRING); // Title - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.set(Type.STRING, 1, ChatRewriter.processTranslate(wrapper.get(Type.STRING, 1))); - } - }); + handler(wrapper -> wrapper.set(Type.STRING, 1, ChatRewriter.processTranslate(wrapper.get(Type.STRING, 1)))); } }); - // InventoryPackets 0x14 -> 0x15 - // InventoryPackets 0x15 -> 0x16 - // InventoryPackets 0x16 -> 0x17 - - // Set cooldown - registerOutgoing(State.PLAY, 0x17, 0x18, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.COOLDOWN, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -380,29 +361,16 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - // WorldPackets 0x18 -> 0x19 - // Disconnect - registerOutgoing(State.PLAY, 0x1A, 0x1B, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_12_1.DISCONNECT, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.set(Type.STRING, 0, ChatRewriter.processTranslate(wrapper.get(Type.STRING, 0))); - } - }); + handler(wrapper -> wrapper.set(Type.STRING, 0, ChatRewriter.processTranslate(wrapper.get(Type.STRING, 0)))); } }); - registerOutgoing(State.PLAY, 0x1B, 0x1C); - // New packet 0x1D - NBT Query - // WorldPackets 0x1C -> 0x1E - registerOutgoing(State.PLAY, 0x1E, 0x20); - registerOutgoing(State.PLAY, 0x1F, 0x21); - // WorldPackets 0x20 -> 0x22 - // Effect packet - registerOutgoing(State.PLAY, 0x21, 0x23, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id @@ -425,9 +393,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - // WorldPackets 0x22 -> 0x24 - // Join (save dimension id) - registerOutgoing(State.PLAY, 0x23, 0x25, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -450,8 +416,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - // Map packet - registerOutgoing(State.PLAY, 0x24, 0x26, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.MAP_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Map id @@ -475,28 +440,15 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - registerOutgoing(State.PLAY, 0x25, 0x27); - registerOutgoing(State.PLAY, 0x26, 0x28); - registerOutgoing(State.PLAY, 0x27, 0x29); - registerOutgoing(State.PLAY, 0x28, 0x2A); - registerOutgoing(State.PLAY, 0x29, 0x2B); - registerOutgoing(State.PLAY, 0x2A, 0x2C); - // Craft recipe response - registerOutgoing(State.PLAY, 0x2B, 0x2D, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_12_1.CRAFT_RECIPE_RESPONSE, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.STRING, "viaversion:legacy/" + wrapper.read(Type.VAR_INT)); - } - }); + handler(wrapper -> wrapper.write(Type.STRING, "viaversion:legacy/" + wrapper.read(Type.VAR_INT))); } }); - registerOutgoing(State.PLAY, 0x2C, 0x2E); - // Combat event - registerOutgoing(State.PLAY, 0x2D, 0x2F, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.COMBAT_EVENT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Event @@ -512,12 +464,7 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - registerOutgoing(State.PLAY, 0x2E, 0x30); - // New 0x31 - Face Player - registerOutgoing(State.PLAY, 0x2F, 0x32); - registerOutgoing(State.PLAY, 0x30, 0x33); - // Unlock recipes - registerOutgoing(State.PLAY, 0x31, 0x34, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.UNLOCK_RECIPES, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // action @@ -603,12 +550,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - // EntityPackets 0x32 -> 0x35 - registerOutgoing(State.PLAY, 0x33, 0x36); - registerOutgoing(State.PLAY, 0x34, 0x37); - - // Respawn (save dimension id) - registerOutgoing(State.PLAY, 0x35, 0x38, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension ID @@ -628,20 +570,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x36, 0x39); - registerOutgoing(State.PLAY, 0x37, 0x3A); - registerOutgoing(State.PLAY, 0x38, 0x3B); - registerOutgoing(State.PLAY, 0x39, 0x3C); - registerOutgoing(State.PLAY, 0x3A, 0x3D); - registerOutgoing(State.PLAY, 0x3B, 0x3E); - // EntityPackets 0x3C -> 0x3F - registerOutgoing(State.PLAY, 0x3D, 0x40); - registerOutgoing(State.PLAY, 0x3E, 0x41); - // InventoryPackets 0x3F -> 0x42 - registerOutgoing(State.PLAY, 0x40, 0x43); - registerOutgoing(State.PLAY, 0x41, 0x44); - // Scoreboard Objective - registerOutgoing(State.PLAY, 0x42, 0x45, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.SCOREBOARD_OBJECTIVE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Objective name @@ -665,9 +594,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x43, 0x46); - // Team packet - registerOutgoing(State.PLAY, 0x44, 0x47, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.TEAMS, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Team Name @@ -720,7 +647,7 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x45, 0x48, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.UPDATE_SCORE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -740,10 +667,8 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - registerOutgoing(State.PLAY, 0x46, 0x49); - registerOutgoing(State.PLAY, 0x47, 0x4A); - // Title - registerOutgoing(State.PLAY, 0x48, 0x4B, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_12_1.TITLE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // Action @@ -760,10 +685,9 @@ public class Protocol1_13To1_12_2 extends Protocol { }); // New 0x4C - Stop Sound - new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(0x49, 0x4D); + new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(ClientboundPackets1_12_1.SOUND); - // Player list header and footer - registerOutgoing(State.PLAY, 0x4A, 0x4E, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_12_1.TAB_LIST, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -777,10 +701,8 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - registerOutgoing(State.PLAY, 0x4B, 0x4F); - registerOutgoing(State.PLAY, 0x4C, 0x50); - // Advancements - registerOutgoing(State.PLAY, 0x4D, 0x51, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_12_1.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -822,21 +744,17 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - registerOutgoing(State.PLAY, 0x4E, 0x52); - registerOutgoing(State.PLAY, 0x4F, 0x53); - // New packet 0x54 - Declare Recipes - // New packet 0x55 - Tags + // Incoming packets - // New packet 0x02 - Login Plugin Message cancelIncoming(State.LOGIN, 0x02); // New 0x01 - Query Block NBT - cancelIncoming(State.PLAY, 0x01); + cancelIncoming(ServerboundPackets1_13.QUERY_BLOCK_NBT); // Tab-Complete - registerIncoming(State.PLAY, 0x1, 0x5, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -868,7 +786,7 @@ public class Protocol1_13To1_12_2 extends Protocol { if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) { TabCompleteTracker tracker = wrapper.user().get(TabCompleteTracker.class); wrapper.cancel(); - tracker.setTimeToSend(System.currentTimeMillis() + Via.getConfig().get1_13TabCompleteDelay() * 50); + tracker.setTimeToSend(System.currentTimeMillis() + Via.getConfig().get1_13TabCompleteDelay() * 50L); tracker.setLastTabComplete(wrapper.get(Type.STRING, 0)); } } @@ -876,14 +794,8 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - registerIncoming(State.PLAY, 0x05, 0x06); - registerIncoming(State.PLAY, 0x06, 0x07); - // InventoryPackets 0x07, 0x08 - registerIncoming(State.PLAY, 0x08, 0x09); - // InventoryPackets 0x09 -> 0x0A - // New 0x0A - Edit book -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x0B, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.EDIT_BOOK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -900,19 +812,12 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - // New 0x0C - Query Entity NBT - cancelIncoming(State.PLAY, 0x0C); - registerIncoming(State.PLAY, 0x0A, 0x0D); - registerIncoming(State.PLAY, 0x0B, 0x0E); - registerIncoming(State.PLAY, 0x0C, 0x0F); - registerIncoming(State.PLAY, 0x0D, 0x10); - registerIncoming(State.PLAY, 0x0E, 0x11); - registerIncoming(State.PLAY, 0x0F, 0x12); - registerIncoming(State.PLAY, 0x10, 0x13); - registerIncoming(State.PLAY, 0x11, 0x14); + // New 0x0C - Query Entity NBT + cancelIncoming(ServerboundPackets1_13.ENTITY_NBT_REQUEST); + // New 0x15 - Pick Item -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x15, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.PICK_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { create(new ValueCreator() { @@ -924,26 +829,15 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); - // Craft recipe request - registerIncoming(State.PLAY, 0x12, 0x16, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.CRAFT_RECIPE_REQUEST, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); // Window id - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.VAR_INT, Integer.parseInt(wrapper.read(Type.STRING).substring(18))); - } - }); + handler(wrapper -> wrapper.write(Type.VAR_INT, Integer.parseInt(wrapper.read(Type.STRING).substring(18)))); } }); - registerIncoming(State.PLAY, 0x13, 0x17); - registerIncoming(State.PLAY, 0x14, 0x18); - registerIncoming(State.PLAY, 0x15, 0x19); - registerIncoming(State.PLAY, 0x16, 0x1A); - // Recipe Book Data - registerIncoming(State.PLAY, 0x17, 0x1B, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.RECIPE_BOOK_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Type @@ -968,53 +862,40 @@ public class Protocol1_13To1_12_2 extends Protocol { }); // New 0x1C - Name Item -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x1C, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.RENAME_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { - create(new ValueCreator() { - @Override - public void write(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.STRING, "MC|ItemName"); // Channel - } + create(wrapper -> { + wrapper.write(Type.STRING, "MC|ItemName"); // Channel }); } }); - registerIncoming(State.PLAY, 0x18, 0x1D); - registerIncoming(State.PLAY, 0x19, 0x1E); - // New 0x1F - Select Trade -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x1F, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.SELECT_TRADE, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { - create(new ValueCreator() { - @Override - public void write(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.STRING, "MC|TrSel"); // Channel - } + create(wrapper -> { + wrapper.write(Type.STRING, "MC|TrSel"); // Channel }); map(Type.VAR_INT, Type.INT); // Slot } }); + // New 0x20 - Set Beacon Effect -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x20, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.SET_BEACON_EFFECT, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { - create(new ValueCreator() { - @Override - public void write(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.STRING, "MC|Beacon"); // Channel - } + create(wrapper -> { + wrapper.write(Type.STRING, "MC|Beacon"); // Channel }); map(Type.VAR_INT, Type.INT); // Primary Effect map(Type.VAR_INT, Type.INT); // Secondary Effect } }); - registerIncoming(State.PLAY, 0x1A, 0x21); - // New 0x22 - Update Command Block -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x22, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { create(new ValueCreator() { @@ -1043,8 +924,9 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); + // New 0x23 - Update Command Block Minecart -> Plugin Message - registerIncoming(State.PLAY, 0x09, 0x23, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { create(new ValueCreator() { @@ -1061,14 +943,11 @@ public class Protocol1_13To1_12_2 extends Protocol { // 0x1B -> 0x24 in InventoryPackets // New 0x25 - Update Structure Block -> Message Channel - registerIncoming(State.PLAY, 0x09, 0x25, new PacketRemapper() { + registerIncoming(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { - create(new ValueCreator() { - @Override - public void write(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.STRING, "MC|Struct"); // Channel - } + create(wrapper -> { + wrapper.write(Type.STRING, "MC|Struct"); // Channel }); handler(POS_TO_3_INT); map(Type.VAR_INT, new ValueTransformer(Type.BYTE) { // Action @@ -1127,12 +1006,6 @@ public class Protocol1_13To1_12_2 extends Protocol { }); } }); - - registerIncoming(State.PLAY, 0x1C, 0x26); - registerIncoming(State.PLAY, 0x1D, 0x27); - registerIncoming(State.PLAY, 0x1E, 0x28); - registerIncoming(State.PLAY, 0x1F, 0x29); - registerIncoming(State.PLAY, 0x20, 0x2A); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ServerboundPackets1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ServerboundPackets1_13.java new file mode 100644 index 000000000..7540a3a87 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/ServerboundPackets1_13.java @@ -0,0 +1,50 @@ +package us.myles.ViaVersion.protocols.protocol1_13to1_12_2; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_13 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + QUERY_BLOCK_NBT, // 0x01 + CHAT_MESSAGE, // 0x02 + CLIENT_STATUS, // 0x03 + CLIENT_SETTINGS, // 0x04 + TAB_COMPLETE, // 0x05 + WINDOW_CONFIRMATION, // 0x06 + CLICK_WINDOW_BUTTON, // 0x07 + CLICK_WINDOW, // 0x08 + CLOSE_WINDOW, // 0x09 + PLUGIN_MESSAGE, // 0x0A + EDIT_BOOK, // 0x0B + ENTITY_NBT_REQUEST, // 0x0C + INTERACT_ENTITY, // 0x0D + KEEP_ALIVE, // 0x0E + PLAYER_MOVEMENT, // 0x12 + PLAYER_POSITION, // 0x0F + PLAYER_POSITION_AND_ROTATION, // 0x10 + PLAYER_ROTATION, // 0x11 + VEHICLE_MOVE, // 0x13 + STEER_BOAT, // 0x14 + PICK_ITEM, // 0x15 + CRAFT_RECIPE_REQUEST, // 0x16 + PLAYER_ABILITIES, // 0x17 + PLAYER_DIGGING, // 0x18 + ENTITY_ACTION, // 0x19 + STEER_VEHICLE, // 0x1A + RECIPE_BOOK_DATA, // 0x1B + RENAME_ITEM, // 0x1C + RESOURCE_PACK_STATUS, // 0x1D + ADVANCEMENT_TAB, // 0x1E + SELECT_TRADE, // 0x1F + SET_BEACON_EFFECT, // 0x20 + HELD_ITEM_CHANGE, // 0x21 + UPDATE_COMMAND_BLOCK, // 0x22 + UPDATE_COMMAND_BLOCK_MINECART, // 0x23 + CREATIVE_INVENTORY_ACTION, // 0x24 + UPDATE_STRUCTURE_BLOCK, // 0x25 + UPDATE_SIGN, // 0x26 + ANIMATION, // 0x27 + SPECTATE, // 0x28 + PLAYER_BLOCK_PLACEMENT, // 0x29 + USE_ITEM, // 0x2A +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java index 53596e8a2..5bcc7595f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java @@ -2,22 +2,22 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_13Types; -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_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.ClientboundPackets1_12_1; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; public class EntityPackets { - public static void register(final Protocol protocol) { + + public static void register(Protocol1_13To1_12_2 protocol) { MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class); - // Spawn Object - protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -76,8 +76,7 @@ public class EntityPackets { } }); - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -98,8 +97,7 @@ public class EntityPackets { } }); - // Spawn player packet - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -115,10 +113,7 @@ public class EntityPackets { } }); - // Destroy entities - metadataRewriter.registerEntityDestroy(0x32, 0x35); - - // Metadata packet - metadataRewriter.registerMetadataRewriter(0x3C, 0x3F, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_12_1.DESTROY_ENTITIES); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_12_1.ENTITY_METADATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 9c5643c53..07e3b96bc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -1,7 +1,12 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets; import com.github.steveice10.opennbt.conversion.ConverterRegistry; -import com.github.steveice10.opennbt.tag.builtin.*; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.IntTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.ShortTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.base.Joiner; import com.google.common.primitives.Ints; import us.myles.ViaVersion.api.PacketWrapper; @@ -12,9 +17,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_12_1to1_12.ClientboundPackets1_12_1; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; 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_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.SoundSource; @@ -32,8 +38,7 @@ public class InventoryPackets { public static void register(Protocol protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer); - // Set slot packet - protocol.registerOutgoing(State.PLAY, 0x16, 0x17, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.SET_SLOT, new PacketRemapper() { @Override public void registerMap() { map(Type.BYTE); // 0 - Window ID @@ -43,9 +48,7 @@ public class InventoryPackets { handler(itemRewriter.itemToClientHandler(Type.FLAT_ITEM)); } }); - - // Window items packet - protocol.registerOutgoing(State.PLAY, 0x14, 0x15, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.WINDOW_ITEMS, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID @@ -54,9 +57,7 @@ public class InventoryPackets { handler(itemRewriter.itemArrayHandler(Type.FLAT_ITEM_ARRAY)); } }); - - // Window property - protocol.registerOutgoing(State.PLAY, 0x15, 0x16, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.WINDOW_PROPERTY, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Window id @@ -76,7 +77,7 @@ public class InventoryPackets { }); // Plugin message Packet -> Trading - protocol.registerOutgoing(State.PLAY, 0x18, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel @@ -178,8 +179,7 @@ public class InventoryPackets { } }); - // Entity Equipment Packet - protocol.registerOutgoing(State.PLAY, 0x3F, 0x42, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.ENTITY_EQUIPMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -191,8 +191,7 @@ public class InventoryPackets { }); - // Click window packet - protocol.registerIncoming(State.PLAY, 0x07, 0x08, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.CLICK_WINDOW, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // 0 - Window ID @@ -206,8 +205,7 @@ public class InventoryPackets { } }); - // Plugin message - protocol.registerIncoming(State.PLAY, 0x09, 0x0A, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // Channel @@ -242,8 +240,7 @@ public class InventoryPackets { } }); - // Creative Inventory Action - protocol.registerIncoming(State.PLAY, 0x1B, 0x24, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.SHORT); // 0 - Slot diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index a4b596f7e..4e33f4abc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -13,7 +13,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.Particle; -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.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler; @@ -57,9 +57,7 @@ public class WorldPackets { public static void register(Protocol protocol) { // Outgoing packets - - // Spawn Painting - protocol.registerOutgoing(State.PLAY, 0x04, 0x04, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.SPAWN_PAINTING, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -82,8 +80,7 @@ public class WorldPackets { } }); - // Update Block Entity - protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Location @@ -113,8 +110,7 @@ public class WorldPackets { } }); - // Block action - protocol.registerOutgoing(State.PLAY, 0xA, 0xA, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.BLOCK_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // Location @@ -162,8 +158,7 @@ public class WorldPackets { } }); - // Block Change - protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); @@ -193,8 +188,7 @@ public class WorldPackets { } }); - // Multi Block Change - protocol.registerOutgoing(State.PLAY, 0x10, 0xF, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.MULTI_BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Chunk X @@ -254,8 +248,7 @@ public class WorldPackets { } }); - // Explosion - protocol.registerOutgoing(State.PLAY, 0x1C, 0x1E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.EXPLOSION, new PacketRemapper() { @Override public void registerMap() { if (!Via.getConfig().isServersideBlockConnections()) @@ -300,8 +293,7 @@ public class WorldPackets { } }); - // Unload Chunk - protocol.registerOutgoing(State.PLAY, 0x1D, 0x1F, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.UNLOAD_CHUNK, new PacketRemapper() { @Override public void registerMap() { if (Via.getConfig().isServersideBlockConnections()) { @@ -317,8 +309,7 @@ public class WorldPackets { } }); - // Named Sound Effect TODO String -> Identifier? Check if identifier is present? - protocol.registerOutgoing(State.PLAY, 0x19, 0x1A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -332,8 +323,7 @@ public class WorldPackets { } }); - // Chunk Data - protocol.registerOutgoing(State.PLAY, 0x20, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -464,8 +454,7 @@ public class WorldPackets { } }); - // Particle - protocol.registerOutgoing(State.PLAY, 0x22, 0x24, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_12_1.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java index 6dcf02f30..1007b427d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java @@ -5,8 +5,14 @@ import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; +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_1To1_14 extends Protocol { +public class Protocol1_14_1To1_14 extends Protocol { + + public Protocol1_14_1To1_14() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); + } @Override protected void registerPackets() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java index 870c50a26..e15e7b334 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java @@ -1,20 +1,19 @@ package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets; import us.myles.ViaVersion.api.entities.Entity1_14Types; -import us.myles.ViaVersion.api.protocol.Protocol; 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_14_1to1_14.Protocol1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; public class EntityPackets { - public static void register(final Protocol protocol) { + public static void register(Protocol1_14_1To1_14 protocol) { MetadataRewriter1_14_1To1_14 metadataRewriter = protocol.get(MetadataRewriter1_14_1To1_14.class); - // Spawn Mob - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -35,11 +34,9 @@ public class EntityPackets { } }); - // Destroy entities - metadataRewriter.registerEntityDestroy(0x37, 0x37); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES); - // Spawn Player - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -55,7 +52,6 @@ public class EntityPackets { } }); - // Entity Metadata - metadataRewriter.registerMetadataRewriter(0x43, 0x43, Types1_14.METADATA_LIST); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java index 25a7ab132..277dfcd8b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_2to1_14_1/Protocol1_14_2To1_14_1.java @@ -1,17 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_14_2to1_14_1; -import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.Protocol; +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_1 extends Protocol { - - @Override - protected void registerPackets() { - - } - - @Override - public void init(UserConnection userConnection) { - - } +public class Protocol1_14_2To1_14_1 extends Protocol { } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_3to1_14_2/Protocol1_14_3To1_14_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_3to1_14_2/Protocol1_14_3To1_14_2.java index 16fb87047..18dcb1f06 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_3to1_14_2/Protocol1_14_3To1_14_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_3to1_14_2/Protocol1_14_3To1_14_2.java @@ -5,14 +5,18 @@ 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_14to1_13_2.ClientboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -public class Protocol1_14_3To1_14_2 extends Protocol { +public class Protocol1_14_3To1_14_2 extends Protocol { + + public Protocol1_14_3To1_14_2() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, null, null); + } @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() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_4to1_14_3/Protocol1_14_4To1_14_3.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_4to1_14_3/Protocol1_14_4To1_14_3.java index 9b8eda613..911e89b75 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_4to1_14_3/Protocol1_14_4To1_14_3.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_4to1_14_3/Protocol1_14_4To1_14_3.java @@ -5,14 +5,18 @@ 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_14to1_13_2.ClientboundPackets1_14; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -public class Protocol1_14_4To1_14_3 extends Protocol { +public class Protocol1_14_4To1_14_3 extends Protocol { + + public Protocol1_14_4To1_14_3() { + super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, null, null); + } @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() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/ClientboundPackets1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/ClientboundPackets1_14.java new file mode 100644 index 000000000..513188c5d --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/ClientboundPackets1_14.java @@ -0,0 +1,100 @@ +package us.myles.ViaVersion.protocols.protocol1_14to1_13_2; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_14 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + CHAT_MESSAGE, // 0x0E + MULTI_BLOCK_CHANGE, // 0x0F + TAB_COMPLETE, // 0x10 + DECLARE_COMMANDS, // 0x11 + WINDOW_CONFIRMATION, // 0x12 + CLOSE_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + PLUGIN_MESSAGE, // 0x18 + NAMED_SOUND, // 0x19 + DISCONNECT, // 0x1A + ENTITY_STATUS, // 0x1B + EXPLOSION, // 0x1C + UNLOAD_CHUNK, // 0x1D + GAME_EVENT, // 0x1E + OPEN_HORSE_WINDOW, // 0x1F + KEEP_ALIVE, // 0x20 + CHUNK_DATA, // 0x21 + EFFECT, // 0x22 + SPAWN_PARTICLE, // 0x23 + UPDATE_LIGHT, // 0x24 + JOIN_GAME, // 0x25 + MAP_DATA, // 0x26 + TRADE_LIST, // 0x27 + ENTITY_POSITION, // 0x28 + ENTITY_POSITION_AND_ROTATION, // 0x29 + ENTITY_ROTATION, // 0x2A + ENTITY_MOVEMENT, // 0x2B + VEHICLE_MOVE, // 0x2C + OPEN_BOOK, // 0x2D + OPEN_WINDOW, // 0x2E + OPEN_SIGN_EDITOR, // 0x2F + CRAFT_RECIPE_RESPONSE, // 0x30 + PLAYER_ABILITIES, // 0x31 + COMBAT_EVENT, // 0x32 + PLAYER_INFO, // 0x33 + FACE_PLAYER, // 0x34 + PLAYER_POSITION, // 0x35 + UNLOCK_RECIPES, // 0x36 + DESTROY_ENTITIES, // 0x37 + REMOVE_ENTITY_EFFECT, // 0x38 + RESOURCE_PACK, // 0x39 + RESPAWN, // 0x3A + ENTITY_HEAD_LOOK, // 0x3B + SELECT_ADVANCEMENTS_TAB, // 0x3C + WORLD_BORDER, // 0x3D + CAMERA, // 0x3E + HELD_ITEM_CHANGE, // 0x3F + UPDATE_VIEW_POSITION, // 0x40 + UPDATE_VIEW_DISTANCE, // 0x41 + DISPLAY_SCOREBOARD, // 0x42 + ENTITY_METADATA, // 0x43 + ATTACH_ENTITY, // 0x44 + ENTITY_VELOCITY, // 0x45 + ENTITY_EQUIPMENT, // 0x46 + SET_EXPERIENCE, // 0x47 + UPDATE_HEALTH, // 0x48 + SCOREBOARD_OBJECTIVE, // 0x49 + SET_PASSENGERS, // 0x4A + TEAMS, // 0x4B + UPDATE_SCORE, // 0x4C + SPAWN_POSITION, // 0x4D + TIME_UPDATE, // 0x4E + TITLE, // 0x4F + ENTITY_SOUND, // 0x50 + SOUND, // 0x51 + STOP_SOUND, // 0x52 + TAB_LIST, // 0x53 + NBT_QUERY, // 0x54 + COLLECT_ITEM, // 0x55 + ENTITY_TELEPORT, // 0x56 + ADVANCEMENTS, // 0x57 + ENTITY_PROPERTIES, // 0x58 + ENTITY_EFFECT, // 0x59 + DECLARE_RECIPES, // 0x5A + TAGS, // 0x5B + ACKNOWLEDGE_PLAYER_DIGGING, // 0x5C +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java index e45011be8..f668965c0 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java @@ -8,7 +8,8 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.SoundRewriter; 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.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.EntityPackets; @@ -18,10 +19,10 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_14To1_13_2 extends Protocol { +public class Protocol1_14To1_13_2 extends Protocol { public Protocol1_14To1_13_2() { - super(true); + super(ClientboundPackets1_13.class, ClientboundPackets1_14.class, ServerboundPackets1_13.class, ServerboundPackets1_14.class, true); } @Override @@ -33,61 +34,9 @@ public class Protocol1_14To1_13_2 extends Protocol { WorldPackets.register(this); PlayerPackets.register(this); - registerOutgoing(State.PLAY, 0x16, 0x15); + new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(ClientboundPackets1_13.SOUND); - registerOutgoing(State.PLAY, 0x1A, 0x19); - registerOutgoing(State.PLAY, 0x1B, 0x1A); - registerOutgoing(State.PLAY, 0x1C, 0x1B); - registerOutgoing(State.PLAY, 0x1D, 0x54); - registerOutgoing(State.PLAY, 0x1F, 0x1D); - registerOutgoing(State.PLAY, 0x20, 0x1E); - registerOutgoing(State.PLAY, 0x21, 0x20); - - registerOutgoing(State.PLAY, 0x27, 0x2B); - - registerOutgoing(State.PLAY, 0x2B, 0x2C); - - registerOutgoing(State.PLAY, 0x2D, 0x30); - registerOutgoing(State.PLAY, 0x2E, 0x31); - registerOutgoing(State.PLAY, 0x2F, 0x32); - registerOutgoing(State.PLAY, 0x30, 0x33); - registerOutgoing(State.PLAY, 0x31, 0x34); - // Position and look - registerOutgoing(State.PLAY, 0x32, 0x35); - - registerOutgoing(State.PLAY, 0x34, 0x36); - - registerOutgoing(State.PLAY, 0x36, 0x38); - registerOutgoing(State.PLAY, 0x37, 0x39); - - registerOutgoing(State.PLAY, 0x39, 0x3B); - registerOutgoing(State.PLAY, 0x3A, 0x3C); - registerOutgoing(State.PLAY, 0x3B, 0x3D); - registerOutgoing(State.PLAY, 0x3C, 0x3E); - registerOutgoing(State.PLAY, 0x3D, 0x3F); - registerOutgoing(State.PLAY, 0x3E, 0x42); - - registerOutgoing(State.PLAY, 0x40, 0x44); - registerOutgoing(State.PLAY, 0x41, 0x45); - - registerOutgoing(State.PLAY, 0x43, 0x47); - registerOutgoing(State.PLAY, 0x44, 0x48); - registerOutgoing(State.PLAY, 0x45, 0x49); - registerOutgoing(State.PLAY, 0x46, 0x4A); - registerOutgoing(State.PLAY, 0x47, 0x4B); - registerOutgoing(State.PLAY, 0x48, 0x4C); - - registerOutgoing(State.PLAY, 0x4A, 0x4E); - registerOutgoing(State.PLAY, 0x4B, 0x4F); - registerOutgoing(State.PLAY, 0x4C, 0x52); - - new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(0x4D, 0x51); - - registerOutgoing(State.PLAY, 0x4E, 0x53); - registerOutgoing(State.PLAY, 0x4F, 0x55); - registerOutgoing(State.PLAY, 0x50, 0x56); - - registerOutgoing(State.PLAY, 0x51, 0x57, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -128,10 +77,7 @@ public class Protocol1_14To1_13_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x52, 0x58); - registerOutgoing(State.PLAY, 0x53, 0x59); - - registerOutgoing(State.PLAY, 0x55, 0x5B, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_13.TAGS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -194,54 +140,12 @@ public class Protocol1_14To1_13_2 extends Protocol { } }); - //Set Difficulty packet added in 19w11a - cancelIncoming(State.PLAY, 0x02); - - registerIncoming(State.PLAY, 0x02, 0x03); - registerIncoming(State.PLAY, 0x03, 0x04); - registerIncoming(State.PLAY, 0x04, 0x05); - registerIncoming(State.PLAY, 0x05, 0x06); - registerIncoming(State.PLAY, 0x06, 0x07); - registerIncoming(State.PLAY, 0x07, 0x08); - - registerIncoming(State.PLAY, 0x09, 0x0A); - registerIncoming(State.PLAY, 0x0A, 0x0B); - - registerIncoming(State.PLAY, 0x0C, 0x0D); - registerIncoming(State.PLAY, 0x0D, 0x0E); - - //Lock Difficulty packet added in 19w11a - cancelIncoming(State.PLAY, 0x10); - - registerIncoming(State.PLAY, 0x0E, 0x0F); - registerIncoming(State.PLAY, 0x0F, 0x14); - registerIncoming(State.PLAY, 0x10, 0x11); - registerIncoming(State.PLAY, 0x11, 0x12); - registerIncoming(State.PLAY, 0x12, 0x13); - registerIncoming(State.PLAY, 0x13, 0x15); - registerIncoming(State.PLAY, 0x14, 0x16); - registerIncoming(State.PLAY, 0x15, 0x17); - registerIncoming(State.PLAY, 0x16, 0x18); - registerIncoming(State.PLAY, 0x17, 0x19); - - registerIncoming(State.PLAY, 0x19, 0x1B); - registerIncoming(State.PLAY, 0x1A, 0x1C); - - registerIncoming(State.PLAY, 0x1C, 0x1E); - registerIncoming(State.PLAY, 0x1D, 0x1F); - registerIncoming(State.PLAY, 0x1E, 0x20); - registerIncoming(State.PLAY, 0x20, 0x22); - registerIncoming(State.PLAY, 0x21, 0x23); - - registerIncoming(State.PLAY, 0x23, 0x25); - - //Unknown packet added in 19w13a - cancelIncoming(State.PLAY, 0x27); - - registerIncoming(State.PLAY, 0x27, 0x2A); - registerIncoming(State.PLAY, 0x28, 0x2B); - - registerIncoming(State.PLAY, 0x2A, 0x2D); + // Set Difficulty packet added in 19w11a + cancelIncoming(ServerboundPackets1_14.SET_DIFFICULTY); + // Lock Difficulty packet added in 19w11a + cancelIncoming(ServerboundPackets1_14.LOCK_DIFFICULTY); + // Unknown packet added in 19w13a + cancelIncoming(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/ServerboundPackets1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/ServerboundPackets1_14.java new file mode 100644 index 000000000..bb287f33d --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/ServerboundPackets1_14.java @@ -0,0 +1,53 @@ +package us.myles.ViaVersion.protocols.protocol1_14to1_13_2; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_14 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + QUERY_BLOCK_NBT, // 0x01 + SET_DIFFICULTY, // 0x02 + CHAT_MESSAGE, // 0x03 + CLIENT_STATUS, // 0x04 + CLIENT_SETTINGS, // 0x05 + TAB_COMPLETE, // 0x06 + WINDOW_CONFIRMATION, // 0x07 + CLICK_WINDOW_BUTTON, // 0x08 + CLICK_WINDOW, // 0x09 + CLOSE_WINDOW, // 0x0A + PLUGIN_MESSAGE, // 0x0B + EDIT_BOOK, // 0x0C + ENTITY_NBT_REQUEST, // 0x0D + INTERACT_ENTITY, // 0x0E + KEEP_ALIVE, // 0x0F + LOCK_DIFFICULTY, // 0x10 + PLAYER_POSITION, // 0x11 + PLAYER_POSITION_AND_ROTATION, // 0x12 + PLAYER_ROTATION, // 0x13 + PLAYER_MOVEMENT, // 0x14 + VEHICLE_MOVE, // 0x15 + STEER_BOAT, // 0x16 + PICK_ITEM, // 0x17 + CRAFT_RECIPE_REQUEST, // 0x18 + PLAYER_ABILITIES, // 0x19 + PLAYER_DIGGING, // 0x1A + ENTITY_ACTION, // 0x1B + STEER_VEHICLE, // 0x1C + RECIPE_BOOK_DATA, // 0x1D + RENAME_ITEM, // 0x1E + RESOURCE_PACK_STATUS, // 0x1F + ADVANCEMENT_TAB, // 0x20 + SELECT_TRADE, // 0x21 + SET_BEACON_EFFECT, // 0x22 + HELD_ITEM_CHANGE, // 0x23 + UPDATE_COMMAND_BLOCK, // 0x24 + UPDATE_COMMAND_BLOCK_MINECART, // 0x25 + CREATIVE_INVENTORY_ACTION, // 0x26 + UPDATE_JIGSAW_BLOCK, // 0x27 + UPDATE_STRUCTURE_BLOCK, // 0x28 + UPDATE_SIGN, // 0x29 + ANIMATION, // 0x2A + SPECTATE, // 0x2B + PLAYER_BLOCK_PLACEMENT, // 0x2C + USE_ITEM, // 0x2D +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index fb7cbf2f9..b3de6fe43 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -6,13 +6,13 @@ import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; -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_2; import us.myles.ViaVersion.api.type.types.version.Types1_14; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_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.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2; @@ -23,11 +23,10 @@ import java.util.List; public class EntityPackets { - public static void register(final Protocol protocol) { + public static void register(Protocol1_14To1_13_2 protocol) { MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class); - // Spawn entity - protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -104,8 +103,7 @@ public class EntityPackets { } }); - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -126,8 +124,7 @@ public class EntityPackets { } }); - // Spawn painting - protocol.registerOutgoing(State.PLAY, 0x04, 0x04, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PAINTING, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -138,8 +135,7 @@ public class EntityPackets { } }); - // 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 @@ -155,8 +151,7 @@ public class EntityPackets { } }); - // Animation - protocol.registerOutgoing(State.PLAY, 0x06, 0x06, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.ENTITY_ANIMATION, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -184,8 +179,7 @@ public class EntityPackets { } }); - // Use bed - protocol.registerOutgoing(State.PLAY, 0x33, 0x43, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.USE_BED, ClientboundPackets1_14.ENTITY_METADATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -208,10 +202,7 @@ public class EntityPackets { } }); - // Destroy entities - metadataRewriter.registerEntityDestroy(0x35, 0x37); - - // Metadata packet - metadataRewriter.registerMetadataRewriter(0x3F, 0x43, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_13.DESTROY_ENTITIES); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index 8b00344d1..eca326ba4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -1,7 +1,11 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; import com.github.steveice10.opennbt.conversion.ConverterRegistry; -import com.github.steveice10.opennbt.tag.builtin.*; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.DoubleTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.collect.Sets; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; @@ -11,10 +15,11 @@ 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_13to1_12_2.ChatRewriter; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.InventoryNameRewriter; 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_14to1_13_2.storage.EntityTracker1_14; @@ -28,11 +33,9 @@ public class InventoryPackets { public static void register(Protocol protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer); - // Set cooldown - itemRewriter.registerSetCooldown(0x18, 0x17, InventoryPackets::getNewItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_13.COOLDOWN, InventoryPackets::getNewItemId); - // Open Inventory - protocol.registerOutgoing(State.PLAY, 0x14, -1, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.OPEN_WINDOW, null, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -105,14 +108,10 @@ public class InventoryPackets { } }); - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x15, 0x14); + itemRewriter.registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); + itemRewriter.registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x17, 0x16); - - // Plugin message - protocol.registerOutgoing(State.PLAY, 0x19, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // Channel @@ -164,11 +163,9 @@ public class InventoryPackets { } }); - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x42, 0x46); + itemRewriter.registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); - // Declare Recipes - protocol.registerOutgoing(State.PLAY, 0x54, 0x5A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.DECLARE_RECIPES, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -218,11 +215,9 @@ public class InventoryPackets { }); - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x08, 0x09); + itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); - // Select trade - protocol.registerIncoming(State.PLAY, 0x1F, 0x21, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.SELECT_TRADE, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -244,11 +239,9 @@ public class InventoryPackets { } }); - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x24, 0x26); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); } - public static void toClient(Item item) { if (item == null) return; item.setIdentifier(getNewItemId(item.getIdentifier())); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java index c74bceb21..75a4ce6fb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/PlayerPackets.java @@ -11,22 +11,20 @@ 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_14to1_13_2.ServerboundPackets1_14; public class PlayerPackets { public static void register(Protocol protocol) { - - // Open Sign Editor - protocol.registerOutgoing(State.PLAY, 0x2C, 0x2F, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.OPEN_SIGN_EDITOR, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION, Type.POSITION1_14); } }); - // Query Block NBT - protocol.registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.QUERY_BLOCK_NBT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -34,14 +32,13 @@ public class PlayerPackets { } }); - // Edit Book - protocol.registerIncoming(State.PLAY, 0x0B, 0x0C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - final Item item = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); + Item item = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); InventoryPackets.toServer(item); // Client limit when editing a book was upped from 50 to 100 in 1.14, but some anti-exploit plugins ban with a size higher than the old client limit @@ -63,8 +60,7 @@ public class PlayerPackets { } }); - // Player Digging - protocol.registerIncoming(State.PLAY, 0x18, 0x1A, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.PLAYER_DIGGING, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -73,8 +69,7 @@ public class PlayerPackets { } }); - // Recipe Book Data - protocol.registerIncoming(State.PLAY, 0x1B, 0x1D, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.RECIPE_BOOK_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -101,32 +96,26 @@ public class PlayerPackets { } }); - // Update Command Block - protocol.registerIncoming(State.PLAY, 0x22, 0x24, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.UPDATE_COMMAND_BLOCK, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION1_14, Type.POSITION); + } + }); + protocol.registerIncoming(ServerboundPackets1_14.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION1_14, Type.POSITION); + } + }); + protocol.registerIncoming(ServerboundPackets1_14.UPDATE_SIGN, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION1_14, Type.POSITION); } }); - // Update Structure Block - protocol.registerIncoming(State.PLAY, 0x25, 0x28, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.POSITION1_14, Type.POSITION); - } - }); - - // Update Sign - protocol.registerIncoming(State.PLAY, 0x26, 0x29, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.POSITION1_14, Type.POSITION); - } - }); - - // Player Block Placement - protocol.registerIncoming(State.PLAY, 0x29, 0x2C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_14.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java index bf74034a5..56302f093 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java @@ -15,7 +15,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.rewriters.BlockRewriter; 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.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData; @@ -41,8 +41,7 @@ public class WorldPackets { public static void register(final Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, null, Protocol1_14To1_13_2::getNewBlockStateId, Protocol1_14To1_13_2::getNewBlockId); - // Block Break Animation - protocol.registerOutgoing(State.PLAY, 0x08, 0x08, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_BREAK_ANIMATION, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -50,17 +49,13 @@ public class WorldPackets { map(Type.BYTE); } }); - - // Update Block Entity - protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION, Type.POSITION1_14); } }); - - // Block Action - protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_ACTION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION, Type.POSITION1_14); // Location @@ -75,9 +70,7 @@ public class WorldPackets { }); } }); - - // Block Change - protocol.registerOutgoing(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION, Type.POSITION1_14); @@ -93,8 +86,7 @@ public class WorldPackets { } }); - // Server Difficulty - protocol.registerOutgoing(State.PLAY, 0x0D, 0x0D, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SERVER_DIFFICULTY, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); @@ -107,11 +99,9 @@ public class WorldPackets { } }); - // Multi Block Change - blockRewriter.registerMultiBlockChange(0x0F, 0x0F); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE); - // Explosion - protocol.registerOutgoing(State.PLAY, 0x1E, 0x1C, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.EXPLOSION, new PacketRemapper() { @Override public void registerMap() { map(Type.FLOAT); // X @@ -134,8 +124,7 @@ public class WorldPackets { } }); - // Chunk - protocol.registerOutgoing(State.PLAY, 0x22, 0x21, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -264,8 +253,7 @@ public class WorldPackets { } }); - // Effect - protocol.registerOutgoing(State.PLAY, 0x23, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // Effect Id @@ -286,12 +274,10 @@ public class WorldPackets { } }); - // Spawn particle - blockRewriter.registerSpawnParticle(Type.FLOAT, 0x24, 0x23, 3, 20, 27, - MetadataRewriter1_14To1_13_2::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM); + blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, + MetadataRewriter1_14To1_13_2::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.FLOAT); - // Join Game - protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -334,8 +320,7 @@ public class WorldPackets { } }); - // Map Data - protocol.registerOutgoing(State.PLAY, 0x26, 0x26, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.MAP_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -350,8 +335,7 @@ public class WorldPackets { } }); - // Respawn - protocol.registerOutgoing(State.PLAY, 0x38, 0x3A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension ID @@ -379,8 +363,7 @@ public class WorldPackets { } }); - // Spawn Position - protocol.registerOutgoing(State.PLAY, 0x49, 0x4D, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_POSITION, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION, Type.POSITION1_14); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_1to1_15/Protocol1_15_1To1_15.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_1to1_15/Protocol1_15_1To1_15.java index f5773ba77..93acae479 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_1to1_15/Protocol1_15_1To1_15.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_1to1_15/Protocol1_15_1To1_15.java @@ -1,10 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_15_1to1_15; import us.myles.ViaVersion.api.protocol.Protocol; +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_15_1To1_15 extends Protocol { - - @Override - protected void registerPackets() { - } +public class Protocol1_15_1To1_15 extends Protocol { } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_2to1_15_1/Protocol1_15_2To1_15_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_2to1_15_1/Protocol1_15_2To1_15_1.java index 370817009..e140f3b1e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_2to1_15_1/Protocol1_15_2To1_15_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15_2to1_15_1/Protocol1_15_2To1_15_1.java @@ -1,10 +1,8 @@ package us.myles.ViaVersion.protocols.protocol1_15_2to1_15_1; import us.myles.ViaVersion.api.protocol.Protocol; +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_15_2To1_15_1 extends Protocol { - - @Override - protected void registerPackets() { - } +public class Protocol1_15_2To1_15_1 extends Protocol { } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/ClientboundPackets1_15.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/ClientboundPackets1_15.java new file mode 100644 index 000000000..2ec9a0170 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/ClientboundPackets1_15.java @@ -0,0 +1,100 @@ +package us.myles.ViaVersion.protocols.protocol1_15to1_14_4; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_15 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + ACKNOWLEDGE_PLAYER_DIGGING, // 0x08 + BLOCK_BREAK_ANIMATION, // 0x09 + BLOCK_ENTITY_DATA, // 0x0A + BLOCK_ACTION, // 0x0B + BLOCK_CHANGE, // 0x0C + BOSSBAR, // 0x0D + SERVER_DIFFICULTY, // 0x0E + CHAT_MESSAGE, // 0x0F + MULTI_BLOCK_CHANGE, // 0x10 + TAB_COMPLETE, // 0x11 + DECLARE_COMMANDS, // 0x12 + WINDOW_CONFIRMATION, // 0x13 + CLOSE_WINDOW, // 0x14 + WINDOW_ITEMS, // 0x15 + WINDOW_PROPERTY, // 0x16 + SET_SLOT, // 0x17 + COOLDOWN, // 0x18 + PLUGIN_MESSAGE, // 0x19 + NAMED_SOUND, // 0x1A + DISCONNECT, // 0x1B + ENTITY_STATUS, // 0x1C + EXPLOSION, // 0x1D + UNLOAD_CHUNK, // 0x1E + GAME_EVENT, // 0x1F + OPEN_HORSE_WINDOW, // 0x20 + KEEP_ALIVE, // 0x21 + CHUNK_DATA, // 0x22 + EFFECT, // 0x23 + SPAWN_PARTICLE, // 0x24 + UPDATE_LIGHT, // 0x25 + JOIN_GAME, // 0x26 + MAP_DATA, // 0x27 + TRADE_LIST, // 0x28 + ENTITY_POSITION, // 0x29 + ENTITY_POSITION_AND_ROTATION, // 0x2A + ENTITY_ROTATION, // 0x2B + ENTITY_MOVEMENT, // 0x2C + VEHICLE_MOVE, // 0x2D + OPEN_BOOK, // 0x2E + OPEN_WINDOW, // 0x2F + OPEN_SIGN_EDITOR, // 0x30 + CRAFT_RECIPE_RESPONSE, // 0x31 + PLAYER_ABILITIES, // 0x32 + COMBAT_EVENT, // 0x33 + PLAYER_INFO, // 0x34 + FACE_PLAYER, // 0x35 + PLAYER_POSITION, // 0x36 + UNLOCK_RECIPES, // 0x37 + DESTROY_ENTITIES, // 0x38 + REMOVE_ENTITY_EFFECT, // 0x39 + RESOURCE_PACK, // 0x3A + RESPAWN, // 0x3B + ENTITY_HEAD_LOOK, // 0x3C + SELECT_ADVANCEMENTS_TAB, // 0x3D + WORLD_BORDER, // 0x3E + CAMERA, // 0x3F + HELD_ITEM_CHANGE, // 0x40 + UPDATE_VIEW_POSITION, // 0x41 + UPDATE_VIEW_DISTANCE, // 0x42 + DISPLAY_SCOREBOARD, // 0x43 + ENTITY_METADATA, // 0x44 + ATTACH_ENTITY, // 0x45 + ENTITY_VELOCITY, // 0x46 + ENTITY_EQUIPMENT, // 0x47 + SET_EXPERIENCE, // 0x48 + UPDATE_HEALTH, // 0x49 + SCOREBOARD_OBJECTIVE, // 0x4A + SET_PASSENGERS, // 0x4B + TEAMS, // 0x4C + UPDATE_SCORE, // 0x4D + SPAWN_POSITION, // 0x4E + TIME_UPDATE, // 0x4F + TITLE, // 0x50 + ENTITY_SOUND, // 0x51 + SOUND, // 0x52 + STOP_SOUND, // 0x53 + TAB_LIST, // 0x54 + NBT_QUERY, // 0x55 + COLLECT_ITEM, // 0x56 + ENTITY_TELEPORT, // 0x57 + ADVANCEMENTS, // 0x58 + ENTITY_PROPERTIES, // 0x59 + ENTITY_EFFECT, // 0x5A + DECLARE_RECIPES, // 0x5B + TAGS, // 0x5C +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/Protocol1_15To1_14_4.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/Protocol1_15To1_14_4.java index 0ddb1d23b..85c043817 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/Protocol1_15To1_14_4.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/Protocol1_15To1_14_4.java @@ -10,7 +10,8 @@ import us.myles.ViaVersion.api.rewriters.SoundRewriter; import us.myles.ViaVersion.api.rewriters.TagRewriter; import us.myles.ViaVersion.api.rewriters.TagType; 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.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.EntityPackets; @@ -20,12 +21,12 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class Protocol1_15To1_14_4 extends Protocol { +public class Protocol1_15To1_14_4 extends Protocol { private TagRewriter tagRewriter; public Protocol1_15To1_14_4() { - super(true); + super(ClientboundPackets1_14.class, ClientboundPackets1_15.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class, true); } @Override @@ -38,24 +39,17 @@ public class Protocol1_15To1_14_4 extends Protocol { InventoryPackets.register(this); SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)); - soundRewriter.registerSound(0x50, 0x51); // Entity Sound Effect (added somewhere in 1.14) - soundRewriter.registerSound(0x51, 0x52); + soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND); // Entity Sound Effect (added somewhere in 1.14) + soundRewriter.registerSound(ClientboundPackets1_14.SOUND); - // Edit Book - registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - InventoryPackets.toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); - } - }); + handler(wrapper -> InventoryPackets.toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); } }); - // Advancements - registerOutgoing(State.PLAY, 0x57, 0x58, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_14.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -96,87 +90,8 @@ public class Protocol1_15To1_14_4 extends Protocol { } }); - // Tags tagRewriter = new TagRewriter(this, Protocol1_15To1_14_4::getNewBlockId, InventoryPackets::getNewItemId, EntityPackets::getNewEntityId); - tagRewriter.register(0x5B, 0x5C); - - registerOutgoing(State.PLAY, 0x08, 0x09); - registerOutgoing(State.PLAY, 0x09, 0x0A); - - registerOutgoing(State.PLAY, 0x0C, 0x0D); - registerOutgoing(State.PLAY, 0x0D, 0x0E); - registerOutgoing(State.PLAY, 0x0E, 0x0F); - registerOutgoing(State.PLAY, 0x10, 0x11); - registerOutgoing(State.PLAY, 0x11, 0x12); - registerOutgoing(State.PLAY, 0x12, 0x13); - registerOutgoing(State.PLAY, 0x13, 0x14); - - registerOutgoing(State.PLAY, 0x15, 0x16); - - registerOutgoing(State.PLAY, 0x18, 0x19); - registerOutgoing(State.PLAY, 0x19, 0x1A); - registerOutgoing(State.PLAY, 0x1A, 0x1B); - 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, 0x2E, 0x2F); - registerOutgoing(State.PLAY, 0x2F, 0x30); - registerOutgoing(State.PLAY, 0x30, 0x31); - registerOutgoing(State.PLAY, 0x31, 0x32); - registerOutgoing(State.PLAY, 0x32, 0x33); - 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, 0x43); - - registerOutgoing(State.PLAY, 0x44, 0x45); - registerOutgoing(State.PLAY, 0x45, 0x46); - - registerOutgoing(State.PLAY, 0x47, 0x48); - registerOutgoing(State.PLAY, 0x48, 0x49); - registerOutgoing(State.PLAY, 0x49, 0x4A); - registerOutgoing(State.PLAY, 0x4A, 0x4B); - registerOutgoing(State.PLAY, 0x4B, 0x4C); - registerOutgoing(State.PLAY, 0x4C, 0x4D); - registerOutgoing(State.PLAY, 0x4D, 0x4E); - registerOutgoing(State.PLAY, 0x4E, 0x4F); - registerOutgoing(State.PLAY, 0x4F, 0x50); - - - registerOutgoing(State.PLAY, 0x52, 0x53); - registerOutgoing(State.PLAY, 0x53, 0x54); - registerOutgoing(State.PLAY, 0x54, 0x55); - registerOutgoing(State.PLAY, 0x55, 0x56); - registerOutgoing(State.PLAY, 0x56, 0x57); - - registerOutgoing(State.PLAY, 0x58, 0x59); - registerOutgoing(State.PLAY, 0x59, 0x5A); + tagRewriter.register(ClientboundPackets1_14.TAGS); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java index d38987c79..776c91dbb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java @@ -3,11 +3,10 @@ package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -import us.myles.ViaVersion.api.protocol.Protocol; 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; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; @@ -16,14 +15,12 @@ import java.util.List; public class EntityPackets { - public static void register(Protocol protocol) { + public static void register(Protocol1_15To1_14_4 protocol) { MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class); - // Spawn entity - metadataRewriter.registerSpawnTrackerWithData(0x00, 0x00, Entity1_15Types.EntityType.FALLING_BLOCK, Protocol1_15To1_14_4::getNewBlockStateId); + metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_14.SPAWN_ENTITY, Entity1_15Types.EntityType.FALLING_BLOCK, Protocol1_15To1_14_4::getNewBlockStateId); - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -52,8 +49,7 @@ public class EntityPackets { } }); - // Spawn player packet - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -79,10 +75,8 @@ public class EntityPackets { } }); - // Metadata packet - metadataRewriter.registerMetadataRewriter(0x43, 0x44, Types1_14.METADATA_LIST); - - metadataRewriter.registerEntityDestroy(0x37, 0x38); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_14.DESTROY_ENTITIES); } public static int getNewEntityId(int oldId) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java index 39753bf10..3bc4a619c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/InventoryPackets.java @@ -8,7 +8,8 @@ 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_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.data.MappingData; public class InventoryPackets { @@ -16,14 +17,10 @@ public class InventoryPackets { public static void register(Protocol protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer); - // Set cooldown - itemRewriter.registerSetCooldown(0x17, 0x18, InventoryPackets::getNewItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN, InventoryPackets::getNewItemId); + itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x14, 0x15); - - // Trade list packet - protocol.registerOutgoing(State.PLAY, 0x27, 0x28, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -62,14 +59,10 @@ public class InventoryPackets { } }); - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x16, 0x17); + itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerEntityEquipment(ClientboundPackets1_14.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x46, 0x47); - - // Declare Recipes - protocol.registerOutgoing(State.PLAY, 0x5A, 0x5B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -135,11 +128,8 @@ public class InventoryPackets { } }); - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09); - - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x26, 0x26); + itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); } public static void toClient(Item item) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/PlayerPackets.java index c30dd6139..91e710a7c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/PlayerPackets.java @@ -5,15 +5,14 @@ import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.protocol.Protocol; 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_15to1_14_4.storage.EntityTracker1_15; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class PlayerPackets { public static void register(Protocol protocol) { - // Respawn - protocol.registerOutgoing(State.PLAY, 0x3A, 0x3B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); @@ -28,8 +27,7 @@ public class PlayerPackets { } }); - // Join Game - protocol.registerOutgoing(State.PLAY, 0x25, 0x26, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index 5a9b2cb8b..fa76a961e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.BlockRewriter; 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.types.Chunk1_14Type; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; @@ -19,20 +19,12 @@ public class WorldPackets { public static void register(Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15To1_14_4::getNewBlockStateId, Protocol1_15To1_14_4::getNewBlockId); - // Block action - blockRewriter.registerBlockAction(0x0A, 0x0B); + blockRewriter.registerBlockAction(ClientboundPackets1_14.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_14.BLOCK_CHANGE); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_14.MULTI_BLOCK_CHANGE); + blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING); - // Block Change - blockRewriter.registerBlockChange(0x0B, 0x0C); - - // Multi Block Change - blockRewriter.registerMultiBlockChange(0x0F, 0x10); - - // Acknowledge player digging - blockRewriter.registerAcknowledgePlayerDigging(0x5C, 0x08); - - // Chunk Data - protocol.registerOutgoing(State.PLAY, 0x21, 0x22, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_14.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -78,11 +70,8 @@ public class WorldPackets { } }); - // Effect - blockRewriter.registerEffect(0x22, 0x23, 1010, 2001, InventoryPackets::getNewItemId); - - // Spawn Particle - protocol.registerOutgoing(State.PLAY, 0x23, 0x24, new PacketRemapper() { + blockRewriter.registerEffect(ClientboundPackets1_14.EFFECT, 1010, 2001, InventoryPackets::getNewItemId); + protocol.registerOutgoing(ClientboundPackets1_14.SPAWN_PARTICLE, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Particle ID diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/ClientboundPackets1_16.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/ClientboundPackets1_16.java new file mode 100644 index 000000000..485c43b9a --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/ClientboundPackets1_16.java @@ -0,0 +1,99 @@ +package us.myles.ViaVersion.protocols.protocol1_16to1_15_2; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_16 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_MOB, // 0x02 + SPAWN_PAINTING, // 0x03 + SPAWN_PLAYER, // 0x04 + ENTITY_ANIMATION, // 0x05 + STATISTICS, // 0x06 + ACKNOWLEDGE_PLAYER_DIGGING, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + CHAT_MESSAGE, // 0x0E + MULTI_BLOCK_CHANGE, // 0x0F + TAB_COMPLETE, // 0x10 + DECLARE_COMMANDS, // 0x11 + WINDOW_CONFIRMATION, // 0x12 + CLOSE_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + PLUGIN_MESSAGE, // 0x18 + NAMED_SOUND, // 0x19 + DISCONNECT, // 0x1A + ENTITY_STATUS, // 0x1B + EXPLOSION, // 0x1C + UNLOAD_CHUNK, // 0x1D + GAME_EVENT, // 0x1E + OPEN_HORSE_WINDOW, // 0x1F + KEEP_ALIVE, // 0x20 + CHUNK_DATA, // 0x21 + EFFECT, // 0x22 + SPAWN_PARTICLE, // 0x23 + UPDATE_LIGHT, // 0x24 + JOIN_GAME, // 0x25 + MAP_DATA, // 0x26 + TRADE_LIST, // 0x27 + ENTITY_POSITION, // 0x28 + ENTITY_POSITION_AND_ROTATION, // 0x29 + ENTITY_ROTATION, // 0x2A + ENTITY_MOVEMENT, // 0x2B + VEHICLE_MOVE, // 0x2C + OPEN_BOOK, // 0x2D + OPEN_WINDOW, // 0x2E + OPEN_SIGN_EDITOR, // 0x2F + CRAFT_RECIPE_RESPONSE, // 0x30 + PLAYER_ABILITIES, // 0x31 + COMBAT_EVENT, // 0x32 + PLAYER_INFO, // 0x33 + FACE_PLAYER, // 0x34 + PLAYER_POSITION, // 0x35 + UNLOCK_RECIPES, // 0x36 + DESTROY_ENTITIES, // 0x37 + REMOVE_ENTITY_EFFECT, // 0x38 + RESOURCE_PACK, // 0x39 + RESPAWN, // 0x3A + ENTITY_HEAD_LOOK, // 0x3B + SELECT_ADVANCEMENTS_TAB, // 0x3C + WORLD_BORDER, // 0x3D + CAMERA, // 0x3E + HELD_ITEM_CHANGE, // 0x3F + UPDATE_VIEW_POSITION, // 0x40 + UPDATE_VIEW_DISTANCE, // 0x41 + SPAWN_POSITION, // 0x42 + DISPLAY_SCOREBOARD, // 0x43 + ENTITY_METADATA, // 0x44 + ATTACH_ENTITY, // 0x45 + ENTITY_VELOCITY, // 0x46 + ENTITY_EQUIPMENT, // 0x47 + SET_EXPERIENCE, // 0x48 + UPDATE_HEALTH, // 0x49 + SCOREBOARD_OBJECTIVE, // 0x4A + SET_PASSENGERS, // 0x4B + TEAMS, // 0x4C + UPDATE_SCORE, // 0x4D + TIME_UPDATE, // 0x4E + TITLE, // 0x4F + ENTITY_SOUND, // 0x50 + SOUND, // 0x51 + STOP_SOUND, // 0x52 + TAB_LIST, // 0x53 + NBT_QUERY, // 0x54 + COLLECT_ITEM, // 0x55 + ENTITY_TELEPORT, // 0x56 + ADVANCEMENTS, // 0x57 + ENTITY_PROPERTIES, // 0x58 + ENTITY_EFFECT, // 0x59 + DECLARE_RECIPES, // 0x5A + TAGS, // 0x5B +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java index a284224b6..47f423259 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java @@ -9,6 +9,8 @@ import us.myles.ViaVersion.api.rewriters.TagRewriter; import us.myles.ViaVersion.api.rewriters.TagType; 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.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.EntityPackets; @@ -19,13 +21,13 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.UUID; -public class Protocol1_16To1_15_2 extends Protocol { +public class Protocol1_16To1_15_2 extends Protocol { public static final UUID ZERO_UUID = new UUID(0, 0); private TagRewriter tagRewriter; public Protocol1_16To1_15_2() { - super(true); + super(ClientboundPackets1_15.class, ClientboundPackets1_16.class, ServerboundPackets1_14.class, ServerboundPackets1_16.class, true); } @Override @@ -37,7 +39,7 @@ public class Protocol1_16To1_15_2 extends Protocol { InventoryPackets.register(this); tagRewriter = new TagRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId); - tagRewriter.register(0x5C, 0x5B); + tagRewriter.register(ClientboundPackets1_15.TAGS); // Login Success registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() { @@ -51,8 +53,7 @@ public class Protocol1_16To1_15_2 extends Protocol { } }); - // Chat Message - registerOutgoing(State.PLAY, 0x0F, 0x0E, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_15.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); @@ -62,11 +63,10 @@ public class Protocol1_16To1_15_2 extends Protocol { }); SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)); - soundRewriter.registerSound(0x51, 0x50); - soundRewriter.registerSound(0x52, 0x51); + soundRewriter.registerSound(ClientboundPackets1_15.SOUND); + soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND); - // Advancements - registerOutgoing(State.PLAY, 0x58, 0x57, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_15.ADVANCEMENTS, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -104,91 +104,8 @@ public class Protocol1_16To1_15_2 extends Protocol { } }); - registerOutgoing(State.PLAY, 0x04, 0x03); - registerOutgoing(State.PLAY, 0x06, 0x05); - registerOutgoing(State.PLAY, 0x07, 0x06); - registerOutgoing(State.PLAY, 0x09, 0x08); - registerOutgoing(State.PLAY, 0x0A, 0x09); - registerOutgoing(State.PLAY, 0x0D, 0x0C); - 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, 0x19, 0x18); - registerOutgoing(State.PLAY, 0x1A, 0x19); - registerOutgoing(State.PLAY, 0x1B, 0x1A); - registerOutgoing(State.PLAY, 0x1C, 0x1B); - registerOutgoing(State.PLAY, 0x1D, 0x1C); - registerOutgoing(State.PLAY, 0x1E, 0x1D); - registerOutgoing(State.PLAY, 0x1F, 0x1E); - 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, 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, 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, 0x4E, 0x42); - registerOutgoing(State.PLAY, 0x4F, 0x4E); - registerOutgoing(State.PLAY, 0x50, 0x4F); - registerOutgoing(State.PLAY, 0x53, 0x52); - registerOutgoing(State.PLAY, 0x54, 0x53); - registerOutgoing(State.PLAY, 0x55, 0x54); - registerOutgoing(State.PLAY, 0x56, 0x55); - registerOutgoing(State.PLAY, 0x57, 0x56); - registerOutgoing(State.PLAY, 0x5A, 0x59); - - cancelIncoming(State.PLAY, 0x0F); // Generate jisaw - cancelIncoming(State.PLAY, 0x28); // Jigsaw update - registerIncoming(State.PLAY, 0x0F, 0x10); - registerIncoming(State.PLAY, 0x10, 0x11); - registerIncoming(State.PLAY, 0x11, 0x12); - registerIncoming(State.PLAY, 0x12, 0x13); - registerIncoming(State.PLAY, 0x13, 0x14); - registerIncoming(State.PLAY, 0x14, 0x15); - registerIncoming(State.PLAY, 0x15, 0x16); - registerIncoming(State.PLAY, 0x16, 0x17); - registerIncoming(State.PLAY, 0x17, 0x18); - registerIncoming(State.PLAY, 0x18, 0x19); - registerIncoming(State.PLAY, 0x19, 0x1A); - registerIncoming(State.PLAY, 0x1A, 0x1B); - registerIncoming(State.PLAY, 0x1B, 0x1C); - registerIncoming(State.PLAY, 0x1C, 0x1D); - registerIncoming(State.PLAY, 0x1D, 0x1E); - registerIncoming(State.PLAY, 0x1E, 0x1F); - registerIncoming(State.PLAY, 0x1F, 0x20); - registerIncoming(State.PLAY, 0x20, 0x21); - registerIncoming(State.PLAY, 0x21, 0x22); - registerIncoming(State.PLAY, 0x22, 0x23); - registerIncoming(State.PLAY, 0x23, 0x24); - registerIncoming(State.PLAY, 0x24, 0x25); - registerIncoming(State.PLAY, 0x28, 0x29); - registerIncoming(State.PLAY, 0x29, 0x2A); - registerIncoming(State.PLAY, 0x2A, 0x2B); - registerIncoming(State.PLAY, 0x2B, 0x2C); - registerIncoming(State.PLAY, 0x2C, 0x2D); - registerIncoming(State.PLAY, 0x2D, 0x2E); + cancelIncoming(ServerboundPackets1_16.GENERATE_JIGSAW); + cancelIncoming(ServerboundPackets1_16.UPDATE_JIGSAW_BLOCK); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/ServerboundPackets1_16.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/ServerboundPackets1_16.java new file mode 100644 index 000000000..9cb91b26e --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/ServerboundPackets1_16.java @@ -0,0 +1,54 @@ +package us.myles.ViaVersion.protocols.protocol1_16to1_15_2; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_16 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + QUERY_BLOCK_NBT, // 0x01 + SET_DIFFICULTY, // 0x02 + CHAT_MESSAGE, // 0x03 + CLIENT_STATUS, // 0x04 + CLIENT_SETTINGS, // 0x05 + TAB_COMPLETE, // 0x06 + WINDOW_CONFIRMATION, // 0x07 + CLICK_WINDOW_BUTTON, // 0x08 + CLICK_WINDOW, // 0x09 + CLOSE_WINDOW, // 0x0A + PLUGIN_MESSAGE, // 0x0B + EDIT_BOOK, // 0x0C + ENTITY_NBT_REQUEST, // 0x0D + INTERACT_ENTITY, // 0x0E + GENERATE_JIGSAW, // 0x0F + KEEP_ALIVE, // 0x10 + LOCK_DIFFICULTY, // 0x11 + PLAYER_POSITION, // 0x12 + PLAYER_POSITION_AND_ROTATION, // 0x13 + PLAYER_ROTATION, // 0x14 + PLAYER_MOVEMENT, // 0x15 + VEHICLE_MOVE, // 0x16 + STEER_BOAT, // 0x17 + PICK_ITEM, // 0x18 + CRAFT_RECIPE_REQUEST, // 0x19 + PLAYER_ABILITIES, // 0x1A + PLAYER_DIGGING, // 0x1B + ENTITY_ACTION, // 0x1C + STEER_VEHICLE, // 0x1D + RECIPE_BOOK_DATA, // 0x1E + RENAME_ITEM, // 0x1F + RESOURCE_PACK_STATUS, // 0x20 + ADVANCEMENT_TAB, // 0x21 + SELECT_TRADE, // 0x22 + SET_BEACON_EFFECT, // 0x23 + HELD_ITEM_CHANGE, // 0x24 + UPDATE_COMMAND_BLOCK, // 0x25 + UPDATE_COMMAND_BLOCK_MINECART, // 0x26 + CREATIVE_INVENTORY_ACTION, // 0x27 + UPDATE_JIGSAW_BLOCK, // 0x28 + UPDATE_STRUCTURE_BLOCK, // 0x29 + UPDATE_SIGN, // 0x2A + ANIMATION, // 0x2B + SPECTATE, // 0x2C + PLAYER_BLOCK_PLACEMENT, // 0x2D + USE_ITEM, // 0x2E +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java index 0e554d233..f4826ef49 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java @@ -9,13 +9,13 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.entities.Entity1_16Types; -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.remapper.ValueTransformer; 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_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.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2; @@ -102,11 +102,11 @@ public class EntityPackets { return tag; } - public static void register(Protocol protocol) { + public static void register(Protocol1_16To1_15_2 protocol) { MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class); // Spawn lightning -> Spawn entity - protocol.registerOutgoing(State.PLAY, 0x02, 0x00, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, ClientboundPackets1_16.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -131,23 +131,13 @@ public class EntityPackets { } }); - // Spawn entity - metadataRewriter.registerSpawnTrackerWithData(0x00, 0x00, Entity1_16Types.EntityType.FALLING_BLOCK, Protocol1_16To1_15_2::getNewBlockStateId); + metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.EntityType.FALLING_BLOCK, Protocol1_16To1_15_2::getNewBlockStateId); + metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB); + metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.EntityType.PLAYER); + metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST); + metadataRewriter.registerEntityDestroy(ClientboundPackets1_15.DESTROY_ENTITIES); - // Spawn mob packet - metadataRewriter.registerTracker(0x03, 0x02); - - // Spawn player packet - metadataRewriter.registerTracker(0x05, 0x04, Entity1_16Types.EntityType.PLAYER); - - // Metadata - metadataRewriter.registerMetadataRewriter(0x44, 0x44, Types1_14.METADATA_LIST); - - // Entity Destroy - metadataRewriter.registerEntityDestroy(0x38, 0x37); - - // Respawn - protocol.registerOutgoing(State.PLAY, 0x3B, 0x3A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.RESPAWN, new PacketRemapper() { @Override public void registerMap() { handler(DIMENSION_HANDLER); @@ -166,8 +156,7 @@ public class EntityPackets { } }); - // 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); // Entity ID @@ -205,8 +194,7 @@ public class EntityPackets { } }); - // Entity Properties - protocol.registerOutgoing(State.PLAY, 0x59, 0x58, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index 1cd2544f9..d5cf51d52 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -11,7 +11,8 @@ 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.api.type.types.UUIDIntArrayType; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; +import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData; import java.util.UUID; @@ -21,8 +22,7 @@ public class InventoryPackets { public static void register(Protocol protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer); - // Open Window - protocol.registerOutgoing(State.PLAY, 0x2F, 0x2E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -37,9 +37,7 @@ public class InventoryPackets { }); } }); - - // Window Property - protocol.registerOutgoing(State.PLAY, 0x16, 0x15, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.WINDOW_PROPERTY, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); // Window id @@ -58,14 +56,10 @@ public class InventoryPackets { } }); - // Set cooldown - itemRewriter.registerSetCooldown(0x18, 0x17, InventoryPackets::getNewItemId); + itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN, InventoryPackets::getNewItemId); + itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); - // Window items packet - itemRewriter.registerWindowItems(Type.FLAT_VAR_INT_ITEM_ARRAY, 0x15, 0x14); - - // Trade list packet - protocol.registerOutgoing(State.PLAY, 0x28, 0x27, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.TRADE_LIST, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -100,14 +94,10 @@ public class InventoryPackets { } }); - // Set slot packet - itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x17, 0x16); + itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); - // Entity Equipment Packet - itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x47); - - // Declare Recipes - protocol.registerOutgoing(State.PLAY, 0x5B, 0x5A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.DECLARE_RECIPES, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -166,14 +156,10 @@ public class InventoryPackets { } }); - // Click window packet - itemRewriter.registerClickWindow(Type.FLAT_VAR_INT_ITEM, 0x09, 0x09); + itemRewriter.registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); + itemRewriter.registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); - // Creative Inventory Action - itemRewriter.registerCreativeInvAction(Type.FLAT_VAR_INT_ITEM, 0x26, 0x27); - - // Edit Book - protocol.registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> InventoryPackets.toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java index 476f9a836..27fe2f2de 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java @@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.BlockRewriter; 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_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; @@ -26,20 +26,12 @@ public class WorldPackets { public static void register(Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16To1_15_2::getNewBlockStateId, Protocol1_16To1_15_2::getNewBlockId); - // Block action - blockRewriter.registerBlockAction(0x0B, 0x0A); + blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE); + blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE); + blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING); - // Block Change - blockRewriter.registerBlockChange(0x0C, 0x0B); - - // Multi Block Change - blockRewriter.registerMultiBlockChange(0x10, 0x0F); - - // Acknowledge player digging - blockRewriter.registerAcknowledgePlayerDigging(0x08, 0x07); - - // Chunk Data - protocol.registerOutgoing(State.PLAY, 0x22, 0x21, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { @@ -96,12 +88,9 @@ public class WorldPackets { } }); - // Effect - blockRewriter.registerEffect(0x23, 0x22, 1010, 2001, InventoryPackets::getNewItemId); - - // Spawn Particle - blockRewriter.registerSpawnParticle(Type.DOUBLE, 0x24, 0x23, 3, 23, 32, - WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM); + blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, InventoryPackets::getNewItemId); + blockRewriter.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32, + WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); } public static int getNewParticleId(int id) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_8/ClientboundPackets1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_8/ClientboundPackets1_8.java new file mode 100644 index 000000000..962162ab7 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_8/ClientboundPackets1_8.java @@ -0,0 +1,81 @@ +package us.myles.ViaVersion.protocols.protocol1_8; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_8 implements ClientboundPacketType { + + KEEP_ALIVE, // 0x00 + JOIN_GAME, // 0x01 + CHAT_MESSAGE, // 0x02 + TIME_UPDATE, // 0x03 + ENTITY_EQUIPMENT, // 0x04 + SPAWN_POSITION, // 0x05 + UPDATE_HEALTH, // 0x06 + RESPAWN, // 0x07 + PLAYER_POSITION, // 0x08 + HELD_ITEM_CHANGE, // 0x09 + USE_BED, // 0x0A + ENTITY_ANIMATION, // 0x0B + SPAWN_PLAYER, // 0x0C + COLLECT_ITEM, // 0x0D + SPAWN_ENTITY, // 0x0E + SPAWN_MOB, // 0x0F + SPAWN_PAINTING, // 0x10 + SPAWN_EXPERIENCE_ORB, // 0x11 + ENTITY_VELOCITY, // 0x12 + DESTROY_ENTITIES, // 0x13 + ENTITY_MOVEMENT, // 0x14 + ENTITY_POSITION, // 0x15 + ENTITY_ROTATION, // 0x16 + ENTITY_POSITION_AND_ROTATION, // 0x17 + ENTITY_TELEPORT, // 0x18 + ENTITY_HEAD_LOOK, // 0x19 + ENTITY_STATUS, // 0x1A + ATTACH_ENTITY, // 0x1B + ENTITY_METADATA, // 0x1C + ENTITY_EFFECT, // 0x1D + REMOVE_ENTITY_EFFECT, // 0x1E + SET_EXPERIENCE, // 0x1F + ENTITY_PROPERTIES, // 0x20 + CHUNK_DATA, // 0x21 + MULTI_BLOCK_CHANGE, // 0x22 + BLOCK_CHANGE, // 0x23 + BLOCK_ACTION, // 0x24 + BLOCK_BREAK_ANIMATION, // 0x25 + MAP_BULK_CHUNK, // 0x26 + EXPLOSION, // 0x27 + EFFECT, // 0x28 + NAMED_SOUND, // 0x29 + SPAWN_PARTICLE, // 0x2A + GAME_EVENT, // 0x2B + SPAWN_GLOBAL_ENTITY, // 0x2C + OPEN_WINDOW, // 0x2D + CLOSE_WINDOW, // 0x2E + SET_SLOT, // 0x2F + WINDOW_ITEMS, // 0x30 + WINDOW_PROPERTY, // 0x31 + WINDOW_CONFIRMATION, // 0x32 + UPDATE_SIGN, // 0x33 + MAP_DATA, // 0x34 + BLOCK_ENTITY_DATA, // 0x35 + OPEN_SIGN_EDITOR, // 0x36 + STATISTICS, // 0x37 + PLAYER_INFO, // 0x38 + PLAYER_ABILITIES, // 0x39 + TAB_COMPLETE, // 0x3A + SCOREBOARD_OBJECTIVE, // 0x3B + UPDATE_SCORE, // 0x3C + DISPLAY_SCOREBOARD, // 0x3D + TEAMS, // 0x3E + PLUGIN_MESSAGE, // 0x3F + DISCONNECT, // 0x40 + SERVER_DIFFICULTY, // 0x41 + COMBAT_EVENT, // 0x42 + CAMERA, // 0x43 + WORLD_BORDER, // 0x44 + TITLE, // 0x45 + SET_COMPRESSION, // 0x46 + TAB_LIST, // 0x47 + RESOURCE_PACK, // 0x48 + UPDATE_ENTITY_NBT, // 0x49 +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_8/ServerboundPackets1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_8/ServerboundPackets1_8.java new file mode 100644 index 000000000..85b339d2c --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_8/ServerboundPackets1_8.java @@ -0,0 +1,33 @@ +package us.myles.ViaVersion.protocols.protocol1_8; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_8 implements ServerboundPacketType { + + KEEP_ALIVE, // 0x00 + CHAT_MESSAGE, // 0x01 + INTERACT_ENTITY, // 0x02 + PLAYER_MOVEMENT, // 0x03 + PLAYER_POSITION, // 0x04 + PLAYER_ROTATION, // 0x05 + PLAYER_POSITION_AND_ROTATION, // 0x06 + PLAYER_DIGGING, // 0x07 + PLAYER_BLOCK_PLACEMENT, // 0x08 + HELD_ITEM_CHANGE, // 0x09 + ANIMATION, // 0x0A + ENTITY_ACTION, // 0x0B + STEER_VEHICLE, // 0x0C + CLOSE_WINDOW, // 0x0D + CLICK_WINDOW, // 0x0E + WINDOW_CONFIRMATION, // 0x0F + CREATIVE_INVENTORY_ACTION, // 0x10 + CLICK_WINDOW_BUTTON, // 0x11 + UPDATE_SIGN, // 0x12 + PLAYER_ABILITIES, // 0x13 + TAB_COMPLETE, // 0x14 + CLIENT_SETTINGS, // 0x15 + CLIENT_STATUS, // 0x16 + PLUGIN_MESSAGE, // 0x17 + SPECTATE, // 0x18 + RESOURCE_PACK_STATUS, // 0x19 +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/Protocol1_9_1_2To1_9_3_4.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/Protocol1_9_1_2To1_9_3_4.java index 12821a29b..1b3ebcbb3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/Protocol1_9_1_2To1_9_3_4.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/Protocol1_9_1_2To1_9_3_4.java @@ -9,27 +9,25 @@ 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_9_1_2to1_9_3_4.chunks.BlockEntity; 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.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ClientboundPackets1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; -public class Protocol1_9_1_2To1_9_3_4 extends Protocol { +// Goes BACKWARDS from 1.9.3/4 to 1.9.1/2 +public class Protocol1_9_1_2To1_9_3_4 extends Protocol { + + public Protocol1_9_1_2To1_9_3_4() { + super(ClientboundPackets1_9_3.class, ClientboundPackets1_9.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9.class); + } @Override protected void registerPackets() { - - //Unchanged packet structure - registerOutgoing(State.PLAY, 0x46, 0x47); //Sound effect - registerOutgoing(State.PLAY, 0x47, 0x48); //Player list header and footer - registerOutgoing(State.PLAY, 0x48, 0x49); //Collect item - registerOutgoing(State.PLAY, 0x49, 0x4A); //Entity teleport - registerOutgoing(State.PLAY, 0x4A, 0x4B); //Entity properties - registerOutgoing(State.PLAY, 0x4B, 0x4C); //Entity effect - - //Update block entity - registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); //Position @@ -54,8 +52,7 @@ public class Protocol1_9_1_2To1_9_3_4 extends Protocol { } }); - // Chunk Packet - registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -74,8 +71,7 @@ public class Protocol1_9_1_2To1_9_3_4 extends Protocol { } }); - // Join (save dimension id) - registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -94,8 +90,7 @@ public class Protocol1_9_1_2To1_9_3_4 extends Protocol { } }); - // Respawn (save dimension id) - registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension ID @@ -115,7 +110,8 @@ public class Protocol1_9_1_2To1_9_3_4 extends Protocol { @Override public void init(UserConnection userConnection) { - if (!userConnection.has(ClientWorld.class)) + if (!userConnection.has(ClientWorld.class)) { userConnection.put(new ClientWorld(userConnection)); + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1To1_9.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1To1_9.java index 8fd1ab5cc..45be14ce7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1To1_9.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1To1_9.java @@ -5,14 +5,20 @@ 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_9to1_8.ClientboundPackets1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; + +public class Protocol1_9_1To1_9 extends Protocol { + + public Protocol1_9_1To1_9() { + super(ClientboundPackets1_9.class, ClientboundPackets1_9.class, ServerboundPackets1_9.class, ServerboundPackets1_9.class); + } -public class Protocol1_9_1To1_9 extends Protocol { @Override protected void registerPackets() { // Currently supports 1.9.1 and 1.9.2 - // Join Game Packet - registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Player ID @@ -26,8 +32,7 @@ public class Protocol1_9_1To1_9 extends Protocol { } }); - // Sound Effect Packet - registerOutgoing(State.PLAY, 0x47, 0x47, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound ID diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/ClientboundPackets1_9_3.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/ClientboundPackets1_9_3.java new file mode 100644 index 000000000..77558b97f --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/ClientboundPackets1_9_3.java @@ -0,0 +1,83 @@ +package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_9_3 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + TAB_COMPLETE, // 0x0E + CHAT_MESSAGE, // 0x0F + MULTI_BLOCK_CHANGE, // 0x10 + WINDOW_CONFIRMATION, // 0x11 + CLOSE_WINDOW, // 0x12 + OPEN_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + PLUGIN_MESSAGE, // 0x18 + NAMED_SOUND, // 0x19 + DISCONNECT, // 0x1A + ENTITY_STATUS, // 0x1B + EXPLOSION, // 0x1C + UNLOAD_CHUNK, // 0x1D + GAME_EVENT, // 0x1E + KEEP_ALIVE, // 0x1F + CHUNK_DATA, // 0x20 + EFFECT, // 0x21 + SPAWN_PARTICLE, // 0x22 + JOIN_GAME, // 0x23 + MAP_DATA, // 0x24 + ENTITY_POSITION, // 0x26 + ENTITY_POSITION_AND_ROTATION, // 0x27 + ENTITY_ROTATION, // 0x28 + ENTITY_MOVEMENT, // 0x25 + VEHICLE_MOVE, // 0x29 + OPEN_SIGN_EDITOR, // 0x2A + PLAYER_ABILITIES, // 0x2B + COMBAT_EVENT, // 0x2C + PLAYER_INFO, // 0x2D + PLAYER_POSITION, // 0x2E + USE_BED, // 0x2F + DESTROY_ENTITIES, // 0x31 + REMOVE_ENTITY_EFFECT, // 0x32 + RESOURCE_PACK, // 0x33 + RESPAWN, // 0x34 + ENTITY_HEAD_LOOK, // 0x35 + WORLD_BORDER, // 0x37 + CAMERA, // 0x38 + HELD_ITEM_CHANGE, // 0x39 + DISPLAY_SCOREBOARD, // 0x3A + ENTITY_METADATA, // 0x3B + ATTACH_ENTITY, // 0x3C + ENTITY_VELOCITY, // 0x3D + ENTITY_EQUIPMENT, // 0x3E + SET_EXPERIENCE, // 0x3F + UPDATE_HEALTH, // 0x40 + SCOREBOARD_OBJECTIVE, // 0x41 + SET_PASSENGERS, // 0x42 + TEAMS, // 0x43 + UPDATE_SCORE, // 0x44 + SPAWN_POSITION, // 0x45 + TIME_UPDATE, // 0x46 + TITLE, // 0x47 + SOUND, // 0x48 + TAB_LIST, // 0x49 + COLLECT_ITEM, // 0x4A + ENTITY_TELEPORT, // 0x4B + ENTITY_PROPERTIES, // 0x4C + ENTITY_EFFECT, // 0x4D +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java index a64368a92..58b82a7af 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java @@ -12,30 +12,26 @@ 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_9_3to1_9_1_2.chunks.FakeTileEntity; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ClientboundPackets1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; import java.util.List; -public class Protocol1_9_3To1_9_1_2 extends Protocol { +public class Protocol1_9_3To1_9_1_2 extends Protocol { + + public Protocol1_9_3To1_9_1_2() { + super(ClientboundPackets1_9.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9.class, ServerboundPackets1_9_3.class); + } + @Override protected void registerPackets() { - - //Unchanged packet structure - registerOutgoing(State.PLAY, 0x47, 0x46); //Sound effect - registerOutgoing(State.PLAY, 0x48, 0x47); //Player list header and footer - registerOutgoing(State.PLAY, 0x49, 0x48); //Collect item - registerOutgoing(State.PLAY, 0x4A, 0x49); //Entity teleport - registerOutgoing(State.PLAY, 0x4B, 0x4A); //Entity properties - registerOutgoing(State.PLAY, 0x4C, 0x4B); //Entity effect - // Sign update packet - registerOutgoing(State.PLAY, 0x46, -1, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9.UPDATE_SIGN, null, new PacketRemapper() { @Override public void registerMap() { - handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -67,8 +63,7 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol { } }); - // Chunk packet - registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -104,8 +99,7 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol { } }); - // Join (save dimension id) - registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Entity ID @@ -123,8 +117,7 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol { } }); - // Respawn (save dimension id) - registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension ID @@ -142,7 +135,8 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol { @Override public void init(UserConnection user) { - if (!user.has(ClientWorld.class)) + if (!user.has(ClientWorld.class)) { user.put(new ClientWorld(user)); + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/ServerboundPackets1_9_3.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/ServerboundPackets1_9_3.java new file mode 100644 index 000000000..f20e4f55e --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/ServerboundPackets1_9_3.java @@ -0,0 +1,37 @@ +package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_9_3 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + TAB_COMPLETE, // 0x01 + CHAT_MESSAGE, // 0x02 + CLIENT_STATUS, // 0x03 + CLIENT_SETTINGS, // 0x04 + WINDOW_CONFIRMATION, // 0x05 + CLICK_WINDOW_BUTTON, // 0x06 + CLICK_WINDOW, // 0x07 + CLOSE_WINDOW, // 0x08 + PLUGIN_MESSAGE, // 0x09 + INTERACT_ENTITY, // 0x0A + KEEP_ALIVE, // 0x0B + PLAYER_POSITION, // 0x0C + PLAYER_POSITION_AND_ROTATION, // 0x0D + PLAYER_ROTATION, // 0x0E + PLAYER_MOVEMENT, // 0x0F + VEHICLE_MOVE, // 0x10 + STEER_BOAT, // 0x11 + PLAYER_ABILITIES, // 0x12 + PLAYER_DIGGING, // 0x13 + ENTITY_ACTION, // 0x14 + STEER_VEHICLE, // 0x15 + RESOURCE_PACK_STATUS, // 0x16 + HELD_ITEM_CHANGE, // 0x17 + CREATIVE_INVENTORY_ACTION, // 0x18 + UPDATE_SIGN, // 0x19 + ANIMATION, // 0x1A + SPECTATE, // 0x1B + PLAYER_BLOCK_PLACEMENT, // 0x1C + USE_ITEM, // 0x1D +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ClientboundPackets1_9.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ClientboundPackets1_9.java new file mode 100644 index 000000000..d89372dea --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ClientboundPackets1_9.java @@ -0,0 +1,84 @@ +package us.myles.ViaVersion.protocols.protocol1_9to1_8; + +import us.myles.ViaVersion.api.protocol.ClientboundPacketType; + +public enum ClientboundPackets1_9 implements ClientboundPacketType { + + SPAWN_ENTITY, // 0x00 + SPAWN_EXPERIENCE_ORB, // 0x01 + SPAWN_GLOBAL_ENTITY, // 0x02 + SPAWN_MOB, // 0x03 + SPAWN_PAINTING, // 0x04 + SPAWN_PLAYER, // 0x05 + ENTITY_ANIMATION, // 0x06 + STATISTICS, // 0x07 + BLOCK_BREAK_ANIMATION, // 0x08 + BLOCK_ENTITY_DATA, // 0x09 + BLOCK_ACTION, // 0x0A + BLOCK_CHANGE, // 0x0B + BOSSBAR, // 0x0C + SERVER_DIFFICULTY, // 0x0D + TAB_COMPLETE, // 0x0E + CHAT_MESSAGE, // 0x0F + MULTI_BLOCK_CHANGE, // 0x10 + WINDOW_CONFIRMATION, // 0x11 + CLOSE_WINDOW, // 0x12 + OPEN_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + PLUGIN_MESSAGE, // 0x18 + NAMED_SOUND, // 0x19 + DISCONNECT, // 0x1A + ENTITY_STATUS, // 0x1B + EXPLOSION, // 0x1C + UNLOAD_CHUNK, // 0x1D + GAME_EVENT, // 0x1E + KEEP_ALIVE, // 0x1F + CHUNK_DATA, // 0x20 + EFFECT, // 0x21 + SPAWN_PARTICLE, // 0x22 + JOIN_GAME, // 0x23 + MAP_DATA, // 0x24 + ENTITY_POSITION, // 0x26 + ENTITY_POSITION_AND_ROTATION, // 0x27 + ENTITY_ROTATION, // 0x28 + ENTITY_MOVEMENT, // 0x25 + VEHICLE_MOVE, // 0x29 + OPEN_SIGN_EDITOR, // 0x2A + PLAYER_ABILITIES, // 0x2B + COMBAT_EVENT, // 0x2C + PLAYER_INFO, // 0x2D + PLAYER_POSITION, // 0x2E + USE_BED, // 0x2F + DESTROY_ENTITIES, // 0x31 + REMOVE_ENTITY_EFFECT, // 0x32 + RESOURCE_PACK, // 0x33 + RESPAWN, // 0x34 + ENTITY_HEAD_LOOK, // 0x35 + WORLD_BORDER, // 0x37 + CAMERA, // 0x38 + HELD_ITEM_CHANGE, // 0x39 + DISPLAY_SCOREBOARD, // 0x3A + ENTITY_METADATA, // 0x3B + ATTACH_ENTITY, // 0x3C + ENTITY_VELOCITY, // 0x3D + ENTITY_EQUIPMENT, // 0x3E + SET_EXPERIENCE, // 0x3F + UPDATE_HEALTH, // 0x40 + SCOREBOARD_OBJECTIVE, // 0x41 + SET_PASSENGERS, // 0x42 + TEAMS, // 0x43 + UPDATE_SCORE, // 0x44 + SPAWN_POSITION, // 0x45 + TIME_UPDATE, // 0x46 + TITLE, // 0x47 + UPDATE_SIGN, // 0x48 + SOUND, // 0x49 + TAB_LIST, // 0x4A + COLLECT_ITEM, // 0x4B + ENTITY_TELEPORT, // 0x4C + ENTITY_PROPERTIES, // 0x4D + ENTITY_EFFECT, // 0x4E +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java index 0861ee7c1..91eabf123 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java @@ -11,6 +11,8 @@ 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_8.ClientboundPackets1_8; +import us.myles.ViaVersion.protocols.protocol1_8.ServerboundPackets1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.*; @@ -19,7 +21,7 @@ import us.myles.ViaVersion.util.GsonUtil; import java.util.List; -public class Protocol1_9To1_8 extends Protocol { +public class Protocol1_9To1_8 extends Protocol { public static final ValueTransformer FIX_JSON = new ValueTransformer(Type.STRING) { @Override public String transform(PacketWrapper wrapper, String line) { @@ -27,6 +29,10 @@ public class Protocol1_9To1_8 extends Protocol { } }; + public Protocol1_9To1_8() { + super(ClientboundPackets1_8.class, ClientboundPackets1_9.class, ServerboundPackets1_8.class, ServerboundPackets1_9.class); + } + public static String fixJson(String line) { if (line == null || line.equalsIgnoreCase("null")) { line = "{\"text\":\"\"}"; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ServerboundPackets1_9.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ServerboundPackets1_9.java new file mode 100644 index 000000000..fd2ae5781 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ServerboundPackets1_9.java @@ -0,0 +1,37 @@ +package us.myles.ViaVersion.protocols.protocol1_9to1_8; + +import us.myles.ViaVersion.api.protocol.ServerboundPacketType; + +public enum ServerboundPackets1_9 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + TAB_COMPLETE, // 0x01 + CHAT_MESSAGE, // 0x02 + CLIENT_STATUS, // 0x03 + CLIENT_SETTINGS, // 0x04 + WINDOW_CONFIRMATION, // 0x05 + CLICK_WINDOW_BUTTON, // 0x06 + CLICK_WINDOW, // 0x07 + CLOSE_WINDOW, // 0x08 + PLUGIN_MESSAGE, // 0x09 + INTERACT_ENTITY, // 0x0A + KEEP_ALIVE, // 0x0B + PLAYER_POSITION, // 0x0C + PLAYER_POSITION_AND_ROTATION, // 0x0D + PLAYER_ROTATION, // 0x0E + PLAYER_MOVEMENT, // 0x0F + VEHICLE_MOVE, // 0x10 + STEER_BOAT, // 0x11 + PLAYER_ABILITIES, // 0x12 + PLAYER_DIGGING, // 0x13 + ENTITY_ACTION, // 0x14 + STEER_VEHICLE, // 0x15 + RESOURCE_PACK_STATUS, // 0x16 + HELD_ITEM_CHANGE, // 0x17 + CREATIVE_INVENTORY_ACTION, // 0x18 + UPDATE_SIGN, // 0x19 + ANIMATION, // 0x1A + SPECTATE, // 0x1B + PLAYER_BLOCK_PLACEMENT, // 0x1C + USE_ITEM, // 0x1D +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index e2abd4c7a..17bb84b3a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -7,20 +7,24 @@ import us.myles.ViaVersion.api.Triple; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -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.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_8; import us.myles.ViaVersion.api.type.types.version.Types1_9; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_8.ClientboundPackets1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; public class EntityPackets { public static final ValueTransformer toNewShort = new ValueTransformer(Type.SHORT) { @@ -30,9 +34,9 @@ public class EntityPackets { } }; - public static void register(final Protocol protocol) { + public static void register(Protocol1_9To1_8 protocol) { // Attach Entity Packet - protocol.registerOutgoing(State.PLAY, 0x1B, 0x3A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ATTACH_ENTITY, new PacketRemapper() { @Override public void registerMap() { @@ -68,8 +72,7 @@ public class EntityPackets { }); } }); - // Entity Teleport Packet - protocol.registerOutgoing(State.PLAY, 0x18, 0x4A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_TELEPORT, new PacketRemapper() { @Override public void registerMap() { @@ -101,8 +104,7 @@ public class EntityPackets { } }); - // Entity Look Move Packet - protocol.registerOutgoing(State.PLAY, 0x17, 0x26, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_POSITION_AND_ROTATION, new PacketRemapper() { @Override public void registerMap() { @@ -117,8 +119,7 @@ public class EntityPackets { map(Type.BOOLEAN); // 6 - On Ground } }); - // Entity Relative Move Packet - protocol.registerOutgoing(State.PLAY, 0x15, 0x25, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_POSITION, new PacketRemapper() { @Override public void registerMap() { @@ -130,8 +131,7 @@ public class EntityPackets { map(Type.BOOLEAN); // 4 - On Ground } }); - // Entity Equipment Packet - protocol.registerOutgoing(State.PLAY, 0x04, 0x3C, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_EQUIPMENT, new PacketRemapper() { @Override public void registerMap() { @@ -179,8 +179,7 @@ public class EntityPackets { }); } }); - // Entity Metadata Packet - protocol.registerOutgoing(State.PLAY, 0x1C, 0x39, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_METADATA, new PacketRemapper() { @Override public void registerMap() { @@ -218,7 +217,7 @@ public class EntityPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); - if (metadataList.size() == 0) { + if (metadataList.isEmpty()) { wrapper.cancel(); } } @@ -226,9 +225,7 @@ public class EntityPackets { } }); - // Entity Effect Packet - protocol.registerOutgoing(State.PLAY, 0x1D, 0x4C, new PacketRemapper() { - + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -247,16 +244,12 @@ public class EntityPackets { } }); + protocol.cancelOutgoing(ClientboundPackets1_8.UPDATE_ENTITY_NBT); - // Update Entity NBT - protocol.cancelOutgoing(State.PLAY, 0x49, 0x49); - - // Combat Event Packet - protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.COMBAT_EVENT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); //Event id - handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { @@ -270,8 +263,7 @@ public class EntityPackets { } }); - // Entity Properties Packet - protocol.registerOutgoing(State.PLAY, 0x20, 0x4B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.ENTITY_PROPERTIES, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); @@ -327,22 +319,8 @@ public class EntityPackets { }); - /* Packets which do not have any field remapping or handlers */ - - protocol.registerOutgoing(State.PLAY, 0x1A, 0x1B); // Entity Status Packet - protocol.registerOutgoing(State.PLAY, 0x16, 0x27); // Entity Look Packet - protocol.registerOutgoing(State.PLAY, 0x14, 0x28); // Entity Packet - - protocol.registerOutgoing(State.PLAY, 0x0A, 0x2F); // Use Bed Packet - - protocol.registerOutgoing(State.PLAY, 0x1E, 0x31); // Remove Entity Effect Packet - protocol.registerOutgoing(State.PLAY, 0x19, 0x34); // Entity Head Look Packet - protocol.registerOutgoing(State.PLAY, 0x12, 0x3B); // Entity Velocity Packet - /* Incoming Packets */ - - // Entity Action Packet - protocol.registerIncoming(State.PLAY, 0x0B, 0x14, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.ENTITY_ACTION, new PacketRemapper() { @Override public void registerMap() { @@ -363,9 +341,7 @@ public class EntityPackets { } }); - - // Use Entity Packet - protocol.registerIncoming(State.PLAY, 0x02, 0x0A, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.INTERACT_ENTITY, new PacketRemapper() { @Override public void registerMap() { @@ -392,11 +368,5 @@ public class EntityPackets { }); } }); - - /* Packets which do not have any field remapping or handlers */ - - protocol.registerIncoming(State.PLAY, 0x0C, 0x15); // Steer Vehicle Packet - protocol.registerIncoming(State.PLAY, 0x18, 0x1B); // Spectate Packet - } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java index 50ec5fd50..a3eaeb03c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java @@ -7,17 +7,17 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; 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_8.ClientboundPackets1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker; public class InventoryPackets { public static void register(Protocol protocol) { - // Window Property Packet - protocol.registerOutgoing(State.PLAY, 0x31, 0x15, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.WINDOW_PROPERTY, new PacketRemapper() { @Override public void registerMap() { @@ -56,8 +56,7 @@ public class InventoryPackets { }); } }); - // Window Open Packet - protocol.registerOutgoing(State.PLAY, 0x2D, 0x13, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.OPEN_WINDOW, new PacketRemapper() { @Override public void registerMap() { @@ -87,12 +86,9 @@ public class InventoryPackets { }); } }); - // Window Set Slot Packet - protocol.registerOutgoing(State.PLAY, 0x2F, 0x16, new PacketRemapper() { - + protocol.registerOutgoing(ClientboundPackets1_8.SET_SLOT, new PacketRemapper() { @Override public void registerMap() { - map(Type.BYTE); // 0 - Window ID map(Type.SHORT); // 1 - Slot ID map(Type.ITEM); // 2 - Slot Value @@ -121,8 +117,7 @@ public class InventoryPackets { }); } }); - // Window Set Slots Packet - protocol.registerOutgoing(State.PLAY, 0x30, 0x14, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.WINDOW_ITEMS, new PacketRemapper() { @Override public void registerMap() { @@ -162,8 +157,7 @@ public class InventoryPackets { }); } }); - // Close Window Packet - protocol.registerOutgoing(State.PLAY, 0x2E, 0x12, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.CLOSE_WINDOW, new PacketRemapper() { @Override public void registerMap() { @@ -179,8 +173,7 @@ public class InventoryPackets { } }); - // Map Packet - protocol.registerOutgoing(State.PLAY, 0x34, 0x24, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.MAP_DATA, new PacketRemapper() { @Override public void registerMap() { @@ -196,14 +189,9 @@ public class InventoryPackets { } }); - /* Packets which do not have any field remapping or handlers */ - protocol.registerOutgoing(State.PLAY, 0x09, 0x37); // Held Item Change Packet - protocol.registerOutgoing(State.PLAY, 0x32, 0x11); // Confirm Transaction Packet /* Incoming Packets */ - - // Creative Inventory Slot Action Packet - protocol.registerIncoming(State.PLAY, 0x10, 0x18, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.CREATIVE_INVENTORY_ACTION, new PacketRemapper() { @Override public void registerMap() { @@ -240,8 +228,7 @@ public class InventoryPackets { } }); - // Player Click Window Packet - protocol.registerIncoming(State.PLAY, 0x0E, 0x07, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.CLICK_WINDOW, new PacketRemapper() { @Override public void registerMap() { @@ -297,8 +284,7 @@ public class InventoryPackets { } }); - // Close Window Incoming Packet - protocol.registerIncoming(State.PLAY, 0x0D, 0x08, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.CLOSE_WINDOW, new PacketRemapper() { @Override public void registerMap() { @@ -313,8 +299,7 @@ public class InventoryPackets { } }); - // Held Item Change Packet - protocol.registerIncoming(State.PLAY, 0x09, 0x17, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.HELD_ITEM_CHANGE, new PacketRemapper() { @Override public void registerMap() { // Blocking patch @@ -330,10 +315,5 @@ public class InventoryPackets { }); } }); - - /* Packets which do not have any field remapping or handlers */ - - protocol.registerIncoming(State.PLAY, 0x0F, 0x05); // Confirm Transaction Packet - protocol.registerIncoming(State.PLAY, 0x11, 0x06); // Enchant Item Packet } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index 1d06e815c..eb22c7892 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -5,16 +5,16 @@ import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.entities.Entity1_10Types; import us.myles.ViaVersion.api.minecraft.item.Item; -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.remapper.ValueCreator; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_8.ClientboundPackets1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.PlayerMovementMapper; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider; @@ -24,9 +24,8 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import us.myles.ViaVersion.util.GsonUtil; public class PlayerPackets { - public static void register(Protocol protocol) { - // Chat Message Packet - protocol.registerOutgoing(State.PLAY, 0x02, 0x0F, new PacketRemapper() { + public static void register(Protocol1_9To1_8 protocol) { + protocol.registerOutgoing(ClientboundPackets1_8.CHAT_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Chat Message (json) @@ -47,8 +46,7 @@ public class PlayerPackets { } }); - // Header and Footer Packet - protocol.registerOutgoing(State.PLAY, 0x47, 0x48, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.TAB_LIST, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Header @@ -56,16 +54,14 @@ public class PlayerPackets { } }); - // Disconnect Packet - protocol.registerOutgoing(State.PLAY, 0x40, 0x1A, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.DISCONNECT, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Reason } }); - // Title Packet - protocol.registerOutgoing(State.PLAY, 0x45, 0x45, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.TITLE, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Action @@ -83,8 +79,7 @@ public class PlayerPackets { } }); - // Player Position Packet - protocol.registerOutgoing(State.PLAY, 0x08, 0x2E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.PLAYER_POSITION, new PacketRemapper() { @Override public void registerMap() { map(Type.DOUBLE); // 0 - Player X @@ -105,8 +100,7 @@ public class PlayerPackets { } }); - // Team Packet - protocol.registerOutgoing(State.PLAY, 0x3E, 0x41, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.TEAMS, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Team Name @@ -170,8 +164,7 @@ public class PlayerPackets { } }); - // Join Game Packet - protocol.registerOutgoing(State.PLAY, 0x01, 0x23, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Player ID @@ -230,8 +223,7 @@ public class PlayerPackets { } }); - // Player List Item Packet - protocol.registerOutgoing(State.PLAY, 0x38, 0x2D, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.PLAYER_INFO, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Action @@ -283,8 +275,7 @@ public class PlayerPackets { } }); - // Packet Plugin Message Outgoing - protocol.registerOutgoing(State.PLAY, 0x3F, 0x18, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel Name @@ -326,8 +317,7 @@ public class PlayerPackets { } }); - // Update Health Packet - protocol.registerOutgoing(State.PLAY, 0x06, 0x3E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.UPDATE_HEALTH, new PacketRemapper() { @Override public void registerMap() { map(Type.FLOAT); // 0 - Health @@ -346,8 +336,7 @@ public class PlayerPackets { } }); - // Respawn Packet - protocol.registerOutgoing(State.PLAY, 0x07, 0x33, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.RESPAWN, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Dimension @@ -380,8 +369,7 @@ public class PlayerPackets { } }); - // Change Game State Packet - protocol.registerOutgoing(State.PLAY, 0x2B, 0x1E, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.GAME_EVENT, new PacketRemapper() { @Override public void registerMap() { map(Type.UNSIGNED_BYTE); //0 - Reason @@ -400,33 +388,11 @@ public class PlayerPackets { }); /* Removed packets */ + protocol.cancelOutgoing(ClientboundPackets1_8.SET_COMPRESSION); - // Set Compression - protocol.cancelOutgoing(State.PLAY, 0x46, 0x46); - - /* Packets which do not have any field remapping or handlers */ - - protocol.registerOutgoing(State.PLAY, 0x3A, 0x0E); // Tab Complete Response Packet - protocol.registerOutgoing(State.PLAY, 0x0B, 0x06); // Animation Packet - protocol.registerOutgoing(State.PLAY, 0x37, 0x07); // Stats Packet - protocol.registerOutgoing(State.PLAY, 0x36, 0x2A); // Open Sign Editor Packet - protocol.registerOutgoing(State.PLAY, 0x39, 0x2B); // Player Abilities Packet - protocol.registerOutgoing(State.PLAY, 0x00, 0x1F); // Keep Alive Packet - protocol.registerOutgoing(State.PLAY, 0x48, 0x32); // Resource Pack Send Packet - protocol.registerOutgoing(State.PLAY, 0x43, 0x36); // Camera Packet - - protocol.registerOutgoing(State.PLAY, 0x3D, 0x38); // Display Scoreboard Packet - protocol.registerOutgoing(State.PLAY, 0x3B, 0x3F); // Scoreboard Objective Packet - protocol.registerOutgoing(State.PLAY, 0x3C, 0x42); // Update Score Packet - - protocol.registerOutgoing(State.PLAY, 0x05, 0x43); // Spawn Position Packet - protocol.registerOutgoing(State.PLAY, 0x1F, 0x3D); // Set XP Packet - protocol.registerOutgoing(State.PLAY, 0x0D, 0x49); // Collect Item Packet /* Incoming Packets */ - - // Tab Complete Request Packet - protocol.registerIncoming(State.PLAY, 0x14, 0x01, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.TAB_COMPLETE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Requested Command @@ -434,8 +400,7 @@ public class PlayerPackets { } }); - // Client Settings Packet - protocol.registerIncoming(State.PLAY, 0x15, 0x04, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.CLIENT_SETTINGS, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - locale @@ -463,25 +428,18 @@ public class PlayerPackets { } }); - // Animation Request Packet - protocol.registerIncoming(State.PLAY, 0x0A, 0x1A, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.ANIMATION, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT, Type.NOTHING); // 0 - Hand } }); - // TP Confirm - protocol.cancelIncoming(State.PLAY, 0x00); + protocol.cancelIncoming(ServerboundPackets1_9.TELEPORT_CONFIRM); + protocol.cancelIncoming(ServerboundPackets1_9.VEHICLE_MOVE); + protocol.cancelIncoming(ServerboundPackets1_9.STEER_BOAT); - // Vehicle Move - protocol.cancelIncoming(State.PLAY, 0x10); - - // Steer Boat - protocol.cancelIncoming(State.PLAY, 0x11); - - // Packet Plugin Message Incoming - protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLUGIN_MESSAGE, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Channel Name @@ -514,8 +472,7 @@ public class PlayerPackets { } }); - // Client Status Packet - protocol.registerIncoming(State.PLAY, 0x16, 0x03, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.CLIENT_STATUS, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Action ID @@ -536,8 +493,7 @@ public class PlayerPackets { } }); - // Player Position Packet - protocol.registerIncoming(State.PLAY, 0x04, 0x0C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLAYER_POSITION, new PacketRemapper() { @Override public void registerMap() { map(Type.DOUBLE); // 0 - X @@ -547,9 +503,7 @@ public class PlayerPackets { handler(new PlayerMovementMapper()); } }); - - // Player Move & Look Packet - protocol.registerIncoming(State.PLAY, 0x06, 0x0D, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLAYER_POSITION_AND_ROTATION, new PacketRemapper() { @Override public void registerMap() { map(Type.DOUBLE); // 0 - X @@ -561,9 +515,7 @@ public class PlayerPackets { handler(new PlayerMovementMapper()); } }); - - // Player Look Packet - protocol.registerIncoming(State.PLAY, 0x05, 0x0E, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLAYER_ROTATION, new PacketRemapper() { @Override public void registerMap() { map(Type.FLOAT); // 0 - Yaw @@ -572,24 +524,12 @@ public class PlayerPackets { handler(new PlayerMovementMapper()); } }); - - // Player Packet - protocol.registerIncoming(State.PLAY, 0x03, 0x0F, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLAYER_MOVEMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.BOOLEAN); // 0 - Ground handler(new PlayerMovementMapper()); } }); - - /* Packets which do not have any field remapping or handlers */ - - protocol.registerIncoming(State.PLAY, 0x01, 0x02); // Chat Message Packet - protocol.registerIncoming(State.PLAY, 0x13, 0x12); // Player Abilities Request Packet - protocol.registerIncoming(State.PLAY, 0x19, 0x16); // Resource Pack Status Packet - - protocol.registerIncoming(State.PLAY, 0x00, 0x0B); // Keep Alive Request Packet - - } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index 1ed6d246c..072b35088 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -6,7 +6,6 @@ import us.myles.ViaVersion.api.entities.Entity1_10Types; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9; -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.remapper.ValueCreator; @@ -14,7 +13,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_8; import us.myles.ViaVersion.api.type.types.version.Types1_9; -import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_8.ClientboundPackets1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8; @@ -31,9 +30,8 @@ public class SpawnPackets { } }; - public static void register(final Protocol protocol) { - // Spawn Object Packet - protocol.registerOutgoing(State.PLAY, 0x0E, 0x00, new PacketRemapper() { + public static void register(Protocol1_9To1_8 protocol) { + protocol.registerOutgoing(ClientboundPackets1_8.SPAWN_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -118,8 +116,7 @@ public class SpawnPackets { } }); - // Spawn XP Packet - protocol.registerOutgoing(State.PLAY, 0x11, 0x01, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.SPAWN_EXPERIENCE_ORB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -143,8 +140,7 @@ public class SpawnPackets { } }); - // Spawn Global Entity Packet - protocol.registerOutgoing(State.PLAY, 0x2C, 0x02, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.SPAWN_GLOBAL_ENTITY, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -167,8 +163,7 @@ public class SpawnPackets { } }); - // Spawn Mob Packet - protocol.registerOutgoing(State.PLAY, 0x0F, 0x03, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.SPAWN_MOB, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -235,8 +230,7 @@ public class SpawnPackets { } }); - // Spawn Painting Packet - protocol.registerOutgoing(State.PLAY, 0x10, 0x04, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.SPAWN_PAINTING, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -251,8 +245,6 @@ public class SpawnPackets { tracker.sendMetadataBuffer(entityID); } }); - - create(new ValueCreator() { @Override public void write(PacketWrapper wrapper) throws Exception { @@ -268,8 +260,7 @@ public class SpawnPackets { } }); - // Spawn Player Packet - protocol.registerOutgoing(State.PLAY, 0x0C, 0x05, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.SPAWN_PLAYER, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -341,8 +332,7 @@ public class SpawnPackets { } }); - // Entity Destroy Packet - protocol.registerOutgoing(State.PLAY, 0x13, 0x30, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.DESTROY_ENTITIES, new PacketRemapper() { @Override public void registerMap() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 2648b103e..d700c8381 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -13,9 +13,10 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; 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_8.ClientboundPackets1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect; @@ -31,8 +32,7 @@ import java.util.Optional; public class WorldPackets { public static void register(Protocol protocol) { - // Sign Update Packet - protocol.registerOutgoing(State.PLAY, 0x33, 0x46, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.UPDATE_SIGN, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Sign Position @@ -43,8 +43,7 @@ public class WorldPackets { } }); - // Play Effect Packet - protocol.registerOutgoing(State.PLAY, 0x28, 0x21, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.EFFECT, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Effect ID @@ -76,8 +75,7 @@ public class WorldPackets { } }); - // Play Named Sound Effect Packet - protocol.registerOutgoing(State.PLAY, 0x29, 0x19, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.NAMED_SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.STRING); // 0 - Sound Name @@ -105,7 +103,6 @@ public class WorldPackets { int z = wrapper.passthrough(Type.INT); //Position Z if (tracker.interactedBlockRecently((int) Math.floor(x / 8.0), (int) Math.floor(y / 8.0), (int) Math.floor(z / 8.0))) { wrapper.cancel(); - return; } } } @@ -113,8 +110,7 @@ public class WorldPackets { } }); - // Chunk Packet - protocol.registerOutgoing(State.PLAY, 0x21, 0x20, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -141,8 +137,7 @@ public class WorldPackets { } }); - // Bulk Chunk Packet - protocol.registerOutgoing(State.PLAY, 0x26, -1, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.MAP_BULK_CHUNK, null, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -176,8 +171,7 @@ public class WorldPackets { } }); - // Update Block Entity Packet - protocol.registerOutgoing(State.PLAY, 0x35, 0x09, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Block Position @@ -214,29 +208,17 @@ public class WorldPackets { } }); - // Block Change Packet - protocol.registerOutgoing(State.PLAY, 0x23, 0x0B, new PacketRemapper() { + protocol.registerOutgoing(ClientboundPackets1_8.BLOCK_CHANGE, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); map(Type.VAR_INT); } }); - /* Packets which do not have any field remapping or handlers */ - protocol.registerOutgoing(State.PLAY, 0x25, 0x08); // Block Break Animation Packet - protocol.registerOutgoing(State.PLAY, 0x24, 0x0A); // Block Action Packet - protocol.registerOutgoing(State.PLAY, 0x41, 0x0D); // Server Difficulty Packet - protocol.registerOutgoing(State.PLAY, 0x22, 0x10); // Multi Block Change Packet - protocol.registerOutgoing(State.PLAY, 0x27, 0x1C); // Explosion Packet - protocol.registerOutgoing(State.PLAY, 0x2A, 0x22); // Particle Packet - protocol.registerOutgoing(State.PLAY, 0x03, 0x44); // Update Time Packet - protocol.registerOutgoing(State.PLAY, 0x44, 0x35); // World Border Packet /* Incoming Packets */ - - // Sign Update Request Packet - protocol.registerIncoming(State.PLAY, 0x12, 0x19, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.UPDATE_SIGN, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Sign Position @@ -247,8 +229,7 @@ public class WorldPackets { } }); - // Player Digging Packet - protocol.registerIncoming(State.PLAY, 0x07, 0x13, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLAYER_DIGGING, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT, Type.UNSIGNED_BYTE); // 0 - Status @@ -279,8 +260,7 @@ public class WorldPackets { } }); - // Use Item Packet - protocol.registerIncoming(State.PLAY, -1, 0x1D, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.USE_ITEM, null, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @@ -324,8 +304,7 @@ public class WorldPackets { } }); - // Block Placement Packet - protocol.registerIncoming(State.PLAY, 0x08, 0x1C, new PacketRemapper() { + protocol.registerIncoming(ServerboundPackets1_9.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() { @Override public void registerMap() { map(Type.POSITION); // 0 - Position diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_9_1/Protocol1_9To1_9_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_9_1/Protocol1_9To1_9_1.java index 30ad7c794..dab2a898b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_9_1/Protocol1_9To1_9_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_9_1/Protocol1_9To1_9_1.java @@ -5,14 +5,20 @@ 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_9to1_8.ClientboundPackets1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ServerboundPackets1_9; + +public class Protocol1_9To1_9_1 extends Protocol { + + public Protocol1_9To1_9_1() { + super(ClientboundPackets1_9.class, ClientboundPackets1_9.class, ServerboundPackets1_9.class, ServerboundPackets1_9.class); + } -public class Protocol1_9To1_9_1 extends Protocol { @Override protected void registerPackets() { // Currently supports 1.9.1 and 1.9.2 - // Join Game Packet - registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() { + + registerOutgoing(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { map(Type.INT); // 0 - Player ID @@ -26,8 +32,7 @@ public class Protocol1_9To1_9_1 extends Protocol { } }); - // Sound Effect Packet - registerOutgoing(State.PLAY, 0x47, 0x47, new PacketRemapper() { + registerOutgoing(ClientboundPackets1_9.SOUND, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Sound ID diff --git a/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java b/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java index 5e9047d52..dae27fa7a 100644 --- a/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.update; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import net.md_5.bungee.api.ChatColor; +import org.jetbrains.annotations.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.util.GsonUtil; @@ -40,6 +41,7 @@ public class UpdateUtil { }); } + @Nullable private static String getUpdateMessage(boolean console) { if (Via.getPlatform().getPluginVersion().equals("${project.version}")) { return "You are using a debug/custom version, consider updating."; @@ -71,6 +73,7 @@ public class UpdateUtil { return null; } + @Nullable private static String getNewestVersion() { try { URL url = new URL(URL + PLUGIN + LATEST_VERSION + "?" + System.currentTimeMillis()); diff --git a/common/src/main/java/us/myles/ViaVersion/update/Version.java b/common/src/main/java/us/myles/ViaVersion/update/Version.java index f6e31a3f2..7812a1c1c 100644 --- a/common/src/main/java/us/myles/ViaVersion/update/Version.java +++ b/common/src/main/java/us/myles/ViaVersion/update/Version.java @@ -10,7 +10,7 @@ import java.util.regex.Pattern; public class Version implements Comparable { private static final Pattern semVer = Pattern.compile("(?0|[1-9]\\d*)\\.(?0|[1-9]\\d*)(?:\\.(?0|[1-9]\\d*))?(?:-(?[A-z0-9.-]*))?"); private final int[] parts = new int[3]; - private String tag; + private final String tag; public Version(String value) { if (value == null) @@ -48,9 +48,9 @@ public class Version implements Comparable { } // Simple tag check - if (verA.tag.length() == 0 && verB.tag.length() > 0) + if (verA.tag.isEmpty() && !verB.tag.isEmpty()) return 1; - if (verA.tag.length() > 0 && verB.tag.length() == 0) + if (!verA.tag.isEmpty() && verB.tag.isEmpty()) return -1; return 0; @@ -74,7 +74,7 @@ public class Version implements Comparable { for (int i = 0; i < parts.length; i += 1) split[i] = String.valueOf(parts[i]); - return Joiner.on(".").join(split) + (tag.length() != 0 ? "-" + tag : ""); + return Joiner.on(".").join(split) + (!tag.isEmpty() ? "-" + tag : ""); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/util/BiIntConsumer.java b/common/src/main/java/us/myles/ViaVersion/util/BiIntConsumer.java index 6c2a43d0e..4d7ddaa95 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/BiIntConsumer.java +++ b/common/src/main/java/us/myles/ViaVersion/util/BiIntConsumer.java @@ -2,5 +2,6 @@ package us.myles.ViaVersion.util; @FunctionalInterface public interface BiIntConsumer { + void consume(int i1, int i2); } diff --git a/common/src/main/java/us/myles/ViaVersion/util/Config.java b/common/src/main/java/us/myles/ViaVersion/util/Config.java index 522d18cfc..b2d863f7f 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/Config.java +++ b/common/src/main/java/us/myles/ViaVersion/util/Config.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.util; +import org.jetbrains.annotations.Nullable; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; @@ -124,6 +125,7 @@ public abstract class Config implements ConfigurationProvider { return this.config; } + @Nullable public T get(String key, Class clazz, T def) { Object o = this.config.get(key); if (o != null) { @@ -142,7 +144,8 @@ public abstract class Config implements ConfigurationProvider { } } - public String getString(String key, String def) { + @Nullable + public String getString(String key, @Nullable String def) { final Object o = this.config.get(key); if (o != null) { return (String) o; diff --git a/pom.xml b/pom.xml index 404fd2fb1..d140ccb8b 100644 --- a/pom.xml +++ b/pom.xml @@ -126,6 +126,14 @@ provided + + + org.jetbrains + annotations + 19.0.0 + provided + + org.junit.jupiter diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java index 10291f92c..1207f0b70 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.sponge.commands; +import org.jetbrains.annotations.Nullable; import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; @@ -9,7 +10,6 @@ import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import us.myles.ViaVersion.commands.ViaCommandHandler; -import javax.annotation.Nullable; import java.util.List; import java.util.Optional;