3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Merge pull request #336 from OnlyBMan/inventory

Implements Skulls and Heads
Dieser Commit ist enthalten in:
Redned 2020-04-15 14:46:09 -05:00 committet von GitHub
Commit 5ffd5d50f1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 105 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -67,6 +67,8 @@ public class BlockTranslator {
private static final Map<BlockState, String> JAVA_ID_TO_BLOCK_ENTITY_MAP = new HashMap<>(); private static final Map<BlockState, String> JAVA_ID_TO_BLOCK_ENTITY_MAP = new HashMap<>();
private static final Object2ByteMap<BlockState> BED_COLORS = new Object2ByteOpenHashMap<>(); 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<>();
public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap(); public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap();
public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap(); public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap();
@ -147,6 +149,17 @@ public class BlockTranslator {
JAVA_ID_TO_BLOCK_ENTITY_MAP.put(javaBlockState, javaId); JAVA_ID_TO_BLOCK_ENTITY_MAP.put(javaBlockState, javaId);
} }
JsonNode skullVariation = entry.getValue().get("variation");
if(skullVariation != null) {
SKULL_VARIANTS.put(javaBlockState, (byte) skullVariation.intValue());
}
JsonNode skullRotation = entry.getValue().get("skull_rotation");
if (skullRotation != null) {
SKULL_ROTATIONS.put(javaBlockState, (byte) skullRotation.intValue());
}
// If the Java ID is bed, signal that it needs a tag to show color // If the Java ID is bed, signal that it needs a tag to show color
// The color is in the namespace ID in Java Edition but it's a tag in Bedrock. // The color is in the namespace ID in Java Edition but it's a tag in Bedrock.
JsonNode bedColor = entry.getValue().get("bed_color"); JsonNode bedColor = entry.getValue().get("bed_color");
@ -268,6 +281,20 @@ public class BlockTranslator {
return -1; return -1;
} }
public static byte getSkullVariant(BlockState state) {
if (SKULL_VARIANTS.containsKey(state)) {
return SKULL_VARIANTS.getByte(state);
}
return 0;
}
public static byte getSkullRotation(BlockState state) {
if (SKULL_ROTATIONS.containsKey(state)) {
return SKULL_ROTATIONS.getByte(state);
}
return 0;
}
public static BlockState getJavaWaterloggedState(int bedrockId) { public static BlockState getJavaWaterloggedState(int bedrockId) {
return BEDROCK_TO_JAVA_BLOCK_MAP.get(1 << 31 | bedrockId); return BEDROCK_TO_JAVA_BLOCK_MAP.get(1 << 31 | bedrockId);
} }

Datei anzeigen

@ -0,0 +1,67 @@
/*
* 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.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.tag.CompoundTag;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.utils.BlockEntityUtils;
import java.util.concurrent.TimeUnit;
public class SkullBlockEntityTranslator {
public static void checkForSkullVariant(GeyserSession session, BlockState blockState, Vector3i position) {
byte skullVariant = BlockTranslator.getSkullVariant(blockState);
byte rotation = BlockTranslator.getSkullRotation(blockState);
if (skullVariant > -1) {
Position pos = new Position(position.getX(), position.getY(), position.getZ());
CompoundTag finalSkullTag = getSkullTag(skullVariant, pos, rotation);
// Delay needed, otherwise newly placed skulls will not appear
// Delay is not needed for skulls already placed on login
session.getConnector().getGeneralThreadPool().schedule(() ->
BlockEntityUtils.updateBlockEntity(session, finalSkullTag, pos),
500,
TimeUnit.MILLISECONDS
);
}
}
public static CompoundTag getSkullTag(byte skullvariant, Position pos, byte rotation) {
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
.intTag("x", pos.getX())
.intTag("y", pos.getY())
.intTag("z", pos.getZ())
.stringTag("id", "Skull")
.floatTag("Rotation", rotation * 22.5f);
tagBuilder.byteTag("SkullType", skullvariant);
return tagBuilder.buildRootTag();
}
}

Datei anzeigen

@ -120,9 +120,13 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
for (Map.Entry<Position, BlockState> blockEntityEntry: chunkData.beds.entrySet()) { for (Map.Entry<Position, BlockState> blockEntityEntry: chunkData.beds.entrySet()) {
ChunkUtils.updateBlock(session, blockEntityEntry.getValue(), blockEntityEntry.getKey()); ChunkUtils.updateBlock(session, blockEntityEntry.getValue(), blockEntityEntry.getKey());
} }
for (Map.Entry<Position, BlockState> blockEntityEntry: chunkData.skulls.entrySet()) {
ChunkUtils.updateBlock(session, blockEntityEntry.getValue(), blockEntityEntry.getKey());
}
chunkData.signs.clear(); chunkData.signs.clear();
chunkData.gateways.clear(); chunkData.gateways.clear();
chunkData.beds.clear(); chunkData.beds.clear();
chunkData.skulls.clear();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }

Datei anzeigen

@ -42,6 +42,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.block.entity.BlockEntityTranslator; import org.geysermc.connector.network.translators.block.entity.BlockEntityTranslator;
import org.geysermc.connector.network.translators.block.entity.SkullBlockEntityTranslator;
import org.geysermc.connector.world.chunk.ChunkPosition; import org.geysermc.connector.world.chunk.ChunkPosition;
import org.geysermc.connector.network.translators.Translators; import org.geysermc.connector.network.translators.Translators;
import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.network.translators.block.BlockTranslator;
@ -86,6 +87,10 @@ public class ChunkUtils {
// Beds need to be updated separately to add the bed color tag // Beds need to be updated separately to add the bed color tag
// Previously this was done by matching block state but this resulted in only one bed per color+orientation showing // Previously this was done by matching block state but this resulted in only one bed per color+orientation showing
chunkData.beds.put(pos, blockState); chunkData.beds.put(pos, blockState);
} else if (BlockTranslator.getSkullVariant(blockState) > 0) {
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
//Doing the same stuff as beds
chunkData.skulls.put(pos, blockState);
} else { } else {
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), id); section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), id);
} }
@ -160,6 +165,7 @@ public class ChunkUtils {
// Since Java stores bed colors as part of the namespaced ID and Bedrock stores it as a tag // Since Java stores bed colors as part of the namespaced ID and Bedrock stores it as a tag
// This is the only place I could find that interacts with the Java block state and block updates // This is the only place I could find that interacts with the Java block state and block updates
BedBlockEntityTranslator.checkForBedColor(session, blockState, position); BedBlockEntityTranslator.checkForBedColor(session, blockState, position);
SkullBlockEntityTranslator.checkForSkullVariant(session, blockState, position);
} }
public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) { public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) {
@ -194,5 +200,6 @@ public class ChunkUtils {
public Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> signs = new Object2IntOpenHashMap<>(); public Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> signs = new Object2IntOpenHashMap<>();
public Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> gateways = new Object2IntOpenHashMap<>(); public Object2IntMap<com.nukkitx.nbt.tag.CompoundTag> gateways = new Object2IntOpenHashMap<>();
public Map<Position, BlockState> beds = new HashMap<>(); public Map<Position, BlockState> beds = new HashMap<>();
public Map<Position, BlockState> skulls = new HashMap<>();
} }
} }