3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Move bed-specific code to BedBlockEntityTranslator.java

Dieser Commit ist enthalten in:
BuildTools 2020-03-26 10:22:44 -04:00
Ursprung 5301c8c3f6
Commit 545ab0f268
2 geänderte Dateien mit 44 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,41 @@
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 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 BedBlockEntityTranslator {
public static void checkForBedColor(GeyserSession session, BlockState blockState, Vector3i position) {
byte bedcolor = BlockTranslator.getBedColor(blockState);
// If Bed Color is not -1 then it is indeed a bed with a color.
if (bedcolor > -1) {
Position pos = new Position(position.getX(), position.getY(), position.getZ());
com.nukkitx.nbt.tag.CompoundTag finalbedTag = getBedTag(bedcolor, pos);
// Delay needed, otherwise newly placed beds will not get their color
// Delay is not needed for beds already placed on login
session.getConnector().getGeneralThreadPool().schedule(() ->
BlockEntityUtils.updateBlockEntity(session, finalbedTag, pos),
500,
TimeUnit.MILLISECONDS
);
}
}
public static com.nukkitx.nbt.tag.CompoundTag getBedTag(byte bedcolor, Position pos) {
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
.intTag("x", pos.getX())
.intTag("y", pos.getY())
.intTag("z", pos.getZ())
.stringTag("id", "Bed");
tagBuilder.byteTag("color", bedcolor);
return tagBuilder.buildRootTag();
}
}

Datei anzeigen

@ -31,7 +31,6 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
@ -45,8 +44,7 @@ import org.geysermc.connector.network.translators.block.entity.BlockEntityTransl
import org.geysermc.connector.world.chunk.ChunkPosition;
import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.world.chunk.ChunkSection;
import java.util.concurrent.TimeUnit;
import org.geysermc.connector.network.translators.block.entity.BedBlockEntityTranslator;
import static org.geysermc.connector.network.translators.block.BlockTranslator.BEDROCK_WATER_ID;
@ -77,7 +75,7 @@ public class ChunkUtils {
chunkData.signs.put(blockState.getId(), TranslatorsInit.getBlockEntityTranslators().get("Sign").getDefaultBedrockTag("Sign", pos.getX(), pos.getY(), pos.getZ()));
} else if (BlockTranslator.getBedColor(blockState) > -1) {
Position pos = new ChunkPosition(column.getX(), column.getZ()).getBlock(x, (chunkY << 4) + y, z);
chunkData.beds.put(blockState.getId(), getBedTag(BlockTranslator.getBedColor(blockState), pos));
chunkData.beds.put(blockState.getId(), BedBlockEntityTranslator.getBedTag(BlockTranslator.getBedColor(blockState), pos));
} else {
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), id);
}
@ -138,19 +136,7 @@ public class ChunkUtils {
// 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
byte bedcolor = BlockTranslator.getBedColor(blockState);
// If Bed Color is not -1 then it is indeed a bed with a color.
if (bedcolor > -1) {
Position pos = new Position(position.getX(), position.getY(), position.getZ());
com.nukkitx.nbt.tag.CompoundTag finalbedTag = getBedTag(bedcolor, pos);
// Delay needed, otherwise newly placed beds will not get their color
// Delay is not needed for beds already placed on login
session.getConnector().getGeneralThreadPool().schedule(() ->
BlockEntityUtils.updateBlockEntity(session, finalbedTag, pos),
500,
TimeUnit.MILLISECONDS
);
}
BedBlockEntityTranslator.checkForBedColor(session, blockState, position);
}
@ -186,13 +172,4 @@ public class ChunkUtils {
public Int2ObjectMap<com.nukkitx.nbt.tag.CompoundTag> signs = new Int2ObjectOpenHashMap<>();
public Int2ObjectMap<com.nukkitx.nbt.tag.CompoundTag> beds = new Int2ObjectOpenHashMap<>();
}
public static com.nukkitx.nbt.tag.CompoundTag getBedTag(byte bedcolor, Position pos) {
CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
.intTag("x", pos.getX())
.intTag("y", pos.getY())
.intTag("z", pos.getZ())
.stringTag("id", "Bed");
tagBuilder.byteTag("color", bedcolor);
return tagBuilder.buildRootTag();
}
}