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

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

# Conflicts:
#	common-files/src/main/resources/translations/en.yml
#	common-files/src/main/resources/translations/zh_cn.yml
This commit is contained in:
jhqwqmc
2025-12-05 03:02:13 +08:00
47 changed files with 418 additions and 116 deletions

View File

@@ -19,6 +19,7 @@ import net.momirealms.craftengine.bukkit.compatibility.quickshop.QuickShopItemEx
import net.momirealms.craftengine.bukkit.compatibility.region.WorldGuardRegionCondition; import net.momirealms.craftengine.bukkit.compatibility.region.WorldGuardRegionCondition;
import net.momirealms.craftengine.bukkit.compatibility.skript.SkriptHook; import net.momirealms.craftengine.bukkit.compatibility.skript.SkriptHook;
import net.momirealms.craftengine.bukkit.compatibility.slimeworld.SlimeFormatStorageAdaptor; import net.momirealms.craftengine.bukkit.compatibility.slimeworld.SlimeFormatStorageAdaptor;
import net.momirealms.craftengine.bukkit.compatibility.tag.CustomNameplateHatSettings;
import net.momirealms.craftengine.bukkit.compatibility.tag.CustomNameplateProviders; import net.momirealms.craftengine.bukkit.compatibility.tag.CustomNameplateProviders;
import net.momirealms.craftengine.bukkit.compatibility.viaversion.ViaVersionUtils; import net.momirealms.craftengine.bukkit.compatibility.viaversion.ViaVersionUtils;
import net.momirealms.craftengine.bukkit.compatibility.worldedit.WorldEditBlockRegister; import net.momirealms.craftengine.bukkit.compatibility.worldedit.WorldEditBlockRegister;
@@ -97,6 +98,7 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
registerTagResolverProvider(new CustomNameplateProviders.Background()); registerTagResolverProvider(new CustomNameplateProviders.Background());
registerTagResolverProvider(new CustomNameplateProviders.Nameplate()); registerTagResolverProvider(new CustomNameplateProviders.Nameplate());
registerTagResolverProvider(new CustomNameplateProviders.Bubble()); registerTagResolverProvider(new CustomNameplateProviders.Bubble());
new CustomNameplateHatSettings().register();
logHook("CustomNameplates"); logHook("CustomNameplates");
} }
Key worldGuardRegion = Key.of("worldguard:region"); Key worldGuardRegion = Key.of("worldguard:region");

View File

@@ -108,11 +108,6 @@ public class CheckItemExpansion extends PlaceholderExpansion {
} }
private int getItemCount(BukkitServerPlayer player, String[] param) { private int getItemCount(BukkitServerPlayer player, String[] param) {
Key itemId = Key.of(param[0], param[1]); return player.clearOrCountMatchingInventoryItems(Key.of(param[0], param[1]), 0);
Predicate<Object> predicate = nmsStack -> this.plugin.itemManager().wrap(ItemStackUtils.asCraftMirror(nmsStack)).id().equals(itemId);
Object inventory = FastNMS.INSTANCE.method$Player$getInventory(player.serverPlayer());
Object inventoryMenu = FastNMS.INSTANCE.field$Player$inventoryMenu(player.serverPlayer());
Object craftSlots = FastNMS.INSTANCE.method$InventoryMenu$getCraftSlots(inventoryMenu);
return FastNMS.INSTANCE.method$Inventory$clearOrCountMatchingItems(inventory, predicate, 0, craftSlots);
} }
} }

View File

@@ -0,0 +1,84 @@
package net.momirealms.craftengine.bukkit.compatibility.tag;
import io.papermc.paper.event.entity.EntityEquipmentChangedEvent;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemSettings;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.util.CustomDataType;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.customnameplates.api.CNPlayer;
import net.momirealms.customnameplates.api.CustomNameplates;
import net.momirealms.customnameplates.api.CustomNameplatesAPI;
import net.momirealms.customnameplates.api.feature.tag.TagRenderer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
public final class CustomNameplateHatSettings implements Listener {
public static final CustomDataType<Double> HAT_HEIGHT = new CustomDataType<>();
public void register() {
ItemSettings.Modifiers.registerFactory("hat-height", height -> {
double heightD = ResourceConfigUtils.getAsDouble(height, "hat-height");
return settings -> settings.addCustomData(HAT_HEIGHT, heightD);
});
Bukkit.getPluginManager().registerEvents(this, BukkitCraftEngine.instance().javaPlugin());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEquipmentChange(EntityEquipmentChangedEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
Map<EquipmentSlot, EntityEquipmentChangedEvent.EquipmentChange> equipmentChanges = event.getEquipmentChanges();
EntityEquipmentChangedEvent.EquipmentChange equipmentChange = equipmentChanges.get(EquipmentSlot.HEAD);
if (equipmentChange == null) return;
ItemStack newItem = equipmentChange.newItem();
updateHatHeight(player, newItem);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
// 稍微延迟一下,可以等待背包同步插件的处理
if (VersionHelper.isFolia()) {
player.getScheduler().runDelayed(BukkitCraftEngine.instance().javaPlugin(), t1 -> {
if (player.isOnline()) {
updateHatHeight(player, player.getInventory().getItem(EquipmentSlot.HEAD));
}
}, null, 10);
} else {
CraftEngine.instance().scheduler().sync().runLater(() -> {
if (player.isOnline()) {
updateHatHeight(player, player.getInventory().getItem(EquipmentSlot.HEAD));
}
}, 10);
}
}
public void updateHatHeight(Player player, ItemStack newItem) {
CNPlayer cnPlayer = CustomNameplatesAPI.getInstance().getPlayer(player.getUniqueId());
if (cnPlayer == null) return;
TagRenderer tagRender = CustomNameplates.getInstance().getUnlimitedTagManager().getTagRender(cnPlayer);
if (tagRender == null) return;
Item<ItemStack> wrapped = BukkitItemManager.instance().wrap(newItem);
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
if (optionalCustomItem.isEmpty()) {
tagRender.hatOffset(0d);
return;
}
Double customHeight = optionalCustomItem.get().settings().getCustomData(HAT_HEIGHT);
tagRender.hatOffset(Objects.requireNonNullElse(customHeight, 0d));
}
}

View File

@@ -9,11 +9,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityType
import net.momirealms.craftengine.bukkit.util.LocationUtils; import net.momirealms.craftengine.bukkit.util.LocationUtils;
import net.momirealms.craftengine.core.entity.furniture.*; import net.momirealms.craftengine.core.entity.furniture.*;
import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxConfig; import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitBoxConfig;
import net.momirealms.craftengine.core.entity.player.InteractionResult;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.QuaternionUtils; import net.momirealms.craftengine.core.util.QuaternionUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.Vec3d;
import net.momirealms.craftengine.core.world.WorldPosition; import net.momirealms.craftengine.core.world.WorldPosition;
import net.momirealms.craftengine.core.world.collision.AABB; import net.momirealms.craftengine.core.world.collision.AABB;
import org.bukkit.Location; import org.bukkit.Location;
@@ -75,7 +71,7 @@ public class BukkitFurniture extends Furniture {
// 检查新位置是否可用 // 检查新位置是否可用
List<AABB> aabbs = new ArrayList<>(); List<AABB> aabbs = new ArrayList<>();
for (FurnitureHitBoxConfig<?> hitBoxConfig : getCurrentVariant().hitBoxConfigs()) { for (FurnitureHitBoxConfig<?> hitBoxConfig : getCurrentVariant().hitBoxConfigs()) {
hitBoxConfig.prepareForPlacement(position, aabbs::add); hitBoxConfig.prepareBoundingBox(position, aabbs::add, false);
} }
if (!aabbs.isEmpty()) { if (!aabbs.isEmpty()) {
if (!FastNMS.INSTANCE.checkEntityCollision(position.world.serverWorld(), aabbs.stream().map(it -> FastNMS.INSTANCE.constructor$AABB(it.minX, it.minY, it.minZ, it.maxX, it.maxY, it.maxZ)).toList())) { if (!FastNMS.INSTANCE.checkEntityCollision(position.world.serverWorld(), aabbs.stream().map(it -> FastNMS.INSTANCE.constructor$AABB(it.minX, it.minY, it.minZ, it.maxX, it.maxY, it.maxZ)).toList())) {

View File

@@ -71,8 +71,8 @@ public class CustomFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<C
} }
@Override @Override
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) { public void prepareBoundingBox(WorldPosition targetPos, Consumer<AABB> aabbConsumer, boolean ignoreBlocksBuilding) {
if (this.blocksBuilding) { if (this.blocksBuilding || ignoreBlocksBuilding) {
Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position); Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position);
aabbConsumer.accept(AABB.makeBoundingBox(relativePosition, this.width, this.height)); aabbConsumer.accept(AABB.makeBoundingBox(relativePosition, this.width, this.height));
} }

View File

@@ -56,8 +56,8 @@ public class HappyGhastFurnitureHitboxConfig extends AbstractFurnitureHitBoxConf
} }
@Override @Override
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) { public void prepareBoundingBox(WorldPosition targetPos, Consumer<AABB> aabbConsumer, boolean ignoreBlocksBuilding) {
if (this.blocksBuilding) { if (this.blocksBuilding || ignoreBlocksBuilding) {
Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position); Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position);
aabbConsumer.accept(AABB.makeBoundingBox(relativePosition, 4 * this.scale, 4 * this.scale)); aabbConsumer.accept(AABB.makeBoundingBox(relativePosition, 4 * this.scale, 4 * this.scale));
} }

