From 520eb15ce9f3f8128454657f7f27fad2510ed9b3 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 20 Jan 2019 17:19:26 +0100 Subject: [PATCH] Handle skull block entities --- .../block_entity_handlers/SkullHandler.java | 39 ++++++ .../packets/BlockItemPackets1_13.java | 1 + .../BackwardsBlockEntityProvider.java | 5 +- .../storage/BackwardsBlockStorage.java | 6 +- .../data/mapping-1.12.2to1.13.json | 122 +++++++++++++++++- 5 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java new file mode 100644 index 00000000..fd7b04f0 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java @@ -0,0 +1,39 @@ +/* + * 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.protocol.protocol1_12_2to1_13.block_entity_handlers; + +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.viaversion.libs.opennbt.tag.builtin.ByteTag; +import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; + +public class SkullHandler implements BackwardsBlockEntityHandler { + private final int SKULL_START = 5447; + + @Override + public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + int pos = (blockId - SKULL_START) % 20; + byte type = (byte) Math.floor((blockId - SKULL_START) / 20); + + // Set type + tag.put(new ByteTag("SkullType", type)); + + // Remove wall skulls + if (pos < 4) { + return tag; + } + + // Add rotation for normal skulls + tag.put(new ByteTag("Rot", (byte) ((pos - 4) & 255))); + + return tag; + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 7e38ec27..0361c576 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -73,6 +73,7 @@ public class BlockItemPackets1_13 extends Rewriter { BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); switch (wrapper.get(Type.UNSIGNED_BYTE, 0)) { + case 4: case 6: case 11: wrapper.set(Type.NBT, 0, diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java index ea99ae58..14036af2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java @@ -13,6 +13,7 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BannerHandler; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BedHandler; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SkullHandler; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -27,10 +28,10 @@ public class BackwardsBlockEntityProvider implements Provider { private final Map handlers = new ConcurrentHashMap<>(); public BackwardsBlockEntityProvider() { - handlers.put("minecraft:flower_pot", new FlowerPotHandler()); + handlers.put("minecraft:flower_pot", new FlowerPotHandler()); // TODO requires special treatment, manually send handlers.put("minecraft:bed", new BedHandler()); handlers.put("minecraft:banner", new BannerHandler()); -// handlers.put("minecraft:skull", ); + handlers.put("minecraft:skull", new SkullHandler()); // handlers.put("minecraft:mob_spawner", ); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java index d6834629..9fad83dd 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java @@ -41,9 +41,9 @@ public class BackwardsBlockStorage extends StoredObject { // whitelist.add(7110 + i); // } - // Skeleton skulls -// for (int i = 0; i < 5; i++) -// whitelist.add(5447 + i); + // Skulls + for (int i = 5447; i <= 5566; i++) + whitelist.add(i); } diff --git a/core/src/main/resources/assets/viabackwards/data/mapping-1.12.2to1.13.json b/core/src/main/resources/assets/viabackwards/data/mapping-1.12.2to1.13.json index 7ae182f9..e851eb36 100644 --- a/core/src/main/resources/assets/viabackwards/data/mapping-1.12.2to1.13.json +++ b/core/src/main/resources/assets/viabackwards/data/mapping-1.12.2to1.13.json @@ -5127,6 +5127,126 @@ "minecraft:black_wall_banner[facing=north]": "minecraft:white_wall_banner[facing=north]", "minecraft:black_wall_banner[facing=south]": "minecraft:white_wall_banner[facing=south]", "minecraft:black_wall_banner[facing=west]": "minecraft:white_wall_banner[facing=west]", - "minecraft:black_wall_banner[facing=east]": "minecraft:white_wall_banner[facing=east]" + "minecraft:black_wall_banner[facing=east]": "minecraft:white_wall_banner[facing=east]", + "minecraft:skeleton_wall_skull[facing=north]": "id:2306", + "minecraft:skeleton_wall_skull[facing=south]": "id:2307", + "minecraft:skeleton_wall_skull[facing=west]": "id:2308", + "minecraft:skeleton_wall_skull[facing=east]": "id:2309", + "minecraft:skeleton_skull[rotation=0]": "id:2305", + "minecraft:skeleton_skull[rotation=1]": "id:2305", + "minecraft:skeleton_skull[rotation=2]": "id:2305", + "minecraft:skeleton_skull[rotation=3]": "id:2305", + "minecraft:skeleton_skull[rotation=4]": "id:2305", + "minecraft:skeleton_skull[rotation=5]": "id:2305", + "minecraft:skeleton_skull[rotation=6]": "id:2305", + "minecraft:skeleton_skull[rotation=7]": "id:2305", + "minecraft:skeleton_skull[rotation=8]": "id:2305", + "minecraft:skeleton_skull[rotation=9]": "id:2305", + "minecraft:skeleton_skull[rotation=10]": "id:2305", + "minecraft:skeleton_skull[rotation=11]": "id:2305", + "minecraft:skeleton_skull[rotation=12]": "id:2305", + "minecraft:skeleton_skull[rotation=13]": "id:2305", + "minecraft:skeleton_skull[rotation=14]": "id:2305", + "minecraft:skeleton_skull[rotation=15]": "id:2305", + "minecraft:wither_skeleton_wall_skull[facing=north]": "id:2306", + "minecraft:wither_skeleton_wall_skull[facing=south]": "id:2307", + "minecraft:wither_skeleton_wall_skull[facing=west]": "id:2308", + "minecraft:wither_skeleton_wall_skull[facing=east]": "id:2309", + "minecraft:wither_skeleton_skull[rotation=0]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=1]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=2]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=3]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=4]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=5]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=6]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=7]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=8]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=9]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=10]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=11]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=12]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=13]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=14]": "id:2305", + "minecraft:wither_skeleton_skull[rotation=15]": "id:2305", + "minecraft:zombie_wall_head[facing=north]": "id:2306", + "minecraft:zombie_wall_head[facing=south]": "id:2307", + "minecraft:zombie_wall_head[facing=west]": "id:2308", + "minecraft:zombie_wall_head[facing=east]": "id:2309", + "minecraft:zombie_head[rotation=0]": "id:2305", + "minecraft:zombie_head[rotation=1]": "id:2305", + "minecraft:zombie_head[rotation=2]": "id:2305", + "minecraft:zombie_head[rotation=3]": "id:2305", + "minecraft:zombie_head[rotation=4]": "id:2305", + "minecraft:zombie_head[rotation=5]": "id:2305", + "minecraft:zombie_head[rotation=6]": "id:2305", + "minecraft:zombie_head[rotation=7]": "id:2305", + "minecraft:zombie_head[rotation=8]": "id:2305", + "minecraft:zombie_head[rotation=9]": "id:2305", + "minecraft:zombie_head[rotation=10]": "id:2305", + "minecraft:zombie_head[rotation=11]": "id:2305", + "minecraft:zombie_head[rotation=12]": "id:2305", + "minecraft:zombie_head[rotation=13]": "id:2305", + "minecraft:zombie_head[rotation=14]": "id:2305", + "minecraft:zombie_head[rotation=15]": "id:2305", + "minecraft:player_wall_head[facing=north]": "id:2306", + "minecraft:player_wall_head[facing=south]": "id:2307", + "minecraft:player_wall_head[facing=west]": "id:2308", + "minecraft:player_wall_head[facing=east]": "id:2309", + "minecraft:player_head[rotation=0]": "id:2305", + "minecraft:player_head[rotation=1]": "id:2305", + "minecraft:player_head[rotation=2]": "id:2305", + "minecraft:player_head[rotation=3]": "id:2305", + "minecraft:player_head[rotation=4]": "id:2305", + "minecraft:player_head[rotation=5]": "id:2305", + "minecraft:player_head[rotation=6]": "id:2305", + "minecraft:player_head[rotation=7]": "id:2305", + "minecraft:player_head[rotation=8]": "id:2305", + "minecraft:player_head[rotation=9]": "id:2305", + "minecraft:player_head[rotation=10]": "id:2305", + "minecraft:player_head[rotation=11]": "id:2305", + "minecraft:player_head[rotation=12]": "id:2305", + "minecraft:player_head[rotation=13]": "id:2305", + "minecraft:player_head[rotation=14]": "id:2305", + "minecraft:player_head[rotation=15]": "id:2305", + "minecraft:creeper_wall_head[facing=north]": "id:2306", + "minecraft:creeper_wall_head[facing=south]": "id:2307", + "minecraft:creeper_wall_head[facing=west]": "id:2308", + "minecraft:creeper_wall_head[facing=east]": "id:2309", + "minecraft:creeper_head[rotation=0]": "id:2305", + "minecraft:creeper_head[rotation=1]": "id:2305", + "minecraft:creeper_head[rotation=2]": "id:2305", + "minecraft:creeper_head[rotation=3]": "id:2305", + "minecraft:creeper_head[rotation=4]": "id:2305", + "minecraft:creeper_head[rotation=5]": "id:2305", + "minecraft:creeper_head[rotation=6]": "id:2305", + "minecraft:creeper_head[rotation=7]": "id:2305", + "minecraft:creeper_head[rotation=8]": "id:2305", + "minecraft:creeper_head[rotation=9]": "id:2305", + "minecraft:creeper_head[rotation=10]": "id:2305", + "minecraft:creeper_head[rotation=11]": "id:2305", + "minecraft:creeper_head[rotation=12]": "id:2305", + "minecraft:creeper_head[rotation=13]": "id:2305", + "minecraft:creeper_head[rotation=14]": "id:2305", + "minecraft:creeper_head[rotation=15]": "id:2305", + "minecraft:dragon_wall_head[facing=north]": "id:2306", + "minecraft:dragon_wall_head[facing=south]": "id:2307", + "minecraft:dragon_wall_head[facing=west]": "id:2308", + "minecraft:dragon_wall_head[facing=east]": "id:2309", + "minecraft:dragon_head[rotation=0]": "id:2305", + "minecraft:dragon_head[rotation=1]": "id:2305", + "minecraft:dragon_head[rotation=2]": "id:2305", + "minecraft:dragon_head[rotation=3]": "id:2305", + "minecraft:dragon_head[rotation=4]": "id:2305", + "minecraft:dragon_head[rotation=5]": "id:2305", + "minecraft:dragon_head[rotation=6]": "id:2305", + "minecraft:dragon_head[rotation=7]": "id:2305", + "minecraft:dragon_head[rotation=8]": "id:2305", + "minecraft:dragon_head[rotation=9]": "id:2305", + "minecraft:dragon_head[rotation=10]": "id:2305", + "minecraft:dragon_head[rotation=11]": "id:2305", + "minecraft:dragon_head[rotation=12]": "id:2305", + "minecraft:dragon_head[rotation=13]": "id:2305", + "minecraft:dragon_head[rotation=14]": "id:2305", + "minecraft:dragon_head[rotation=15]": "id:2305" } } \ No newline at end of file