mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
更新nbt库适配1.21.5组件变化
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.util.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.util.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.world.BlockInWorld;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerBlockActionContext extends PlayerOptionalContext {
|
||||
private BlockInWorld block;
|
||||
|
||||
public PlayerBlockActionContext(@NotNull Player player, @NotNull ContextHolder contexts) {
|
||||
super(player, contexts);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public abstract class Entity {
|
||||
|
||||
public abstract float getYRot();
|
||||
|
||||
public abstract World level();
|
||||
public abstract World world();
|
||||
|
||||
public abstract Direction getDirection();
|
||||
|
||||
|
||||
@@ -170,7 +170,8 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
PlayerOptionalContext.of(player, ContextHolder.builder()
|
||||
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
|
||||
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))
|
||||
.build()).tagResolvers())
|
||||
.build())
|
||||
.tagResolvers())
|
||||
);
|
||||
if (emojis.size() >= maxTimes) break;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.momirealms.craftengine.core.font;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.context.ContextKey;
|
||||
|
||||
public class EmojiParameters {
|
||||
public static final ContextKey<String> KEYWORD = new ContextKey<>(Key.of("keyword"));
|
||||
public static final ContextKey<String> EMOJI = new ContextKey<>(Key.of("emoji"));
|
||||
public final class EmojiParameters {
|
||||
private EmojiParameters() {}
|
||||
|
||||
public static final ContextKey<String> KEYWORD = ContextKey.of("keyword");
|
||||
public static final ContextKey<String> EMOJI = ContextKey.of("emoji");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class UseOnContext {
|
||||
private final Item<?> itemStack;
|
||||
|
||||
public UseOnContext(Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
this(player.level(), player, hand, player.getItemInHand(hand), hit);
|
||||
this(player.world(), player, hand, player.getItemInHand(hand), hit);
|
||||
}
|
||||
|
||||
public UseOnContext(World world, Player player, InteractionHand hand, Item<?> stack, BlockHitResult hit) {
|
||||
|
||||
@@ -4,18 +4,19 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.entity.Entity;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.context.ContextKey;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
|
||||
public class LootParameters {
|
||||
public static final ContextKey<Vec3d> LOCATION = new ContextKey<>(Key.of("craftengine:location"));
|
||||
public static final ContextKey<World> WORLD = new ContextKey<>(Key.of("craftengine:world"));
|
||||
public static final ContextKey<Entity> ENTITY = new ContextKey<>(Key.of("craftengine:entity"));
|
||||
public static final ContextKey<Boolean> FALLING_BLOCK = new ContextKey<>(Key.of("craftengine:falling_block"));
|
||||
public static final ContextKey<Float> EXPLOSION_RADIUS = new ContextKey<>(Key.of("craftengine:explosion_radius"));
|
||||
public static final ContextKey<Player> PLAYER = new ContextKey<>(Key.of("craftengine:player"));
|
||||
public static final ContextKey<Item<?>> TOOL = new ContextKey<>(Key.of("craftengine:tool"));
|
||||
public static final ContextKey<ImmutableBlockState> BLOCK_STATE = new ContextKey<>(Key.of("craftengine:block_state"));
|
||||
public final class LootParameters {
|
||||
private LootParameters() {}
|
||||
|
||||
public static final ContextKey<Vec3d> LOCATION = ContextKey.of("location");
|
||||
public static final ContextKey<World> WORLD = ContextKey.of("world");
|
||||
public static final ContextKey<Entity> ENTITY = ContextKey.of("entity");
|
||||
public static final ContextKey<Boolean> FALLING_BLOCK = ContextKey.of("falling_block");
|
||||
public static final ContextKey<Float> EXPLOSION_RADIUS = ContextKey.of("explosion_radius");
|
||||
public static final ContextKey<Player> PLAYER = ContextKey.of("player");
|
||||
public static final ContextKey<Item<?>> TOOL = ContextKey.of("tool");
|
||||
public static final ContextKey<ImmutableBlockState> BLOCK_STATE = ContextKey.of("block_state");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.pack.conflict.matcher;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.conflict.PathContext;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.condition.AllOfCondition;
|
||||
import net.momirealms.craftengine.core.util.context.Condition;
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.pack.conflict.matcher;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.conflict.PathContext;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.util.condition.InvertedCondition;
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
import net.momirealms.craftengine.core.util.condition.AllOfCondition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
import net.kyori.adventure.text.serializer.json.legacyimpl.NBTLegacyHoverEventSerializer;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import net.momirealms.sparrow.nbt.serializer.NBTComponentSerializer;
|
||||
import net.momirealms.sparrow.nbt.serializer.NBTSerializerOptions;
|
||||
|
||||
/**
|
||||
* Helper class for handling Adventure components and related functionalities.
|
||||
@@ -34,8 +35,22 @@ public class AdventureHelper {
|
||||
builder.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get());
|
||||
builder.editOptions((b) -> b.value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, false));
|
||||
}
|
||||
if (!VersionHelper.isOrAbove1_21_5()) {
|
||||
builder.editOptions((b) -> {
|
||||
b.value(JSONOptions.EMIT_CLICK_EVENT_TYPE, JSONOptions.ClickEventValueMode.CAMEL_CASE);
|
||||
b.value(JSONOptions.EMIT_HOVER_EVENT_TYPE, JSONOptions.HoverEventValueMode.CAMEL_CASE);
|
||||
b.value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_KEY_AS_TYPE_AND_UUID_AS_ID, true);
|
||||
});
|
||||
}
|
||||
this.gsonComponentSerializer = builder.build();
|
||||
this.nbtComponentSerializer = NBTComponentSerializer.builder().build();
|
||||
this.nbtComponentSerializer = NBTComponentSerializer.builder()
|
||||
.editOptions((b) -> {
|
||||
if (!VersionHelper.isOrAbove1_21_5()) {
|
||||
b.value(NBTSerializerOptions.EMIT_CLICK_EVENT_TYPE, false);
|
||||
b.value(NBTSerializerOptions.EMIT_HOVER_EVENT_TYPE, false);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private static class SingletonHolder {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.momirealms.craftengine.core.util.context;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.util.context.parameter.BlockParameterProvider;
|
||||
import net.momirealms.craftengine.core.util.context.parameter.CommonParameterProvider;
|
||||
import net.momirealms.craftengine.core.util.context.parameter.PlayerParameterProvider;
|
||||
import net.momirealms.craftengine.core.world.BlockInWorld;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerBlockActionContext extends PlayerOptionalContext {
|
||||
|
||||
public PlayerBlockActionContext(@NotNull Player player, @NotNull BlockInWorld block, @NotNull ContextHolder contexts) {
|
||||
super(player, contexts, List.of(new CommonParameterProvider(), new PlayerParameterProvider(player), new BlockParameterProvider(block)));
|
||||
}
|
||||
|
||||
public static PlayerBlockActionContext of(@NotNull Player player, @NotNull BlockInWorld block, @NotNull ContextHolder contexts) {
|
||||
return new PlayerBlockActionContext(player, block, contexts);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.util.context.parameter.PlayerParameterPro
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerOptionalContext extends AbstractAdditionalCommonContext implements MiniMessageTagContext {
|
||||
public static final PlayerOptionalContext EMPTY = new PlayerOptionalContext(null, ContextHolder.EMPTY);
|
||||
|
||||
@@ -22,6 +22,7 @@ public class BlockParameterProvider implements LazyContextParameterProvider {
|
||||
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_Z, BlockInWorld::z);
|
||||
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_OWNER, BlockInWorld::owner);
|
||||
CONTEXT_FUNCTIONS.put(BlockParameters.BLOCK_STATE, BlockInWorld::getAsString);
|
||||
CONTEXT_FUNCTIONS.put(BlockParameters.WORLD_NAME, b -> b.world().name());
|
||||
}
|
||||
|
||||
private final BlockInWorld block;
|
||||
|
||||
@@ -4,17 +4,16 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.context.ContextKey;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class BlockParameters {
|
||||
private BlockParameters() {}
|
||||
|
||||
public static final ContextKey<Double> X = new ContextKey<>(Key.of("craftengine:block.x"));
|
||||
public static final ContextKey<Double> Y = new ContextKey<>(Key.of("craftengine:block.y"));
|
||||
public static final ContextKey<Double> Z = new ContextKey<>(Key.of("craftengine:block.z"));
|
||||
public static final ContextKey<Integer> BLOCK_X = new ContextKey<>(Key.of("craftengine:block.block_x"));
|
||||
public static final ContextKey<Integer> BLOCK_Y = new ContextKey<>(Key.of("craftengine:block.block_y"));
|
||||
public static final ContextKey<Integer> BLOCK_Z = new ContextKey<>(Key.of("craftengine:block.block_z"));
|
||||
public static final ContextKey<ImmutableBlockState> BLOCK_STATE = new ContextKey<>(Key.of("craftengine:block.state"));
|
||||
public static final ContextKey<Key> BLOCK_OWNER = new ContextKey<>(Key.of("craftengine:block.owner"));
|
||||
public static final ContextKey<Double> X = ContextKey.of("block.x");
|
||||
public static final ContextKey<Double> Y = ContextKey.of("block.y");
|
||||
public static final ContextKey<Double> Z = ContextKey.of("block.z");
|
||||
public static final ContextKey<Integer> BLOCK_X = ContextKey.of("block.block_x");
|
||||
public static final ContextKey<Integer> BLOCK_Y = ContextKey.of("block.block_y");
|
||||
public static final ContextKey<Integer> BLOCK_Z = ContextKey.of("block.block_z");
|
||||
public static final ContextKey<ImmutableBlockState> BLOCK_STATE = ContextKey.of("block.state");
|
||||
public static final ContextKey<Key> BLOCK_OWNER = ContextKey.of("block.owner.id");
|
||||
public static final ContextKey<String> WORLD_NAME = ContextKey.of("block.world.name");
|
||||
}
|
||||
|
||||
@@ -14,7 +14,10 @@ public class CommonParameterProvider implements LazyContextParameterProvider {
|
||||
|
||||
private static final Map<ContextKey<?>, Function<CommonParameterProvider, Object>> CONTEXT_FUNCTIONS = new HashMap<>();
|
||||
static {
|
||||
CONTEXT_FUNCTIONS.put(CommonParameters.RANDOM, (f) -> RandomUtils.generateRandomDouble(0,1));
|
||||
CONTEXT_FUNCTIONS.put(CommonParameters.RANDOM, (f) -> {
|
||||
f.lastRandom = RandomUtils.generateRandomDouble(0,1);
|
||||
return f.lastRandom;
|
||||
});
|
||||
CONTEXT_FUNCTIONS.put(CommonParameters.LAST_RANDOM, (f) -> {
|
||||
if (f.lastRandom == -1) {
|
||||
f.lastRandom = RandomUtils.generateRandomDouble(0, 1);
|
||||
|
||||
@@ -24,6 +24,7 @@ public class PlayerParameterProvider implements LazyContextParameterProvider {
|
||||
CONTEXT_FUNCTIONS.put(PlayerParameters.BLOCK_Z, p -> MCUtils.fastFloor(p.z()));
|
||||
CONTEXT_FUNCTIONS.put(PlayerParameters.NAME, Player::name);
|
||||
CONTEXT_FUNCTIONS.put(PlayerParameters.UUID, Player::uuid);
|
||||
CONTEXT_FUNCTIONS.put(PlayerParameters.WORLD_NAME, p -> p.world().name());
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.util.context.parameter;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.context.ContextKey;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -8,12 +7,13 @@ import java.util.UUID;
|
||||
public final class PlayerParameters {
|
||||
private PlayerParameters() {}
|
||||
|
||||
public static final ContextKey<Double> X = new ContextKey<>(Key.of("craftengine:player.x"));
|
||||
public static final ContextKey<Double> Y = new ContextKey<>(Key.of("craftengine:player.y"));
|
||||
public static final ContextKey<Double> Z = new ContextKey<>(Key.of("craftengine:player.z"));
|
||||
public static final ContextKey<Integer> BLOCK_X = new ContextKey<>(Key.of("craftengine:player.block_x"));
|
||||
public static final ContextKey<Integer> BLOCK_Y = new ContextKey<>(Key.of("craftengine:player.block_y"));
|
||||
public static final ContextKey<Integer> BLOCK_Z = new ContextKey<>(Key.of("craftengine:player.block_z"));
|
||||
public static final ContextKey<String> NAME = new ContextKey<>(Key.of("craftengine:player.name"));
|
||||
public static final ContextKey<UUID> UUID = new ContextKey<>(Key.of("craftengine:player.uuid"));
|
||||
public static final ContextKey<Double> X = ContextKey.of("player.x");
|
||||
public static final ContextKey<Double> Y = ContextKey.of("player.y");
|
||||
public static final ContextKey<Double> Z = ContextKey.of("player.z");
|
||||
public static final ContextKey<Integer> BLOCK_X = ContextKey.of("player.block_x");
|
||||
public static final ContextKey<Integer> BLOCK_Y = ContextKey.of("player.block_y");
|
||||
public static final ContextKey<Integer> BLOCK_Z = ContextKey.of("player.block_z");
|
||||
public static final ContextKey<String> NAME = ContextKey.of("player.name");
|
||||
public static final ContextKey<String> WORLD_NAME = ContextKey.of("player.world.name");
|
||||
public static final ContextKey<UUID> UUID = ContextKey.of("player.uuid");
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ public interface BlockInWorld {
|
||||
|
||||
String getAsString();
|
||||
|
||||
World world();
|
||||
|
||||
int x();
|
||||
|
||||
int y();
|
||||
|
||||
Reference in New Issue
Block a user