Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 22:40:18 +01:00
Extended collision boxes almost work
Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
Dieser Commit ist enthalten in:
Ursprung
0bd14899a1
Commit
5f5159d30e
@ -294,11 +294,11 @@ public class MappingsReader_v1 extends MappingsReader {
|
|||||||
// This is needed to find the correct selection box for the given block
|
// This is needed to find the correct selection box for the given block
|
||||||
int id = BlockRegistries.JAVA_IDENTIFIERS.getOrDefault(stateKey, -1);
|
int id = BlockRegistries.JAVA_IDENTIFIERS.getOrDefault(stateKey, -1);
|
||||||
BoxComponent boxComponent = createBoxComponent(id, 0, 16, 0);
|
BoxComponent boxComponent = createBoxComponent(id, 0, 16, 0);
|
||||||
BoxComponent extendedboxComponent = createBoxComponent(id, 16, 32, -16);
|
BoxComponent extendedBoxComponent = createBoxComponent(id, 16, 32, -16);
|
||||||
CustomBlockComponents.Builder builder = new CustomBlockComponentsBuilder()
|
CustomBlockComponents.Builder builder = new CustomBlockComponentsBuilder()
|
||||||
.collisionBox(boxComponent)
|
.collisionBox(boxComponent)
|
||||||
.selectionBox(boxComponent)
|
.selectionBox(boxComponent)
|
||||||
.extendedCollisionBox(extendedboxComponent);
|
.extendedCollisionBox(extendedBoxComponent);
|
||||||
|
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
// No other components were defined
|
// No other components were defined
|
||||||
|
@ -69,6 +69,7 @@ import org.geysermc.geyser.util.BlockEntityUtils;
|
|||||||
import org.geysermc.geyser.util.ChunkUtils;
|
import org.geysermc.geyser.util.ChunkUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -109,6 +110,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData());
|
ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData());
|
||||||
|
int runningSectionExtendedCollisions[] = new int[BlockStorage.SIZE];
|
||||||
for (int sectionY = 0; sectionY < chunkSize; sectionY++) {
|
for (int sectionY = 0; sectionY < chunkSize; sectionY++) {
|
||||||
ChunkSection javaSection = session.getCodecHelper().readChunkSection(in, biomeGlobalPalette);
|
ChunkSection javaSection = session.getCodecHelper().readChunkSection(in, biomeGlobalPalette);
|
||||||
javaChunks[sectionY] = javaSection.getChunkData();
|
javaChunks[sectionY] = javaSection.getChunkData();
|
||||||
@ -141,14 +143,18 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
|
|||||||
section.getBlockStorageArray()[1].setFullBlock(xzy, session.getBlockMappings().getBedrockWaterId());
|
section.getBlockStorageArray()[1].setFullBlock(xzy, session.getBlockMappings().getBedrockWaterId());
|
||||||
}
|
}
|
||||||
|
|
||||||
int bedrockExtendedCollisionId = BlockRegistries.EXTENDED_COLLISION_BOXES.getOrDefault(javaId, -1);
|
// Extended collision blocks
|
||||||
if (bedrockExtendedCollisionId != -1) {
|
switch (yzx) {
|
||||||
int y = xzy & 0xF;
|
case 0 -> Arrays.fill(runningSectionExtendedCollisions, 256, 4095, 0);
|
||||||
if (y < 15) {
|
case 256 -> Arrays.fill(runningSectionExtendedCollisions, 0, 256, 0);
|
||||||
// We will set within this chunk section
|
}
|
||||||
} else {
|
if (javaId == BlockStateValues.JAVA_AIR_ID && runningSectionExtendedCollisions[yzx] != 0) {
|
||||||
// We will set within the next chunk section
|
section.getBlockStorageArray()[0].setFullBlock(xzy, runningSectionExtendedCollisions[yzx]);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
int aboveBedrockExtendedCollisionId = BlockRegistries.EXTENDED_COLLISION_BOXES.getOrDefault(javaId, -1);
|
||||||
|
if (aboveBedrockExtendedCollisionId != -1) {
|
||||||
|
runningSectionExtendedCollisions[((yzx & 0x0ff) | (((yzx >> 8) + ((xzy & 0xF) < 15 ? 1 : -15)) << 8))] = aboveBedrockExtendedCollisionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if block is piston or flower to see if we'll need to create additional block entities, as they're only block entities in Bedrock
|
// Check if block is piston or flower to see if we'll need to create additional block entities, as they're only block entities in Bedrock
|
||||||
@ -222,7 +228,23 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
|
|||||||
// No blocks are waterlogged, simply convert coordinate order
|
// No blocks are waterlogged, simply convert coordinate order
|
||||||
// This could probably be optimized further...
|
// This could probably be optimized further...
|
||||||
for (int yzx = 0; yzx < BlockStorage.SIZE; yzx++) {
|
for (int yzx = 0; yzx < BlockStorage.SIZE; yzx++) {
|
||||||
bedrockData.set(indexYZXtoXZY(yzx), javaData.get(yzx));
|
int paletteId = javaData.get(yzx);
|
||||||
|
int xzy = indexYZXtoXZY(yzx);
|
||||||
|
bedrockData.set(xzy, paletteId);
|
||||||
|
|
||||||
|
switch (yzx) {
|
||||||
|
case 0 -> Arrays.fill(runningSectionExtendedCollisions, 256, 4095, 0);
|
||||||
|
case 256 -> Arrays.fill(runningSectionExtendedCollisions, 0, 256, 0);
|
||||||
|
}
|
||||||
|
int javaId = javaPalette.idToState(paletteId);
|
||||||
|
if (javaId == BlockStateValues.JAVA_AIR_ID && runningSectionExtendedCollisions[yzx] != 0) {
|
||||||
|
bedrockData.set(xzy, layer0.idFor(runningSectionExtendedCollisions[yzx]));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int aboveBedrockExtendedCollisionId = BlockRegistries.EXTENDED_COLLISION_BOXES.getOrDefault(javaId, -1);
|
||||||
|
if (aboveBedrockExtendedCollisionId != -1) {
|
||||||
|
runningSectionExtendedCollisions[((yzx & 0x0ff) | (((yzx >> 8) + ((xzy & 0xF) < 15 ? 1 : -15)) << 8))] = aboveBedrockExtendedCollisionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layers = new BlockStorage[]{ layer0 };
|
layers = new BlockStorage[]{ layer0 };
|
||||||
@ -238,6 +260,20 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
|
|||||||
if (waterloggedPaletteIds.get(paletteId)) {
|
if (waterloggedPaletteIds.get(paletteId)) {
|
||||||
layer1Data[xzy >> 5] |= 1 << (xzy & 0x1F);
|
layer1Data[xzy >> 5] |= 1 << (xzy & 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (yzx) {
|
||||||
|
case 0 -> Arrays.fill(runningSectionExtendedCollisions, 256, 4095, 0);
|
||||||
|
case 256 -> Arrays.fill(runningSectionExtendedCollisions, 0, 256, 0);
|
||||||
|
}
|
||||||
|
int javaId = javaPalette.idToState(paletteId);
|
||||||
|
if (javaId == BlockStateValues.JAVA_AIR_ID && runningSectionExtendedCollisions[yzx] != 0) {
|
||||||
|
bedrockData.set(xzy, layer0.idFor(runningSectionExtendedCollisions[yzx]));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int aboveBedrockExtendedCollisionId = BlockRegistries.EXTENDED_COLLISION_BOXES.getOrDefault(javaId, -1);
|
||||||
|
if (aboveBedrockExtendedCollisionId != -1) {
|
||||||
|
runningSectionExtendedCollisions[((yzx & 0x0ff) | (((yzx >> 8) + ((xzy & 0xF) < 15 ? 1 : -15)) << 8))] = aboveBedrockExtendedCollisionId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// V1 palette
|
// V1 palette
|
||||||
|
@ -129,7 +129,7 @@ public class ChunkUtils {
|
|||||||
// Otherwise, let's still store our reference to the item frame, but let the new block take precedence for now
|
// Otherwise, let's still store our reference to the item frame, but let the new block take precedence for now
|
||||||
}
|
}
|
||||||
|
|
||||||
int blockId = session.getBlockMappings().getBedrockBlockId(blockState);
|
int bedrockId = session.getBlockMappings().getBedrockBlockId(blockState);
|
||||||
int skullVariant = BlockStateValues.getSkullVariant(blockState);
|
int skullVariant = BlockStateValues.getSkullVariant(blockState);
|
||||||
if (skullVariant == -1) {
|
if (skullVariant == -1) {
|
||||||
// Skull is gone
|
// Skull is gone
|
||||||
@ -138,17 +138,36 @@ public class ChunkUtils {
|
|||||||
// The changed block was a player skull so check if a custom block was defined for this skull
|
// The changed block was a player skull so check if a custom block was defined for this skull
|
||||||
SkullCache.Skull skull = session.getSkullCache().updateSkull(position, blockState);
|
SkullCache.Skull skull = session.getSkullCache().updateSkull(position, blockState);
|
||||||
if (skull != null && skull.getCustomRuntimeId() != -1) {
|
if (skull != null && skull.getCustomRuntimeId() != -1) {
|
||||||
blockId = skull.getCustomRuntimeId();
|
bedrockId = skull.getCustomRuntimeId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extended collision boxes for custom blocks
|
||||||
|
int aboveBedrockExtendedCollisionId = BlockRegistries.EXTENDED_COLLISION_BOXES.getOrDefault(blockState, -1);
|
||||||
|
int aboveBlock = session.getChunkCache().getBlockAt(position.getX(), position.getY() + 1, position.getZ());
|
||||||
|
if (aboveBedrockExtendedCollisionId != -1) {
|
||||||
|
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||||
|
updateBlockPacket.setDataLayer(0);
|
||||||
|
updateBlockPacket.setBlockPosition(position.add(0, 1, 0));
|
||||||
|
updateBlockPacket.setRuntimeId(aboveBedrockExtendedCollisionId);
|
||||||
|
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
|
||||||
|
session.sendUpstreamPacket(updateBlockPacket);
|
||||||
|
} else if (aboveBlock == BlockStateValues.JAVA_AIR_ID) {
|
||||||
|
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||||
|
updateBlockPacket.setDataLayer(0);
|
||||||
|
updateBlockPacket.setBlockPosition(position.add(0, 1, 0));
|
||||||
|
updateBlockPacket.setRuntimeId(session.getBlockMappings().getBedrockAirId());
|
||||||
|
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
|
||||||
|
session.sendUpstreamPacket(updateBlockPacket);
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent moving_piston from being placed
|
// Prevent moving_piston from being placed
|
||||||
// It's used for extending piston heads, but it isn't needed on Bedrock and causes pistons to flicker
|
// It's used for extending piston heads, but it isn't needed on Bedrock and causes pistons to flicker
|
||||||
if (!BlockStateValues.isMovingPiston(blockState)) {
|
if (!BlockStateValues.isMovingPiston(blockState)) {
|
||||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||||
updateBlockPacket.setDataLayer(0);
|
updateBlockPacket.setDataLayer(0);
|
||||||
updateBlockPacket.setBlockPosition(position);
|
updateBlockPacket.setBlockPosition(position);
|
||||||
updateBlockPacket.setRuntimeId(blockId);
|
updateBlockPacket.setRuntimeId(bedrockId);
|
||||||
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
|
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
|
||||||
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
|
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
|
||||||
session.sendUpstreamPacket(updateBlockPacket);
|
session.sendUpstreamPacket(updateBlockPacket);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren