diff --git a/all/pom.xml b/all/pom.xml
index 7db043b3..0cee5e97 100644
--- a/all/pom.xml
+++ b/all/pom.xml
@@ -81,5 +81,11 @@
viabackwards-sponge
${project.parent.version}
+
+
+ nl.matsv
+ viabackwards-velocity
+ ${project.parent.version}
+
\ No newline at end of file
diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java
index ed54c7ad..4ce67b3e 100644
--- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java
+++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java
@@ -22,8 +22,8 @@ import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
+import us.myles.ViaVersion.update.Version;
-import java.lang.reflect.Field;
import java.util.Collections;
import java.util.logging.Logger;
@@ -54,21 +54,22 @@ public interface ViaBackwardsPlatform {
*/
Logger getLogger();
- // TODO remove or better implement later
default boolean isOutdated() {
+ String minimumVVVersion = "2.0.0";
boolean upToDate = false;
try {
- Class> clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion");
- Field v1_13 = clazz.getField("v1_13");
+ Class> vvVersionInfo = Class.forName("us.myles.ViaVersion.sponge.VersionInfo");
+ String vvVersion = (String) vvVersionInfo.getField("VERSION").get(null);
- upToDate = (v1_13 != null);
- } catch (ClassNotFoundException | NoSuchFieldException ignored) {
+ upToDate = (vvVersion != null
+ && new Version(vvVersion).compareTo(new Version(minimumVVVersion + "--")) >= 0);
+ } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
}
if (!upToDate) {
getLogger().severe("================================");
getLogger().severe("YOUR VIAVERSION IS OUTDATED");
- getLogger().severe("PLEASE USE THE LATEST VERSION");
+ getLogger().severe("PLEASE USE VIAVERSION " + minimumVVVersion + " OR NEWER");
getLogger().severe("LINK: https://viaversion.com");
getLogger().severe("VIABACKWARDS WILL NOW DISABLE");
getLogger().severe("================================");
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java
index e3ba3962..bf77e218 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java
@@ -8,20 +8,20 @@ import java.util.Map;
import java.util.Optional;
public class EntityTypeMapping {
- private static Map entityTypes = new HashMap<>();
+ private static Map entityTypes = new HashMap<>();
- static {
- try {
- Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
- field.setAccessible(true);
- Map entityTypes = (Map) field.get(null);
- entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
- } catch (NoSuchFieldException | IllegalAccessException ex) {
- ex.printStackTrace();
- }
- }
+ static {
+ try {
+ Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
+ field.setAccessible(true);
+ Map entityTypes = (Map) field.get(null);
+ entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
+ } catch (NoSuchFieldException | IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ }
- public static Optional getOldId(int type1_13) {
- return Optional.ofNullable(entityTypes.get(type1_13));
- }
+ public static Optional getOldId(int type1_13) {
+ return Optional.ofNullable(entityTypes.get(type1_13));
+ }
}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java
index e6f167d9..5788fee2 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java
@@ -7,20 +7,20 @@ import java.util.HashMap;
import java.util.Map;
public class NamedSoundMapping {
- private static Map sounds = new HashMap<>();
+ private static Map sounds = new HashMap<>();
- static {
- try {
- Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew");
- field.setAccessible(true);
- Map sounds = (Map) field.get(null);
- sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12));
- } catch (NoSuchFieldException | IllegalAccessException ex) {
- ex.printStackTrace();
- }
- }
+ static {
+ try {
+ Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew");
+ field.setAccessible(true);
+ Map sounds = (Map) field.get(null);
+ sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12));
+ } catch (NoSuchFieldException | IllegalAccessException ex) {
+ ex.printStackTrace();
+ }
+ }
- public static String getOldId(String sound1_13) {
- return sounds.get(sound1_13);
- }
+ public static String getOldId(String sound1_13) {
+ return sounds.get(sound1_13);
+ }
}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java
index bfb85bd7..578ed5f9 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java
@@ -4,42 +4,42 @@ import java.util.HashMap;
import java.util.Map;
public class PaintingMapping {
- private static Map paintings = new HashMap<>();
+ private static Map paintings = new HashMap<>();
- public static void init() {
- add("kebab");
- add("aztec");
- add("alban");
- add("aztec2");
- add("bomb");
- add("plant");
- add("wasteland");
- add("pool");
- add("courbet");
- add("sea");
- add("sunset");
- add("creebet");
- add("wanderer");
- add("graham");
- add("match");
- add("bust");
- add("stage");
- add("void");
- add("skullandroses");
- add("wither");
- add("fighters");
- add("pointer");
- add("pigscene");
- add("burningskull");
- add("skeleton");
- add("donkeykong");
- }
+ public static void init() {
+ add("kebab");
+ add("aztec");
+ add("alban");
+ add("aztec2");
+ add("bomb");
+ add("plant");
+ add("wasteland");
+ add("pool");
+ add("courbet");
+ add("sea");
+ add("sunset");
+ add("creebet");
+ add("wanderer");
+ add("graham");
+ add("match");
+ add("bust");
+ add("stage");
+ add("void");
+ add("skullandroses");
+ add("wither");
+ add("fighters");
+ add("pointer");
+ add("pigscene");
+ add("burningskull");
+ add("skeleton");
+ add("donkeykong");
+ }
- private static void add(String motive) {
- paintings.put(paintings.size(), motive);
- }
+ private static void add(String motive) {
+ paintings.put(paintings.size(), motive);
+ }
- public static String getStringId(int id) {
- return paintings.getOrDefault(id, "kebab");
- }
+ public static String getStringId(int id) {
+ return paintings.getOrDefault(id, "kebab");
+ }
}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java
index 99fa1628..c9096b01 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java
@@ -9,36 +9,36 @@ import java.util.Arrays;
import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData;
public class SoundMapping {
- private static short[] sounds = new short[662];
+ private static short[] sounds = new short[662];
- public static void init() {
- JsonObject mapping1_12 = loadData("mapping-1.12.json");
- JsonObject mapping1_13 = loadData("mapping-1.13.json");
+ public static void init() {
+ JsonObject mapping1_12 = loadData("mapping-1.12.json");
+ JsonObject mapping1_13 = loadData("mapping-1.13.json");
- Arrays.fill(sounds, (short) -1);
- mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"));
- }
+ Arrays.fill(sounds, (short) -1);
+ mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"));
+ }
- private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
- for (int i = 0; i < oldIdentifiers.size(); i++) {
- JsonElement v = oldIdentifiers.get(i);
- Integer index = findIndex(newIdentifiers, v.getAsString());
- if (index == null) continue; //There will be missing sounds, since we are goind backwards
- output[i] = index.shortValue();
- }
- }
+ private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
+ for (int i = 0; i < oldIdentifiers.size(); i++) {
+ JsonElement v = oldIdentifiers.get(i);
+ Integer index = findIndex(newIdentifiers, v.getAsString());
+ if (index == null) continue; //There will be missing sounds, since we are goind backwards
+ output[i] = index.shortValue();
+ }
+ }
- private static Integer findIndex(JsonArray array, String value) {
- for (int i = 0; i < array.size(); i++) {
- JsonElement v = array.get(i);
- if (v.getAsString().equals(value)) {
- return i;
- }
- }
- return null;
- }
+ private static Integer findIndex(JsonArray array, String value) {
+ for (int i = 0; i < array.size(); i++) {
+ JsonElement v = array.get(i);
+ if (v.getAsString().equals(value)) {
+ return i;
+ }
+ }
+ return null;
+ }
- public static int getOldSound(int newSound) {
- return newSound >= sounds.length ? -1 : sounds[newSound];
- }
+ public static int getOldSound(int newSound) {
+ return newSound >= sounds.length ? -1 : sounds[newSound];
+ }
}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
index 7fa67106..611705f7 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
@@ -195,7 +195,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter lore = new ArrayList<>();
boolean dummyEnchatment = true;
- for (Tag enchantmentEntry : enchantments) {
+ for (Tag enchantmentEntry : enchantments.clone()) {
if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
- if(enchantmentMappings.containsKey(newId)){
+ if (enchantmentMappings.containsKey(newId)) {
lore.add(new StringTag("", enchantmentMappings.get(newId)));
noMapped.add(enchantmentEntry);
- }else{
+ } else {
dummyEnchatment = false;
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
@@ -681,20 +681,20 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = lore.iterator();
- while(iterator.hasNext()){
+ while (iterator.hasNext()) {
oldLore.add(iterator.next().clone());
}
display.put(oldLore);
@@ -712,10 +712,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = lore.iterator();
- while(iterator.hasNext()){
+ while (iterator.hasNext()) {
oldLore.add(iterator.next().clone());
}
display.put(oldLore);
@@ -853,10 +853,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = oldLore.iterator();
- while (iterator.hasNext()){
+ while (iterator.hasNext()) {
loreTag.add(iterator.next());
}
display.remove("Lore");
@@ -915,10 +915,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = noMapped.iterator();
- while (iterator.hasNext()){
+ while (iterator.hasNext()) {
enchantments.add(iterator.next());
}
tag.remove(NBT_TAG_NAME + "|Enchantments");
@@ -944,10 +944,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = noMapped.iterator();
- while (iterator.hasNext()){
+ while (iterator.hasNext()) {
newStoredEnch.add(iterator.next());
}
}
@@ -1057,7 +1057,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter {
// Remove boat splash timer
registerMetaHandler().filter(EntityType.BOAT, 12).removed();
- //Remove shooter UUID
- registerMetaHandler().filter(EntityType.ABSTRACT_ARROW, true, 7).removed();
-
- registerMetaHandler().filter(EntityType.SPECTRAL_ARROW, 8).handleIndexChange(7);
-
// Remove Trident special loyalty level
- registerMetaHandler().filter(EntityType.TRIDENT, 8).removed();
+ registerMetaHandler().filter(EntityType.TRIDENT, 7).removed();
// Handle new wolf colors
registerMetaHandler().filter(EntityType.WOLF, 17).handle(e -> {
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java
index df6fc885..7a49b6fa 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java
@@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
+import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
@@ -17,6 +18,25 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPacke
public class PlayerPacket1_13 extends Rewriter {
@Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
+ // Login Plugin Request
+ protocol.out(State.LOGIN, 0x04, -1, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper packetWrapper) throws Exception {
+ packetWrapper.cancel();
+ packetWrapper.create(0x02, new ValueCreator() { // Plugin response
+ @Override
+ public void write(PacketWrapper newWrapper) throws Exception {
+ newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id
+ newWrapper.write(Type.BOOLEAN, false); // Success
+ }
+ }).sendToServer(Protocol1_12_2To1_13.class);
+ }
+ });
+ }
+ });
//Plugin Message
protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() {
@@ -30,21 +50,21 @@ public class PlayerPacket1_13 extends Rewriter {
wrapper.write(Type.STRING, "MC|TrList");
wrapper.passthrough(Type.INT); //Passthrough Window ID
- int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
- for (int i = 0; i < size; i++) {
- //Input Item
- Item input = wrapper.read(Type.FLAT_ITEM);
- wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input));
- //Output Item
- Item output = wrapper.read(Type.FLAT_ITEM);
- wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output));
+ int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
+ for (int i = 0; i < size; i++) {
+ //Input Item
+ Item input = wrapper.read(Type.FLAT_ITEM);
+ wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input));
+ //Output Item
+ Item output = wrapper.read(Type.FLAT_ITEM);
+ wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output));
- boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
- if (secondItem) {
- //Second Item
- Item second = wrapper.read(Type.FLAT_ITEM);
- wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second));
- }
+ boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
+ if (secondItem) {
+ //Second Item
+ Item second = wrapper.read(Type.FLAT_ITEM);
+ wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second));
+ }
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses
@@ -158,7 +178,7 @@ public class PlayerPacket1_13 extends Rewriter {
String match = wrapper.read(Type.STRING);
wrapper.write(Type.STRING, (start == 0 ? "/" : "") + match);
// Ignore tooltip
- if (wrapper.read(Type.BOOLEAN)) wrapper.read(Type.STRING);
+ if (wrapper.read(Type.BOOLEAN)) wrapper.read(Type.STRING);
}
}
});
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java
index c82a4221..acc31982 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java
@@ -11,76 +11,76 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class SoundPackets1_13 extends Rewriter {
- private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"};
+ private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"};
- @Override
- protected void registerPackets(Protocol1_12_2To1_13 protocol) {
+ @Override
+ protected void registerPackets(Protocol1_12_2To1_13 protocol) {
- //Named Sound Event
- protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.STRING);
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- String newSound = wrapper.get(Type.STRING, 0);
- String oldSound = NamedSoundMapping.getOldId(newSound);
- if (oldSound != null) {
- wrapper.set(Type.STRING, 0, oldSound);
- }
- }
- });
- }
- });
+ //Named Sound Event
+ protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.STRING);
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ String newSound = wrapper.get(Type.STRING, 0);
+ String oldSound = NamedSoundMapping.getOldId(newSound);
+ if (oldSound != null) {
+ wrapper.set(Type.STRING, 0, oldSound);
+ }
+ }
+ });
+ }
+ });
- //Stop Sound
- protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() {
- @Override
- public void registerMap() {
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- wrapper.write(Type.STRING, "MC|StopSound");
- byte flags = wrapper.read(Type.BYTE);
- String source;
- if ((flags & 0x01) != 0) {
- source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
- } else {
- source = "";
- }
- String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
+ //Stop Sound
+ protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ wrapper.write(Type.STRING, "MC|StopSound");
+ byte flags = wrapper.read(Type.BYTE);
+ String source;
+ if ((flags & 0x01) != 0) {
+ source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
+ } else {
+ source = "";
+ }
+ String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
- wrapper.write(Type.STRING, source);
- wrapper.write(Type.STRING, sound);
- }
- });
- }
- });
+ wrapper.write(Type.STRING, source);
+ wrapper.write(Type.STRING, sound);
+ }
+ });
+ }
+ });
- //Sound Effect
- protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.VAR_INT);
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- int newSound = wrapper.get(Type.VAR_INT, 0);
- int oldSound = SoundMapping.getOldSound(newSound);
- if (oldSound == -1) {
- wrapper.cancel();
- } else {
- wrapper.set(Type.VAR_INT, 0, oldSound);
- }
- }
- });
- }
- });
- }
+ //Sound Effect
+ protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT);
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ int newSound = wrapper.get(Type.VAR_INT, 0);
+ int oldSound = SoundMapping.getOldSound(newSound);
+ if (oldSound == -1) {
+ wrapper.cancel();
+ } else {
+ wrapper.set(Type.VAR_INT, 0, oldSound);
+ }
+ }
+ });
+ }
+ });
+ }
- @Override
- protected void registerRewrites() {
+ @Override
+ protected void registerRewrites() {
- }
+ }
}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java
index d724dce7..33f7af9e 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java
@@ -1,6 +1,9 @@
package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2;
import nl.matsv.viabackwards.api.BackwardsProtocol;
+import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets1_13_2;
+import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets1_13_2;
+import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets1_13_2;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
@@ -8,17 +11,14 @@ 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 nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets;
-import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets;
-import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets;
public class Protocol1_13_1To1_13_2 extends BackwardsProtocol {
@Override
protected void registerPackets() {
- InventoryPackets.register(this);
- WorldPackets.register(this);
- EntityPackets.register(this);
+ InventoryPackets1_13_2.register(this);
+ WorldPackets1_13_2.register(this);
+ EntityPackets1_13_2.register(this);
//Edit Book
registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java
similarity index 99%
rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets.java
rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java
index ad4ecd2d..000800c1 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java
@@ -12,7 +12,7 @@ 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;
-public class EntityPackets {
+public class EntityPackets1_13_2 {
public static void register(Protocol protocol) {
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java
similarity index 99%
rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java
rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java
index ecd88eec..44a44b48 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java
@@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
-public class InventoryPackets {
+public class InventoryPackets1_13_2 {
public static void register(Protocol protocol) {
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java
similarity index 97%
rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets.java
rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java
index 9fc17e0a..92d31a2e 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java
@@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
-public class WorldPackets {
+public class WorldPackets1_13_2 {
public static void register(Protocol protocol) {
//spawn particle
@@ -24,6 +24,7 @@ public class WorldPackets {
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
+
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java
deleted file mode 100644
index 72ebe475..00000000
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1;
-
-import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets;
-import us.myles.ViaVersion.api.Via;
-import us.myles.ViaVersion.api.data.UserConnection;
-import us.myles.ViaVersion.api.entities.Entity1_13Types;
-import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
-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_13;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class MetadataRewriter {
-
- public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List metadatas, UserConnection connection) {
- for (Metadata metadata : new ArrayList<>(metadatas)) {
- try {
- // 1.13 changed item to flat item (no data)
- if (metadata.getMetaType() == MetaType1_13.Slot) {
- InventoryPackets.toClient((Item) metadata.getValue());
- } else if (metadata.getMetaType() == MetaType1_13.BlockID) {
- // Convert to new block id
- int data = (int) metadata.getValue();
- metadata.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
- }
- if (type == null) continue;
- if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
- // New block format
- int data = (int) metadata.getValue();
- metadata.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
- }
- if(type.is(EntityType.ITEM)){
-
- }
- } catch (Exception e) {
- metadatas.remove(metadata);
- if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
- Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
- Via.getPlatform().getLogger().warning("Metadata: " + metadata);
- e.printStackTrace();
- }
- }
- }
- }
-
-}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java
index 7992037e..1704d890 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java
@@ -1,9 +1,10 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1;
import nl.matsv.viabackwards.api.BackwardsProtocol;
-import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets;
-import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets;
-import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets;
+import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
+import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1;
+import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets1_13_1;
+import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets1_13_1;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
@@ -12,16 +13,15 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
-import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_13To1_13_1 extends BackwardsProtocol {
@Override
protected void registerPackets() {
- EntityPackets.register(this);
- InventoryPackets.register(this);
- WorldPackets.register(this);
+ new EntityPackets1_13_1().register(this);
+ InventoryPackets1_13_1.register(this);
+ WorldPackets1_13_1.register(this);
//Tab complete
registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@@ -47,7 +47,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
- InventoryPackets.toServer(wrapper.get(Type.FLAT_ITEM, 0));
+ InventoryPackets1_13_1.toServer(wrapper.get(Type.FLAT_ITEM, 0));
wrapper.write(Type.VAR_INT, 0);
}
});
@@ -128,7 +128,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
wrapper.passthrough(Type.STRING); // Title
wrapper.passthrough(Type.STRING); // Description
Item icon = wrapper.passthrough(Type.FLAT_ITEM);
- InventoryPackets.toClient(icon);
+ InventoryPackets1_13_1.toClient(icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)
@@ -169,7 +169,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
wrapper.passthrough(Type.STRING);
Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY);
for (int j = 0; j < items.length; j++) {
- items[j] = InventoryPackets.getOldItemId(items[j]);
+ items[j] = InventoryPackets1_13_1.getOldItemId(items[j]);
}
}
}
@@ -214,9 +214,15 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
}
@Override
- public void init(UserConnection userConnection) {
- userConnection.put(new EntityTracker(userConnection));
- if (!userConnection.has(ClientWorld.class))
- userConnection.put(new ClientWorld(userConnection));
+ public void init(UserConnection user) {
+ // Register EntityTracker if it doesn't exist yet.
+ if (!user.has(EntityTracker.class))
+ user.put(new EntityTracker(user));
+
+ // Init protocol in EntityTracker
+ user.get(EntityTracker.class).initProtocol(this);
+
+ if (!user.has(ClientWorld.class))
+ user.put(new ClientWorld(user));
}
}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java
deleted file mode 100644
index d1eb8d2a..00000000
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
-
-import com.google.common.base.Optional;
-import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.MetadataRewriter;
-import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
-import us.myles.ViaVersion.api.PacketWrapper;
-import us.myles.ViaVersion.api.entities.Entity1_13Types;
-import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
-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_13to1_12_2.storage.EntityTracker;
-
-public class EntityPackets {
-
- public static void register(Protocol protocol) {
-
- //spawn entity
- protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.VAR_INT); // 0 - Entity id
- map(Type.UUID); // 1 - UUID
- map(Type.BYTE); // 2 - Type
- map(Type.DOUBLE); // 3 - X
- map(Type.DOUBLE); // 4 - Y
- map(Type.DOUBLE); // 5 - Z
- map(Type.BYTE); // 6 - Pitch
- map(Type.BYTE); // 7 - Yaw
- map(Type.INT); // 8 - Data
-
- // Track Entity
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- int entityId = wrapper.get(Type.VAR_INT, 0);
- byte type = wrapper.get(Type.BYTE, 0);
- Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true);
-
- if (entType != null) {
- if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) {
- int data = wrapper.get(Type.INT, 0);
- wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
- }
- }
- // Register Type ID
- wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
- }
- });
- }
- });
- // Spawn mob packet
- protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.VAR_INT); // 0 - Entity ID
- map(Type.UUID); // 1 - Entity UUID
- map(Type.VAR_INT); // 2 - Entity Type
- map(Type.DOUBLE); // 3 - X
- map(Type.DOUBLE); // 4 - Y
- map(Type.DOUBLE); // 5 - Z
- map(Type.BYTE); // 6 - Yaw
- map(Type.BYTE); // 7 - Pitch
- map(Type.BYTE); // 8 - Head Pitch
- map(Type.SHORT); // 9 - Velocity X
- map(Type.SHORT); // 10 - Velocity Y
- map(Type.SHORT); // 11 - Velocity Z
- map(Types1_13.METADATA_LIST); // 12 - Metadata
-
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- int entityId = wrapper.get(Type.VAR_INT, 0);
- int type = wrapper.get(Type.VAR_INT, 1);
-
- Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
-
- // Register Type ID
- wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
-
- MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
- }
- });
- }
- });
-
- // Spawn player packet
- protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.VAR_INT); // 0 - Entity ID
- map(Type.UUID); // 1 - Player UUID
- map(Type.DOUBLE); // 2 - X
- map(Type.DOUBLE); // 3 - Y
- map(Type.DOUBLE); // 4 - Z
- map(Type.BYTE); // 5 - Yaw
- map(Type.BYTE); // 6 - Pitch
- map(Types1_13.METADATA_LIST); // 7 - Metadata
-
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- int entityId = wrapper.get(Type.VAR_INT, 0);
-
- Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
- // Register Type ID
- wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
- MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
- }
- });
- }
- });
- // Destroy entities
- protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
-
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
- wrapper.user().get(EntityTracker.class).removeEntity(entity);
- }
- });
- }
- });
-
-
- // Metadata packet
- protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.VAR_INT); // 0 - Entity ID
- map(Types1_13.METADATA_LIST); // 1 - Metadata list
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- int entityId = wrapper.get(Type.VAR_INT, 0);
-
- Optional type = wrapper.user().get(EntityTracker.class).get(entityId);
- MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
- }
- });
- }
- });
- }
-
-}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java
new file mode 100644
index 00000000..984c7478
--- /dev/null
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java
@@ -0,0 +1,360 @@
+package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets;
+
+import nl.matsv.viabackwards.ViaBackwards;
+import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
+import nl.matsv.viabackwards.api.entities.types.EntityType1_12;
+import nl.matsv.viabackwards.api.entities.types.EntityType1_13;
+import nl.matsv.viabackwards.api.entities.types.EntityType1_13.EntityType;
+import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
+import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
+import us.myles.ViaVersion.api.PacketWrapper;
+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_13;
+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_9_3to1_9_1_2.storage.ClientWorld;
+
+public class EntityPackets1_13_1 extends EntityRewriter {
+
+ @Override
+ protected void registerPackets(Protocol1_13To1_13_1 protocol) {
+
+ // Spawn Object
+ protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity id
+ map(Type.UUID); // 1 - UUID
+ map(Type.BYTE); // 2 - Type
+ map(Type.DOUBLE); // 3 - X
+ map(Type.DOUBLE); // 4 - Y
+ map(Type.DOUBLE); // 5 - Z
+ map(Type.BYTE); // 6 - Pitch
+ map(Type.BYTE); // 7 - Yaw
+ map(Type.INT); // 8 - Data
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ int entityId = wrapper.get(Type.VAR_INT, 0);
+ byte type = wrapper.get(Type.BYTE, 0);
+ EntityType entType = EntityType1_13.getTypeFromId(type, true);
+ if (entType == null) {
+ ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
+ return;
+ }
+
+ // Rewrite falling block
+ if (entType.is(EntityType.FALLING_BLOCK)) {
+ int data = wrapper.get(Type.INT, 0);
+ wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
+ }
+
+ // Track Entity
+ addTrackedEntity(
+ wrapper.user(),
+ entityId,
+ entType
+ );
+ }
+ });
+ }
+ });
+
+ // Spawn Experience Orb
+ protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT);
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ addTrackedEntity(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ EntityType.XP_ORB
+ );
+ }
+ });
+ }
+ });
+
+ // Spawn Global Entity
+ protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT);
+ map(Type.BYTE);
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ addTrackedEntity(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ EntityType.LIGHTNING_BOLT
+ );
+ }
+ });
+ }
+ });
+
+ // Spawn Mob
+ protocol.out(State.PLAY, 0x3, 0x3, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Type.UUID); // 1 - Entity UUID
+ map(Type.VAR_INT); // 2 - Entity Type
+ map(Type.DOUBLE); // 3 - X
+ map(Type.DOUBLE); // 4 - Y
+ map(Type.DOUBLE); // 5 - Z
+ map(Type.BYTE); // 6 - Yaw
+ map(Type.BYTE); // 7 - Pitch
+ map(Type.BYTE); // 8 - Head Pitch
+ map(Type.SHORT); // 9 - Velocity X
+ map(Type.SHORT); // 10 - Velocity Y
+ map(Type.SHORT); // 11 - Velocity Z
+ map(Types1_13.METADATA_LIST); // 12 - Metadata
+
+ // Track Entity
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ int type = wrapper.get(Type.VAR_INT, 1);
+
+ EntityType entityType = EntityType1_13.getTypeFromId(type, false);
+ addTrackedEntity(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ entityType
+ );
+ }
+ });
+
+ // Rewrite Metadata
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ MetaStorage storage = new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0));
+ handleMeta(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ storage
+ );
+
+ // Don't handle new ids / base meta since it's not used for this version
+
+ // Rewrite Metadata
+ wrapper.set(
+ Types1_13.METADATA_LIST,
+ 0,
+ storage.getMetaDataList()
+ );
+ }
+ });
+ }
+ });
+
+ // Spawn player packet
+ protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Type.UUID); // 1 - Player UUID
+ map(Type.DOUBLE); // 2 - X
+ map(Type.DOUBLE); // 3 - Y
+ map(Type.DOUBLE); // 4 - Z
+ map(Type.BYTE); // 5 - Yaw
+ map(Type.BYTE); // 6 - Pitch
+ map(Types1_13.METADATA_LIST); // 7 - Metadata
+
+ // Track Entity
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ addTrackedEntity(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ EntityType.PLAYER
+ );
+ }
+ });
+
+ // Rewrite Metadata
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ wrapper.set(
+ Types1_13.METADATA_LIST,
+ 0,
+ handleMeta(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0))
+ ).getMetaDataList()
+ );
+ }
+ });
+ }
+ });
+
+ //Spawn Painting
+ protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT);
+ map(Type.UUID);
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ addTrackedEntity(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ EntityType.PAINTING
+ );
+ }
+ });
+ }
+ });
+
+ // Join Game
+ protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.INT); // 0 - Entity ID
+ map(Type.UNSIGNED_BYTE); // 1 - Gamemode
+ map(Type.INT); // 2 - Dimension
+
+ // Track Entity
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ addTrackedEntity(
+ wrapper.user(),
+ wrapper.get(Type.INT, 0),
+ EntityType1_12.EntityType.PLAYER
+ );
+ }
+ });
+
+ // Save dimension
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
+ int dimensionId = wrapper.get(Type.INT, 1);
+ clientChunks.setEnvironment(dimensionId);
+ }
+ });
+ }
+ });
+
+ // Respawn
+ protocol.out(State.PLAY, 0x38, 0x38, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.INT); // 0 - Dimension ID\
+
+ // Save dimension
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
+ int dimensionId = wrapper.get(Type.INT, 0);
+ clientWorld.setEnvironment(dimensionId);
+ }
+ });
+ }
+ });
+
+ // Destroy entities
+ protocol.out(State.PLAY, 0x35, 0x35, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
+ getEntityTracker(wrapper.user()).removeEntity(entity);
+ }
+ });
+ }
+ });
+
+
+ // Metadata packet
+ protocol.out(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
+ @Override
+ public void registerMap() {
+ map(Type.VAR_INT); // 0 - Entity ID
+ map(Types1_13.METADATA_LIST); // 1 - Metadata list
+
+ handler(new PacketHandler() {
+ @Override
+ public void handle(PacketWrapper wrapper) throws Exception {
+ wrapper.set(
+ Types1_13.METADATA_LIST,
+ 0,
+ handleMeta(
+ wrapper.user(),
+ wrapper.get(Type.VAR_INT, 0),
+ new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0))
+ ).getMetaDataList()
+ );
+ }
+ });
+ }
+ });
+ }
+
+ @Override
+ protected void registerRewrites() {
+
+ // Rewrite items & blocks
+ registerMetaHandler().handle(e -> {
+ Metadata meta = e.getData();
+
+ if (meta.getMetaType() == MetaType1_13.Slot) {
+ InventoryPackets1_13_1.toClient((Item) meta.getValue());
+ } else if (meta.getMetaType() == MetaType1_13.BlockID) {
+ // Convert to new block id
+ int data = (int) meta.getValue();
+ meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
+ }
+
+ return meta;
+ });
+
+ // Remove shooter UUID
+ registerMetaHandler().
+ filter(EntityType.ABSTRACT_ARROW, true, 7)
+ .removed();
+
+ // Move colors to old position
+ registerMetaHandler().filter(EntityType.SPECTRAL_ARROW, 8)
+ .handleIndexChange(7);
+
+ // Move loyalty level to old position
+ registerMetaHandler().filter(EntityType.TRIDENT, 8)
+ .handleIndexChange(7);
+
+ // Rewrite Minecart blocks
+ registerMetaHandler()
+ .filter(EntityType.MINECART_ABSTRACT, true, 9)
+ .handle(e -> {
+ Metadata meta = e.getData();
+
+ int data = (int) meta.getValue();
+ meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data));
+
+ return meta;
+ });
+ }
+}
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java
similarity index 99%
rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java
rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java
index 32c5c3fb..058037e7 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java
@@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
-public class InventoryPackets {
+public class InventoryPackets1_13_1 {
public static void register(Protocol protocol) {
diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets1_13_1.java
similarity index 79%
rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java
rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets1_13_1.java
index aa0029ff..2d3dc3fa 100644
--- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java
+++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets1_13_1.java
@@ -13,7 +13,7 @@ import us.myles.ViaVersion.packets.State;
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;
-public class WorldPackets {
+public class WorldPackets1_13_1 {
public static void register(Protocol protocol) {
//Chunk
@@ -109,7 +109,7 @@ public class WorldPackets {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record
- wrapper.set(Type.INT, 1, data = InventoryPackets.getNewItemId(data));
+ wrapper.set(Type.INT, 1, data = InventoryPackets1_13_1.getNewItemId(data));
} else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, data = Protocol1_13To1_13_1.getNewBlockStateId(data));
}
@@ -118,42 +118,6 @@ public class WorldPackets {
}
});
- //join game
- protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.INT); // 0 - Entity ID
- map(Type.UNSIGNED_BYTE); // 1 - Gamemode
- map(Type.INT); // 2 - Dimension
-
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- // Store the player
- ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
- int dimensionId = wrapper.get(Type.INT, 1);
- clientChunks.setEnvironment(dimensionId);
- }
- });
- }
- });
-
- //respawn
- protocol.registerOutgoing(State.PLAY, 0x38, 0x38, new PacketRemapper() {
- @Override
- public void registerMap() {
- map(Type.INT); // 0 - Dimension ID
- handler(new PacketHandler() {
- @Override
- public void handle(PacketWrapper wrapper) throws Exception {
- ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
- int dimensionId = wrapper.get(Type.INT, 0);
- clientWorld.setEnvironment(dimensionId);
- }
- });
- }
- });
-
//spawn particle
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override
@@ -176,7 +140,7 @@ public class WorldPackets {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
} else if (id == 27) {
- InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM));
+ InventoryPackets1_13_1.toClient(wrapper.passthrough(Type.FLAT_ITEM));
}
}
});
diff --git a/pom.xml b/pom.xml
index 9a000266..e1d7713f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,7 @@
bukkit
bungee
sponge
+ velocity
all
diff --git a/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java b/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java
index 39fb6b9b..090ea4df 100644
--- a/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java
+++ b/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java
@@ -11,14 +11,14 @@
package nl.matsv.viabackwards;
import com.google.inject.Inject;
+import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.sponge.VersionInfo;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
-import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
+import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
-import org.spongepowered.api.plugin.PluginContainer;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.util.logging.Logger;
@@ -31,26 +31,21 @@ import java.util.logging.Logger;
dependencies = {@Dependency(id = "viaversion")}
)
public class SpongePlugin implements ViaBackwardsPlatform {
+ @Getter
private Logger logger;
@Inject
- private PluginContainer container;
+ private org.slf4j.Logger loggerSlf4j;
@Listener(order = Order.LATE)
- public void onServerStart(GameAboutToStartServerEvent e) {
+ public void onGameStart(GameInitializationEvent e) {
// Setup Logger
- this.logger = new LoggerWrapper(container.getLogger());
+ this.logger = new LoggerWrapper(loggerSlf4j);
// Init!
this.init();
}
- @Override
- public Logger getLogger() {
- return logger;
- }
-
- // TODO check how to for sponge, site was offline
@Override
public void disable() {
-
+ // Not possible
}
}
diff --git a/velocity/pom.xml b/velocity/pom.xml
new file mode 100644
index 00000000..ff974ef4
--- /dev/null
+++ b/velocity/pom.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+ viabackwards-parent
+ nl.matsv
+ 2.4.0-SNAPSHOT
+
+ 4.0.0
+
+ viabackwards-velocity
+
+
+
+
+ .
+ true
+ src/main/resources/
+
+ *
+
+
+
+
+
+
+ org.codehaus.mojo
+ templating-maven-plugin
+ 1.0.0
+
+
+ filter-src
+
+ filter-sources
+
+
+
+
+
+
+
+
+
+ velocity-maven-repo
+ Velocity maven repo
+ https://repo.velocitypowered.com/snapshots/
+
+ true
+
+
+ true
+
+
+
+
+
+
+
+ nl.matsv
+ viabackwards-core
+ ${project.parent.version}
+
+
+
+
+ com.velocitypowered
+ velocity-api
+ 1.0-SNAPSHOT
+ provided
+
+
+
\ No newline at end of file
diff --git a/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java b/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java
new file mode 100644
index 00000000..f12f184f
--- /dev/null
+++ b/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2016 Matsv
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package nl.matsv.viabackwards.velocity;
+
+public class VersionInfo {
+ public static final String VERSION = "${project.version}";
+}
diff --git a/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java b/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java
new file mode 100644
index 00000000..f20d6f58
--- /dev/null
+++ b/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016 Matsv
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package nl.matsv.viabackwards;
+
+import com.google.inject.Inject;
+import com.velocitypowered.api.event.PostOrder;
+import com.velocitypowered.api.event.Subscribe;
+import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
+import com.velocitypowered.api.plugin.Dependency;
+import com.velocitypowered.api.plugin.Plugin;
+import lombok.Getter;
+import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
+import nl.matsv.viabackwards.velocity.VersionInfo;
+import us.myles.ViaVersion.sponge.util.LoggerWrapper;
+
+import java.util.logging.Logger;
+
+@Plugin(id = "viabackwards",
+ name = "ViaBackwards",
+ version = VersionInfo.VERSION,
+ authors = {"Matsv"},
+ description = "Allow older Minecraft versions to connect to an newer server version.",
+ dependencies = {@Dependency(id = "viaversion")}
+)
+public class VelocityPlugin implements ViaBackwardsPlatform {
+ @Getter
+ private Logger logger;
+ @Inject
+ private org.slf4j.Logger loggerSlf4j;
+
+ @Subscribe(order = PostOrder.LATE)
+ public void onProxyStart(ProxyInitializeEvent e) {
+ // Setup Logger
+ this.logger = new LoggerWrapper(loggerSlf4j);
+ // Init!
+ this.init();
+ }
+
+ @Override
+ public void disable() {
+ // Not possible
+ }
+}