Fix compilation for Spigot

This commit is contained in:
Camotoy 2024-05-17 21:14:59 -04:00
parent beef01f3fc
commit a439f3e3d7
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
5 changed files with 34 additions and 29 deletions

View file

@ -25,10 +25,8 @@
package org.geysermc.geyser.platform.spigot.world;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValueType;
import org.cloudburstmc.math.vector.Vector3i;
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@ -40,13 +38,16 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.cloudburstmc.math.vector.Vector3i;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.level.physics.Direction;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.PistonCache;
import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValueType;
import java.util.List;
import java.util.Map;
@ -85,7 +86,7 @@ public class GeyserPistonListener implements Listener {
PistonValueType type = isExtend ? PistonValueType.PUSHING : PistonValueType.PULLING;
boolean sticky = event.isSticky();
Object2IntMap<Vector3i> attachedBlocks = new Object2IntArrayMap<>();
Object2ObjectMap<Vector3i, BlockState> attachedBlocks = new Object2ObjectArrayMap<>();
boolean blocksFilled = false;
for (Map.Entry<UUID, GeyserSession> entry : geyser.getSessionManager().getSessions().entrySet()) {
@ -108,10 +109,10 @@ public class GeyserPistonListener implements Listener {
List<Block> blocks = isExtend ? ((BlockPistonExtendEvent) event).getBlocks() : ((BlockPistonRetractEvent) event).getBlocks();
for (Block block : blocks) {
Location attachedLocation = block.getLocation();
int blockId = worldManager.getBlockNetworkId(block);
BlockState state = BlockState.of(worldManager.getBlockNetworkId(block));
// Ignore blocks that will be destroyed
if (BlockStateValues.canPistonMoveBlock(blockId, isExtend)) {
attachedBlocks.put(getVector(attachedLocation), blockId);
if (BlockStateValues.canPistonMoveBlock(state, isExtend)) {
attachedBlocks.put(getVector(attachedLocation), state);
}
}
blocksFilled = true;

View file

@ -30,8 +30,8 @@ import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.Getter;
import lombok.Setter;
import org.cloudburstmc.math.vector.Vector3i;
@ -157,7 +157,7 @@ public final class GeyserboundPacketHandlerImpl extends AbstractGeyserboundPacke
.stream()
.map(entry -> Pair.of(entry.getKey(), BlockState.of(entry.getIntValue())))
.filter(pair -> BlockStateValues.canPistonMoveBlock(pair.value(), isExtend));
Object2ObjectMap<Vector3i, BlockState> attachedBlocks = new Object2ObjectOpenHashMap<>();
Object2ObjectMap<Vector3i, BlockState> attachedBlocks = new Object2ObjectArrayMap<>();
stream.forEach(pair -> attachedBlocks.put(pair.key(), pair.value()));
session.executeInEventLoop(() -> {

View file

@ -62,6 +62,16 @@ public final class BlockState {
return this.block == block;
}
private String paramsToString() {
StringBuilder builder = new StringBuilder();
var it = this.states.entrySet().iterator();
while (it.hasNext()) {
var entry = it.next();
builder.append(entry.getKey()).append("=").append(entry.getValue());
}
return builder.toString();
}
public static BlockState of(int javaId) {
return BlockRegistries.BLOCK_STATES.get(javaId);
}

View file

@ -26,6 +26,7 @@
package org.geysermc.geyser.translator.level.block.entity;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.geyser.level.block.type.BlockState;
@ -56,6 +57,10 @@ public abstract class BlockEntityTranslator {
return getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(type), x, y, z);
}
public static NbtMapBuilder getConstantBedrockTag(String bedrockId, Vector3i position) {
return getConstantBedrockTag(bedrockId, position.getX(), position.getY(), position.getZ());
}
public static NbtMapBuilder getConstantBedrockTag(String bedrockId, int x, int y, int z) {
return NbtMap.builder()
.putInt("x", x)

View file

@ -25,6 +25,7 @@
package org.geysermc.geyser.translator.level.block.entity;
import it.unimi.dsi.fastutil.ints.IntArrays;
import it.unimi.dsi.fastutil.objects.*;
import org.geysermc.geyser.level.block.Blocks;
import org.geysermc.geyser.level.block.type.Block;
@ -74,7 +75,7 @@ public class PistonBlockEntity {
/**
* A flattened array of the positions of attached blocks, stored in XYZ order.
*/
private int[] flattenedAttachedBlocks = new int[0];
private int[] flattenedAttachedBlocks = IntArrays.EMPTY_ARRAY;
private boolean placedFinalBlocks = true;
@ -732,18 +733,14 @@ public class PistonBlockEntity {
* @return A piston data tag
*/
private NbtMap buildPistonTag() {
NbtMapBuilder builder = NbtMap.builder()
.putString("id", "PistonArm")
NbtMapBuilder builder = BlockEntityTranslator.getConstantBedrockTag("PistonArm", position)
.putIntArray("AttachedBlocks", flattenedAttachedBlocks)
.putFloat("Progress", progress)
.putFloat("LastProgress", lastProgress)
.putByte("NewState", getState())
.putByte("State", getState())
.putBoolean("Sticky", sticky)
.putBoolean("isMovable", false)
.putInt("x", position.getX())
.putInt("y", position.getY())
.putInt("z", position.getZ());
.putBoolean("isMovable", false);
return builder.build();
}
@ -756,17 +753,13 @@ public class PistonBlockEntity {
* @return A piston data tag for a fully extended/retracted piston
*/
public static NbtMap buildStaticPistonTag(Vector3i position, boolean extended, boolean sticky) {
NbtMapBuilder builder = NbtMap.builder()
.putString("id", "PistonArm")
NbtMapBuilder builder = BlockEntityTranslator.getConstantBedrockTag("PistonArm", position)
.putFloat("Progress", extended ? 1.0f : 0.0f)
.putFloat("LastProgress", extended ? 1.0f : 0.0f)
.putByte("NewState", (byte) (extended ? 2 : 0))
.putByte("State", (byte) (extended ? 2 : 0))
.putBoolean("Sticky", sticky)
.putBoolean("isMovable", false)
.putInt("x", position.getX())
.putInt("y", position.getY())
.putInt("z", position.getZ());
.putBoolean("isMovable", false);
return builder.build();
}
@ -781,17 +774,13 @@ public class PistonBlockEntity {
private NbtMap buildMovingBlockTag(Vector3i position, BlockState state, Vector3i pistonPosition) {
// Get Bedrock block state data
NbtMap movingBlock = session.getBlockMappings().getBedrockBlock(state).getState();
NbtMapBuilder builder = NbtMap.builder()
.putString("id", "MovingBlock")
NbtMapBuilder builder = BlockEntityTranslator.getConstantBedrockTag("MovingBlock", position)
.putBoolean("expanding", action == PistonValueType.PUSHING)
.putCompound("movingBlock", movingBlock)
.putBoolean("isMovable", true)
.putInt("pistonPosX", pistonPosition.getX())
.putInt("pistonPosY", pistonPosition.getY())
.putInt("pistonPosZ", pistonPosition.getZ())
.putInt("x", position.getX())
.putInt("y", position.getY())
.putInt("z", position.getZ());
.putInt("pistonPosZ", pistonPosition.getZ());
if (state.block() instanceof PistonBlock piston) {
builder.putCompound("movingEntity", piston.createTag(session, position, state));
}