forked from GeyserMC/Geyser
Optimize waterlogged check
This commit is contained in:
parent
a4279d1f34
commit
776d4c6585
3 changed files with 15 additions and 14 deletions
|
@ -25,19 +25,27 @@
|
|||
|
||||
package org.geysermc.connector.network.translators.block;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class BlockEntry {
|
||||
|
||||
public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0);
|
||||
|
||||
private String javaIdentifier;
|
||||
private int javaId;
|
||||
private final String javaIdentifier;
|
||||
private final int javaId;
|
||||
private final int bedrockRuntimeId;
|
||||
private final boolean waterlogged;
|
||||
|
||||
private int bedrockRuntimeId;
|
||||
public BlockEntry(String javaIdentifier, int javaId, int bedrockRuntimeId) {
|
||||
this.javaIdentifier = javaIdentifier;
|
||||
this.javaId = javaId;
|
||||
this.bedrockRuntimeId = bedrockRuntimeId;
|
||||
this.waterlogged = (javaIdentifier.contains("waterlogged=true")
|
||||
|| javaIdentifier.startsWith("minecraft:kelp")
|
||||
|| javaIdentifier.contains("seagrass")
|
||||
|| javaIdentifier.startsWith("minecraft:bubble_column"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
|
|
@ -17,11 +17,4 @@ public class BlockTranslator {
|
|||
return javaIdentifierMap.computeIfAbsent(javaIdentifier, key -> Toolbox.BLOCK_ENTRIES.values()
|
||||
.stream().filter(blockEntry -> blockEntry.getJavaIdentifier().equals(key)).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
public boolean isWaterLogged(BlockEntry entry) {
|
||||
return (entry.getJavaIdentifier().contains("waterlogged=true")
|
||||
|| entry.getJavaIdentifier().startsWith("minecraft:kelp")
|
||||
|| entry.getJavaIdentifier().contains("seagrass")
|
||||
|| entry.getJavaIdentifier().startsWith("minecraft:bubble_column"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class ChunkUtils {
|
|||
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
||||
block.getBedrockRuntimeId());
|
||||
|
||||
if (TranslatorsInit.getBlockTranslator().isWaterLogged(block)) {
|
||||
if (block.isWaterlogged()) {
|
||||
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
|
||||
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), water.getBedrockRuntimeId());
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class ChunkUtils {
|
|||
UpdateBlockPacket waterPacket = new UpdateBlockPacket();
|
||||
waterPacket.setDataLayer(1);
|
||||
waterPacket.setBlockPosition(pos);
|
||||
if (TranslatorsInit.getBlockTranslator().isWaterLogged(blockEntry)) {
|
||||
if (blockEntry.isWaterlogged()) {
|
||||
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
|
||||
waterPacket.setRuntimeId(water.getBedrockRuntimeId());
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue