Merge branch 'dev' of https://github.com/Matsv/ViaBackwards into 1.13_items

# Conflicts:
#	core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java
This commit is contained in:
Marco Neuhaus 2019-02-16 00:07:36 +01:00
commit e35f264e89
25 changed files with 779 additions and 481 deletions

View File

@ -81,5 +81,11 @@
<artifactId>viabackwards-sponge</artifactId> <artifactId>viabackwards-sponge</artifactId>
<version>${project.parent.version}</version> <version>${project.parent.version}</version>
</dependency> </dependency>
<dependency>
<groupId>nl.matsv</groupId>
<artifactId>viabackwards-velocity</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -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 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.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; 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.Collections;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -54,21 +54,22 @@ public interface ViaBackwardsPlatform {
*/ */
Logger getLogger(); Logger getLogger();
// TODO remove or better implement later
default boolean isOutdated() { default boolean isOutdated() {
String minimumVVVersion = "2.0.0";
boolean upToDate = false; boolean upToDate = false;
try { try {
Class<?> clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion"); Class<?> vvVersionInfo = Class.forName("us.myles.ViaVersion.sponge.VersionInfo");
Field v1_13 = clazz.getField("v1_13"); String vvVersion = (String) vvVersionInfo.getField("VERSION").get(null);
upToDate = (v1_13 != null); upToDate = (vvVersion != null
} catch (ClassNotFoundException | NoSuchFieldException ignored) { && new Version(vvVersion).compareTo(new Version(minimumVVVersion + "--")) >= 0);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
} }
if (!upToDate) { if (!upToDate) {
getLogger().severe("================================"); getLogger().severe("================================");
getLogger().severe("YOUR VIAVERSION IS OUTDATED"); 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("LINK: https://viaversion.com");
getLogger().severe("VIABACKWARDS WILL NOW DISABLE"); getLogger().severe("VIABACKWARDS WILL NOW DISABLE");
getLogger().severe("================================"); getLogger().severe("================================");

View File

@ -8,20 +8,20 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class EntityTypeMapping { public class EntityTypeMapping {
private static Map<Integer, Integer> entityTypes = new HashMap<>(); private static Map<Integer, Integer> entityTypes = new HashMap<>();
static { static {
try { try {
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes"); Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
field.setAccessible(true); field.setAccessible(true);
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null); Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null);
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12)); entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
} catch (NoSuchFieldException | IllegalAccessException ex) { } catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static Optional<Integer> getOldId(int type1_13) { public static Optional<Integer> getOldId(int type1_13) {
return Optional.ofNullable(entityTypes.get(type1_13)); return Optional.ofNullable(entityTypes.get(type1_13));
} }
} }

View File

@ -7,20 +7,20 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class NamedSoundMapping { public class NamedSoundMapping {
private static Map<String, String> sounds = new HashMap<>(); private static Map<String, String> sounds = new HashMap<>();
static { static {
try { try {
Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew"); Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew");
field.setAccessible(true); field.setAccessible(true);
Map<String, String> sounds = (Map<String, String>) field.get(null); Map<String, String> sounds = (Map<String, String>) field.get(null);
sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12)); sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12));
} catch (NoSuchFieldException | IllegalAccessException ex) { } catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static String getOldId(String sound1_13) { public static String getOldId(String sound1_13) {
return sounds.get(sound1_13); return sounds.get(sound1_13);
} }
} }

View File

@ -4,42 +4,42 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class PaintingMapping { public class PaintingMapping {
private static Map<Integer, String> paintings = new HashMap<>(); private static Map<Integer, String> paintings = new HashMap<>();
public static void init() { public static void init() {
add("kebab"); add("kebab");
add("aztec"); add("aztec");
add("alban"); add("alban");
add("aztec2"); add("aztec2");
add("bomb"); add("bomb");
add("plant"); add("plant");
add("wasteland"); add("wasteland");
add("pool"); add("pool");
add("courbet"); add("courbet");
add("sea"); add("sea");
add("sunset"); add("sunset");
add("creebet"); add("creebet");
add("wanderer"); add("wanderer");
add("graham"); add("graham");
add("match"); add("match");
add("bust"); add("bust");
add("stage"); add("stage");
add("void"); add("void");
add("skullandroses"); add("skullandroses");
add("wither"); add("wither");
add("fighters"); add("fighters");
add("pointer"); add("pointer");
add("pigscene"); add("pigscene");
add("burningskull"); add("burningskull");
add("skeleton"); add("skeleton");
add("donkeykong"); add("donkeykong");
} }
private static void add(String motive) { private static void add(String motive) {
paintings.put(paintings.size(), motive); paintings.put(paintings.size(), motive);
} }
public static String getStringId(int id) { public static String getStringId(int id) {
return paintings.getOrDefault(id, "kebab"); return paintings.getOrDefault(id, "kebab");
} }
} }

View File

@ -9,36 +9,36 @@ import java.util.Arrays;
import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData; import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData;
public class SoundMapping { public class SoundMapping {
private static short[] sounds = new short[662]; private static short[] sounds = new short[662];
public static void init() { public static void init() {
JsonObject mapping1_12 = loadData("mapping-1.12.json"); JsonObject mapping1_12 = loadData("mapping-1.12.json");
JsonObject mapping1_13 = loadData("mapping-1.13.json"); JsonObject mapping1_13 = loadData("mapping-1.13.json");
Arrays.fill(sounds, (short) -1); Arrays.fill(sounds, (short) -1);
mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds")); mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"));
} }
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
for (int i = 0; i < oldIdentifiers.size(); i++) { for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i); JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString()); Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) continue; //There will be missing sounds, since we are goind backwards if (index == null) continue; //There will be missing sounds, since we are goind backwards
output[i] = index.shortValue(); output[i] = index.shortValue();
} }
} }
private static Integer findIndex(JsonArray array, String value) { private static Integer findIndex(JsonArray array, String value) {
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
JsonElement v = array.get(i); JsonElement v = array.get(i);
if (v.getAsString().equals(value)) { if (v.getAsString().equals(value)) {
return i; return i;
} }
} }
return null; return null;
} }
public static int getOldSound(int newSound) { public static int getOldSound(int newSound) {
return newSound >= sounds.length ? -1 : sounds[newSound]; return newSound >= sounds.length ? -1 : sounds[newSound];
} }
} }

