9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 20:39:10 +00:00

更新nbt库适配1.21.5组件变化

This commit is contained in:
XiaoMoMi
2025-05-03 19:12:48 +08:00
parent 2b7b218bd3
commit c1aac8c9f8
30 changed files with 109 additions and 144 deletions

View File

@@ -3,8 +3,8 @@ package net.momirealms.craftengine.bukkit.api;
import net.momirealms.craftengine.bukkit.entity.BukkitEntity;
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.bukkit.world.BukkitBlockInWorld;
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;

View File

@@ -49,7 +49,7 @@ public class BukkitEntity extends Entity {
}
@Override
public World level() {
public World world() {
return new BukkitWorld(literalObject().getWorld());
}

View File

@@ -100,7 +100,7 @@ public class ItemEventListener implements Listener {
if (optionalItemBehaviors.isPresent()) {
for (ItemBehavior itemBehavior : optionalItemBehaviors.get()) {
InteractionResult result = itemBehavior.use(player.level(), player, hand);
InteractionResult result = itemBehavior.use(player.world(), player, hand);
if (result == InteractionResult.SUCCESS_AND_CANCEL) {
event.setCancelled(true);
return;
@@ -167,7 +167,7 @@ public class ItemEventListener implements Listener {
event.setCancelled(true);
return;
}
int maxY = player.level().worldHeight().getMaxBuildHeight() - 1;
int maxY = player.world().worldHeight().getMaxBuildHeight() - 1;
if (direction == Direction.UP
&& result != InteractionResult.SUCCESS
&& pos.y() >= maxY

View File

@@ -1,13 +1,16 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import com.saicone.rtag.util.ChatComponent;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.AdventureHelper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.incendo.cloud.Command;
import org.incendo.cloud.parser.standard.StringParser;
public class TestCommand extends BukkitCommandFeature<CommandSender> {
@@ -19,9 +22,12 @@ public class TestCommand extends BukkitCommandFeature<CommandSender> {
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
return builder
.senderType(Player.class)
.required("text", StringParser.greedyStringParser())
.handler(context -> {
Player player = context.sender();
player.getInventory().addItem(BukkitItemManager.instance().createWrappedItem(Key.from("default:topaz"), null).getItem());
plugin().senderFactory().wrap(context.sender()).sendMessage(Component.text(
ChatComponent.toTag(ComponentUtils.adventureToMinecraft(AdventureHelper.miniMessage().deserialize(context.get("text")))).toString()
));
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.miniMessage().deserialize(context.get("text")));
});
}

View File

@@ -1349,7 +1349,7 @@ public class PacketConsumers {
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to handle ServerboundSetCreativeModeSlotPacket", e);
}
}, (World) player.level().platformWorld(), (MCUtils.fastFloor(player.x())) >> 4, (MCUtils.fastFloor(player.z())) >> 4);
}, (World) player.world().platformWorld(), (MCUtils.fastFloor(player.x())) >> 4, (MCUtils.fastFloor(player.z())) >> 4);
} else {
handleSetCreativeSlotPacketOnMainThread(player, packet);
}

View File

@@ -677,7 +677,7 @@ public class BukkitServerPlayer extends Player {
}
@Override
public World level() {
public World world() {
return new BukkitWorld(platformPlayer().getWorld());
}

View File

@@ -11,7 +11,7 @@ public class ParticleUtils {
} catch (IllegalArgumentException e) {
return switch (particle) {
case "REDSTONE" -> Particle.valueOf("DUST");
case "VILLAGER_HAPPY" -> Particle.valueOf(VersionHelper.isOrAbove1_20_5() ? "HAPPY_VILLAGER" : "VILLAGER_HAPPY");
case "VILLAGER_HAPPY", "HAPPY_VILLAGER" -> Particle.valueOf(VersionHelper.isOrAbove1_20_5() ? "HAPPY_VILLAGER" : "VILLAGER_HAPPY");
default -> Particle.valueOf(particle);
};
}

View File

@@ -14,9 +14,9 @@ import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.text.minimessage.NamedArgumentTag;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.world.BlockInWorld;
import net.momirealms.craftengine.core.world.World;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
@@ -80,6 +80,11 @@ public class BukkitBlockInWorld implements BlockInWorld {
return this.block.getZ();
}
@Override
public World world() {
return new BukkitWorld(this.block.getWorld());
}
@Override
public String getAsString() {
ImmutableBlockState state = CraftEngineBlocks.getCustomBlockState(this.block);

View File

@@ -6,9 +6,9 @@ import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.BlockInWorld;
import net.momirealms.craftengine.core.world.Vec3d;
import net.momirealms.craftengine.core.world.World;
import net.momirealms.craftengine.core.world.BlockInWorld;
import net.momirealms.craftengine.core.world.WorldHeight;
import org.bukkit.Location;
import org.bukkit.SoundCategory;