9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 02:49:15 +00:00

统一使用adaptor

This commit is contained in:
XiaoMoMi
2025-12-26 04:58:18 +08:00
parent 418446e3b2
commit 4420e4ceae
24 changed files with 79 additions and 39 deletions

View File

@@ -6,7 +6,9 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.bukkit.world.BukkitExistingBlock;
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
import net.momirealms.craftengine.bukkit.world.BukkitWorldManager;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.world.CEWorld;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
@@ -36,7 +38,7 @@ public final class BukkitAdaptors {
* This enables CraftEngine world operations on Bukkit world instances.
*
* @param world the Bukkit World to adapt, must not be null
* @return a non-null BukkitWorld instance wrapping the provided world
* @return the BukkitWorld instance wrapping the provided world
*/
@NotNull
public static BukkitWorld adapt(@NotNull final World world) {

View File

@@ -198,7 +198,7 @@ public final class CraftEngineBlocks {
boolean sendLevelEvent) {
ImmutableBlockState state = getCustomBlockState(block);
if (state == null || state.isEmpty()) return false;
World world = new BukkitWorld(block.getWorld());
World world = BukkitAdaptors.adapt(block.getWorld());
Location location = block.getLocation();
WorldPosition position = new WorldPosition(world, location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5);
if (dropLoot) {

View File

@@ -7,7 +7,6 @@ import net.momirealms.craftengine.bukkit.nms.CollisionEntity;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
import net.momirealms.craftengine.core.entity.furniture.AnchorType;
import net.momirealms.craftengine.core.entity.furniture.CustomFurniture;
import net.momirealms.craftengine.core.entity.furniture.Furniture;
@@ -73,6 +72,7 @@ public final class CraftEngineFurniture {
@Nullable
public static BukkitFurniture rayTrace(Player player, double maxDistance) {
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
if (serverPlayer == null) return null;
Location eyeLocation = serverPlayer.getEyeLocation();
RayTraceResult result = player.getWorld().rayTrace(eyeLocation, eyeLocation.getDirection(), maxDistance, FluidCollisionMode.NEVER, true, 0d, CraftEngineFurniture::isCollisionEntity);
if (result == null)
@@ -92,6 +92,7 @@ public final class CraftEngineFurniture {
@Nullable
public static BukkitFurniture rayTrace(Player player) {
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
if (serverPlayer == null) return null;
Location eyeLocation = serverPlayer.getEyeLocation();
RayTraceResult result = player.getWorld().rayTrace(eyeLocation, eyeLocation.getDirection(), serverPlayer.getCachedInteractionRange(), FluidCollisionMode.NEVER, true, 0d, CraftEngineFurniture::isCollisionEntity);
if (result == null)
@@ -433,7 +434,7 @@ public final class CraftEngineFurniture {
Location location = ((BukkitFurniture) furniture).getDropLocation();
furniture.destroy();
LootTable<ItemStack> lootTable = (LootTable<ItemStack>) furniture.config.lootTable();
World world = new BukkitWorld(location.getWorld());
World world = BukkitAdaptors.adapt(location.getWorld());
WorldPosition position = new WorldPosition(world, location.getX(), location.getY(), location.getZ());
if (dropLoot && lootTable != null) {
ContextHolder.Builder builder = ContextHolder.builder()

View File

@@ -107,7 +107,7 @@ public final class BlockEventListener implements Listener {
Player player = event.getPlayer();
Location location = block.getLocation();
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
net.momirealms.craftengine.core.world.World world = new BukkitWorld(player.getWorld());
net.momirealms.craftengine.core.world.World world = BukkitAdaptors.adapt(player.getWorld());
WorldPosition position = new WorldPosition(world, location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5);
Item<ItemStack> itemInHand = serverPlayer.getItemInHand(InteractionHand.MAIN_HAND);
@@ -224,7 +224,7 @@ public final class BlockEventListener implements Listener {
event.setExpToDrop(0);
}
Location location = block.getLocation();
net.momirealms.craftengine.core.world.World world = new BukkitWorld(location.getWorld());
net.momirealms.craftengine.core.world.World world = BukkitAdaptors.adapt(location.getWorld());
WorldPosition position = new WorldPosition(world, location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5);
ContextHolder.Builder builder = ContextHolder.builder()
.withParameter(DirectContextParameters.POSITION, position)
@@ -255,7 +255,7 @@ public final class BlockEventListener implements Listener {
Cancellable cancellable = Cancellable.of(event::isCancelled, event::setCancelled);
state.owner().value().execute(PlayerOptionalContext.of(BukkitAdaptors.adapt(player), ContextHolder.builder()
.withParameter(DirectContextParameters.EVENT, cancellable)
.withParameter(DirectContextParameters.POSITION, new WorldPosition(new BukkitWorld(event.getWorld()), LocationUtils.toVec3d(location)))
.withParameter(DirectContextParameters.POSITION, new WorldPosition(BukkitAdaptors.adapt(event.getWorld()), LocationUtils.toVec3d(location)))
.withParameter(DirectContextParameters.BLOCK, new BukkitExistingBlock(block))
.withParameter(DirectContextParameters.CUSTOM_BLOCK_STATE, state)
), EventTrigger.STEP);

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBlocks;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
@@ -31,7 +32,7 @@ public abstract class AbstractCanSurviveBlockBehavior extends BukkitBlockBehavio
if (!canSurvive(thisBlock, args, () -> true)) {
BlockStateUtils.getOptionalCustomBlockState(blockState).ifPresent(customState -> {
if (!customState.isEmpty() && customState.owner().value() == this.customBlock) {
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
net.momirealms.craftengine.core.world.World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(LocationUtils.fromBlockPos(blockPos)));
world.playBlockSound(position, customState.settings().sounds().breakSound());
FastNMS.INSTANCE.method$LevelWriter$destroyBlock(level, blockPos, true);

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
@@ -175,7 +176,7 @@ public class CropBlockBehavior extends BukkitBlockBehavior {
int i = this.getAge(customState) + this.boneMealBonus.getInt(
SimpleContext.of(ContextHolder.builder()
.withParameter(DirectContextParameters.CUSTOM_BLOCK_STATE, customState)
.withParameter(DirectContextParameters.POSITION, new WorldPosition(new BukkitWorld(world), Vec3d.atCenterOf(new Vec3i(x, y, z))))
.withParameter(DirectContextParameters.POSITION, new WorldPosition(BukkitAdaptors.adapt(world), Vec3d.atCenterOf(new Vec3i(x, y, z))))
.build())
);
int maxAge = this.ageProperty.max;

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
@@ -261,7 +262,7 @@ public class DoorBlockBehavior extends AbstractCanSurviveBlockBehavior implement
world.sendGameEvent(player == null ? null : (org.bukkit.entity.Player) player.platformPlayer(), isOpen ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, new Vector(pos.x(), pos.y(), pos.z()));
SoundData soundData = isOpen ? this.openSound : this.closeSound;
if (soundData != null) {
new BukkitWorld(world).playBlockSound(
BukkitAdaptors.adapt(world).playBlockSound(
new Vec3d(pos.x() + 0.5, pos.y() + 0.5, pos.z() + 0.5),
soundData
);
@@ -313,7 +314,7 @@ public class DoorBlockBehavior extends AbstractCanSurviveBlockBehavior implement
world.sendGameEvent(null, flag ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, new Vector(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ()));
SoundData soundData = flag ? this.openSound : this.closeSound;
if (soundData != null) {
new BukkitWorld(world).playBlockSound(
BukkitAdaptors.adapt(world).playBlockSound(
new Vec3d(FastNMS.INSTANCE.field$Vec3i$x(blockPos) + 0.5, FastNMS.INSTANCE.field$Vec3i$y(blockPos) + 0.5, FastNMS.INSTANCE.field$Vec3i$z(blockPos) + 0.5),
soundData
);

View File

@@ -56,7 +56,7 @@ public class DoubleHighBlockBehavior extends AbstractCanSurviveBlockBehavior {
return MBlocks.AIR$defaultState;
} else if (half == DoubleBlockHalf.LOWER && direction == CoreReflections.instance$Direction$DOWN && !canSurvive(thisBlock, blockState, level, blockPos)) {
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
world.playBlockSound(position, customState.settings().sounds().breakSound());
FastNMS.INSTANCE.method$LevelAccessor$levelEvent(level, WorldEvents.BLOCK_BREAK_EFFECT, blockPos, customState.customBlockState().registryId());

View File

@@ -87,7 +87,7 @@ public class FallingBlockBehavior extends BukkitBlockBehavior {
Object blockState = CoreReflections.field$FallingBlockEntity$blockState.get(fallingBlockEntity);
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState);
if (optionalCustomState.isEmpty()) return;
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
net.momirealms.craftengine.core.world.World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
WorldPosition position = new WorldPosition(world, CoreReflections.field$Entity$xo.getDouble(fallingBlockEntity), CoreReflections.field$Entity$yo.getDouble(fallingBlockEntity), CoreReflections.field$Entity$zo.getDouble(fallingBlockEntity));
if (this.destroySound != null) {
world.playBlockSound(position, this.destroySound);
@@ -106,7 +106,7 @@ public class FallingBlockBehavior extends BukkitBlockBehavior {
ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(stateId);
if (immutableBlockState == null || immutableBlockState.isEmpty()) return;
if (!entity.getEntityData(BaseEntityData.Silent)) {
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
net.momirealms.craftengine.core.world.World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
if (this.landSound != null) {
world.playBlockSound(Vec3d.atCenterOf(LocationUtils.fromBlockPos(pos)), this.landSound);
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
@@ -169,7 +170,7 @@ public class FenceGateBlockBehavior extends BukkitBlockBehavior implements IsPat
if (this.canOpenByWindCharge && FastNMS.INSTANCE.method$Explosion$canTriggerBlocks(args[3])) {
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(args[0]);
if (optionalCustomState.isEmpty()) return;
this.toggle(optionalCustomState.get(), new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(args[1])), LocationUtils.fromBlockPos(args[2]), null);
this.toggle(optionalCustomState.get(), BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(args[1])), LocationUtils.fromBlockPos(args[2]), null);
}
}
@@ -196,7 +197,7 @@ public class FenceGateBlockBehavior extends BukkitBlockBehavior implements IsPat
hasSignal = event.getNewCurrent() > 0;
}
World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
boolean changed = isOpen(customState) != hasSignal;
if (hasSignal && changed) {
Object abovePos = LocationUtils.above(blockPos);

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
@@ -144,7 +145,7 @@ public class TrapDoorBlockBehavior extends BukkitBlockBehavior implements IsPath
if (this.canOpenByWindCharge && FastNMS.INSTANCE.method$Explosion$canTriggerBlocks(args[3])) {
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(args[0]);
if (optionalCustomState.isEmpty()) return;
this.toggle(optionalCustomState.get(), new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(args[1])), LocationUtils.fromBlockPos(args[2]), null);
this.toggle(optionalCustomState.get(), BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(args[1])), LocationUtils.fromBlockPos(args[2]), null);
}
}
@@ -171,7 +172,7 @@ public class TrapDoorBlockBehavior extends BukkitBlockBehavior implements IsPath
hasSignal = event.getNewCurrent() > 0;
}
World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
boolean changed = customState.get(this.openProperty) != hasSignal;
if (hasSignal && changed) {
Object abovePos = LocationUtils.above(blockPos);

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.entity;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.util.EntityUtils;
import net.momirealms.craftengine.bukkit.util.LocationUtils;
@@ -62,7 +63,7 @@ public class BukkitEntity extends AbstractEntity {
@Override
public World world() {
return new BukkitWorld(platformEntity().getWorld());
return BukkitAdaptors.adapt(platformEntity().getWorld());
}
@Override

View File

@@ -66,7 +66,7 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
event.setDroppedExp(0);
}
Location location = entity.getLocation();
net.momirealms.craftengine.core.world.World world = new BukkitWorld(entity.getWorld());
net.momirealms.craftengine.core.world.World world = BukkitAdaptors.adapt(entity.getWorld());
WorldPosition position = new WorldPosition(world, location.getX(), location.getY(), location.getZ());
ContextHolder.Builder builder = ContextHolder.builder()
.withParameter(DirectContextParameters.POSITION, position);

View File

@@ -14,6 +14,7 @@ import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.This;
import net.bytebuddy.matcher.ElementMatchers;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
@@ -117,7 +118,7 @@ public final class BlockStateGenerator {
}
Object serverLevel = FastNMS.INSTANCE.method$LootParams$Builder$getLevel(builder);
World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(serverLevel));
World world = BukkitAdaptors.adapt(FastNMS.INSTANCE.method$Level$getCraftWorld(serverLevel));
ContextHolder.Builder lootBuilder = new ContextHolder.Builder()
.withParameter(DirectContextParameters.POSITION, new WorldPosition(world, FastNMS.INSTANCE.field$Vec3$x(vec3), FastNMS.INSTANCE.field$Vec3$y(vec3), FastNMS.INSTANCE.field$Vec3$z(vec3)));
if (!item.isEmpty()) {

View File

@@ -6,6 +6,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
import net.momirealms.craftengine.bukkit.block.entity.BlockEntityHolder;
@@ -1093,7 +1094,7 @@ public class BukkitServerPlayer extends Player {
@Override
public World world() {
return new BukkitWorld(platformPlayer().getWorld());
return BukkitAdaptors.adapt(platformPlayer().getWorld());
}
@Override

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.bukkit.util;
import io.papermc.paper.entity.Shearable;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.item.behavior.BlockItemBehavior;
import net.momirealms.craftengine.bukkit.item.behavior.FlintAndSteelItemBehavior;
@@ -195,7 +196,7 @@ public final class InteractUtils {
&& redstoneWire.getFace(BlockFace.WEST).equals(RedstoneWire.Connection.NONE);
if (isCross || isDot) {
BlockPos blockPos = result.getBlockPos();
BukkitWorld bukkitWorld = new BukkitWorld(player.getWorld());
BukkitWorld bukkitWorld = BukkitAdaptors.adapt(player.getWorld());
World world = bukkitWorld.platformWorld();
Direction[] directions = {Direction.EAST, Direction.WEST, Direction.SOUTH, Direction.NORTH};

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.util;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
import net.momirealms.craftengine.core.world.BlockPos;
@@ -18,7 +19,7 @@ public final class LocationUtils {
}
public static WorldPosition toWorldPosition(Location location) {
return new WorldPosition(new BukkitWorld(location.getWorld()), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw());
return new WorldPosition(BukkitAdaptors.adapt(location.getWorld()), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw());
}
public static Object toVec(Vec3d vec) {

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.world;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
@@ -90,7 +91,7 @@ public class BukkitExistingBlock implements ExistingBlock {
@Override
public World world() {
return new BukkitWorld(this.block.getWorld());
return BukkitAdaptors.adapt(this.block.getWorld());
}
@Override

View File

@@ -31,15 +31,18 @@ import java.util.UUID;
public class BukkitWorld implements World {
private final WeakReference<org.bukkit.World> world;
private final UUID uuid;
private CEWorld ceWorld;
private WorldHeight worldHeight;
public BukkitWorld(org.bukkit.World world) {
public BukkitWorld(@NotNull org.bukkit.World world) {
this.world = new WeakReference<>(world);
this.uuid = world.getUID();
}
@Override
public org.bukkit.World platformWorld() {
return world.get();
return this.world.get();
}
@Override
@@ -139,7 +142,10 @@ public class BukkitWorld implements World {
@Override
public CEWorld storageWorld() {
return BukkitWorldManager.instance().getWorld(uuid());
if (this.ceWorld == null) {
this.ceWorld = BukkitWorldManager.instance().getWorld(uuid());
}
return this.ceWorld;
}
@Override
@@ -156,4 +162,15 @@ public class BukkitWorld implements World {
}
return tracked;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof BukkitWorld that)) return false;
return this.uuid.equals(that.uuid());
}
@Override
public int hashCode() {
return this.uuid.hashCode();
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.world;
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.injector.WorldStorageInjector;
@@ -77,7 +78,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
} else {
World bukkitWorld = Bukkit.getWorld(uuid);
if (bukkitWorld != null) {
world = this.loadWorld(new BukkitWorld(bukkitWorld));
world = this.loadWorld(wrap(bukkitWorld));
}
}
return world;
@@ -95,7 +96,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
public void delayedInit() {
// 此时大概率为空,暂且保留代码
for (World world : Bukkit.getWorlds()) {
BukkitWorld wrappedWorld = new BukkitWorld(world);
BukkitWorld wrappedWorld = wrap(world);
try {
CEWorld ceWorld = this.worlds.computeIfAbsent(world.getUID(), k -> new BukkitCEWorld(wrappedWorld, this.storageAdaptor));
injectChunkGenerator(ceWorld);
@@ -144,7 +145,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
World world = event.getWorld();
UUID uuid = world.getUID();
if (this.worlds.containsKey(uuid)) return;
CEWorld ceWorld = new BukkitCEWorld(new BukkitWorld(world), this.storageAdaptor);
CEWorld ceWorld = new BukkitCEWorld(wrap(world), this.storageAdaptor);
this.worlds.put(uuid, ceWorld);
this.resetWorldArray();
this.injectChunkGenerator(ceWorld);
@@ -165,7 +166,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
}
ceWorld.setTicking(true);
} else {
this.loadWorld(new BukkitWorld(world));
this.loadWorld(wrap(world));
}
}
@@ -217,7 +218,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onWorldUnload(WorldUnloadEvent event) {
unloadWorld(new BukkitWorld(event.getWorld()));
unloadWorld(wrap(event.getWorld()));
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -255,9 +256,9 @@ public class BukkitWorldManager implements WorldManager, Listener {
}
@Override
public <T> net.momirealms.craftengine.core.world.World wrap(T world) {
public <T> BukkitWorld wrap(T world) {
if (world instanceof World w) {
return new BukkitWorld(w);
return BukkitAdaptors.adapt(w);
} else {
throw new IllegalArgumentException(world.getClass() + " is not a Bukkit World");
}

View File

@@ -12,7 +12,7 @@ repositories {
dependencies {
// JOML
compileOnly("org.joml:joml:1.10.8")
compileOnly("org.joml:joml:${rootProject.properties["joml_version"]}")
// YAML
compileOnly(files("${rootProject.rootDir}/libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar"))
compileOnly("org.yaml:snakeyaml:${rootProject.properties["snake_yaml_version"]}")

View File

@@ -14,7 +14,6 @@ public class FurnitureHitBoxTypes {
public static final Key INTERACTION = Key.of("minecraft:interaction");
public static final Key SHULKER = Key.of("minecraft:shulker");
public static final Key HAPPY_GHAST = Key.of("minecraft:happy_ghast");
public static final Key VIRTUAL = Key.of("minecraft:virtual");
public static final Key CUSTOM = Key.of("minecraft:custom");
public static void register(Key key, FurnitureHitBoxConfigFactory<?> factory) {

View File

@@ -14,8 +14,8 @@ public final class RandomUtils {
return min + (max - min) * ThreadLocalRandom.current().nextFloat();
}
public static int generateRandomInt(int min, int max) {
return min >= max ? min : ThreadLocalRandom.current().nextInt(max - min) + min;
public static int generateRandomInt(int minInclusive, int maxExclusive) {
return minInclusive >= maxExclusive ? minInclusive : ThreadLocalRandom.current().nextInt(maxExclusive - minInclusive) + minInclusive;
}
public static boolean generateRandomBoolean() {

View File

@@ -19,6 +19,15 @@ public class WorldPosition implements Position {
this.yRot = 0f;
}
public WorldPosition(World world, Vec3i position) {
this.x = position.x();
this.y = position.y();
this.z = position.z();
this.world = world;
this.xRot = 0f;
this.yRot = 0f;
}
public WorldPosition(World world, Position position, float xRot, float yRot) {
this.x = position.x();
this.y = position.y();