View File

@ -195,7 +195,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
Item[] items = wrapper.get(Type.ITEM_ARRAY, 0); Item[] items = wrapper.get(Type.ITEM_ARRAY, 0);
for (int i = 0; i < items.length; i++) for (int i = 0; i < items.length; i++)
items[i] = handleItemToClient(items[i]); items[i] = handleItemToClient(items[i]);
wrapper.set(Type.ITEM_ARRAY,0, items); wrapper.set(Type.ITEM_ARRAY, 0, items);
} }
}); });
} }
@ -635,14 +635,14 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
ListTag ench = new ListTag("ench", CompoundTag.class); ListTag ench = new ListTag("ench", CompoundTag.class);
List<Tag> lore = new ArrayList<>(); List<Tag> lore = new ArrayList<>();
boolean dummyEnchatment = true; boolean dummyEnchatment = true;
for (Tag enchantmentEntry : enchantments) { for (Tag enchantmentEntry : enchantments.clone()) {
if (enchantmentEntry instanceof CompoundTag) { if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag(""); CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
if(enchantmentMappings.containsKey(newId)){ if (enchantmentMappings.containsKey(newId)) {
lore.add(new StringTag("", enchantmentMappings.get(newId))); lore.add(new StringTag("", enchantmentMappings.get(newId)));
noMapped.add(enchantmentEntry); noMapped.add(enchantmentEntry);
}else{ } else {
dummyEnchatment = false; dummyEnchatment = false;
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) { if (oldId == null && newId.startsWith("viaversion:legacy/")) {
@ -681,20 +681,20 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
tag.put(noMapped); tag.put(noMapped);
tag.put(ench); tag.put(ench);
if(!lore.isEmpty()){ if (!lore.isEmpty()) {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display==null) { if (display == null) {
tag.put(display = new CompoundTag("display")); tag.put(display = new CompoundTag("display"));
tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay")); tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay"));
} }
ListTag loreTag = display.get("Lore"); ListTag loreTag = display.get("Lore");
if (loreTag==null){ if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class)); display.put(loreTag = new ListTag("Lore", StringTag.class));
} }
ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class); ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
Iterator<Tag> iterator = lore.iterator(); Iterator<Tag> iterator = lore.iterator();
while(iterator.hasNext()){ while (iterator.hasNext()) {
oldLore.add(iterator.next().clone()); oldLore.add(iterator.next().clone());
} }
display.put(oldLore); display.put(oldLore);
@ -712,10 +712,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
if (enchantmentEntry instanceof CompoundTag) { if (enchantmentEntry instanceof CompoundTag) {
CompoundTag enchEntry = new CompoundTag(""); CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
if(enchantmentMappings.containsKey(newId)){ if (enchantmentMappings.containsKey(newId)) {
lore.add(new StringTag("", enchantmentMappings.get(newId))); lore.add(new StringTag("", enchantmentMappings.get(newId)));
noMapped.add(enchantmentEntry); noMapped.add(enchantmentEntry);
}else{ } else {
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId); Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) { if (oldId == null && newId.startsWith("viaversion:legacy/")) {
oldId = Short.valueOf(newId.substring(18)); oldId = Short.valueOf(newId.substring(18));
@ -735,20 +735,20 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
tag.put(noMapped); tag.put(noMapped);
tag.put(newStoredEnch); tag.put(newStoredEnch);
if(!lore.isEmpty()){ if (!lore.isEmpty()) {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if (display==null) { if (display == null) {
tag.put(display = new CompoundTag("display")); tag.put(display = new CompoundTag("display"));
tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay")); tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay"));
} }
ListTag loreTag = display.get("Lore"); ListTag loreTag = display.get("Lore");
if (loreTag==null){ if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class)); display.put(loreTag = new ListTag("Lore", StringTag.class));
} }
ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class); ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
Iterator<Tag> iterator = lore.iterator(); Iterator<Tag> iterator = lore.iterator();
while(iterator.hasNext()){ while (iterator.hasNext()) {
oldLore.add(iterator.next().clone()); oldLore.add(iterator.next().clone());
} }
display.put(oldLore); display.put(oldLore);
@ -853,10 +853,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
// Display Name now uses JSON // Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) { if (tag.get("display") instanceof CompoundTag) {
CompoundTag display = tag.get("display"); CompoundTag display = tag.get("display");
if(tag.get(NBT_TAG_NAME + "|noDisplay") instanceof ByteTag){ if (tag.get(NBT_TAG_NAME + "|noDisplay") instanceof ByteTag) {
tag.remove("display"); tag.remove("display");
tag.remove(NBT_TAG_NAME + "|noDisplay"); tag.remove(NBT_TAG_NAME + "|noDisplay");
}else{ } else {
if (display.get("Name") instanceof StringTag) { if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name"); StringTag name = display.get("Name");
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue())); display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
@ -866,12 +866,12 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
) )
); );
} }
if(display.get(NBT_TAG_NAME + "|OldLore") instanceof ListTag){ if (display.get(NBT_TAG_NAME + "|OldLore") instanceof ListTag) {
ListTag loreTag = new ListTag("Lore", StringTag.class); ListTag loreTag = new ListTag("Lore", StringTag.class);
ListTag oldLore = display.get(NBT_TAG_NAME + "|OldLore"); ListTag oldLore = display.get(NBT_TAG_NAME + "|OldLore");
Iterator<Tag> iterator = oldLore.iterator(); Iterator<Tag> iterator = oldLore.iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
loreTag.add(iterator.next()); loreTag.add(iterator.next());
} }
display.remove("Lore"); display.remove("Lore");
@ -915,10 +915,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
enchantments.add(enchantmentEntry); enchantments.add(enchantmentEntry);
} }
} }
if(tag.get(NBT_TAG_NAME + "|Enchantments") instanceof ListTag){ if (tag.get(NBT_TAG_NAME + "|Enchantments") instanceof ListTag) {
ListTag noMapped = tag.get(NBT_TAG_NAME + "|Enchantments"); ListTag noMapped = tag.get(NBT_TAG_NAME + "|Enchantments");
Iterator<Tag> iterator = noMapped.iterator(); Iterator<Tag> iterator = noMapped.iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
enchantments.add(iterator.next()); enchantments.add(iterator.next());
} }
tag.remove(NBT_TAG_NAME + "|Enchantments"); tag.remove(NBT_TAG_NAME + "|Enchantments");
@ -944,10 +944,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
newStoredEnch.add(enchantmentEntry); newStoredEnch.add(enchantmentEntry);
} }
} }
if(tag.get(NBT_TAG_NAME + "|Enchantments") instanceof ListTag){ if (tag.get(NBT_TAG_NAME + "|Enchantments") instanceof ListTag) {
ListTag noMapped = tag.get(NBT_TAG_NAME + "|StoredEnchantments"); ListTag noMapped = tag.get(NBT_TAG_NAME + "|StoredEnchantments");
Iterator<Tag> iterator = noMapped.iterator(); Iterator<Tag> iterator = noMapped.iterator();
while (iterator.hasNext()){ while (iterator.hasNext()) {
newStoredEnch.add(iterator.next()); newStoredEnch.add(iterator.next());
} }
} }
@ -1057,7 +1057,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
} }
private void handleEnchantmentClient(Item item){ private void handleEnchantmentClient(Item item) {
} }
} }

