fix piston retracting

This commit is contained in:
onebeastchris 2024-07-25 19:21:05 +02:00
parent b40df1e346
commit ef10ed5ff9
4 changed files with 16 additions and 13 deletions

View file

@ -82,6 +82,7 @@ public class PistonBaseBlockMixin {
for (Map.Entry<UUID, GeyserSession> entry : GeyserImpl.getInstance().getSessionManager().getSessions().entrySet()) {
Player player = level.getPlayerByUUID(entry.getKey());
//noinspection resource
if (player == null || !player.level().equals(level)) {
continue;
}

View file

@ -162,7 +162,6 @@ public final class BlockRegistryPopulator {
// as we no longer send a block palette
Object2ObjectMap<NbtMap, GeyserBedrockBlock> blockStateOrderedMap = new Object2ObjectOpenHashMap<>(blockStates.size());
GeyserBedrockBlock[] bedrockRuntimeMap = new GeyserBedrockBlock[blockStates.size()];
GeyserImpl.getInstance().getLogger().info(blockStates.size() + " block states found");
for (int i = 0; i < blockStates.size(); i++) {
NbtMap tag = blockStates.get(i);
if (blockStateOrderedMap.containsKey(tag)) {

View file

@ -37,7 +37,6 @@ import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.block.Blocks;
import org.geysermc.geyser.level.block.property.Properties;
@ -230,9 +229,8 @@ public class PistonBlockEntity {
BlockState state = session.getGeyser().getWorldManager().blockAt(session, blockInFront);
if (state.is(Blocks.PISTON_HEAD)) {
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, blockInFront);
} else if ((session.getGeyser().getPlatformType() == PlatformType.SPIGOT || session.getErosionHandler().isActive()) && state.is(Blocks.AIR)) {
// TODO pistons fabric????
// Spigot removes the piston head from the cache, but we need to send the block update ourselves
} else if ((session.getGeyser().getWorldManager().hasOwnChunkCache() || session.getErosionHandler().isActive()) && state.is(Blocks.AIR)) {
// The platform removes the piston head from the cache, but we need to send the block update ourselves
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, blockInFront);
}
}

View file

@ -82,17 +82,22 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
Direction direction = Direction.fromPistonValue(pistonValue.getDirection());
PistonCache pistonCache = session.getPistonCache();
// TODO pistons modded
if (session.getGeyser().getPlatformType() == PlatformType.SPIGOT || session.getErosionHandler().isActive()) {
// Mostly handled in the GeyserPistonEvents class
// Retracting sticky pistons is an exception, since the event is not called on Spigot from 1.13.2 - 1.17.1
// See https://github.com/PaperMC/Paper/blob/6fa1983e9ce177a4a412d5b950fd978620174777/patches/server/0304-Fire-BlockPistonRetractEvent-for-all-empty-pistons.patch
if (session.getGeyser().getWorldManager().hasOwnChunkCache() || session.getErosionHandler().isActive()) {
// Mostly handled in the GeyserPistonEvents class (Spigot) / the PistonBlockBaseMixin (Mod platforms)
// However, the retracting event is not fully covered. (Spigot)
// Mod platforms only handle pistons moving blocks; not the retracting of pistons.
if (action == PistonValueType.PULLING || action == PistonValueType.CANCELLED_MID_PUSH) {
BlockState pistonBlock = session.getGeyser().getWorldManager().blockAt(session, position);
if (!isSticky(pistonBlock)) {
// Retracting sticky pistons is an exception, since the event is not called on Spigot from 1.13.2 - 1.17.1
// See https://github.com/PaperMC/Paper/blob/6fa1983e9ce177a4a412d5b950fd978620174777/patches/server/0304-Fire-BlockPistonRetractEvent-for-all-empty-pistons.patch
boolean isSticky = isSticky(pistonBlock);
if (session.getGeyser().getPlatformType() == PlatformType.SPIGOT && !isSticky) {
return;
}
if (action != PistonValueType.CANCELLED_MID_PUSH) {
// Only sticky pistons that don't pull any blocks are affected
if (action != PistonValueType.CANCELLED_MID_PUSH && isSticky) {
Vector3i blockInFrontPos = position.add(direction.getUnitVector());
int blockInFront = session.getGeyser().getWorldManager().getBlockAt(session, blockInFrontPos);
if (blockInFront != Block.JAVA_AIR_ID) {
@ -100,7 +105,7 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
return;
}
}
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(position, pos -> new PistonBlockEntity(session, pos, direction, true, true));
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(position, pos -> new PistonBlockEntity(session, pos, direction, isSticky, true));
if (blockEntity.getAction() != action) {
blockEntity.setAction(action, Object2ObjectMaps.emptyMap());
}