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; package org.geysermc.geyser.platform.spigot.world;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValueType; import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import org.cloudburstmc.math.vector.Vector3i; import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -40,13 +38,16 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonEvent; import org.bukkit.event.block.BlockPistonEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.cloudburstmc.math.vector.Vector3i;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.level.block.BlockStateValues; 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.level.physics.Direction;
import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager; import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.PistonCache; import org.geysermc.geyser.session.cache.PistonCache;
import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity; 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.List;
import java.util.Map; import java.util.Map;
@ -85,7 +86,7 @@ public class GeyserPistonListener implements Listener {
PistonValueType type = isExtend ? PistonValueType.PUSHING : PistonValueType.PULLING; PistonValueType type = isExtend ? PistonValueType.PUSHING : PistonValueType.PULLING;
boolean sticky = event.isSticky(); boolean sticky = event.isSticky();
Object2IntMap<Vector3i> attachedBlocks = new Object2IntArrayMap<>(); Object2ObjectMap<Vector3i, BlockState> attachedBlocks = new Object2ObjectArrayMap<>();
boolean blocksFilled = false; boolean blocksFilled = false;
for (Map.Entry<UUID, GeyserSession> entry : geyser.getSessionManager().getSessions().entrySet()) { 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(); List<Block> blocks = isExtend ? ((BlockPistonExtendEvent) event).getBlocks() : ((BlockPistonRetractEvent) event).getBlocks();
for (Block block : blocks) { for (Block block : blocks) {
Location attachedLocation = block.getLocation(); Location attachedLocation = block.getLocation();
int blockId = worldManager.getBlockNetworkId(block); BlockState state = BlockState.of(worldManager.getBlockNetworkId(block));
// Ignore blocks that will be destroyed // Ignore blocks that will be destroyed
if (BlockStateValues.canPistonMoveBlock(blockId, isExtend)) { if (BlockStateValues.canPistonMoveBlock(state, isExtend)) {
attachedBlocks.put(getVector(attachedLocation), blockId); attachedBlocks.put(getVector(attachedLocation), state);
} }
} }
blocksFilled = true; 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.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; 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.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.math.vector.Vector3i;
@ -157,7 +157,7 @@ public final class GeyserboundPacketHandlerImpl extends AbstractGeyserboundPacke
.stream() .stream()
.map(entry -> Pair.of(entry.getKey(), BlockState.of(entry.getIntValue()))) .map(entry -> Pair.of(entry.getKey(), BlockState.of(entry.getIntValue())))
.filter(pair -> BlockStateValues.canPistonMoveBlock(pair.value(), isExtend)); .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())); stream.forEach(pair -> attachedBlocks.put(pair.key(), pair.value()));
session.executeInEventLoop(() -> { session.executeInEventLoop(() -> {

View file

@ -62,6 +62,16 @@ public final class BlockState {
return this.block == block; 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) { public static BlockState of(int javaId) {
return BlockRegistries.BLOCK_STATES.get(javaId); return BlockRegistries.BLOCK_STATES.get(javaId);
} }

View file

@ -26,6 +26,7 @@
package org.geysermc.geyser.translator.level.block.entity; package org.geysermc.geyser.translator.level.block.entity;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
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.geysermc.geyser.level.block.type.BlockState; import org.geysermc.geyser.level.block.type.BlockState;
@ -56,6 +57,10 @@ public abstract class BlockEntityTranslator {
return getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(type), x, y, z); 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) { public static NbtMapBuilder getConstantBedrockTag(String bedrockId, int x, int y, int z) {
return NbtMap.builder() return NbtMap.builder()
.putInt("x", x) .putInt("x", x)

View file

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