View File

@@ -70,8 +70,8 @@ public class InteractionFurnitureHitboxConfig extends AbstractFurnitureHitBoxCon
} }
@Override @Override
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) { public void prepareBoundingBox(WorldPosition targetPos, Consumer<AABB> aabbConsumer, boolean ignoreBlocksBuilding) {
if (this.blocksBuilding) { if (this.blocksBuilding || ignoreBlocksBuilding) {
Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position); Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position);
aabbConsumer.accept(AABB.makeBoundingBox(relativePosition, size.x, size.y)); aabbConsumer.accept(AABB.makeBoundingBox(relativePosition, size.x, size.y));
} }

View File

@@ -145,8 +145,8 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig<
} }
@Override @Override
public void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer) { public void prepareBoundingBox(WorldPosition targetPos, Consumer<AABB> aabbConsumer, boolean ignoreBlocksBuilding) {
if (this.blocksBuilding) { if (this.blocksBuilding || ignoreBlocksBuilding) {
Quaternionf conjugated = QuaternionUtils.toQuaternionf(0f, (float) Math.toRadians(180 - targetPos.yRot()), 0f).conjugate(); Quaternionf conjugated = QuaternionUtils.toQuaternionf(0f, (float) Math.toRadians(180 - targetPos.yRot()), 0f).conjugate();
Vector3f offset = conjugated.transform(new Vector3f(position())); Vector3f offset = conjugated.transform(new Vector3f(position()));
aabbConsumer.accept(this.aabbCreator.create(targetPos.x, targetPos.y, targetPos.z, targetPos.yRot, offset)); aabbConsumer.accept(this.aabbCreator.create(targetPos.x, targetPos.y, targetPos.z, targetPos.yRot, offset));

View File

@@ -114,7 +114,7 @@ public class FurnitureItemBehavior extends ItemBehavior {
List<AABB> aabbs = new ArrayList<>(); List<AABB> aabbs = new ArrayList<>();
// 收集阻挡的碰撞箱 // 收集阻挡的碰撞箱
for (FurnitureHitBoxConfig<?> hitBoxConfig : variant.hitBoxConfigs()) { for (FurnitureHitBoxConfig<?> hitBoxConfig : variant.hitBoxConfigs()) {
hitBoxConfig.prepareForPlacement(furniturePos, aabbs::add); hitBoxConfig.prepareBoundingBox(furniturePos, aabbs::add, false);
} }
// 检查方块、实体阻挡 // 检查方块、实体阻挡
if (!aabbs.isEmpty()) { if (!aabbs.isEmpty()) {

View File

@@ -75,6 +75,7 @@ import java.lang.ref.Reference;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
public class BukkitServerPlayer extends Player { public class BukkitServerPlayer extends Player {
public static final Key SELECTED_LOCALE_KEY = Key.of("craftengine:locale"); public static final Key SELECTED_LOCALE_KEY = Key.of("craftengine:locale");
@@ -566,7 +567,7 @@ public class BukkitServerPlayer extends Player {
FurnitureVariant currentVariant = furniture.getCurrentVariant(); FurnitureVariant currentVariant = furniture.getCurrentVariant();
List<AABB> aabbs = new ArrayList<>(); List<AABB> aabbs = new ArrayList<>();
for (FurnitureHitBoxConfig<?> config : currentVariant.hitBoxConfigs()) { for (FurnitureHitBoxConfig<?> config : currentVariant.hitBoxConfigs()) {
config.prepareForPlacement(furniture.position(), aabbs::add); config.prepareBoundingBox(furniture.position(), aabbs::add, true);
} }
Key endRod = Key.of("soul_fire_flame"); Key endRod = Key.of("soul_fire_flame");
for (AABB aabb : aabbs) { for (AABB aabb : aabbs) {
@@ -1492,6 +1493,15 @@ public class BukkitServerPlayer extends Player {
this.trackedBlockEntityRenderers.clear(); this.trackedBlockEntityRenderers.clear();
} }
@Override
public int clearOrCountMatchingInventoryItems(Key itemId, int count) {
Predicate<Object> predicate = nmsStack -> this.plugin.itemManager().wrap(ItemStackUtils.asCraftMirror(nmsStack)).id().equals(itemId);
Object inventory = FastNMS.INSTANCE.method$Player$getInventory(serverPlayer());
Object inventoryMenu = FastNMS.INSTANCE.field$Player$inventoryMenu(serverPlayer());
Object craftSlots = FastNMS.INSTANCE.method$InventoryMenu$getCraftSlots(inventoryMenu);
return FastNMS.INSTANCE.method$Inventory$clearOrCountMatchingItems(inventory, predicate, count, craftSlots);
}
@Override @Override
public void addTrackedFurniture(int entityId, Furniture furniture) { public void addTrackedFurniture(int entityId, Furniture furniture) {
this.trackedFurniture.put(entityId, new VirtualCullableObject(furniture)); this.trackedFurniture.put(entityId, new VirtualCullableObject(furniture));

View File

@@ -170,6 +170,7 @@ warning.config.condition.is_null.missing_argument: "<yellow>Issue found in file
warning.config.condition.hand.missing_hand: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'hand' argument for 'hand' condition.</yellow>" warning.config.condition.hand.missing_hand: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'hand' argument for 'hand' condition.</yellow>"
warning.config.condition.hand.invalid_hand: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid 'hand' argument '<arg:2>' for 'hand' condition. Allowed hand types: [<arg:3>]</yellow>" warning.config.condition.hand.invalid_hand: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid 'hand' argument '<arg:2>' for 'hand' condition. Allowed hand types: [<arg:3>]</yellow>"
warning.config.condition.on_cooldown.missing_id: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'id' argument for 'on_cooldown' condition.</yellow>" warning.config.condition.on_cooldown.missing_id: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'id' argument for 'on_cooldown' condition.</yellow>"
warning.config.condition.inventory_has_item.missing_id: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'id' argument for 'inventory_has_item' condition.</yellow>"
warning.config.structure.not_section: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is expected to be a config section while it's actually a(n) '<arg:2>'.</yellow>" warning.config.structure.not_section: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is expected to be a config section while it's actually a(n) '<arg:2>'.</yellow>"
warning.config.image.duplicate: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'. Please check if there is the same configuration in other files.</yellow>" warning.config.image.duplicate: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'. Please check if there is the same configuration in other files.</yellow>"
warning.config.image.missing_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>" warning.config.image.missing_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>"
@@ -543,6 +544,7 @@ warning.config.function.transform_block.missing_block: "<yellow>Issue found in f
warning.config.function.cycle_block_property.missing_property: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'property' argument for 'cycle_block_property' function.</yellow>" warning.config.function.cycle_block_property.missing_property: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'property' argument for 'cycle_block_property' function.</yellow>"
warning.config.function.set_exp.missing_count: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'count' argument for 'set_exp' function.</yellow>" warning.config.function.set_exp.missing_count: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'count' argument for 'set_exp' function.</yellow>"
warning.config.function.set_level.missing_count: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'count' argument for 'set_level' function.</yellow>" warning.config.function.set_level.missing_count: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'count' argument for 'set_level' function.</yellow>"
warning.config.function.clear_item.missing_id: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'id' argument for 'clear_item' function.</yellow>"
warning.config.function.play_totem_animation.missing_item: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'item' argument for 'play_totem_animation' function.</yellow>" warning.config.function.play_totem_animation.missing_item: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'item' argument for 'play_totem_animation' function.</yellow>"
warning.config.selector.missing_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'type' argument for selector.</yellow>" warning.config.selector.missing_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'type' argument for selector.</yellow>"
warning.config.selector.invalid_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid selector type '<arg:2>'.</yellow>" warning.config.selector.invalid_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid selector type '<arg:2>'.</yellow>"

View File

@@ -170,6 +170,7 @@ warning.config.condition.is_null.missing_argument: "<yellow>在文件 <arg:0>
warning.config.condition.hand.missing_hand: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'hand' 条件必需的 'hand' 参数</yellow>" warning.config.condition.hand.missing_hand: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'hand' 条件必需的 'hand' 参数</yellow>"
warning.config.condition.hand.invalid_hand: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的 'hand' 参数 '<arg:2>' ('hand' 条件). 允许的手部类型: [<arg:3>]</yellow>" warning.config.condition.hand.invalid_hand: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的 'hand' 参数 '<arg:2>' ('hand' 条件). 允许的手部类型: [<arg:3>]</yellow>"
warning.config.condition.on_cooldown.missing_id: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'on_cooldown' 条件必需的 'id' 参数</yellow>" warning.config.condition.on_cooldown.missing_id: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'on_cooldown' 条件必需的 'id' 参数</yellow>"
warning.config.condition.inventory_has_item.missing_id: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'inventory_has_item' 条件必需的 'id' 参数</yellow>"
warning.config.structure.not_section: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 应为配置段落 但实际类型为 '<arg:2>'</yellow>" warning.config.structure.not_section: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 应为配置段落 但实际类型为 '<arg:2>'</yellow>"
warning.config.image.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的图片配置 '<arg:1>' 请检查其他文件中是否存在相同配置</yellow>" warning.config.image.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的图片配置 '<arg:1>' 请检查其他文件中是否存在相同配置</yellow>"
warning.config.image.missing_height: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 缺少必需的 'height' 参数</yellow>" warning.config.image.missing_height: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 缺少必需的 'height' 参数</yellow>"
@@ -544,6 +545,7 @@ warning.config.function.cycle_block_property.missing_property: "<yellow>在文
warning.config.function.set_exp.missing_count: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'set_exp' 函数所需的 'count' 参数</yellow>" warning.config.function.set_exp.missing_count: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'set_exp' 函数所需的 'count' 参数</yellow>"
warning.config.function.set_level.missing_count: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'set_level' 函数所需的 'count' 参数</yellow>" warning.config.function.set_level.missing_count: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'set_level' 函数所需的 'count' 参数</yellow>"
warning.config.function.play_totem_animation.missing_item: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'play_totem_animation' 函数所需的 'item' 参数</yellow>" warning.config.function.play_totem_animation.missing_item: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'play_totem_animation' 函数所需的 'item' 参数</yellow>"
warning.config.function.clear_item.missing_id: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'clear_item' 函数所需的 'id' 参数</yellow>"
warning.config.selector.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少选择器必需的 'type' 参数</yellow>" warning.config.selector.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少选择器必需的 'type' 参数</yellow>"
warning.config.selector.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的选择器类型 '<arg:2>'</yellow>" warning.config.selector.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的选择器类型 '<arg:2>'</yellow>"
warning.config.selector.invalid_target: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的选择器目标 '<arg:2>'</yellow>" warning.config.selector.invalid_target: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的选择器目标 '<arg:2>'</yellow>"

View File

@@ -130,7 +130,7 @@ public abstract class Furniture implements Cullable {
if (aabb == null) { if (aabb == null) {
List<AABB> aabbs = new ArrayList<>(); List<AABB> aabbs = new ArrayList<>();
for (FurnitureHitBoxConfig<?> hitBoxConfig : this.currentVariant.hitBoxConfigs()) { for (FurnitureHitBoxConfig<?> hitBoxConfig : this.currentVariant.hitBoxConfigs()) {
hitBoxConfig.prepareForPlacement(position, aabbs::add); hitBoxConfig.prepareBoundingBox(position, aabbs::add, true);
} }
return new CullingData(getMaxAABB(aabbs), parent.maxDistance, parent.aabbExpansion, parent.rayTracing); return new CullingData(getMaxAABB(aabbs), parent.maxDistance, parent.aabbExpansion, parent.rayTracing);
} else { } else {

View File

@@ -22,6 +22,6 @@ public interface FurnitureHitBoxConfig<H extends FurnitureHitBox> {
boolean canUseItemOn(); boolean canUseItemOn();
void prepareForPlacement(WorldPosition targetPos, Consumer<AABB> aabbConsumer); void prepareBoundingBox(WorldPosition targetPos, Consumer<AABB> aabbConsumer, boolean ignoreBlocksBuilding);
} }

View File

@@ -226,6 +226,8 @@ public abstract class Player extends AbstractEntity implements NetWorkUser {
public abstract void clearTrackedBlockEntities(); public abstract void clearTrackedBlockEntities();
public abstract int clearOrCountMatchingInventoryItems(Key itemId, int count);
@Override @Override
public void remove() { public void remove() {
} }

View File

@@ -31,4 +31,5 @@ public final class CommonConditions {
public static final Key IS_NULL = Key.from("craftengine:is_null"); public static final Key IS_NULL = Key.from("craftengine:is_null");
public static final Key HAND = Key.from("craftengine:hand"); public static final Key HAND = Key.from("craftengine:hand");
public static final Key HAS_PLAYER = Key.from("craftengine:has_player"); public static final Key HAS_PLAYER = Key.from("craftengine:has_player");
public static final Key INVENTORY_HAS_ITEM = Key.from("craftengine:inventory_has_item");
} }

View File

@@ -0,0 +1,51 @@
package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.ItemUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Optional;
public class InventoryHasItemCondition<CTX extends Context> implements Condition<CTX> {
private final Key itemId;
private final NumberProvider count;
public InventoryHasItemCondition(Key itemId, NumberProvider count) {
this.itemId = itemId;
this.count = count;
}
@Override
public Key type() {
return CommonConditions.INVENTORY_HAS_ITEM;
}
@Override
public boolean test(CTX ctx) {
Optional<Player> optionalPlayer = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
if (optionalPlayer.isEmpty()) {
return false;
}
Player player = optionalPlayer.get();
return player.clearOrCountMatchingInventoryItems(this.itemId, 0) >= this.count.getInt(ctx);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(ResourceConfigUtils.get(arguments, "id", "item"), "warning.config.condition.inventory_has_item.missing_id"));
NumberProvider count = NumberProviders.fromObject(arguments.getOrDefault("count", 1));
return new InventoryHasItemCondition<>(itemId, count);
}
}
}

View File

@@ -40,6 +40,7 @@ public class EventConditions {
register(CommonConditions.IS_NULL, new IsNullCondition.FactoryImpl<>()); register(CommonConditions.IS_NULL, new IsNullCondition.FactoryImpl<>());
register(CommonConditions.HAND, new HandCondition.FactoryImpl<>()); register(CommonConditions.HAND, new HandCondition.FactoryImpl<>());
register(CommonConditions.ON_COOLDOWN, new OnCooldownCondition.FactoryImpl<>()); register(CommonConditions.ON_COOLDOWN, new OnCooldownCondition.FactoryImpl<>());
register(CommonConditions.INVENTORY_HAS_ITEM, new InventoryHasItemCondition.FactoryImpl<>());
} }
public static void register(Key key, ConditionFactory<Context> factory) { public static void register(Key key, ConditionFactory<Context> factory) {

View File

@@ -43,6 +43,7 @@ public class EventFunctions {
register(CommonFunctions.SPAWN_FURNITURE, new SpawnFurnitureFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.SPAWN_FURNITURE, new SpawnFurnitureFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.REMOVE_FURNITURE, new RemoveFurnitureFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.REMOVE_FURNITURE, new RemoveFurnitureFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.REPLACE_FURNITURE, new ReplaceFurnitureFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.REPLACE_FURNITURE, new ReplaceFurnitureFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.ROTATE_FURNITURE, new RotateFurnitureFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.MYTHIC_MOBS_SKILL, new MythicMobsSkillFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.MYTHIC_MOBS_SKILL, new MythicMobsSkillFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.TELEPORT, new TeleportFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.TELEPORT, new TeleportFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.SET_VARIABLE, new SetVariableFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.SET_VARIABLE, new SetVariableFunction.FactoryImpl<>(EventConditions::fromMap));
@@ -58,6 +59,8 @@ public class EventFunctions {
register(CommonFunctions.SET_EXP, new SetExpFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.SET_EXP, new SetExpFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.SET_LEVEL, new SetLevelFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.SET_LEVEL, new SetLevelFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.PLAY_TOTEM_ANIMATION, new PlayTotemAnimationFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.PLAY_TOTEM_ANIMATION, new PlayTotemAnimationFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.CLOSE_INVENTORY, new CloseInventoryFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.CLEAR_ITEM, new ClearItemFunction.FactoryImpl<>(EventConditions::fromMap));
} }
public static void register(Key key, FunctionFactory<Context> factory) { public static void register(Key key, FunctionFactory<Context> factory) {

View File

@@ -18,7 +18,7 @@ public class BreakBlockFunction<CTX extends Context> extends AbstractConditional
private final NumberProvider y; private final NumberProvider y;
private final NumberProvider z; private final NumberProvider z;
public BreakBlockFunction(NumberProvider x, NumberProvider y, NumberProvider z, List<Condition<CTX>> predicates) { public BreakBlockFunction(List<Condition<CTX>> predicates, NumberProvider y, NumberProvider z, NumberProvider x) {
super(predicates); super(predicates);
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -47,7 +47,7 @@ public class BreakBlockFunction<CTX extends Context> extends AbstractConditional
NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")); NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>"));
NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")); NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>"));
NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")); NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>"));
return new BreakBlockFunction<>(x, y, z, getPredicates(arguments)); return new BreakBlockFunction<>(getPredicates(arguments), y, z, x);
} }
} }
} }

View File

@@ -0,0 +1,54 @@
package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class ClearItemFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final Key itemId;
private final NumberProvider count;
public ClearItemFunction(List<Condition<CTX>> predicates, Key itemId, NumberProvider count) {
super(predicates);
this.itemId = itemId;
this.count = count;
}
@Override
protected void runInternal(CTX ctx) {
Optional<Player> optionalPlayer = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
if (optionalPlayer.isEmpty()) {
return;
}
Player player = optionalPlayer.get();
player.clearOrCountMatchingInventoryItems(itemId, count.getInt(ctx));
}
@Override
public Key type() {
return CommonFunctions.CLEAR_ITEM;
}
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}
@Override
public Function<CTX> create(Map<String, Object> arguments) {
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(ResourceConfigUtils.get(arguments, "id", "item"), "warning.config.function.clear_item.missing_id"));
NumberProvider count = NumberProviders.fromObject(arguments.getOrDefault("count", 1));
return new ClearItemFunction<>(getPredicates(arguments), itemId, count);
}
}
}

View File

@@ -0,0 +1,50 @@
package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
public class CloseInventoryFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final PlayerSelector<CTX> selector;
public CloseInventoryFunction(List<Condition<CTX>> predicates, @Nullable PlayerSelector<CTX> selector) {
super(predicates);
this.selector = selector;
}
@Override
public void runInternal(CTX ctx) {
if (this.selector == null) {
ctx.getOptionalParameter(DirectContextParameters.PLAYER).ifPresent(Player::closeInventory);
} else {
for (Player viewer : this.selector.get(ctx)) {
viewer.closeInventory();
}
}
}
@Override
public Key type() {
return CommonFunctions.CLOSE_INVENTORY;
}
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}
@Override
public Function<CTX> create(Map<String, Object> arguments) {
return new CloseInventoryFunction<>(getPredicates(arguments), PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()));
}
}
}

