3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-20 06:50:10 +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;
public class EntityTypeMapping {
private static Map<Integer, Integer> entityTypes = new HashMap<>();
private static Map<Integer, Integer> entityTypes = new HashMap<>();
static {
try {
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
field.setAccessible(true);
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) 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<Integer, Integer> entityTypes = (Map<Integer, Integer>) 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<Integer> getOldId(int type1_13) {
return Optional.ofNullable(entityTypes.get(type1_13));
}
public static Optional<Integer> getOldId(int type1_13) {
return Optional.ofNullable(entityTypes.get(type1_13));
}
}

Datei anzeigen

@ -7,20 +7,20 @@ import java.util.HashMap;
import java.util.Map;
public class NamedSoundMapping {
private static Map<String, String> sounds = new HashMap<>();
private static Map<String, String> sounds = new HashMap<>();
static {
try {
Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew");
field.setAccessible(true);
Map<String, String> sounds = (Map<String, String>) 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<String, String> sounds = (Map<String, String>) 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);
}
}

Datei anzeigen

@ -4,42 +4,42 @@ import java.util.HashMap;
import java.util.Map;
public class PaintingMapping {
private static Map<Integer, String> paintings = new HashMap<>();
private static Map<Integer, String> 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");
}
}

Datei anzeigen

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

Datei anzeigen

@ -195,7 +195,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
Item[] items = wrapper.get(Type.ITEM_ARRAY, 0);
for (int i = 0; i < items.length; 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) {
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 {
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
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(ench);
if(!lore.isEmpty()){
if (!lore.isEmpty()) {
CompoundTag display = tag.get("display");
if (display==null) {
if (display == null) {
tag.put(display = new CompoundTag("display"));
tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay"));
}
ListTag loreTag = display.get("Lore");
if (loreTag==null){
if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class));
}
ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
Iterator<Tag> iterator = lore.iterator();
while(iterator.hasNext()){
while (iterator.hasNext()) {
oldLore.add(iterator.next().clone());
}
display.put(oldLore);
@ -692,10 +692,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
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 {
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
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(newStoredEnch);
if(!lore.isEmpty()){
if (!lore.isEmpty()) {
CompoundTag display = tag.get("display");
if (display==null) {
if (display == null) {
tag.put(display = new CompoundTag("display"));
tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay"));
}
ListTag loreTag = display.get("Lore");
if (loreTag==null){
if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class));
}
ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
Iterator<Tag> iterator = lore.iterator();
while(iterator.hasNext()){
while (iterator.hasNext()) {
oldLore.add(iterator.next().clone());
}
display.put(oldLore);
@ -833,10 +833,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
// Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) {
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(NBT_TAG_NAME + "|noDisplay");
}else{
} else {
if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name");
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 oldLore = display.get(NBT_TAG_NAME + "|OldLore");
Iterator<Tag> iterator = oldLore.iterator();
while (iterator.hasNext()){
while (iterator.hasNext()) {
loreTag.add(iterator.next());
}
display.remove("Lore");
@ -877,10 +877,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
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");
Iterator<Tag> iterator = noMapped.iterator();
while (iterator.hasNext()){
while (iterator.hasNext()) {
enchantments.add(iterator.next());
}
}
@ -905,10 +905,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
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");
Iterator<Tag> iterator = noMapped.iterator();
while (iterator.hasNext()){
while (iterator.hasNext()) {
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.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 +158,7 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
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);
}
}
});

Datei anzeigen

@ -11,76 +11,76 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
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
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() {
}
}
}