From fc264d0b0f90b4115a583cbe7a58da15389a4721 Mon Sep 17 00:00:00 2001 From: Myles Date: Sun, 29 Jul 2018 12:14:17 +0100 Subject: [PATCH] Cleanup various debug code --- .../MetadataRewriter.java | 2 +- .../data/MappingData.java | 103 +++++++------- .../data/ParticleRewriter.java | 18 ++- .../packets/InventoryPackets.java | 131 +++++++++--------- .../packets/WorldPackets.java | 33 ++--- .../providers/BlockEntityProvider.java | 5 +- .../blockentities/BannerHandler.java | 12 +- .../providers/blockentities/BedHandler.java | 3 +- .../blockentities/FlowerPotHandler.java | 45 +++--- .../providers/blockentities/SkullHandler.java | 7 +- .../types/Chunk1_13Type.java | 9 +- .../types/Chunk1_9_3_4Type.java | 5 +- 12 files changed, 189 insertions(+), 184 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java index 595f865fb..0a59e1dc6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/MetadataRewriter.java @@ -6,11 +6,11 @@ import us.myles.ViaVersion.api.entities.Entity1_13Types; 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.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.ArrayList; import java.util.List; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index 714c0944d..44e8c0554 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -7,6 +7,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.util.GsonUtil; import java.io.IOException; @@ -28,8 +29,7 @@ public class MappingData { JsonObject mapping1_12 = loadData("mapping-1.12.json"); JsonObject mapping1_13 = loadData("mapping-1.13.json"); - // TODO: Remove how verbose this is - System.out.println("Loading block mapping..."); + Via.getPlatform().getLogger().info("Loading block mapping..."); try { Class.forName("io.netty.util.collection.IntObjectMap"); blockMappings = new BMNettyCollections(); @@ -37,61 +37,44 @@ public class MappingData { blockMappings = new BMJDKCollections(); } blockMappings.init(mapping1_12, mapping1_13); - System.out.println("Loading item mapping..."); + Via.getPlatform().getLogger().info("Loading item mapping..."); mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items")); - System.out.println("Loading new tags..."); + Via.getPlatform().getLogger().info("Loading new tags..."); loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags")); loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags")); loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags")); - System.out.println("Loading enchantments..."); + Via.getPlatform().getLogger().info("Loading enchantments..."); loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments")); - System.out.println("Loading sound mapping..."); + Via.getPlatform().getLogger().info("Loading sound mapping..."); mapIdentifiers(oldToNewSounds, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); } + public static JsonObject loadData(String name) { + InputStream stream = MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name); + InputStreamReader reader = new InputStreamReader(stream); + try { + JsonObject jsonObject = GsonUtil.getGson().fromJson(reader, JsonObject.class); + return jsonObject; + } finally { + try { + reader.close(); + } catch (IOException ignored) { + // Ignored + } + } + } + private static void mapIdentifiers(Map output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { for (Map.Entry entry : oldIdentifiers.entrySet()) { Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { - System.out.println("No key for " + entry.getValue() + " :( "); + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); continue; } output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); } } - private static Map.Entry findValue(JsonObject object, String needle) { - for (Map.Entry entry : object.entrySet()) { - String value = entry.getValue().getAsString(); - if (value.equals(needle)) { - return entry; - } - } - return null; - } - - private static void mapIdentifiers(Map 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) { - System.out.println("No key for " + v + " :( "); - continue; - } - output.put(i, index); - } - } - - 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 void loadTags(Map output, JsonObject newTags) { for (Map.Entry entry : newTags.entrySet()) { JsonArray ids = entry.getValue().getAsJsonArray(); @@ -109,23 +92,41 @@ public class MappingData { } } - public static JsonObject loadData(String name) { - InputStream stream = MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name); - InputStreamReader reader = new InputStreamReader(stream); - try { - JsonObject jsonObject = GsonUtil.getGson().fromJson(reader, JsonObject.class); - return jsonObject; - } finally { - try { - reader.close(); - } catch (IOException ignored) { - // Ignored + private static void mapIdentifiers(Map 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) { + Via.getPlatform().getLogger().warning("No key for " + v + " :( "); + continue; + } + output.put(i, index); + } + } + + private static Map.Entry findValue(JsonObject object, String needle) { + for (Map.Entry entry : object.entrySet()) { + String value = entry.getValue().getAsString(); + if (value.equals(needle)) { + return entry; } } + 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 interface BlockMappings { void init(JsonObject mapping1_12, JsonObject mapping1_13); + Integer getNewBlock(int old); } @@ -160,7 +161,7 @@ public class MappingData { for (Map.Entry entry : oldIdentifiers.entrySet()) { Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { - System.out.println("No key for " + entry.getValue() + " :( "); + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); continue; } output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index d749d3cd7..804c09f12 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -15,6 +15,7 @@ import java.util.Random; public class ParticleRewriter { private static List particles = new LinkedList<>(); + private static Random rand = new Random(); static { add(34); // (0->34) explode -> minecraft:poof @@ -102,10 +103,6 @@ public class ParticleRewriter { particles.add(new NewParticle(newId, dataHandler)); } - interface ParticleDataHandler { - Particle handler(Particle particle, Integer[] data); - } - // Randomized because the previous one was a lot of different colors at once! :) private static ParticleDataHandler reddustHandler() { return new ParticleDataHandler() { @@ -120,6 +117,10 @@ public class ParticleRewriter { }; } + private static float randomFloat() { + return rand.nextFloat(); + } + // Rewrite IconCrack items to new format :) private static ParticleDataHandler iconcrackHandler() { return new ParticleDataHandler() { @@ -157,6 +158,9 @@ public class ParticleRewriter { }; } + interface ParticleDataHandler { + Particle handler(Particle particle, Integer[] data); + } @Data @RequiredArgsConstructor @@ -171,11 +175,5 @@ public class ParticleRewriter { } } - private static Random rand = new Random(); - - private static float randomFloat() { - return rand.nextFloat(); - } - } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 5ef43a183..8ab9f565e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -5,6 +5,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.io.BaseEncoding; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -92,7 +93,7 @@ public class InventoryPackets { flags |= 1; Optional finalSource = SoundSource.findBySource(originalSource); if (!finalSource.isPresent()) { - System.out.println("Could not handle unknown sound source " + originalSource + " falling back to default: master"); + Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master"); finalSource = Optional.of(SoundSource.MASTER); } @@ -133,10 +134,8 @@ public class InventoryPackets { wrapper.passthrough(Type.INT); // Maximum number of trade uses } } else { - String originalChannel = channel; channel = getNewPluginChannelId(channel); if (channel == null) { - System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug wrapper.cancel(); return; } else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) { @@ -144,10 +143,11 @@ public class InventoryPackets { List rewrittenChannels = new ArrayList<>(); for (int i = 0; i < channels.length; i++) { String rewritten = getNewPluginChannelId(channels[i]); - if (rewritten != null) + if (rewritten != null) { rewrittenChannels.add(rewritten); - else - System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]); + } else { + Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]); + } } wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); } @@ -213,10 +213,8 @@ public class InventoryPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { String channel = wrapper.get(Type.STRING, 0); - String originalChannel = channel; channel = getOldPluginChannelId(channel); if (channel == null) { - System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug wrapper.cancel(); return; } else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) { @@ -224,10 +222,11 @@ public class InventoryPackets { List rewrittenChannels = new ArrayList<>(); for (int i = 0; i < channels.length; i++) { String rewritten = getOldPluginChannelId(channels[i]); - if (rewritten != null) + if (rewritten != null) { rewrittenChannels.add(rewritten); - else - System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]); + } else { + Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]); + } } wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); } @@ -319,8 +318,8 @@ public class InventoryPackets { CompoundTag enchantmentEntry = new CompoundTag(""); short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); String newId = MappingData.oldEnchantmentsIds.get(oldId); - if (newId == null){ - newId = "viaversion:legacy/"+oldId; + if (newId == null) { + newId = "viaversion:legacy/" + oldId; } enchantmentEntry.put(new StringTag("id", newId)); enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue())); @@ -339,7 +338,7 @@ public class InventoryPackets { short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue(); String newId = MappingData.oldEnchantmentsIds.get(oldId); if (newId == null) { - newId = "viaversion:legacy/"+oldId; + newId = "viaversion:legacy/" + oldId; } enchantmentEntry.put(new StringTag("id", newId @@ -389,7 +388,7 @@ public class InventoryPackets { } else if (MappingData.oldToNewItems.containsKey(rawId & ~0xF)) { rawId &= ~0xF; // Remove data } else { - System.out.println("FAILED TO GET 1.13 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T + Via.getPlatform().getLogger().warning("Failed to get 1.13 item for " + item.getId()); rawId = 16; // Stone } } @@ -398,7 +397,38 @@ public class InventoryPackets { item.setData((short) 0); } - // TODO cleanup / smarter rewrite system + public static String getNewPluginChannelId(String old) { + switch (old) { + case "MC|TrList": + return "minecraft:trader_list"; + case "MC|Brand": + return "minecraft:brand"; + case "MC|BOpen": + return "minecraft:book_open"; + case "MC|DebugPath": + return "minecraft:debug/paths"; + case "MC|DebugNeighborsUpdate": + return "minecraft:debug/neighbors_update"; + case "REGISTER": + return "minecraft:register"; + case "UNREGISTER": + return "minecraft:unregister"; + case "BungeeCord": + return "bungeecord:main"; + case "WDL|INIT": + return "wdl:init"; + case "WDL|CONTROL": + return "wdl:init"; + case "WDL|REQUEST": + return "wdl:request"; + default: + return old.matches("[0-9a-z_-]+:[0-9a-z_/.-]+") // Identifier regex + ? old + : "viaversion:legacy/" + BaseEncoding.base32().lowerCase().withPadChar('-').encode( + old.getBytes(StandardCharsets.UTF_8)); + } + } + public static void toServer(Item item) { if (item == null) return; @@ -439,7 +469,7 @@ public class InventoryPackets { } if (rawId == null) { - System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); + Via.getPlatform().getLogger().warning("Failed to get 1.12 item for " + item.getId()); rawId = 0x10000; // Stone } @@ -506,7 +536,7 @@ public class InventoryPackets { CompoundTag enchEntry = new CompoundTag(""); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); 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)); } enchEntry.put( @@ -527,9 +557,10 @@ public class InventoryPackets { ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class); for (Tag enchantmentEntry : storedEnch) { if (enchantmentEntry instanceof CompoundTag) { - CompoundTag enchEntry = new CompoundTag("");String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); + CompoundTag enchEntry = new CompoundTag(""); + String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); 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)); } enchEntry.put( @@ -548,52 +579,6 @@ public class InventoryPackets { } } - public static boolean isDamageable(int id) { - return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel - || id == 261 // bow - || id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes - || id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe - || id >= 290 && id <= 294 // hoes - || id >= 298 && id <= 317 // armors - || id == 346 // fishing rod - || id == 359 // shears - || id == 398 // carrot on a stick - || id == 442 // shield - || id == 443; // elytra - } - - public static String getNewPluginChannelId(String old) { - switch (old) { - case "MC|TrList": - return "minecraft:trader_list"; - case "MC|Brand": - return "minecraft:brand"; - case "MC|BOpen": - return "minecraft:book_open"; - case "MC|DebugPath": - return "minecraft:debug/paths"; - case "MC|DebugNeighborsUpdate": - return "minecraft:debug/neighbors_update"; - case "REGISTER": - return "minecraft:register"; - case "UNREGISTER": - return "minecraft:unregister"; - case "BungeeCord": - return "bungeecord:main"; - case "WDL|INIT": - return "wdl:init"; - case "WDL|CONTROL": - return "wdl:init"; - case "WDL|REQUEST": - return "wdl:request"; - default: - return old.matches("[0-9a-z_-]+:[0-9a-z_/.-]+") // Identifier regex - ? old - : "viaversion:legacy/" + BaseEncoding.base32().lowerCase().withPadChar('-').encode( - old.getBytes(StandardCharsets.UTF_8)); - } - } - public static String getOldPluginChannelId(String newId) { switch (newId) { case "minecraft:register": @@ -617,4 +602,18 @@ public class InventoryPackets { : newId; } } + + public static boolean isDamageable(int id) { + return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel + || id == 261 // bow + || id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes + || id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe + || id >= 290 && id <= 294 // hoes + || id >= 298 && id <= 317 // armors + || id == 346 // fishing rod + || id == 359 // shears + || id == 398 // carrot on a stick + || id == 442 // shield + || id == 443; // elytra + } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 20d59fc34..7bef8b594 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -45,9 +45,9 @@ public class WorldPackets { Optional id = provider.getIntByIdentifier(motive); - if (!id.isPresent()) - System.out.println("Could not find painting motive: " + motive + " falling back to default (0)"); - + if (!id.isPresent()) { + Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)"); + } wrapper.write(Type.VAR_INT, id.or(0)); } }); @@ -245,26 +245,23 @@ public class WorldPackets { } //Handle reddust particle color - ifStatement: if (particle.getId() == 11) { int count = wrapper.get(Type.INT, 1); float speed = wrapper.get(Type.FLOAT, 6); - if (count != 0 || speed != 1) break ifStatement; + // Only handle for count = 0 & speed = 1 + if (count == 0 && speed == 1) { + wrapper.set(Type.INT, 1, 1); + wrapper.set(Type.FLOAT, 6, 0f); - wrapper.set(Type.INT, 1, 1); - wrapper.set(Type.FLOAT, 6, 0f); - - List arguments = particle.getArguments(); - for (int i = 0; i < 3; i++) { - //RGB values are represented by the X/Y/Z offset - arguments.get(i).setValue(wrapper.get(Type.FLOAT, i + 3)); - wrapper.set(Type.FLOAT, i + 3, 0f); + List arguments = particle.getArguments(); + for (int i = 0; i < 3; i++) { + //RGB values are represented by the X/Y/Z offset + arguments.get(i).setValue(wrapper.get(Type.FLOAT, i + 3)); + wrapper.set(Type.FLOAT, i + 3, 0f); + } } } -// System.out.println("Old particle " + particleId + " " + Arrays.toString(data) + " new Particle" + particle); - - wrapper.set(Type.INT, 0, particle.getId()); for (Particle.ParticleData particleData : particle.getArguments()) wrapper.write(particleData.getType(), particleData.getValue()); @@ -285,10 +282,10 @@ public class WorldPackets { } newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data if (newId != null) { - System.out.println("Missing block " + oldId); + Via.getPlatform().getLogger().warning("Missing block " + oldId); return newId; } - System.out.println("Missing block completely " + oldId); + Via.getPlatform().getLogger().warning("Missing block completely " + oldId); // Default stone return 1; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java index a65261642..bdcde9e68 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java @@ -41,8 +41,9 @@ public class BlockEntityProvider implements Provider { String id = (String) tag.get("id").getValue(); if (!handlers.containsKey(id)) { - if (Via.getManager().isDebug()) - System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag); + if (Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag); + } return -1; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java index 53f8e3e97..c321f409f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java @@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; @@ -22,7 +23,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); if (!storage.contains(position)) { - System.out.println("Received an banner color update packet, but there is no banner! O_o " + tag); + Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag); return -1; } @@ -30,13 +31,14 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { int color = (int) tag.get("Base").getValue(); // Standing banner - if (blockId >= BANNER_START && blockId <= BANNER_STOP) + if (blockId >= BANNER_START && blockId <= BANNER_STOP) { blockId += ((15 - color) * 16); // Wall banner - else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) + } else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) { blockId += ((15 - color) * 4); - else - System.out.println("Why does this block have the banner block entity? :(" + tag); + } else { + Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); + } if (tag.get("Patterns") instanceof ListTag) { for (Tag pattern : (ListTag) tag.get("Patterns")) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java index 312cf2520..f676a4c9a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; @@ -15,7 +16,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler { Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); if (!storage.contains(position)) { - System.out.println("Received an bed color update packet, but there is no bed! O_o " + tag); + Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag); return -1; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java index 7d16f57b6..1bd406184 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import us.myles.ViaVersion.api.Pair; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; @@ -13,28 +14,28 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler private static final Map, Integer> flowersNumberId = new ConcurrentHashMap<>(); static { - register("minecraft:air", (byte) 0, (byte) 0, 5265); - register("minecraft:sapling", (byte) 6, (byte) 0, 5266); - register("minecraft:sapling", (byte) 6, (byte) 1, 5267); - register("minecraft:sapling", (byte) 6, (byte) 2, 5268); - register("minecraft:sapling", (byte) 6, (byte) 3, 5269); - register("minecraft:sapling", (byte) 6, (byte) 4, 5270); - register("minecraft:sapling", (byte) 6, (byte) 5, 5271); - register("minecraft:tallgrass", (byte) 31, (byte) 2, 5272); - register("minecraft:yellow_flower", (byte) 37, (byte) 0, 5273); - register("minecraft:red_flower", (byte) 38, (byte) 0, 5274); - register("minecraft:red_flower", (byte) 38, (byte) 1, 5275); - register("minecraft:red_flower", (byte) 38, (byte) 2, 5276); - register("minecraft:red_flower", (byte) 38, (byte) 3, 5277); - register("minecraft:red_flower", (byte) 38, (byte) 4, 5278); - register("minecraft:red_flower", (byte) 38, (byte) 5, 5279); - register("minecraft:red_flower", (byte) 38, (byte) 6, 5280); - register("minecraft:red_flower", (byte) 38, (byte) 7, 5281); - register("minecraft:red_flower", (byte) 38, (byte) 8, 5282); - register("minecraft:red_mushroom", (byte) 40, (byte) 0, 5283); + register("minecraft:air", (byte) 0, (byte) 0, 5265); + register("minecraft:sapling", (byte) 6, (byte) 0, 5266); + register("minecraft:sapling", (byte) 6, (byte) 1, 5267); + register("minecraft:sapling", (byte) 6, (byte) 2, 5268); + register("minecraft:sapling", (byte) 6, (byte) 3, 5269); + register("minecraft:sapling", (byte) 6, (byte) 4, 5270); + register("minecraft:sapling", (byte) 6, (byte) 5, 5271); + register("minecraft:tallgrass", (byte) 31, (byte) 2, 5272); + register("minecraft:yellow_flower", (byte) 37, (byte) 0, 5273); + register("minecraft:red_flower", (byte) 38, (byte) 0, 5274); + register("minecraft:red_flower", (byte) 38, (byte) 1, 5275); + register("minecraft:red_flower", (byte) 38, (byte) 2, 5276); + register("minecraft:red_flower", (byte) 38, (byte) 3, 5277); + register("minecraft:red_flower", (byte) 38, (byte) 4, 5278); + register("minecraft:red_flower", (byte) 38, (byte) 5, 5279); + register("minecraft:red_flower", (byte) 38, (byte) 6, 5280); + register("minecraft:red_flower", (byte) 38, (byte) 7, 5281); + register("minecraft:red_flower", (byte) 38, (byte) 8, 5282); + register("minecraft:red_mushroom", (byte) 40, (byte) 0, 5283); register("minecraft:brown_mushroom", (byte) 39, (byte) 0, 5284); - register("minecraft:deadbush", (byte) 32, (byte) 0, 5285); - register("minecraft:cactus", (byte) 81, (byte) 0, 5286); + register("minecraft:deadbush", (byte) 32, (byte) 0, 5285); + register("minecraft:cactus", (byte) 81, (byte) 0, 5286); } @@ -60,7 +61,7 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler } else if (flowersNumberId.containsKey(pair)) { return flowersNumberId.get(pair); } else { - System.out.println("Could not find flowerpot content " + item + " for " + tag); + Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag); } return -1; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java index 85458e23c..90b0b745b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; @@ -10,13 +11,14 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage; public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { private final int SKULL_WALL_START = 5447; private final int SKULL_END = 5566; + @Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); if (!storage.contains(position)) { - System.out.println("Received an head update packet, but there is no head! O_o " + tag); + Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag); return -1; } @@ -28,12 +30,13 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { id += (byte) tag.get("Rot").getValue(); } } else { - System.out.println("Why does this block have the skull block entity? :(" + tag); + Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag); return -1; } return id; } + private long getLong(Tag tag) { return ((Integer) tag.getValue()).longValue(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java index f5941f5be..ba1247c84 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java @@ -10,9 +10,9 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType; -import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.Chunk1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.ChunkSection1_13; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.ArrayList; import java.util.Arrays; @@ -56,7 +56,7 @@ public class Chunk1_13Type extends PartialType { byte[] biomeData = groundUp ? new byte[256] : null; if (groundUp) { - for (int i = 0; i < 256; i++){ + for (int i = 0; i < 256; i++) { // todo use int in Chunk? biomeData[i] = 0; } @@ -67,8 +67,9 @@ public class Chunk1_13Type extends PartialType { // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); - if (Via.getManager().isDebug()) - System.out.println("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); + if (Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); + } } return new Chunk1_13(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java index dc3239f30..194356017 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java @@ -65,8 +65,9 @@ public class Chunk1_9_3_4Type extends PartialType { // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); - if (Via.getManager().isDebug()) - System.out.println("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); + if (Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); + } } return new Chunk1_9_3_4(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);