View File

@@ -32,6 +32,7 @@ public final class CommonFunctions {
public static final Key SPAWN_FURNITURE = Key.of("craftengine:spawn_furniture"); public static final Key SPAWN_FURNITURE = Key.of("craftengine:spawn_furniture");
public static final Key REMOVE_FURNITURE = Key.of("craftengine:remove_furniture"); public static final Key REMOVE_FURNITURE = Key.of("craftengine:remove_furniture");
public static final Key REPLACE_FURNITURE = Key.of("craftengine:replace_furniture"); public static final Key REPLACE_FURNITURE = Key.of("craftengine:replace_furniture");
public static final Key ROTATE_FURNITURE = Key.of("craftengine:rotate_furniture");
public static final Key MYTHIC_MOBS_SKILL = Key.of("craftengine:mythic_mobs_skill"); public static final Key MYTHIC_MOBS_SKILL = Key.of("craftengine:mythic_mobs_skill");
public static final Key TELEPORT = Key.of("craftengine:teleport"); public static final Key TELEPORT = Key.of("craftengine:teleport");
public static final Key TOAST = Key.of("craftengine:toast"); public static final Key TOAST = Key.of("craftengine:toast");
@@ -49,4 +50,6 @@ public final class CommonFunctions {
public static final Key SET_EXP = Key.of("craftengine:set_exp"); public static final Key SET_EXP = Key.of("craftengine:set_exp");
public static final Key SET_LEVEL = Key.of("craftengine:set_level"); public static final Key SET_LEVEL = Key.of("craftengine:set_level");
public static final Key PLAY_TOTEM_ANIMATION = Key.of("craftengine:play_totem_animation"); public static final Key PLAY_TOTEM_ANIMATION = Key.of("craftengine:play_totem_animation");
public static final Key CLOSE_INVENTORY = Key.of("craftengine:close_inventory");
public static final Key CLEAR_ITEM = Key.of("craftengine:clear_item");
} }

