Optimize waterlogged check

This commit is contained in:
AJ Ferguson 2019-12-22 00:32:49 -09:00
parent a4279d1f34
commit 776d4c6585
3 changed files with 15 additions and 14 deletions

View file

@ -25,19 +25,27 @@
package org.geysermc.connector.network.translators.block; package org.geysermc.connector.network.translators.block;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
@AllArgsConstructor
public class BlockEntry { public class BlockEntry {
public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0); public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0);
private String javaIdentifier; private final String javaIdentifier;
private int javaId; 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {

View file

@ -17,11 +17,4 @@ public class BlockTranslator {
return javaIdentifierMap.computeIfAbsent(javaIdentifier, key -> Toolbox.BLOCK_ENTRIES.values() return javaIdentifierMap.computeIfAbsent(javaIdentifier, key -> Toolbox.BLOCK_ENTRIES.values()
.stream().filter(blockEntry -> blockEntry.getJavaIdentifier().equals(key)).findFirst().orElse(null)); .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"));
}
} }

View file

@ -38,7 +38,7 @@ public class ChunkUtils {
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
block.getBedrockRuntimeId()); block.getBedrockRuntimeId());
if (TranslatorsInit.getBlockTranslator().isWaterLogged(block)) { if (block.isWaterlogged()) {
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]"); BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), water.getBedrockRuntimeId()); section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), water.getBedrockRuntimeId());
} }
@ -63,7 +63,7 @@ public class ChunkUtils {
UpdateBlockPacket waterPacket = new UpdateBlockPacket(); UpdateBlockPacket waterPacket = new UpdateBlockPacket();
waterPacket.setDataLayer(1); waterPacket.setDataLayer(1);
waterPacket.setBlockPosition(pos); waterPacket.setBlockPosition(pos);
if (TranslatorsInit.getBlockTranslator().isWaterLogged(blockEntry)) { if (blockEntry.isWaterlogged()) {
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]"); BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
waterPacket.setRuntimeId(water.getBedrockRuntimeId()); waterPacket.setRuntimeId(water.getBedrockRuntimeId());
} else { } else {