View File

@ -465,13 +465,8 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
// Remove boat splash timer // Remove boat splash timer
registerMetaHandler().filter(EntityType.BOAT, 12).removed(); 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 // Remove Trident special loyalty level
registerMetaHandler().filter(EntityType.TRIDENT, 8).removed(); registerMetaHandler().filter(EntityType.TRIDENT, 7).removed();
// Handle new wolf colors // Handle new wolf colors
registerMetaHandler().filter(EntityType.WOLF, 17).handle(e -> { registerMetaHandler().filter(EntityType.WOLF, 17).handle(e -> {

View File

@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; 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.api.type.Type;
import us.myles.ViaVersion.packets.State; 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.ChatRewriter;
@ -17,6 +18,25 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPacke
public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> { public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
@Override @Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) { 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 //Plugin Message
protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() { protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() {
@ -30,21 +50,21 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
wrapper.write(Type.STRING, "MC|TrList"); wrapper.write(Type.STRING, "MC|TrList");
wrapper.passthrough(Type.INT); //Passthrough Window ID wrapper.passthrough(Type.INT); //Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
//Input Item //Input Item
Item input = wrapper.read(Type.FLAT_ITEM); Item input = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input)); wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input));
//Output Item //Output Item
Item output = wrapper.read(Type.FLAT_ITEM); Item output = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output)); wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) { if (secondItem) {
//Second Item //Second Item
Item second = wrapper.read(Type.FLAT_ITEM); Item second = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second)); wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second));
} }
wrapper.passthrough(Type.BOOLEAN); //Trade disabled wrapper.passthrough(Type.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses wrapper.passthrough(Type.INT); //Number of tools uses
@ -158,7 +178,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
String match = wrapper.read(Type.STRING); String match = wrapper.read(Type.STRING);
wrapper.write(Type.STRING, (start == 0 ? "/" : "") + match); wrapper.write(Type.STRING, (start == 0 ? "/" : "") + match);
// Ignore tooltip // Ignore tooltip
if (wrapper.read(Type.BOOLEAN)) wrapper.read(Type.STRING); if (wrapper.read(Type.BOOLEAN)) wrapper.read(Type.STRING);
} }
} }
}); });

View File

@ -11,76 +11,76 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> { public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
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 @Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) { protected void registerPackets(Protocol1_12_2To1_13 protocol) {
//Named Sound Event //Named Sound Event
protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() { protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); map(Type.STRING);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
String newSound = wrapper.get(Type.STRING, 0); String newSound = wrapper.get(Type.STRING, 0);
String oldSound = NamedSoundMapping.getOldId(newSound); String oldSound = NamedSoundMapping.getOldId(newSound);
if (oldSound != null) { if (oldSound != null) {
wrapper.set(Type.STRING, 0, oldSound); wrapper.set(Type.STRING, 0, oldSound);
} }
} }
}); });
} }
}); });
//Stop Sound //Stop Sound
protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() { protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|StopSound"); wrapper.write(Type.STRING, "MC|StopSound");
byte flags = wrapper.read(Type.BYTE); byte flags = wrapper.read(Type.BYTE);
String source; String source;
if ((flags & 0x01) != 0) { if ((flags & 0x01) != 0) {
source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)]; source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
} else { } else {
source = ""; source = "";
} }
String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : ""; String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
wrapper.write(Type.STRING, source); wrapper.write(Type.STRING, source);
wrapper.write(Type.STRING, sound); wrapper.write(Type.STRING, sound);
} }
}); });
} }
}); });
//Sound Effect //Sound Effect
protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() { protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int newSound = wrapper.get(Type.VAR_INT, 0); int newSound = wrapper.get(Type.VAR_INT, 0);
int oldSound = SoundMapping.getOldSound(newSound); int oldSound = SoundMapping.getOldSound(newSound);
if (oldSound == -1) { if (oldSound == -1) {
wrapper.cancel(); wrapper.cancel();
} else { } else {
wrapper.set(Type.VAR_INT, 0, oldSound); wrapper.set(Type.VAR_INT, 0, oldSound);
} }
} }
}); });
} }
}); });
} }
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
} }
} }