View File

@@ -17,7 +17,7 @@ public class DamageFunction<CTX extends Context> extends AbstractConditionalFunc
private final Key damageType; private final Key damageType;
private final NumberProvider amount; private final NumberProvider amount;
public DamageFunction(PlayerSelector<CTX> selector, Key damageType, NumberProvider amount, List<Condition<CTX>> predicates) { public DamageFunction(List<Condition<CTX>> predicates, Key damageType, NumberProvider amount, PlayerSelector<CTX> selector) {
super(predicates); super(predicates);
this.selector = selector; this.selector = selector;
this.damageType = damageType; this.damageType = damageType;
@@ -45,7 +45,7 @@ public class DamageFunction<CTX extends Context> extends AbstractConditionalFunc
PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.getOrDefault("target", "self"), conditionFactory()); PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.getOrDefault("target", "self"), conditionFactory());
Key damageType = Key.of(ResourceConfigUtils.getAsStringOrNull(arguments.getOrDefault("damage-type", "generic"))); Key damageType = Key.of(ResourceConfigUtils.getAsStringOrNull(arguments.getOrDefault("damage-type", "generic")));
NumberProvider amount = NumberProviders.fromObject(arguments.getOrDefault("amount", 1f)); NumberProvider amount = NumberProviders.fromObject(arguments.getOrDefault("amount", 1f));
return new DamageFunction<>(selector, damageType, amount, getPredicates(arguments)); return new DamageFunction<>(getPredicates(arguments), damageType, amount, selector);
} }
} }
} }

View File

@@ -17,7 +17,7 @@ import java.util.Map;
public class DamageItemFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> { public class DamageItemFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final NumberProvider amount; private final NumberProvider amount;
public DamageItemFunction(NumberProvider amount, List<Condition<CTX>> predicates) { public DamageItemFunction(List<Condition<CTX>> predicates, NumberProvider amount) {
super(predicates); super(predicates);
this.amount = amount; this.amount = amount;
} }
@@ -51,7 +51,7 @@ public class DamageItemFunction<CTX extends Context> extends AbstractConditional
@Override @Override
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
NumberProvider amount = NumberProviders.fromObject(arguments.getOrDefault("amount", 1)); NumberProvider amount = NumberProviders.fromObject(arguments.getOrDefault("amount", 1));
return new DamageItemFunction<>(amount, getPredicates(arguments)); return new DamageItemFunction<>(getPredicates(arguments), amount);
} }
} }
} }

View File

@@ -20,7 +20,7 @@ public class LevelerExpFunction<CTX extends Context> extends AbstractConditional
private final String leveler; private final String leveler;
private final String plugin; private final String plugin;
public LevelerExpFunction(NumberProvider count, String leveler, String plugin, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public LevelerExpFunction(List<Condition<CTX>> predicates, String leveler, String plugin, PlayerSelector<CTX> selector, NumberProvider count) {
super(predicates); super(predicates);
this.count = count; this.count = count;
this.leveler = leveler; this.leveler = leveler;
@@ -58,7 +58,7 @@ public class LevelerExpFunction<CTX extends Context> extends AbstractConditional
Object count = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.function.leveler_exp.missing_count"); Object count = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.function.leveler_exp.missing_count");
String leveler = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("leveler"), "warning.config.function.leveler_exp.missing_leveler"); String leveler = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("leveler"), "warning.config.function.leveler_exp.missing_leveler");
String plugin = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("plugin"), "warning.config.function.leveler_exp.missing_plugin"); String plugin = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("plugin"), "warning.config.function.leveler_exp.missing_plugin");
return new LevelerExpFunction<>(NumberProviders.fromObject(count), leveler, plugin, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new LevelerExpFunction<>(getPredicates(arguments), leveler, plugin, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), NumberProviders.fromObject(count));
} }
} }
} }

View File

@@ -14,7 +14,7 @@ public class MythicMobsSkillFunction<CTX extends Context> extends AbstractCondit
private final String skill; private final String skill;
private final float power; private final float power;
public MythicMobsSkillFunction(String skill, float power, List<Condition<CTX>> predicates) { public MythicMobsSkillFunction(List<Condition<CTX>> predicates, float power, String skill) {
super(predicates); super(predicates);
this.skill = skill; this.skill = skill;
this.power = power; this.power = power;
@@ -42,7 +42,7 @@ public class MythicMobsSkillFunction<CTX extends Context> extends AbstractCondit
public Function<CTX> create(Map<String, Object> args) { public Function<CTX> create(Map<String, Object> args) {
String skill = ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("skill"), "warning.config.function.mythic_mobs_skill.missing_skill"); String skill = ResourceConfigUtils.requireNonEmptyStringOrThrow(args.get("skill"), "warning.config.function.mythic_mobs_skill.missing_skill");
float power = ResourceConfigUtils.getAsFloat(args.getOrDefault("power", 1.0), "power"); float power = ResourceConfigUtils.getAsFloat(args.getOrDefault("power", 1.0), "power");
return new MythicMobsSkillFunction<>(skill, power, getPredicates(args)); return new MythicMobsSkillFunction<>(getPredicates(args), power, skill);
} }
} }
} }

View File

@@ -17,7 +17,7 @@ import java.util.Optional;
public class ParticleFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> { public class ParticleFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final ParticleConfig config; private final ParticleConfig config;
public ParticleFunction(ParticleConfig config, List<Condition<CTX>> predicates) { public ParticleFunction(List<Condition<CTX>> predicates, ParticleConfig config) {
super(predicates); super(predicates);
this.config = config; this.config = config;
} }
@@ -45,7 +45,7 @@ public class ParticleFunction<CTX extends Context> extends AbstractConditionalFu
@Override @Override
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
return new ParticleFunction<>(ParticleConfig.fromMap$function(arguments), getPredicates(arguments)); return new ParticleFunction<>(getPredicates(arguments), ParticleConfig.fromMap$function(arguments));
} }
} }
} }

View File

@@ -26,7 +26,7 @@ public class PlaceBlockFunction<CTX extends Context> extends AbstractConditional
private final NumberProvider z; private final NumberProvider z;
private final NumberProvider updateFlags; private final NumberProvider updateFlags;
public PlaceBlockFunction(LazyReference<BlockStateWrapper> lazyBlockState, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, List<Condition<CTX>> predicates) { public PlaceBlockFunction(List<Condition<CTX>> predicates, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, LazyReference<BlockStateWrapper> lazyBlockState) {
super(predicates); super(predicates);
this.lazyBlockState = lazyBlockState; this.lazyBlockState = lazyBlockState;
this.x = x; this.x = x;
@@ -58,12 +58,7 @@ public class PlaceBlockFunction<CTX extends Context> extends AbstractConditional
@Override @Override
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
String state = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("block-state"), "warning.config.function.place_block.missing_block_state"); String state = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("block-state"), "warning.config.function.place_block.missing_block_state");
return new PlaceBlockFunction<>(LazyReference.lazyReference(() -> CraftEngine.instance().blockManager().createBlockState(state)), return new PlaceBlockFunction<>(getPredicates(arguments), NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")), NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")), NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")), Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())), LazyReference.lazyReference(() -> CraftEngine.instance().blockManager().createBlockState(state)));
NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")),
NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")),
NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")),
Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())),
getPredicates(arguments));
} }
} }
} }

