Fix shulkers being upside down on load (#446)

* Added shulker box direction handeling

* Update mappings

* Added missing Object2ByteMap

* Cleaned javadoc

* Moved shulker box direction conversion to the mappings generator
This commit is contained in:
rtm516 2020-04-29 17:01:56 +01:00 committed by GitHub
parent 87be8c378e
commit 7a9fff1a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 5 deletions

View File

@ -43,6 +43,7 @@ public class BlockStateValues {
private static final Object2ByteMap<BlockState> BED_COLORS = new Object2ByteOpenHashMap<>();
private static final Object2ByteMap<BlockState> SKULL_VARIANTS = new Object2ByteOpenHashMap<>();
private static final Object2ByteMap<BlockState> SKULL_ROTATIONS = new Object2ByteOpenHashMap<>();
private static final Object2ByteMap<BlockState> SHULKERBOX_DIRECTIONS = new Object2ByteOpenHashMap<>();
/**
* Determines if the block state contains Bedrock block information
@ -71,13 +72,19 @@ public class BlockStateValues {
if (skullRotation != null) {
BlockStateValues.SKULL_ROTATIONS.put(javaBlockState, (byte) skullRotation.intValue());
}
JsonNode shulkerDirection = entry.getValue().get("shulker_direction");
if (shulkerDirection != null) {
BlockStateValues.SHULKERBOX_DIRECTIONS.put(javaBlockState, (byte) shulkerDirection.intValue());
}
}
/**
* Banner colors are part of the namespaced ID in Java Edition, but part of the block entity tag in Bedrock.
* This gives an integer color that Bedrock can use.
*
* @param state BlockState of the block
* @return banner color integer or -1 if no color
* @return Banner color integer or -1 if no color
*/
public static int getBannerColor(BlockState state) {
if (BANNER_COLORS.containsKey(state)) {
@ -89,8 +96,9 @@ public class BlockStateValues {
/**
* Bed colors are part of the namespaced ID in Java Edition, but part of the block entity tag in Bedrock.
* This gives a byte color that Bedrock can use - Bedrock needs a byte in the final tag.
*
* @param state BlockState of the block
* @return bed color byte or -1 if no color
* @return Bed color byte or -1 if no color
*/
public static byte getBedColor(BlockState state) {
if (BED_COLORS.containsKey(state)) {
@ -102,8 +110,9 @@ public class BlockStateValues {
/**
* Skull variations are part of the namespaced ID in Java Edition, but part of the block entity tag in Bedrock.
* This gives a byte variant ID that Bedrock can use.
*
* @param state BlockState of the block
* @return skull variant byte or -1 if no variant
* @return Skull variant byte or -1 if no variant
*/
public static byte getSkullVariant(BlockState state) {
if (SKULL_VARIANTS.containsKey(state)) {
@ -113,9 +122,11 @@ public class BlockStateValues {
}
/**
* Skull rotations are part of the namespaced ID in Java Edition, but part of the block entity tag in Bedrock.
* This gives a byte rotation that Bedrock can use.
*
* @param state BlockState of the block
* @return skull rotation value or -1 if no value
* @return Skull rotation value or -1 if no value
*/
public static byte getSkullRotation(BlockState state) {
if (SKULL_ROTATIONS.containsKey(state)) {
@ -124,4 +135,18 @@ public class BlockStateValues {
return -1;
}
/**
* Shulker box directions are part of the namespaced ID in Java Edition, but part of the block entity tag in Bedrock.
* This gives a byte direction that Bedrock can use.
*
* @param state BlockState of the block
* @return Shulker direction value or -1 if no value
*/
public static byte getShulkerBoxDirection(BlockState state) {
if (SHULKERBOX_DIRECTIONS.containsKey(state)) {
return SHULKERBOX_DIRECTIONS.getByte(state);
}
return -1;
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* 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.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.block.entity;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.tag.ByteTag;
import com.nukkitx.nbt.tag.Tag;
import org.geysermc.connector.network.translators.block.BlockStateValues;
import java.util.ArrayList;
import java.util.List;
@BlockEntity(name = "ShulkerBox", delay = false, regex = "shulker_box")
public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
@Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
List<Tag<?>> tags = new ArrayList<>();
byte direction = BlockStateValues.getShulkerBoxDirection(blockState);
// Just in case...
if (direction == -1) direction = 1;
tags.add(new ByteTag("facing", direction));
return tags;
}
@Override
public CompoundTag getDefaultJavaTag(String javaId, int x, int y, int z) {
return null;
}
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
tagBuilder.byteTag("facing", (byte)1);
return tagBuilder.buildRootTag();
}
}

@ -1 +1 @@
Subproject commit 0af94e03efaa7e21651d7cabcef05b1927795cf5
Subproject commit 4e80d3b8e489b12a93b1b98b7bbaf8fa91a7974a