3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 00:22:53 +01:00

Reformat code

Dieser Commit ist enthalten in:
Matsv 2019-01-27 13:01:24 +01:00
Ursprung bf7ea31d35
Commit 29f1f3ea7c
7 geänderte Dateien mit 192 neuen und 192 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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);
} }
}); });
} }
@ -638,10 +638,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));
@ -661,20 +661,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);
@ -692,10 +692,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));
@ -715,20 +715,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);
@ -833,10 +833,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()));
@ -846,12 +846,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");
@ -877,10 +877,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());
} }
} }
@ -905,10 +905,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());
} }
} }
@ -1018,7 +1018,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
} }
private void handleEnchantmentClient(Item item){ private void handleEnchantmentClient(Item item) {
} }
} }

Datei anzeigen

@ -30,21 +30,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 +158,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);
} }
} }
}); });

Datei anzeigen

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