View File

@@ -31,15 +31,7 @@ public class PlaySoundFunction<CTX extends Context> extends AbstractConditionalF
private final PlayerSelector<CTX> selector; private final PlayerSelector<CTX> selector;
public PlaySoundFunction( public PlaySoundFunction(
Key soundEvent, List<Condition<CTX>> predicates, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider volume, NumberProvider pitch, SoundSource source, PlayerSelector<CTX> selector, Key soundEvent
NumberProvider x,
NumberProvider y,
NumberProvider z,
NumberProvider volume,
NumberProvider pitch,
SoundSource source,
PlayerSelector<CTX> selector,
List<Condition<CTX>> predicates
) { ) {
super(predicates); super(predicates);
this.soundEvent = soundEvent; this.soundEvent = soundEvent;
@@ -89,7 +81,7 @@ public class PlaySoundFunction<CTX extends Context> extends AbstractConditionalF
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", 1)); NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", 1));
SoundSource source = Optional.ofNullable(arguments.get("source")).map(String::valueOf).map(it -> SoundSource.valueOf(it.toUpperCase(Locale.ENGLISH))).orElse(SoundSource.MASTER); SoundSource source = Optional.ofNullable(arguments.get("source")).map(String::valueOf).map(it -> SoundSource.valueOf(it.toUpperCase(Locale.ENGLISH))).orElse(SoundSource.MASTER);
PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()); PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.get("target"), conditionFactory());
return new PlaySoundFunction<>(soundEvent, x, y, z, volume, pitch, source, selector, getPredicates(arguments)); return new PlaySoundFunction<>(getPredicates(arguments), x, y, z, volume, pitch, source, selector, soundEvent);
} }
} }
} }

View File

@@ -21,7 +21,7 @@ public class PotionEffectFunction<CTX extends Context> extends AbstractCondition
private final boolean ambient; private final boolean ambient;
private final boolean particles; private final boolean particles;
public PotionEffectFunction(Key potionEffectType, NumberProvider duration, NumberProvider amplifier, boolean ambient, boolean particles, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public PotionEffectFunction(List<Condition<CTX>> predicates, NumberProvider duration, NumberProvider amplifier, boolean ambient, boolean particles, PlayerSelector<CTX> selector, Key potionEffectType) {
super(predicates); super(predicates);
this.potionEffectType = potionEffectType; this.potionEffectType = potionEffectType;
this.duration = duration; this.duration = duration;
@@ -63,7 +63,7 @@ public class PotionEffectFunction<CTX extends Context> extends AbstractCondition
NumberProvider amplifier = NumberProviders.fromObject(arguments.getOrDefault("amplifier", 0)); NumberProvider amplifier = NumberProviders.fromObject(arguments.getOrDefault("amplifier", 0));
boolean ambient = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("ambient", false), "ambient"); boolean ambient = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("ambient", false), "ambient");
boolean particles = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("particles", true), "particles"); boolean particles = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("particles", true), "particles");
return new PotionEffectFunction<>(effectType, duration, amplifier, ambient, particles, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new PotionEffectFunction<>(getPredicates(arguments), duration, amplifier, ambient, particles, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), effectType);
} }
} }
} }

View File

@@ -19,7 +19,7 @@ public class RemoveCooldownFunction<CTX extends Context> extends AbstractConditi
private final String id; private final String id;
private final boolean all; private final boolean all;
public RemoveCooldownFunction(String id, boolean all, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public RemoveCooldownFunction(List<Condition<CTX>> predicates, boolean all, PlayerSelector<CTX> selector, String id) {
super(predicates); super(predicates);
this.selector = selector; this.selector = selector;
this.id = id; this.id = id;
@@ -59,10 +59,10 @@ public class RemoveCooldownFunction<CTX extends Context> extends AbstractConditi
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
boolean all = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("all", false), "all"); boolean all = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("all", false), "all");
if (all) { if (all) {
return new RemoveCooldownFunction<>(null, true, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new RemoveCooldownFunction<>(getPredicates(arguments), true, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), null);
} else { } else {
String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("id"), "warning.config.function.remove_cooldown.missing_id"); String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("id"), "warning.config.function.remove_cooldown.missing_id");
return new RemoveCooldownFunction<>(id, false, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new RemoveCooldownFunction<>(getPredicates(arguments), false, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), id);
} }
} }
} }

View File

@@ -24,7 +24,7 @@ public class RemoveFurnitureFunction<CTX extends Context> extends AbstractCondit
private final boolean dropLoot; private final boolean dropLoot;
private final boolean playSound; private final boolean playSound;
public RemoveFurnitureFunction(boolean dropLoot, boolean playSound, List<Condition<CTX>> predicates) { public RemoveFurnitureFunction(List<Condition<CTX>> predicates, boolean playSound, boolean dropLoot) {
super(predicates); super(predicates);
this.dropLoot = dropLoot; this.dropLoot = dropLoot;
this.playSound = playSound; this.playSound = playSound;
@@ -80,7 +80,7 @@ public class RemoveFurnitureFunction<CTX extends Context> extends AbstractCondit
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
boolean dropLoot = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("drop-loot", true), "drop-loot"); boolean dropLoot = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("drop-loot", true), "drop-loot");
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound"); boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
return new RemoveFurnitureFunction<>(dropLoot, playSound, getPredicates(arguments)); return new RemoveFurnitureFunction<>(getPredicates(arguments), playSound, dropLoot);
} }
} }
} }

View File

@@ -17,7 +17,7 @@ public class RemovePotionEffectFunction<CTX extends Context> extends AbstractCon
private final Key potionEffectType; private final Key potionEffectType;
private final boolean all; private final boolean all;
public RemovePotionEffectFunction(Key potionEffectType, boolean all, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public RemovePotionEffectFunction(List<Condition<CTX>> predicates, boolean all, PlayerSelector<CTX> selector, Key potionEffectType) {
super(predicates); super(predicates);
this.potionEffectType = potionEffectType; this.potionEffectType = potionEffectType;
this.selector = selector; this.selector = selector;
@@ -54,10 +54,10 @@ public class RemovePotionEffectFunction<CTX extends Context> extends AbstractCon
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
boolean all = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("all", false), "all"); boolean all = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("all", false), "all");
if (all) { if (all) {
return new RemovePotionEffectFunction<>(null, true, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new RemovePotionEffectFunction<>(getPredicates(arguments), true, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), null);
} else { } else {
Key effectType = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("potion-effect"), "warning.config.function.remove_potion_effect.missing_potion_effect")); Key effectType = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("potion-effect"), "warning.config.function.remove_potion_effect.missing_potion_effect"));
return new RemovePotionEffectFunction<>(effectType, false, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new RemovePotionEffectFunction<>(getPredicates(arguments), false, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), effectType);
} }
} }
} }

View File