View File

@ -1,6 +1,9 @@
package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2; package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2;
import nl.matsv.viabackwards.api.BackwardsProtocol; 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.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; 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.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; 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 { public class Protocol1_13_1To1_13_2 extends BackwardsProtocol {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
InventoryPackets.register(this); InventoryPackets1_13_2.register(this);
WorldPackets.register(this); WorldPackets1_13_2.register(this);
EntityPackets.register(this); EntityPackets1_13_2.register(this);
//Edit Book //Edit Book
registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {

View File

@ -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.api.type.types.version.Types1_13_2;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class EntityPackets { public class EntityPackets1_13_2 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {

View File

@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class InventoryPackets { public class InventoryPackets1_13_2 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {

View File

@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class WorldPackets { public class WorldPackets1_13_2 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
//spawn particle //spawn particle
@ -24,6 +24,7 @@ public class WorldPackets {
map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count map(Type.INT); // 9 - Particle Count
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {

View File

@ -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<Metadata> 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();
}
}
}
}
}

View File

@ -1,9 +1,10 @@
package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1;
import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets; 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.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; 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.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; 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; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_13To1_13_1 extends BackwardsProtocol { public class Protocol1_13To1_13_1 extends BackwardsProtocol {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
EntityPackets.register(this); new EntityPackets1_13_1().register(this);
InventoryPackets.register(this); InventoryPackets1_13_1.register(this);
WorldPackets.register(this); WorldPackets1_13_1.register(this);
//Tab complete //Tab complete
registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@ -47,7 +47,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { 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); 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); // Title
wrapper.passthrough(Type.STRING); // Description wrapper.passthrough(Type.STRING); // Description
Item icon = wrapper.passthrough(Type.FLAT_ITEM); Item icon = wrapper.passthrough(Type.FLAT_ITEM);
InventoryPackets.toClient(icon); InventoryPackets1_13_1.toClient(icon);
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) if ((flags & 1) != 0)
@ -169,7 +169,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY); Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY);
for (int j = 0; j < items.length; j++) { 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 @Override
public void init(UserConnection userConnection) { public void init(UserConnection user) {
userConnection.put(new EntityTracker(userConnection)); // Register EntityTracker if it doesn't exist yet.
if (!userConnection.has(ClientWorld.class)) if (!user.has(EntityTracker.class))
userConnection.put(new ClientWorld(userConnection)); 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));
} }
} }

