9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 17:09:19 +00:00

Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
jhqwqmc
2025-05-02 20:52:23 +08:00
64 changed files with 397 additions and 240 deletions

View File

@@ -4,7 +4,7 @@ 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.BukkitWorldBlock;
import net.momirealms.craftengine.bukkit.world.BukkitBlockInWorld;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
@@ -26,7 +26,7 @@ public final class BukkitAdaptors {
return new BukkitEntity(entity);
}
public static BukkitWorldBlock adapt(final Block block) {
return new BukkitWorldBlock(block);
public static BukkitBlockInWorld adapt(final Block block) {
return new BukkitBlockInWorld(block);
}
}

View File

@@ -148,10 +148,10 @@ public class CropBlockBehavior extends BushBlockBehavior {
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
net.momirealms.craftengine.core.world.World wrappedWorld = new BukkitWorld(world);
int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, ContextHolder.builder()
int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, 1, ThreadLocalRandom.current(), ContextHolder.builder()
.withParameter(LootParameters.WORLD, wrappedWorld)
.withParameter(LootParameters.LOCATION, Vec3d.atCenterOf(new Vec3i(x, y, z)))
.build(), ThreadLocalRandom.current(), 1));
.build()));
int maxAge = this.ageProperty.max;
if (i > maxAge) {
i = maxAge;

View File

@@ -4,7 +4,7 @@ import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.block.behavior.StrippableBlockBehavior;
import net.momirealms.craftengine.bukkit.util.*;
import net.momirealms.craftengine.bukkit.world.BukkitWorldBlock;
import net.momirealms.craftengine.bukkit.world.BukkitBlockInWorld;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.block.UpdateOption;
@@ -43,7 +43,7 @@ public class AxeItemBehavior extends ItemBehavior {
@SuppressWarnings("unchecked")
@Override
public InteractionResult useOnBlock(UseOnContext context) {
BukkitWorldBlock clicked = (BukkitWorldBlock) context.getLevel().getBlockAt(context.getClickedPos());
BukkitBlockInWorld clicked = (BukkitBlockInWorld) context.getLevel().getBlockAt(context.getClickedPos());
Block block = clicked.block();
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
if (state == null || state.isEmpty()) return InteractionResult.PASS;

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.LocationUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.bukkit.world.BukkitWorldBlock;
import net.momirealms.craftengine.bukkit.world.BukkitBlockInWorld;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.entity.player.InteractionResult;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
@@ -32,7 +32,7 @@ public class BoneMealItemBehavior extends ItemBehavior {
return InteractionResult.PASS;
}
BukkitWorldBlock clicked = (BukkitWorldBlock) context.getLevel().getBlockAt(context.getClickedPos());
BukkitBlockInWorld clicked = (BukkitBlockInWorld) context.getLevel().getBlockAt(context.getClickedPos());
Block block = clicked.block();
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
if (state == null || state.isEmpty()) return InteractionResult.PASS;

View File

@@ -4,7 +4,7 @@ import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.world.BukkitWorldBlock;
import net.momirealms.craftengine.bukkit.world.BukkitBlockInWorld;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.block.UpdateOption;
@@ -35,7 +35,7 @@ public class BucketItemBehavior extends ItemBehavior {
@Override
public InteractionResult useOnBlock(UseOnContext context) {
if (context.getPlayer().isAdventureMode()) return InteractionResult.PASS;
BukkitWorldBlock clicked = (BukkitWorldBlock) context.getLevel().getBlockAt(context.getClickedPos());
BukkitBlockInWorld clicked = (BukkitBlockInWorld) context.getLevel().getBlockAt(context.getClickedPos());
Block block = clicked.block();
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
if (state == null || state.isEmpty()) return InteractionResult.PASS;

View File

@@ -4,7 +4,7 @@ import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.world.BukkitWorldBlock;
import net.momirealms.craftengine.bukkit.world.BukkitBlockInWorld;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.block.UpdateOption;
@@ -33,7 +33,7 @@ public class WaterBucketItemBehavior extends ItemBehavior {
public InteractionResult useOnBlock(UseOnContext context) {
if (context.getPlayer().isAdventureMode()) return InteractionResult.PASS;
BlockPos pos = context.getClickedPos();
BukkitWorldBlock clicked = (BukkitWorldBlock) context.getLevel().getBlockAt(pos);
BukkitBlockInWorld clicked = (BukkitBlockInWorld) context.getLevel().getBlockAt(pos);
Block block = clicked.block();
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
if (state == null || state.isEmpty()) return InteractionResult.PASS;

View File

@@ -12,25 +12,26 @@ 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.WorldBlock;
import net.momirealms.craftengine.core.world.BlockInWorld;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import java.util.Optional;
public class BukkitWorldBlock implements WorldBlock {
public class BukkitBlockInWorld implements BlockInWorld {
private final Block block;
public BukkitWorldBlock(Block block) {
public BukkitBlockInWorld(Block block) {
this.block = block;
}
@SuppressWarnings("unchecked")
@Override
public boolean canBeReplaced(BlockPlaceContext context) {
ImmutableBlockState customState = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockDataToId(block.getBlockData()));
ImmutableBlockState customState = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockDataToId(this.block.getBlockData()));
if (customState != null && !customState.isEmpty()) {
Key clickedBlockId = customState.owner().value().id();
Item<ItemStack> item = (Item<ItemStack>) context.getPlayer().getItemInHand(context.getHand());
@@ -45,14 +46,14 @@ public class BukkitWorldBlock implements WorldBlock {
}
}
}
return block.isReplaceable();
return this.block.isReplaceable();
}
@Override
public boolean isWaterSource(BlockPlaceContext blockPlaceContext) {
try {
Location location = block.getLocation();
Object serverLevel = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(block.getWorld());
Location location = this.block.getLocation();
Object serverLevel = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(this.block.getWorld());
Object fluidData = Reflections.method$Level$getFluidState.invoke(serverLevel, LocationUtils.toBlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
if (fluidData == null) return false;
return Reflections.method$FluidState$getType.invoke(fluidData) == Reflections.instance$Fluids$WATER;
@@ -62,6 +63,21 @@ public class BukkitWorldBlock implements WorldBlock {
}
}
@Override
public int x() {
return this.block.getX();
}
@Override
public int y() {
return this.block.getY();
}
@Override
public int z() {
return this.block.getZ();
}
public Block block() {
return block;
}

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.Vec3d;
import net.momirealms.craftengine.core.world.World;
import net.momirealms.craftengine.core.world.WorldBlock;
import net.momirealms.craftengine.core.world.BlockInWorld;
import net.momirealms.craftengine.core.world.WorldHeight;
import org.bukkit.Location;
import org.bukkit.SoundCategory;
@@ -51,8 +51,8 @@ public class BukkitWorld implements World {
}
@Override
public WorldBlock getBlockAt(int x, int y, int z) {
return new BukkitWorldBlock(platformWorld().getBlockAt(x, y, z));
public BlockInWorld getBlockAt(int x, int y, int z) {
return new BukkitBlockInWorld(platformWorld().getBlockAt(x, y, z));
}
@Override

View File

@@ -0,0 +1,15 @@
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);
}
}

View File

@@ -11,7 +11,7 @@ import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigExce
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.util.context.PlayerContext;
import net.momirealms.craftengine.core.util.context.PlayerOptionalContext;
import org.ahocorasick.trie.Token;
import org.ahocorasick.trie.Trie;
import org.jetbrains.annotations.NotNull;
@@ -121,7 +121,7 @@ public abstract class AbstractFontManager implements FontManager {
continue;
Component content = AdventureHelper.miniMessage().deserialize(
emoji.content(),
PlayerContext.of(player, ContextHolder.builder()
PlayerOptionalContext.of(player, ContextHolder.builder()
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))
.build()).tagResolvers()
@@ -167,7 +167,7 @@ public abstract class AbstractFontManager implements FontManager {
continue;
emojis.put(fragment, AdventureHelper.miniMessage().deserialize(
emoji.content(),
PlayerContext.of(player, ContextHolder.builder()
PlayerOptionalContext.of(player, ContextHolder.builder()
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))
.build()).tagResolvers())
@@ -199,7 +199,7 @@ public abstract class AbstractFontManager implements FontManager {
continue;
emojis.put(fragment, AdventureHelper.miniMessage().deserialize(
emoji.content(),
PlayerContext.of(player,
PlayerOptionalContext.of(player,
ContextHolder.builder()
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))

View File

@@ -2,11 +2,11 @@ package net.momirealms.craftengine.core.item;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.util.context.PlayerContext;
import net.momirealms.craftengine.core.util.context.PlayerOptionalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ItemBuildContext extends PlayerContext {
public class ItemBuildContext extends PlayerOptionalContext {
public static final ItemBuildContext EMPTY = new ItemBuildContext(null, ContextHolder.EMPTY);
public ItemBuildContext(@Nullable Player player, @NotNull ContextHolder contexts) {

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.loot;
import net.momirealms.craftengine.core.util.context.CommonContext;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.util.context.ContextKey;
import net.momirealms.craftengine.core.world.World;
@@ -7,43 +8,26 @@ import net.momirealms.craftengine.core.world.World;
import java.util.Optional;
import java.util.Random;
public class LootContext {
public class LootContext extends CommonContext {
private final World world;
private final ContextHolder contexts;
private final Random randomSource;
private final float luck;
public LootContext(World world, ContextHolder contexts, Random randomSource, float luck) {
public LootContext(World world, float luck, Random randomSource, ContextHolder contexts) {
super(contexts);
this.randomSource = randomSource;
this.contexts = contexts;
this.world = world;
this.luck = luck;
}
public Random randomSource() {
return randomSource;
}
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
return this.contexts.getOptional(parameter);
}
public boolean hasParameter(ContextKey<?> parameter) {
return this.contexts.has(parameter);
}
public <T> T getParameterOrThrow(ContextKey<T> parameter) {
return this.contexts.getOrThrow(parameter);
return this.randomSource;
}
public float luck() {
return luck;
}
public ContextHolder contexts() {
return contexts;
}
public World world() {
return world;
}

View File

@@ -80,7 +80,7 @@ public class LootTable<T> {
}
public ArrayList<Item<T>> getRandomItems(ContextHolder parameters, World world) {
return this.getRandomItems(new LootContext(world, parameters, ThreadLocalRandom.current(), 1));
return this.getRandomItems(new LootContext(world, 1, ThreadLocalRandom.current(), parameters));
}
private ArrayList<Item<T>> getRandomItems(LootContext context) {

View File

@@ -6,11 +6,11 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.List;
import java.util.Map;
public class AllOfCondition implements LootCondition {
public class LootConditionAllOf implements LootCondition {
public static final Factory FACTORY = new Factory();
private final List<LootCondition> conditions;
public AllOfCondition(List<LootCondition> conditions) {
public LootConditionAllOf(List<LootCondition> conditions) {
this.conditions = conditions;
}
@@ -30,11 +30,12 @@ public class AllOfCondition implements LootCondition {
}
public static class Factory implements LootConditionFactory {
@SuppressWarnings("unchecked")
@Override
public LootCondition create(Map<String, Object> arguments) {
List<Map<String, Object>> terms = (List<Map<String, Object>>) arguments.get("terms");
return new AllOfCondition(LootConditions.fromMapList(terms));
return new LootConditionAllOf(LootConditions.fromMapList(terms));
}
}
}

View File

@@ -6,11 +6,11 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.List;
import java.util.Map;
public class AnyOfCondition implements LootCondition {
public class LootConditionAnyOf implements LootCondition {
public static final Factory FACTORY = new Factory();
private final List<LootCondition> conditions;
public AnyOfCondition(List<LootCondition> conditions) {
public LootConditionAnyOf(List<LootCondition> conditions) {
this.conditions = conditions;
}
@@ -34,7 +34,7 @@ public class AnyOfCondition implements LootCondition {
@Override
public LootCondition create(Map<String, Object> arguments) {
List<Map<String, Object>> terms = (List<Map<String, Object>>) arguments.get("terms");
return new AnyOfCondition(LootConditions.fromMapList(terms));
return new LootConditionAnyOf(LootConditions.fromMapList(terms));
}
}
}

View File

@@ -10,12 +10,12 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
public class EnchantmentCondition implements LootCondition {
public class LootConditionEnchantment implements LootCondition {
public static final Factory FACTORY = new Factory();
private final Key id;
private final Function<Integer, Boolean> expression;
public EnchantmentCondition(Key id, Function<Integer, Boolean> expression) {
public LootConditionEnchantment(Key id, Function<Integer, Boolean> expression) {
this.id = id;
this.expression = expression;
}
@@ -50,7 +50,7 @@ public class EnchantmentCondition implements LootCondition {
case ">=" -> expression = (i -> i >= level);
default -> throw new IllegalArgumentException("Unknown operator: " + operator);
}
return new EnchantmentCondition(Key.of(split[0]), expression);
return new LootConditionEnchantment(Key.of(split[0]), expression);
}
}
}

View File

@@ -6,9 +6,9 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
public class FallingCondition implements LootCondition {
public class LootConditionFalling implements LootCondition {
public static final Factory FACTORY = new Factory();
public static final FallingCondition INSTANCE = new FallingCondition();
public static final LootConditionFalling INSTANCE = new LootConditionFalling();
@Override
public Key type() {

View File

@@ -5,11 +5,11 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
public class InvertedCondition implements LootCondition {
public class LootConditionInverted implements LootCondition {
public static final Factory FACTORY = new Factory();
private final LootCondition condition;
public InvertedCondition(LootCondition condition) {
public LootConditionInverted(LootCondition condition) {
this.condition = condition;
}
@@ -28,7 +28,7 @@ public class InvertedCondition implements LootCondition {
@Override
public LootCondition create(Map<String, Object> arguments) {
Map<String, Object> term = (Map<String, Object>) arguments.get("term");
return new InvertedCondition(LootConditions.fromMap(term));
return new LootConditionInverted(LootConditions.fromMap(term));
}
}
}

View File

@@ -12,11 +12,11 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
public class MatchBlockPropertyCondition implements LootCondition {
public class LootConditionMatchBlockProperty implements LootCondition {
public static final Factory FACTORY = new Factory();
private final List<Pair<String, String>> properties;
public MatchBlockPropertyCondition(List<Pair<String, String>> properties) {
public LootConditionMatchBlockProperty(List<Pair<String, String>> properties) {
this.properties = properties;
}
@@ -55,7 +55,7 @@ public class MatchBlockPropertyCondition implements LootCondition {
for (Map.Entry<String, Object> entry : properties.entrySet()) {
propertyList.add(new Pair<>(entry.getKey(), entry.getValue().toString()));
}
return new MatchBlockPropertyCondition(propertyList);
return new LootConditionMatchBlockProperty(propertyList);
}
}
}

View File

@@ -8,12 +8,12 @@ import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.*;
public class MatchItemCondition implements LootCondition {
public class LootConditionMatchItem implements LootCondition {
public static final Factory FACTORY = new Factory();
private final Set<String> ids;
private final boolean regexMatch;
public MatchItemCondition(Collection<String> ids, boolean regexMatch) {
public LootConditionMatchItem(Collection<String> ids, boolean regexMatch) {
this.ids = new HashSet<>(ids);
this.regexMatch = regexMatch;
}
@@ -46,7 +46,7 @@ public class MatchItemCondition implements LootCondition {
public LootCondition create(Map<String, Object> arguments) {
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
boolean regex = (boolean) arguments.getOrDefault("regex", false);
return new MatchItemCondition(ids, regex);
return new LootConditionMatchItem(ids, regex);
}
}
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class RandomCondition implements LootCondition {
public class LootConditionRandom implements LootCondition {
public static final Factory FACTORY = new Factory();
private final float chance;
public RandomCondition(float chance) {
public LootConditionRandom(float chance) {
this.chance = chance;
}
@@ -29,7 +29,7 @@ public class RandomCondition implements LootCondition {
@Override
public LootCondition create(Map<String, Object> arguments) {
float chance = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("value", 0.5f), "value");
return new RandomCondition(chance);
return new LootConditionRandom(chance);
}
}
}

View File

@@ -7,9 +7,9 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
import java.util.Optional;
public class SurvivesExplosionCondition implements LootCondition {
public class LootConditionSurvivesExplosion implements LootCondition {
public static final Factory FACTORY = new Factory();
private static final SurvivesExplosionCondition INSTANCE = new SurvivesExplosionCondition();
private static final LootConditionSurvivesExplosion INSTANCE = new LootConditionSurvivesExplosion();
@Override
public Key type() {

View File

@@ -13,12 +13,12 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class TableBonusCondition implements LootCondition {
public class LootConditionTableBonus implements LootCondition {
public static final Factory FACTORY = new Factory();
private final Key enchantmentType;
private final List<Float> values;
public TableBonusCondition(Key enchantmentType, List<Float> values) {
public LootConditionTableBonus(Key enchantmentType, List<Float> values) {
this.enchantmentType = enchantmentType;
this.values = values;
}
@@ -47,13 +47,13 @@ public class TableBonusCondition implements LootCondition {
Object chances = arguments.get("chances");
if (chances != null) {
if (chances instanceof Number number) {
return new TableBonusCondition(enchantmentType, List.of(number.floatValue()));
return new LootConditionTableBonus(enchantmentType, List.of(number.floatValue()));
} else if (chances instanceof List<?> list) {
List<Float> values = new ArrayList<>(list.size());
for (Object o : list) {
values.add(ResourceConfigUtils.getAsFloat(o, "chances"));
}
return new TableBonusCondition(enchantmentType, values);
return new LootConditionTableBonus(enchantmentType, values);
}
}
throw new LocalizedResourceConfigException("warning.config.loot_table.condition.table_bonus.missing_chances");

View File

@@ -26,16 +26,16 @@ public class LootConditions {
public static final Key FALLING_BLOCK = Key.from("craftengine:falling_block");
static {
register(MATCH_ITEM, MatchItemCondition.FACTORY);
register(MATCH_BLOCK_PROPERTY, MatchBlockPropertyCondition.FACTORY);
register(TABLE_BONUS, TableBonusCondition.FACTORY);
register(SURVIVES_EXPLOSION, SurvivesExplosionCondition.FACTORY);
register(ANY_OF, AnyOfCondition.FACTORY);
register(ALL_OF, AllOfCondition.FACTORY);
register(ENCHANTMENT, EnchantmentCondition.FACTORY);
register(INVERTED, InvertedCondition.FACTORY);
register(FALLING_BLOCK, FallingCondition.FACTORY);
register(RANDOM, RandomCondition.FACTORY);
register(MATCH_ITEM, LootConditionMatchItem.FACTORY);
register(MATCH_BLOCK_PROPERTY, LootConditionMatchBlockProperty.FACTORY);
register(TABLE_BONUS, LootConditionTableBonus.FACTORY);
register(SURVIVES_EXPLOSION, LootConditionSurvivesExplosion.FACTORY);
register(ANY_OF, LootConditionAnyOf.FACTORY);
register(ALL_OF, LootConditionAllOf.FACTORY);
register(ENCHANTMENT, LootConditionEnchantment.FACTORY);
register(INVERTED, LootConditionInverted.FACTORY);
register(FALLING_BLOCK, LootConditionFalling.FACTORY);
register(RANDOM, LootConditionRandom.FACTORY);
}
public static void register(Key key, LootConditionFactory factory) {

View File

@@ -19,12 +19,12 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
public class ApplyBonusCountFunction<T> extends AbstractLootConditionalFunction<T> {
public class LootFunctionApplyBonusCount<T> extends AbstractLootConditionalFunction<T> {
public static final Factory<?> FACTORY = new Factory<>();
private final Key enchantment;
private final Formula formula;
public ApplyBonusCountFunction(List<LootCondition> predicates, Key enchantment, Formula formula) {
public LootFunctionApplyBonusCount(List<LootCondition> predicates, Key enchantment, Formula formula) {
super(predicates);
this.enchantment = enchantment;
this.formula = formula;
@@ -57,7 +57,7 @@ public class ApplyBonusCountFunction<T> extends AbstractLootConditionalFunction<
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());
return new ApplyBonusCountFunction<>(conditions, Key.from(enchantment), Formulas.fromMap(formulaMap));
return new LootFunctionApplyBonusCount<>(conditions, Key.from(enchantment), Formulas.fromMap(formulaMap));
}
}

View File

@@ -15,11 +15,11 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class DropExpFunction<T> extends AbstractLootConditionalFunction<T> {
public class LootFunctionDropExp<T> extends AbstractLootConditionalFunction<T> {
public static final Factory<?> FACTORY = new Factory<>();
private final NumberProvider value;
public DropExpFunction(NumberProvider value, List<LootCondition> predicates) {
public LootFunctionDropExp(NumberProvider value, List<LootCondition> predicates) {
super(predicates);
this.value = value;
}
@@ -44,7 +44,7 @@ public class DropExpFunction<T> extends AbstractLootConditionalFunction<T> {
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());
return new DropExpFunction<>(NumberProviders.fromObject(value), conditions);
return new LootFunctionDropExp<>(NumberProviders.fromObject(value), conditions);
}
}
}

View File

@@ -9,10 +9,10 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.*;
public class ExplosionDecayFunction<T> extends AbstractLootConditionalFunction<T> {
public class LootFunctionExplosionDecay<T> extends AbstractLootConditionalFunction<T> {
public static final Factory<?> FACTORY = new Factory<>();
public ExplosionDecayFunction(List<LootCondition> predicates) {
public LootFunctionExplosionDecay(List<LootCondition> predicates) {
super(predicates);
}
@@ -46,7 +46,7 @@ public class ExplosionDecayFunction<T> extends AbstractLootConditionalFunction<T
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());
return new ExplosionDecayFunction<>(conditions);
return new LootFunctionExplosionDecay<>(conditions);
}
}
}

View File

@@ -14,13 +14,13 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class SetCountFunction<T> extends AbstractLootConditionalFunction<T> {
public class LootFunctionSetCount<T> extends AbstractLootConditionalFunction<T> {
public static final Factory<?> FACTORY = new Factory<>();
private final NumberProvider value;
private final boolean add;
public SetCountFunction(List<LootCondition> conditions, NumberProvider value, boolean add) {
public LootFunctionSetCount(List<LootCondition> conditions, NumberProvider value, boolean add) {
super(conditions);
this.value = value;
this.add = add;
@@ -47,7 +47,7 @@ public class SetCountFunction<T> extends AbstractLootConditionalFunction<T> {
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());
return new SetCountFunction<>(conditions, NumberProviders.fromObject(value), add);
return new LootFunctionSetCount<>(conditions, NumberProviders.fromObject(value), add);
}
}
}

View File

@@ -23,10 +23,10 @@ public class LootFunctions {
public static final Key DROP_EXP = Key.from("craftengine:drop_exp");
static {
register(SET_COUNT, SetCountFunction.FACTORY);
register(EXPLOSION_DECAY, ExplosionDecayFunction.FACTORY);
register(APPLY_BONUS, ApplyBonusCountFunction.FACTORY);
register(DROP_EXP, DropExpFunction.FACTORY);
register(SET_COUNT, LootFunctionSetCount.FACTORY);
register(EXPLOSION_DECAY, LootFunctionExplosionDecay.FACTORY);
register(APPLY_BONUS, LootFunctionApplyBonusCount.FACTORY);
register(DROP_EXP, LootFunctionDropExp.FACTORY);
}
public static <T> void register(Key key, LootFunctionFactory<T> factory) {

View File

@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.font.BitmapImage;
import net.momirealms.craftengine.core.font.Font;
import net.momirealms.craftengine.core.item.EquipmentData;
import net.momirealms.craftengine.core.pack.conflict.PathContext;
import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution;
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional;
import net.momirealms.craftengine.core.pack.host.ResourcePackHost;
import net.momirealms.craftengine.core.pack.host.ResourcePackHosts;
import net.momirealms.craftengine.core.pack.host.impl.NoneHost;
@@ -1159,7 +1159,7 @@ public abstract class AbstractPackManager implements PackManager {
PathContext relativeCTX = PathContext.of(relative);
PathContext targetCTX = PathContext.of(targetPath);
PathContext fileCTX = PathContext.of(file);
for (ConditionalResolution resolution : Config.resolutions()) {
for (ResolutionConditional resolution : Config.resolutions()) {
if (resolution.matcher().test(relativeCTX)) {
resolution.resolution().run(targetCTX, fileCTX);
return FileVisitResult.CONTINUE;

View File

@@ -10,18 +10,13 @@ import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
import java.util.Map;
public class AllOfPathMatcher extends AllOfCondition<PathContext> implements PathMatcher {
public class PathMatcherAllOf extends AllOfCondition<PathContext> implements PathMatcher {
public static final Factory FACTORY = new Factory();
public AllOfPathMatcher(List<? extends Condition<PathContext>> conditions) {
public PathMatcherAllOf(List<? extends Condition<PathContext>> conditions) {
super(conditions);
}
@Override
public Key type() {
return PathMatchers.ALL_OF;
}
public static class Factory implements PathMatcherFactory {
@SuppressWarnings("unchecked")
@@ -30,10 +25,10 @@ public class AllOfPathMatcher extends AllOfCondition<PathContext> implements Pat
Object termsObj = arguments.get("terms");
if (termsObj instanceof List<?> list) {
List<Map<String, Object>> terms = (List<Map<String, Object>>) list;
return new AllOfPathMatcher(PathMatchers.fromMapList(terms));
return new PathMatcherAllOf(PathMatchers.fromMapList(terms));
} else if (termsObj instanceof Map<?, ?>) {
Map<String, Object> terms = MiscUtils.castToMap(termsObj, false);
return new AllOfPathMatcher(PathMatchers.fromMapList(List.of(terms)));
return new PathMatcherAllOf(PathMatchers.fromMapList(List.of(terms)));
} else {
throw new LocalizedException("warning.config.conflict_matcher.all_of.missing_terms");
}

View File

@@ -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.AnyOfCondition;
import net.momirealms.craftengine.core.util.context.Condition;
@@ -10,18 +9,13 @@ import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
import java.util.Map;
public class AnyOfPathMatcher extends AnyOfCondition<PathContext> implements PathMatcher {
public class PathMatcherAnyOf extends AnyOfCondition<PathContext> implements PathMatcher {
public static final Factory FACTORY = new Factory();
public AnyOfPathMatcher(List<? extends Condition<PathContext>> conditions) {
public PathMatcherAnyOf(List<? extends Condition<PathContext>> conditions) {
super(conditions);
}
@Override
public Key type() {
return PathMatchers.ANY_OF;
}
public static class Factory implements PathMatcherFactory {
@SuppressWarnings("unchecked")
@@ -30,10 +24,10 @@ public class AnyOfPathMatcher extends AnyOfCondition<PathContext> implements Pat
Object termsObj = arguments.get("terms");
if (termsObj instanceof List<?> list) {
List<Map<String, Object>> terms = (List<Map<String, Object>>) list;
return new AnyOfPathMatcher(PathMatchers.fromMapList(terms));
return new PathMatcherAnyOf(PathMatchers.fromMapList(terms));
} else if (termsObj instanceof Map<?, ?>) {
Map<String, Object> terms = MiscUtils.castToMap(termsObj, false);
return new AnyOfPathMatcher(PathMatchers.fromMapList(List.of(terms)));
return new PathMatcherAnyOf(PathMatchers.fromMapList(List.of(terms)));
} else {
throw new LocalizedException("warning.config.conflict_matcher.any_of.missing_terms");
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class PathContainsMatcher implements PathMatcher {
public class PathMatcherContains implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String path;
public PathContainsMatcher(String path) {
public PathMatcherContains(String path) {
this.path = path;
}
@@ -31,7 +31,7 @@ public class PathContainsMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path"));
return new PathContainsMatcher(path);
return new PathMatcherContains(path);
}
}
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class ExactPathMatcher implements PathMatcher {
public class PathMatcherExact implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String path;
public ExactPathMatcher(String path) {
public PathMatcherExact(String path) {
this.path = path;
}
@@ -31,7 +31,7 @@ public class ExactPathMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path"));
return new ExactPathMatcher(path);
return new PathMatcherExact(path);
}
}
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class FilenameMatcher implements PathMatcher {
public class PathMatcherFilename implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String name;
public FilenameMatcher(String name) {
public PathMatcherFilename(String name) {
this.name = name;
}
@@ -31,7 +31,7 @@ public class FilenameMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name"));
return new FilenameMatcher(name);
return new PathMatcherFilename(name);
}
}
}

View File

@@ -9,25 +9,20 @@ import net.momirealms.craftengine.core.util.condition.InvertedCondition;
import java.util.Map;
public class InvertedPathMatcher extends InvertedCondition<PathContext> implements PathMatcher {
public class PathMatcherInverted extends InvertedCondition<PathContext> implements PathMatcher {
public static final Factory FACTORY = new Factory();
public InvertedPathMatcher(PathMatcher condition) {
public PathMatcherInverted(PathMatcher condition) {
super(condition);
}
@Override
public Key type() {
return PathMatchers.INVERTED;
}
public static class Factory implements PathMatcherFactory {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object inverted = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("term"), () -> new LocalizedException("warning.config.conflict_matcher.inverted.missing_term"));
Map<String, Object> term = MiscUtils.castToMap(inverted, false);
return new InvertedPathMatcher(PathMatchers.fromMap(term));
return new PathMatcherInverted(PathMatchers.fromMap(term));
}
}
}

View File

@@ -8,11 +8,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
public class ParentPathPrefixMatcher implements PathMatcher {
public class PathMatcherParentPrefix implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String prefix;
public ParentPathPrefixMatcher(String prefix) {
public PathMatcherParentPrefix(String prefix) {
this.prefix = prefix;
}
@@ -34,7 +34,7 @@ public class ParentPathPrefixMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix"));
return new ParentPathPrefixMatcher(prefix);
return new PathMatcherParentPrefix(prefix);
}
}
}

View File

@@ -8,11 +8,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
public class ParentPathSuffixMatcher implements PathMatcher {
public class PathMatcherParentSuffix implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String suffix;
public ParentPathSuffixMatcher(String suffix) {
public PathMatcherParentSuffix(String suffix) {
this.suffix = suffix;
}
@@ -34,7 +34,7 @@ public class ParentPathSuffixMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix"));
return new ParentPathSuffixMatcher(suffix);
return new PathMatcherParentSuffix(suffix);
}
}
}

View File

@@ -8,6 +8,7 @@ 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;
@@ -25,15 +26,15 @@ public class PathMatchers {
public static final Key INVERTED = Key.of("craftengine:inverted");
static {
register(PARENT_PATH_SUFFIX, ParentPathSuffixMatcher.FACTORY);
register(PARENT_PATH_PREFIX, ParentPathPrefixMatcher.FACTORY);
register(PARENT_PATH_SUFFIX, PathMatcherParentSuffix.FACTORY);
register(PARENT_PATH_PREFIX, PathMatcherParentPrefix.FACTORY);
register(PATTERN, PathPatternMatcher.FACTORY);
register(EXACT, ExactPathMatcher.FACTORY);
register(FILENAME, FilenameMatcher.FACTORY);
register(ANY_OF, AnyOfPathMatcher.FACTORY);
register(ALL_OF, AllOfPathMatcher.FACTORY);
register(INVERTED, InvertedPathMatcher.FACTORY);
register(CONTAINS, PathContainsMatcher.FACTORY);
register(EXACT, PathMatcherExact.FACTORY);
register(FILENAME, PathMatcherFilename.FACTORY);
register(ANY_OF, PathMatcherAnyOf.FACTORY);
register(ALL_OF, PathMatcherAllOf.FACTORY);
register(INVERTED, PathMatcherInverted.FACTORY);
register(CONTAINS, PathMatcherContains.FACTORY);
}
public static void register(Key key, PathMatcherFactory factory) {

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.Map;
public record ConditionalResolution(PathMatcher matcher, Resolution resolution) implements Resolution {
public record ResolutionConditional(PathMatcher matcher, Resolution resolution) implements Resolution {
public static final Factory FACTORY = new Factory();
@Override
@@ -26,10 +26,10 @@ public record ConditionalResolution(PathMatcher matcher, Resolution resolution)
public static class Factory implements ResolutionFactory {
@Override
public ConditionalResolution create(Map<String, Object> arguments) {
public ResolutionConditional create(Map<String, Object> arguments) {
Map<String, Object> term = MiscUtils.castToMap(arguments.get("term"), false);
Map<String, Object> resolution = MiscUtils.castToMap(arguments.get("resolution"), false);
return new ConditionalResolution(PathMatchers.fromMap(term), Resolutions.fromMap(resolution));
return new ResolutionConditional(PathMatchers.fromMap(term), Resolutions.fromMap(resolution));
}
}
}

View File

@@ -12,9 +12,9 @@ import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
public class MergeAltasResolution implements Resolution {
public class ResolutionMergeAltas implements Resolution {
public static final Factory FACTORY = new Factory();
public static final MergeAltasResolution INSTANCE = new MergeAltasResolution();
public static final ResolutionMergeAltas INSTANCE = new ResolutionMergeAltas();
@Override
public void run(PathContext existing, PathContext conflict) {

View File

@@ -9,11 +9,11 @@ import net.momirealms.craftengine.core.util.Key;
import java.io.IOException;
import java.util.Map;
public class MergeJsonResolution implements Resolution {
public class ResolutionMergeJson implements Resolution {
public static final Factory FACTORY = new Factory();
private final boolean deeply;
public MergeJsonResolution(boolean deeply) {
public ResolutionMergeJson(boolean deeply) {
this.deeply = deeply;
}
@@ -44,7 +44,7 @@ public class MergeJsonResolution implements Resolution {
@Override
public Resolution create(Map<String, Object> arguments) {
boolean deeply = (boolean) arguments.getOrDefault("deeply", false);
return new MergeJsonResolution(deeply);
return new ResolutionMergeJson(deeply);
}
}
}

View File

@@ -11,11 +11,11 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
public class MergePackMcMetaResolution implements Resolution {
public class ResolutionMergePackMcMeta implements Resolution {
public static final Factory FACTORY = new Factory();
private final String description;
public MergePackMcMetaResolution(String description) {
public ResolutionMergePackMcMeta(String description) {
this.description = description;
}
@@ -209,7 +209,7 @@ public class MergePackMcMetaResolution implements Resolution {
@Override
public Resolution create(Map<String, Object> arguments) {
String description = arguments.getOrDefault("description", "<gray>CraftEngine ResourcePack</gray>").toString();
return new MergePackMcMetaResolution(description);
return new ResolutionMergePackMcMeta(description);
}
}
}

View File

@@ -20,10 +20,10 @@ public class Resolutions {
static {
register(RETAIN_MATCHING, RetainMatchingResolution.FACTORY);
register(MERGE_JSON, MergeJsonResolution.FACTORY);
register(CONDITIONAL, ConditionalResolution.FACTORY);
register(MERGE_PACK_MCMETA, MergePackMcMetaResolution.FACTORY);
register(MERGE_ATLAS, MergeAltasResolution.FACTORY);
register(MERGE_JSON, ResolutionMergeJson.FACTORY);
register(CONDITIONAL, ResolutionConditional.FACTORY);
register(MERGE_PACK_MCMETA, ResolutionMergePackMcMeta.FACTORY);
register(MERGE_ATLAS, ResolutionMergeAltas.FACTORY);
}
public static void register(Key key, ResolutionFactory factory) {

View File

@@ -13,7 +13,7 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.core.entity.furniture.ColliderType;
import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution;
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.PluginProperties;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
@@ -54,7 +54,7 @@ public class Config {
protected boolean resource_pack$remove_tinted_leaves_particle;
protected boolean resource_pack$generate_mod_assets;
protected boolean resource_pack$override_uniform_font;
protected List<ConditionalResolution> resource_pack$duplicated_files_handler;
protected List<ResolutionConditional> resource_pack$duplicated_files_handler;
protected List<String> resource_pack$merge_external_folders;
protected boolean resource_pack$protection$crash_tools$method_1;
@@ -245,7 +245,7 @@ public class Config {
try {
resource_pack$duplicated_files_handler = config.getMapList("resource-pack.duplicated-files-handler").stream().map(it -> {
Map<String, Object> args = MiscUtils.castToMap(it, false);
return ConditionalResolution.FACTORY.create(args);
return ResolutionConditional.FACTORY.create(args);
}).toList();
} catch (LocalizedResourceConfigException e) {
TranslationManager.instance().log(e.node(), e.arguments());
@@ -479,7 +479,7 @@ public class Config {
return instance.resource_pack$delivery$file_to_upload;
}
public static List<ConditionalResolution> resolutions() {
public static List<ResolutionConditional> resolutions() {
return instance.resource_pack$duplicated_files_handler;
}

View File

@@ -17,7 +17,7 @@ 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.context.ContextHolder;
import net.momirealms.craftengine.core.util.context.PlayerContext;
import net.momirealms.craftengine.core.util.context.PlayerOptionalContext;
import java.nio.file.Path;
import java.util.*;
@@ -177,7 +177,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(Constants.BROWSER_TITLE, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(Constants.BROWSER_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}
@@ -292,7 +292,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(Constants.CATEGORY_TITLE, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(Constants.CATEGORY_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}
@@ -353,7 +353,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_NONE_TITLE, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_NONE_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}
@@ -578,7 +578,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_SMITHING_TRANSFORM_TITLE, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_SMITHING_TRANSFORM_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}
@@ -711,7 +711,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_STONECUTTING_TITLE, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_STONECUTTING_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}
@@ -861,7 +861,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(title, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(title, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}
@@ -1056,7 +1056,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
})
.build()
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_CRAFTING_TITLE, PlayerContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_CRAFTING_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
.refresh()
.open(player);
}

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.plugin.text.minimessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.momirealms.craftengine.core.util.context.Context;
import net.momirealms.craftengine.core.util.context.ContextHolder;
public interface MiniMessageTextContext extends Context {

View File

@@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.Optional;
public class NamedArgumentTag implements TagResolver {
private static final String NAME_0 = "argument";
@@ -29,11 +30,12 @@ public class NamedArgumentTag implements TagResolver {
return null;
}
String argumentKey = arguments.popOr("No argument key provided").toString();
ContextKey<String> key = ContextKey.of(Key.of(argumentKey));
if (!this.context.contexts().has(key)) {
ContextKey<?> key = ContextKey.of(Key.withDefaultNamespace(argumentKey, "craftengine"));
Optional<?> optional = this.context.getOptionalParameter(key);
if (optional.isEmpty()) {
throw ctx.newException("Invalid argument key", arguments);
}
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(this.context.contexts().getOrThrow(key), this.context.tagResolvers()));
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(String.valueOf(optional.get()), this.context.tagResolvers()));
}
@Override

View File

@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
import net.momirealms.craftengine.core.loot.condition.LootConditionFactory;
import net.momirealms.craftengine.core.loot.entry.LootEntryContainerFactory;
import net.momirealms.craftengine.core.loot.function.ApplyBonusCountFunction;
import net.momirealms.craftengine.core.loot.function.LootFunctionApplyBonusCount;
import net.momirealms.craftengine.core.loot.function.LootFunctionFactory;
import net.momirealms.craftengine.core.loot.number.NumberProviderFactory;
import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherFactory;
@@ -43,7 +43,7 @@ public class BuiltInRegistries {
public static final Registry<ConditionPropertyFactory> CONDITION_PROPERTY_FACTORY = createRegistry(Registries.CONDITION_PROPERTY_FACTORY);
public static final Registry<SelectPropertyFactory> SELECT_PROPERTY_FACTORY = createRegistry(Registries.SELECT_PROPERTY_FACTORY);
public static final Registry<RecipeFactory<?>> RECIPE_FACTORY = createRegistry(Registries.RECIPE_FACTORY);
public static final Registry<ApplyBonusCountFunction.FormulaFactory> FORMULA_FACTORY = createRegistry(Registries.FORMULA_FACTORY);
public static final Registry<LootFunctionApplyBonusCount.FormulaFactory> FORMULA_FACTORY = createRegistry(Registries.FORMULA_FACTORY);
public static final Registry<PathMatcherFactory> PATH_MATCHER_FACTORY = createRegistry(Registries.PATH_MATCHER_FACTORY);
public static final Registry<ResolutionFactory> RESOLUTION_FACTORY = createRegistry(Registries.RESOLUTION_FACTORY);
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Factory> SMITHING_RESULT_PROCESSOR_FACTORY = createRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY);

View File

@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
import net.momirealms.craftengine.core.loot.condition.LootConditionFactory;
import net.momirealms.craftengine.core.loot.entry.LootEntryContainerFactory;
import net.momirealms.craftengine.core.loot.function.ApplyBonusCountFunction;
import net.momirealms.craftengine.core.loot.function.LootFunctionApplyBonusCount;
import net.momirealms.craftengine.core.loot.function.LootFunctionFactory;
import net.momirealms.craftengine.core.loot.number.NumberProviderFactory;
import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherFactory;
@@ -44,7 +44,7 @@ public class Registries {
public static final ResourceKey<Registry<ConditionPropertyFactory>> CONDITION_PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("condition_property_factory"));
public static final ResourceKey<Registry<SelectPropertyFactory>> SELECT_PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_factory"));
public static final ResourceKey<Registry<RecipeFactory<?>>> RECIPE_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_factory"));
public static final ResourceKey<Registry<ApplyBonusCountFunction.FormulaFactory>> FORMULA_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("formula_factory"));
public static final ResourceKey<Registry<LootFunctionApplyBonusCount.FormulaFactory>> FORMULA_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("formula_factory"));
public static final ResourceKey<Registry<PathMatcherFactory>> PATH_MATCHER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory"));
public static final ResourceKey<Registry<ResolutionFactory>> RESOLUTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_factory"));
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Factory>> SMITHING_RESULT_PROCESSOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory"));

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
@@ -20,4 +21,9 @@ public abstract class AllOfCondition<CTX> implements Condition<CTX> {
}
return true;
}
@Override
public Key type() {
return CommonConditions.ALL_OF;
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
@@ -20,4 +21,9 @@ public abstract class AnyOfCondition<CTX> implements Condition<CTX> {
}
return false;
}
@Override
public Key type() {
return CommonConditions.ANY_OF;
}
}

View File

@@ -0,0 +1,11 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
public final class CommonConditions {
private CommonConditions() {}
public static final Key ALL_OF = Key.of("craftengine:all_of");
public static final Key ANY_OF = Key.of("craftengine:any_of");
public static final Key INVERTED = Key.of("craftengine:inverted");
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.context.Condition;
public abstract class InvertedCondition<CTX> implements Condition<CTX> {
@@ -13,4 +14,9 @@ public abstract class InvertedCondition<CTX> implements Condition<CTX> {
public boolean test(CTX ctx) {
return !this.condition.test(ctx);
}
@Override
public Key type() {
return CommonConditions.INVERTED;
}
}

View File

@@ -1,14 +1,32 @@
package net.momirealms.craftengine.core.util.context;
public abstract class CommonContext implements Context {
protected final ContextHolder holder;
import java.util.Optional;
public CommonContext(ContextHolder holder) {
this.holder = holder;
public abstract class CommonContext implements Context {
protected final ContextHolder contexts;
public CommonContext(ContextHolder contexts) {
this.contexts = contexts;
}
@Override
public ContextHolder contexts() {
return holder;
return contexts;
}
@Override
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
return this.contexts.getOptional(parameter);
}
@Override
public <T> T getParameterOrThrow(ContextKey<T> parameter) {
return this.contexts.getOrThrow(parameter);
}
@Override
public <T> CommonContext withParameter(ContextKey<T> parameter, T value) {
this.contexts.withParameter(parameter, value);
return this;
}
}

View File

@@ -1,4 +1,9 @@
package net.momirealms.craftengine.core.util.context;
public class CommonParameters {
public final class CommonParameters {
private CommonParameters() {}
public static ContextKey<Double> RANDOM = ContextKey.of("random");
public static ContextKey<Double> LAST_RANDOM = ContextKey.of("last_random");
}

View File

@@ -1,6 +1,14 @@
package net.momirealms.craftengine.core.util.context;
import java.util.Optional;
public interface Context {
ContextHolder contexts();
<T> Optional<T> getOptionalParameter(ContextKey<T> parameter);
<T> T getParameterOrThrow(ContextKey<T> parameter);
<T> Context withParameter(ContextKey<T> parameter, T value);
}

View File

@@ -22,7 +22,7 @@ public class ContextKey<T> {
@NotNull
public static <T> ContextKey<T> of(@NotNull String id) {
return new ContextKey<>(Key.of(id));
return new ContextKey<>(Key.withDefaultNamespace(id, "craftengine"));
}
@Override

View File

@@ -0,0 +1,21 @@
package net.momirealms.craftengine.core.util.context;
import java.util.Optional;
public interface LazyContextParameterProvider {
<T> Optional<T> getOptionalParameter(ContextKey<T> parameter);
static LazyContextParameterProvider dummy() {
return DummyContextParameterProvider.INSTANCE;
}
class DummyContextParameterProvider implements LazyContextParameterProvider {
static final DummyContextParameterProvider INSTANCE = new DummyContextParameterProvider();
@Override
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
return Optional.empty();
}
}
}

View File

@@ -1,37 +0,0 @@
package net.momirealms.craftengine.core.util.context;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PlayerContext extends CommonContext implements MiniMessageTextContext {
public static final PlayerContext EMPTY = new PlayerContext(null, ContextHolder.EMPTY);
private final Player player;
private TagResolver[] tagResolvers;
public PlayerContext(@Nullable Player player, @NotNull ContextHolder contexts) {
super(contexts);
this.player = player;
}
@NotNull
public static PlayerContext of(@Nullable Player player, @NotNull ContextHolder contexts) {
return new PlayerContext(player, contexts);
}
@Nullable
public Player player() {
return this.player;
}
@Override
@NotNull
public TagResolver[] tagResolvers() {
if (this.tagResolvers == null) {
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new PlaceholderTag(this.player), new I18NTag(this), new NamedArgumentTag(this)};
}
return this.tagResolvers;
}
}

View File

@@ -0,0 +1,87 @@
package net.momirealms.craftengine.core.util.context;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.momirealms.craftengine.core.entity.Entity;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
import net.momirealms.craftengine.core.util.MCUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
public class PlayerOptionalContext extends CommonContext implements MiniMessageTextContext {
public static final PlayerOptionalContext EMPTY = new PlayerOptionalContext(null, ContextHolder.EMPTY);
private final Player player;
private final LazyContextParameterProvider playerParameterProvider;
private TagResolver[] tagResolvers;
public PlayerOptionalContext(@Nullable Player player, @NotNull ContextHolder contexts) {
super(contexts);
this.player = player;
this.playerParameterProvider = player == null ? LazyContextParameterProvider.dummy() : new PlayerParameterGetter(player);
}
@NotNull
public static PlayerOptionalContext of(@Nullable Player player, @NotNull ContextHolder contexts) {
return new PlayerOptionalContext(player, contexts);
}
@Nullable
public Player player() {
return this.player;
}
@Override
@NotNull
public TagResolver[] tagResolvers() {
if (this.tagResolvers == null) {
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new PlaceholderTag(this.player), new I18NTag(this), new NamedArgumentTag(this)};
}
return this.tagResolvers;
}
@Override
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
Optional<T> optional = this.playerParameterProvider.getOptionalParameter(parameter);
if (optional.isPresent()) {
return optional;
}
return super.getOptionalParameter(parameter);
}
@Override
public <T> T getParameterOrThrow(ContextKey<T> parameter) {
return this.playerParameterProvider.getOptionalParameter(parameter).orElseGet(() -> super.getParameterOrThrow(parameter));
}
public static class PlayerParameterGetter implements LazyContextParameterProvider {
private static final Map<ContextKey<?>, Function<Player, Object>> CONTEXT_FUNCTIONS = new HashMap<>();
static {
CONTEXT_FUNCTIONS.put(PlayerParameters.X, Entity::x);
CONTEXT_FUNCTIONS.put(PlayerParameters.Y, Entity::y);
CONTEXT_FUNCTIONS.put(PlayerParameters.Z, Entity::z);
CONTEXT_FUNCTIONS.put(PlayerParameters.BLOCK_X, p -> MCUtils.fastFloor(p.x()));
CONTEXT_FUNCTIONS.put(PlayerParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y()));
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);
}
private final Player player;
public PlayerParameterGetter(@NotNull Player player) {
this.player = Objects.requireNonNull(player);
}
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
return (Optional<T>) Optional.ofNullable(CONTEXT_FUNCTIONS.get(parameter)).map(f -> f.apply(this.player));
}
}
}

View File

@@ -0,0 +1,18 @@
package net.momirealms.craftengine.core.util.context;
import net.momirealms.craftengine.core.util.Key;
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"));
}

View File

@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.world;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
public interface WorldBlock {
public interface BlockInWorld {
default boolean canBeReplaced(BlockPlaceContext blockPlaceContext) {
return false;
@@ -11,4 +11,10 @@ public interface WorldBlock {
default boolean isWaterSource(BlockPlaceContext blockPlaceContext) {
return false;
}
int x();
int y();
int z();
}

View File

@@ -15,9 +15,9 @@ public interface World {
WorldHeight worldHeight();
WorldBlock getBlockAt(int x, int y, int z);
BlockInWorld getBlockAt(int x, int y, int z);
default WorldBlock getBlockAt(final BlockPos pos) {
default BlockInWorld getBlockAt(final BlockPos pos) {
return getBlockAt(pos.x(), pos.y(), pos.z());
}