@@ -26,16 +26,7 @@ public class ReplaceFurnitureFunction<CTX extends Context> extends AbstractCondi
private final boolean playSound; private final boolean playSound;
public ReplaceFurnitureFunction( public ReplaceFurnitureFunction(
Key newFurnitureId, List<Condition<CTX>> predicates, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider pitch, NumberProvider yaw, String variant, boolean dropLoot, boolean playSound, Key newFurnitureId
NumberProvider x,
NumberProvider y,
NumberProvider z,
NumberProvider pitch,
NumberProvider yaw,
String variant,
boolean dropLoot,
boolean playSound,
List<Condition<CTX>> predicates
) { ) {
super(predicates); super(predicates);
this.newFurnitureId = newFurnitureId; this.newFurnitureId = newFurnitureId;
@@ -96,7 +87,7 @@ public class ReplaceFurnitureFunction<CTX extends Context> extends AbstractCondi
String variant = ResourceConfigUtils.getAsStringOrNull(ResourceConfigUtils.get(arguments, "variant", "anchor-type")); String variant = ResourceConfigUtils.getAsStringOrNull(ResourceConfigUtils.get(arguments, "variant", "anchor-type"));
boolean dropLoot = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("drop-loot", true), "drop-loot"); boolean dropLoot = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("drop-loot", true), "drop-loot");
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound"); boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
return new ReplaceFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, variant, dropLoot, playSound, getPredicates(arguments)); return new ReplaceFurnitureFunction<>(getPredicates(arguments), x, y, z, pitch, yaw, variant, dropLoot, playSound, furnitureId);
} }
} }
} }

View File

@@ -0,0 +1,84 @@
package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.entity.furniture.Furniture;
import net.momirealms.craftengine.core.entity.player.InteractionHand;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.loot.LootTable;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
import net.momirealms.craftengine.core.plugin.context.event.EventFunctions;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.sound.SoundData;
import net.momirealms.craftengine.core.sound.SoundSource;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.World;
import net.momirealms.craftengine.core.world.WorldPosition;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class RotateFurnitureFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final NumberProvider degree;
private final List<Function<Context>> successFunctions;
private final List<Function<Context>> failureFunctions;
public RotateFurnitureFunction(List<Condition<CTX>> predicates, NumberProvider degree, List<Function<Context>> successFunctions, List<Function<Context>> failureFunctions) {
super(predicates);
this.degree = degree;
this.successFunctions = successFunctions;
this.failureFunctions = failureFunctions;
}
@Override
public void runInternal(CTX ctx) {
ctx.getOptionalParameter(DirectContextParameters.FURNITURE).ifPresent(furniture -> rotateFurniture(ctx, furniture));
}
public void rotateFurniture(CTX ctx, Furniture furniture) {
if (!furniture.isValid()) return;
WorldPosition position = furniture.position();
WorldPosition newPos = new WorldPosition(position.world, position.x, position.y, position.z, position.xRot, position.yRot + this.degree.getFloat(ctx));
furniture.moveTo(newPos).thenAccept(success -> {
if (success) {
for (Function<Context> successFunction : this.successFunctions) {
successFunction.run(ctx);
}
} else {
for (Function<Context> failureFunction : this.failureFunctions) {
failureFunction.run(ctx);
}
}
});
}
@Override
public Key type() {
return CommonFunctions.ROTATE_FURNITURE;
}
public NumberProvider degree() {
return degree;
}
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}
@Override
public Function<CTX> create(Map<String, Object> arguments) {
NumberProvider degree = NumberProviders.fromObject(arguments.getOrDefault("degree", 90));
List<Function<Context>> onSuccess = ResourceConfigUtils.parseConfigAsList(arguments.get("on-success"), EventFunctions::fromMap);
List<Function<Context>> onFailure = ResourceConfigUtils.parseConfigAsList(arguments.get("on-failure"), EventFunctions::fromMap);
return new RotateFurnitureFunction<>(getPredicates(arguments), degree, onSuccess, onFailure);
}
}
}

View File

@@ -21,7 +21,7 @@ public class RunFunction<CTX extends Context> extends AbstractConditionalFunctio
private final List<Function<CTX>> functions; private final List<Function<CTX>> functions;
private final NumberProvider delay; private final NumberProvider delay;
public RunFunction(List<Function<CTX>> functions, NumberProvider delay, List<Condition<CTX>> predicates) { public RunFunction(List<Condition<CTX>> predicates, NumberProvider delay, List<Function<CTX>> functions) {
super(predicates); super(predicates);
this.functions = functions; this.functions = functions;
this.delay = delay; this.delay = delay;
@@ -75,7 +75,7 @@ public class RunFunction<CTX extends Context> extends AbstractConditionalFunctio
for (Map<String, Object> function : functions) { for (Map<String, Object> function : functions) {
fun.add(this.functionFactory.apply(function)); fun.add(this.functionFactory.apply(function));
} }
return new RunFunction<>(fun, delay, getPredicates(arguments)); return new RunFunction<>(getPredicates(arguments), delay, fun);
} }
} }
} }

View File

@@ -21,7 +21,7 @@ public class SetCooldownFunction<CTX extends Context> extends AbstractConditiona
private final String id; private final String id;
private final boolean add; private final boolean add;
public SetCooldownFunction(TextProvider time, String id, boolean add, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public SetCooldownFunction(List<Condition<CTX>> predicates, String id, boolean add, PlayerSelector<CTX> selector, TextProvider time) {
super(predicates); super(predicates);
this.time = time; this.time = time;
this.add = add; this.add = add;
@@ -66,7 +66,7 @@ public class SetCooldownFunction<CTX extends Context> extends AbstractConditiona
String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("id"), "warning.config.function.set_cooldown.missing_id"); String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("id"), "warning.config.function.set_cooldown.missing_id");
String time = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("time"), "warning.config.function.set_cooldown.missing_time"); String time = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("time"), "warning.config.function.set_cooldown.missing_time");
boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add"); boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add");
return new SetCooldownFunction<>(TextProviders.fromString(time), id, add, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new SetCooldownFunction<>(getPredicates(arguments), id, add, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), TextProviders.fromString(time));
} }
} }
} }

View File

@@ -17,7 +17,7 @@ public class SetCountFunction<CTX extends Context> extends AbstractConditionalFu
private final NumberProvider count; private final NumberProvider count;
private final boolean add; private final boolean add;
public SetCountFunction(NumberProvider count, boolean add, List<Condition<CTX>> predicates) { public SetCountFunction(List<Condition<CTX>> predicates, boolean add, NumberProvider count) {
super(predicates); super(predicates);
this.count = count; this.count = count;
this.add = add; this.add = add;
@@ -51,7 +51,7 @@ public class SetCountFunction<CTX extends Context> extends AbstractConditionalFu
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.function.set_count.missing_count"); Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.function.set_count.missing_count");
boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add"); boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add");
return new SetCountFunction<>(NumberProviders.fromObject(value), add, getPredicates(arguments)); return new SetCountFunction<>(getPredicates(arguments), add, NumberProviders.fromObject(value));
} }
} }
} }

View File

@@ -19,7 +19,7 @@ public class SetFoodFunction<CTX extends Context> extends AbstractConditionalFun
private final NumberProvider count; private final NumberProvider count;
private final boolean add; private final boolean add;
public SetFoodFunction(NumberProvider count, boolean add, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public SetFoodFunction(List<Condition<CTX>> predicates, boolean add, PlayerSelector<CTX> selector, NumberProvider count) {
super(predicates); super(predicates);
this.count = count; this.count = count;
this.add = add; this.add = add;
@@ -54,7 +54,7 @@ public class SetFoodFunction<CTX extends Context> extends AbstractConditionalFun
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("food"), "warning.config.function.set_food.missing_food"); Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("food"), "warning.config.function.set_food.missing_food");
boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add"); boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add");
return new SetFoodFunction<>(NumberProviders.fromObject(value), add, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new SetFoodFunction<>(getPredicates(arguments), add, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), NumberProviders.fromObject(value));
} }
} }
} }

