mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
fix piston retracting
This commit is contained in:
parent
b40df1e346
commit
ef10ed5ff9
4 changed files with 16 additions and 13 deletions
|
|
@ -82,6 +82,7 @@ public class PistonBaseBlockMixin {
|
||||||
|
|
||||||
for (Map.Entry<UUID, GeyserSession> entry : GeyserImpl.getInstance().getSessionManager().getSessions().entrySet()) {
|
for (Map.Entry<UUID, GeyserSession> entry : GeyserImpl.getInstance().getSessionManager().getSessions().entrySet()) {
|
||||||
Player player = level.getPlayerByUUID(entry.getKey());
|
Player player = level.getPlayerByUUID(entry.getKey());
|
||||||
|
//noinspection resource
|
||||||
if (player == null || !player.level().equals(level)) {
|
if (player == null || !player.level().equals(level)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,6 @@ public final class BlockRegistryPopulator {
|
||||||
// as we no longer send a block palette
|
// as we no longer send a block palette
|
||||||
Object2ObjectMap<NbtMap, GeyserBedrockBlock> blockStateOrderedMap = new Object2ObjectOpenHashMap<>(blockStates.size());
|
Object2ObjectMap<NbtMap, GeyserBedrockBlock> blockStateOrderedMap = new Object2ObjectOpenHashMap<>(blockStates.size());
|
||||||
GeyserBedrockBlock[] bedrockRuntimeMap = new GeyserBedrockBlock[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++) {
|
for (int i = 0; i < blockStates.size(); i++) {
|
||||||
NbtMap tag = blockStates.get(i);
|
NbtMap tag = blockStates.get(i);
|
||||||
if (blockStateOrderedMap.containsKey(tag)) {
|
if (blockStateOrderedMap.containsKey(tag)) {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import org.cloudburstmc.nbt.NbtMap;
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket;
|
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.BlockStateValues;
|
||||||
import org.geysermc.geyser.level.block.Blocks;
|
import org.geysermc.geyser.level.block.Blocks;
|
||||||
import org.geysermc.geyser.level.block.property.Properties;
|
import org.geysermc.geyser.level.block.property.Properties;
|
||||||
|
|
@ -230,9 +229,8 @@ public class PistonBlockEntity {
|
||||||
BlockState state = session.getGeyser().getWorldManager().blockAt(session, blockInFront);
|
BlockState state = session.getGeyser().getWorldManager().blockAt(session, blockInFront);
|
||||||
if (state.is(Blocks.PISTON_HEAD)) {
|
if (state.is(Blocks.PISTON_HEAD)) {
|
||||||
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, blockInFront);
|
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, blockInFront);
|
||||||
} else if ((session.getGeyser().getPlatformType() == PlatformType.SPIGOT || session.getErosionHandler().isActive()) && state.is(Blocks.AIR)) {
|
} else if ((session.getGeyser().getWorldManager().hasOwnChunkCache() || session.getErosionHandler().isActive()) && state.is(Blocks.AIR)) {
|
||||||
// TODO pistons fabric????
|
// The platform removes the piston head from the cache, but we need to send the block update ourselves
|
||||||
// Spigot removes the piston head from the cache, but we need to send the block update ourselves
|
|
||||||
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, blockInFront);
|
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, blockInFront);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,17 +82,22 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
||||||
Direction direction = Direction.fromPistonValue(pistonValue.getDirection());
|
Direction direction = Direction.fromPistonValue(pistonValue.getDirection());
|
||||||
PistonCache pistonCache = session.getPistonCache();
|
PistonCache pistonCache = session.getPistonCache();
|
||||||
|
|
||||||
// TODO pistons modded
|
if (session.getGeyser().getWorldManager().hasOwnChunkCache() || session.getErosionHandler().isActive()) {
|
||||||
if (session.getGeyser().getPlatformType() == PlatformType.SPIGOT || session.getErosionHandler().isActive()) {
|
// Mostly handled in the GeyserPistonEvents class (Spigot) / the PistonBlockBaseMixin (Mod platforms)
|
||||||
// Mostly handled in the GeyserPistonEvents class
|
// However, the retracting event is not fully covered. (Spigot)
|
||||||
// Retracting sticky pistons is an exception, since the event is not called on Spigot from 1.13.2 - 1.17.1
|
// Mod platforms only handle pistons moving blocks; not the retracting of pistons.
|
||||||
// See https://github.com/PaperMC/Paper/blob/6fa1983e9ce177a4a412d5b950fd978620174777/patches/server/0304-Fire-BlockPistonRetractEvent-for-all-empty-pistons.patch
|
|
||||||
if (action == PistonValueType.PULLING || action == PistonValueType.CANCELLED_MID_PUSH) {
|
if (action == PistonValueType.PULLING || action == PistonValueType.CANCELLED_MID_PUSH) {
|
||||||
BlockState pistonBlock = session.getGeyser().getWorldManager().blockAt(session, position);
|
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;
|
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());
|
Vector3i blockInFrontPos = position.add(direction.getUnitVector());
|
||||||
int blockInFront = session.getGeyser().getWorldManager().getBlockAt(session, blockInFrontPos);
|
int blockInFront = session.getGeyser().getWorldManager().getBlockAt(session, blockInFrontPos);
|
||||||
if (blockInFront != Block.JAVA_AIR_ID) {
|
if (blockInFront != Block.JAVA_AIR_ID) {
|
||||||
|
|
@ -100,7 +105,7 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
||||||
return;
|
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) {
|
if (blockEntity.getAction() != action) {
|
||||||
blockEntity.setAction(action, Object2ObjectMaps.emptyMap());
|
blockEntity.setAction(action, Object2ObjectMaps.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue