Finish block state changes

This commit is contained in:
DoctorMacc 2020-06-19 09:06:29 -04:00
parent ad4c1ff0c7
commit 65f61ec703
4 changed files with 8 additions and 8 deletions

View file

@ -114,7 +114,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
case CONTINUE_BREAK:
LevelEventPacket continueBreakPacket = new LevelEventPacket();
continueBreakPacket.setType(LevelEventType.PUNCH_BLOCK);
continueBreakPacket.setData(BlockTranslator.getBedrockBlockId(session.getBreakingBlock() == null ? BlockTranslator.AIR : session.getBreakingBlock()));
continueBreakPacket.setData(BlockTranslator.getBedrockBlockId(session.getBreakingBlock()));
continueBreakPacket.setPosition(packet.getBlockPosition().toFloat());
session.sendUpstreamPacket(continueBreakPacket);
break;

View file

@ -50,13 +50,13 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
LevelEventPacket levelEvent = new LevelEventPacket();
switch (packet.getAction()) {
case FINISH_DIGGING:
double blockHardness = BlockTranslator.JAVA_RUNTIME_ID_TO_HARDNESS.get(session.getBreakingBlock() == null ? 0 : session.getBreakingBlock().getId());
double blockHardness = BlockTranslator.JAVA_RUNTIME_ID_TO_HARDNESS.get(session.getBreakingBlock());
if (session.getGameMode() != GameMode.CREATIVE && blockHardness != 0) {
levelEvent.setType(LevelEventType.DESTROY);
levelEvent.setPosition(Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
levelEvent.setData(BlockTranslator.getBedrockBlockId(session.getBreakingBlock()));
session.sendUpstreamPacket(levelEvent);
session.setBreakingBlock(null);
session.setBreakingBlock(0);
}
ChunkUtils.updateBlock(session, packet.getNewState(), packet.getPosition());
break;
@ -64,7 +64,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
if (session.getGameMode() == GameMode.CREATIVE) {
break;
}
blockHardness = BlockTranslator.JAVA_RUNTIME_ID_TO_HARDNESS.get(packet.getNewState().getId());
blockHardness = BlockTranslator.JAVA_RUNTIME_ID_TO_HARDNESS.get(packet.getNewState());
levelEvent.setType(LevelEventType.BLOCK_START_BREAK);
levelEvent.setPosition(Vector3f.from(
packet.getPosition().getX(),
@ -79,7 +79,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
itemEntry = ItemRegistry.getItem(item);
nbtData = item.getNbt();
}
double breakTime = Math.ceil(BlockUtils.getBreakTime(blockHardness, packet.getNewState().getId(), itemEntry, nbtData, session) * 20);
double breakTime = Math.ceil(BlockUtils.getBreakTime(blockHardness, packet.getNewState(), itemEntry, nbtData, session) * 20);
levelEvent.setData((int) (65535 / breakTime));
session.setBreakingBlock(packet.getNewState());
session.sendUpstreamPacket(levelEvent);
@ -92,7 +92,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
packet.getPosition().getZ()
));
levelEvent.setData(0);
session.setBreakingBlock(null);
session.setBreakingBlock(0);
session.sendUpstreamPacket(levelEvent);
break;
}

View file

@ -45,7 +45,7 @@ public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChang
@Override
public void translate(ServerBlockChangePacket packet, GeyserSession session) {
Position pos = packet.getRecord().getPosition();
boolean updatePlacement = !(session.getConnector().getConfig().isCacheChunks() && session.getConnector().getWorldManager().getBlockAt(session, pos.getX(), pos.getY(), pos.getZ()).getId() == packet.getRecord().getBlock().getId());
boolean updatePlacement = !(session.getConnector().getConfig().isCacheChunks() && session.getConnector().getWorldManager().getBlockAt(session, pos.getX(), pos.getY(), pos.getZ()) == packet.getRecord().getBlock());
ChunkUtils.updateBlock(session, packet.getRecord().getBlock(), packet.getRecord().getPosition());
if (updatePlacement && session.getConnector().getPlatformType() != PlatformType.BUKKIT) {
this.checkPlace(session, packet);

View file

@ -47,7 +47,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator<ServerUpdat
ChunkUtils.CACHED_BLOCK_ENTITIES.get(packet.getPosition())), packet.getPosition());
ChunkUtils.CACHED_BLOCK_ENTITIES.remove(packet.getPosition());
} else {
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), null), packet.getPosition());
BlockEntityUtils.updateBlockEntity(session, translator.getBlockEntityTag(id, packet.getNbt(), 0), packet.getPosition());
}
}
}