View File

@@ -19,7 +19,7 @@ public class SetSaturationFunction<CTX extends Context> extends AbstractConditio
private final NumberProvider count; private final NumberProvider count;
private final boolean add; private final boolean add;
public SetSaturationFunction(NumberProvider count, boolean add, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) { public SetSaturationFunction(List<Condition<CTX>> predicates, boolean add, PlayerSelector<CTX> selector, NumberProvider count) {
super(predicates); super(predicates);
this.count = count; this.count = count;
this.add = add; this.add = add;
@@ -54,7 +54,7 @@ public class SetSaturationFunction<CTX extends Context> extends AbstractConditio
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("saturation"), "warning.config.function.set_saturation.missing_saturation"); Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("saturation"), "warning.config.function.set_saturation.missing_saturation");
boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add"); boolean add = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("add", false), "add");
return new SetSaturationFunction<>(NumberProviders.fromObject(value), add, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments)); return new SetSaturationFunction<>(getPredicates(arguments), add, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), NumberProviders.fromObject(value));
} }
} }
} }

View File

@@ -26,15 +26,7 @@ public class SpawnFurnitureFunction<CTX extends Context> extends AbstractConditi
private final boolean playSound; private final boolean playSound;
public SpawnFurnitureFunction( public SpawnFurnitureFunction(
Key furnitureId, List<Condition<CTX>> predicates, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider pitch, NumberProvider yaw, String variant, boolean playSound, Key furnitureId
NumberProvider x,
NumberProvider y,
NumberProvider z,
NumberProvider pitch,
NumberProvider yaw,
String variant,
boolean playSound,
List<Condition<CTX>> predicates
) { ) {
super(predicates); super(predicates);
this.furnitureId = furnitureId; this.furnitureId = furnitureId;
@@ -86,7 +78,7 @@ public class SpawnFurnitureFunction<CTX extends Context> extends AbstractConditi
NumberProvider yaw = NumberProviders.fromObject(arguments.getOrDefault("yaw", "<arg:position.yaw>")); NumberProvider yaw = NumberProviders.fromObject(arguments.getOrDefault("yaw", "<arg:position.yaw>"));
String variant = ResourceConfigUtils.getAsStringOrNull(ResourceConfigUtils.get(arguments, "variant", "anchor-type")); String variant = ResourceConfigUtils.getAsStringOrNull(ResourceConfigUtils.get(arguments, "variant", "anchor-type"));
boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound"); boolean playSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("play-sound", true), "play-sound");
return new SpawnFurnitureFunction<>(furnitureId, x, y, z, pitch, yaw, variant, playSound, getPredicates(arguments)); return new SpawnFurnitureFunction<>(getPredicates(arguments), x, y, z, pitch, yaw, variant, playSound, furnitureId);
} }
} }
} }

View File

@@ -15,7 +15,7 @@ import java.util.Optional;
public class SwingHandFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> { public class SwingHandFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final Optional<InteractionHand> hand; private final Optional<InteractionHand> hand;
public SwingHandFunction(Optional<InteractionHand> hand, List<Condition<CTX>> predicates) { public SwingHandFunction(List<Condition<CTX>> predicates, Optional<InteractionHand> hand) {
super(predicates); super(predicates);
this.hand = hand; this.hand = hand;
} }
@@ -46,7 +46,7 @@ public class SwingHandFunction<CTX extends Context> extends AbstractConditionalF
@Override @Override
public Function<CTX> create(Map<String, Object> arguments) { public Function<CTX> create(Map<String, Object> arguments) {
Optional<InteractionHand> optionalHand = Optional.ofNullable(arguments.get("hand")).map(it -> InteractionHand.valueOf(it.toString().toUpperCase(Locale.ENGLISH))); Optional<InteractionHand> optionalHand = Optional.ofNullable(arguments.get("hand")).map(it -> InteractionHand.valueOf(it.toString().toUpperCase(Locale.ENGLISH)));
return new SwingHandFunction<>(optionalHand, getPredicates(arguments)); return new SwingHandFunction<>(getPredicates(arguments), optionalHand);
} }
} }
} }

View File

@@ -30,7 +30,7 @@ public class TransformBlockFunction<CTX extends Context> extends AbstractConditi
private final NumberProvider z; private final NumberProvider z;
private final NumberProvider updateFlags; private final NumberProvider updateFlags;
public TransformBlockFunction(LazyReference<BlockStateWrapper> lazyBlockState, CompoundTag properties, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, List<Condition<CTX>> predicates) { public TransformBlockFunction(List<Condition<CTX>> predicates, CompoundTag properties, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, LazyReference<BlockStateWrapper> lazyBlockState) {
super(predicates); super(predicates);
this.properties = properties; this.properties = properties;
this.x = x; this.x = x;
@@ -84,13 +84,8 @@ public class TransformBlockFunction<CTX extends Context> extends AbstractConditi
} }
} }
return new TransformBlockFunction<>( return new TransformBlockFunction<>(
LazyReference.lazyReference(() -> CraftEngine.instance().blockManager().createBlockState(block)), getPredicates(arguments), properties, NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")), NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")), NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")), Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())), LazyReference.lazyReference(() -> CraftEngine.instance().blockManager().createBlockState(block))
properties, );
NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")),
NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")),
NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")),
Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())),
getPredicates(arguments));
} }
} }
} }

View File

@@ -26,7 +26,7 @@ public class UpdateBlockPropertyFunction<CTX extends Context> extends AbstractCo
private final NumberProvider z; private final NumberProvider z;
private final NumberProvider updateFlags; private final NumberProvider updateFlags;
public UpdateBlockPropertyFunction(CompoundTag properties, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, List<Condition<CTX>> predicates) { public UpdateBlockPropertyFunction(List<Condition<CTX>> predicates, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, CompoundTag properties) {
super(predicates); super(predicates);
this.properties = properties; this.properties = properties;
this.x = x; this.x = x;
@@ -67,12 +67,8 @@ public class UpdateBlockPropertyFunction<CTX extends Context> extends AbstractCo
for (Map.Entry<String, Object> entry : state.entrySet()) { for (Map.Entry<String, Object> entry : state.entrySet()) {
properties.putString(entry.getKey(), String.valueOf(entry.getValue())); properties.putString(entry.getKey(), String.valueOf(entry.getValue()));
} }
return new UpdateBlockPropertyFunction<>(properties, return new UpdateBlockPropertyFunction<>(getPredicates(arguments), NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")), NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")), NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")), Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())), properties
NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>")), );
NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>")),
NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")),
Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())),
getPredicates(arguments));
} }
} }
} }

View File

@@ -2,6 +2,7 @@ package net.momirealms.craftengine.core.plugin.entityculling;
import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.world.ChunkPos; import net.momirealms.craftengine.core.world.ChunkPos;
import net.momirealms.craftengine.core.world.MutableVec3d; import net.momirealms.craftengine.core.world.MutableVec3d;

View File

@@ -59,9 +59,9 @@ concurrent_util_version=0.0.3
bucket4j_version=8.15.0 bucket4j_version=8.15.0
# Proxy settings # Proxy settings
#systemProp.socks.proxyHost=127.0.0.1 systemProp.socks.proxyHost=127.0.0.1
#systemProp.socks.proxyPort=7890 systemProp.socks.proxyPort=7890
#systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=7890 systemProp.http.proxyPort=7890
#systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1
#systemProp.https.proxyPort=7890 systemProp.https.proxyPort=7890