View File

@ -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<EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}
});
}
}

View File

@ -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<Protocol1_13To1_13_1> {
@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;
});
}
}

View File

@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class InventoryPackets { public class InventoryPackets1_13_1 {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {

View File

@ -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_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; 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) { public static void register(Protocol protocol) {
//Chunk //Chunk
@ -109,7 +109,7 @@ public class WorldPackets {
int id = wrapper.get(Type.INT, 0); int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1); int data = wrapper.get(Type.INT, 1);
if (id == 1010) { // Play record 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 } else if (id == 2001) { // Block break + block break sound
wrapper.set(Type.INT, 1, data = Protocol1_13To1_13_1.getNewBlockStateId(data)); 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 //spawn particle
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override @Override
@ -176,7 +140,7 @@ public class WorldPackets {
int data = wrapper.passthrough(Type.VAR_INT); int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data)); wrapper.set(Type.VAR_INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data));
} else if (id == 27) { } else if (id == 27) {
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); InventoryPackets1_13_1.toClient(wrapper.passthrough(Type.FLAT_ITEM));
} }
} }
}); });

View File

@ -28,6 +28,7 @@
<module>bukkit</module> <module>bukkit</module>
<module>bungee</module> <module>bungee</module>
<module>sponge</module> <module>sponge</module>
<module>velocity</module>
<module>all</module> <module>all</module>
</modules> </modules>

View File

@ -11,14 +11,14 @@
package nl.matsv.viabackwards; package nl.matsv.viabackwards;
import com.google.inject.Inject; import com.google.inject.Inject;
import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform; import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.sponge.VersionInfo; import nl.matsv.viabackwards.sponge.VersionInfo;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order; 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.Dependency;
import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import us.myles.ViaVersion.sponge.util.LoggerWrapper; import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,26 +31,21 @@ import java.util.logging.Logger;
dependencies = {@Dependency(id = "viaversion")} dependencies = {@Dependency(id = "viaversion")}
) )
public class SpongePlugin implements ViaBackwardsPlatform { public class SpongePlugin implements ViaBackwardsPlatform {
@Getter
private Logger logger; private Logger logger;
@Inject @Inject
private PluginContainer container; private org.slf4j.Logger loggerSlf4j;
@Listener(order = Order.LATE) @Listener(order = Order.LATE)
public void onServerStart(GameAboutToStartServerEvent e) { public void onGameStart(GameInitializationEvent e) {
// Setup Logger // Setup Logger
this.logger = new LoggerWrapper(container.getLogger()); this.logger = new LoggerWrapper(loggerSlf4j);
// Init! // Init!
this.init(); this.init();
} }
@Override
public Logger getLogger() {
return logger;
}
// TODO check how to for sponge, site was offline
@Override @Override
public void disable() { public void disable() {
// Not possible
} }
} }

83
velocity/pom.xml Normal file
View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>2.4.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>viabackwards-velocity</artifactId>
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>src/main/resources/</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
<!-- Stolen from ViaVersion ;) -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filter-src</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>velocity-maven-repo</id>
<name>Velocity maven repo</name>
<url>https://repo.velocitypowered.com/snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<!-- Common Module -->
<dependency>
<groupId>nl.matsv</groupId>
<artifactId>viabackwards-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!-- Velocity API -->
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -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}";
}

View File

@ -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
}
}