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

完善slab行为

This commit is contained in:
XiaoMoMi
2025-06-21 05:09:56 +08:00
parent 16fea80479
commit 0dcf3201b7
7 changed files with 19 additions and 26 deletions

View File

@@ -42,7 +42,7 @@ public class SlabBlockBehavior extends BukkitBlockBehavior {
public boolean canBeReplaced(BlockPlaceContext context, ImmutableBlockState state) {
SlabType type = state.get(this.typeProperty);
Item<ItemStack> item = (Item<ItemStack>) context.getItem();
if (type == SlabType.DOUBLE) return false;
if (type == SlabType.DOUBLE || item == null) return false;
Optional<CustomItem<ItemStack>> itemInHand = item.getCustomItem();
if (itemInHand.isEmpty()) return false;
CustomItem<ItemStack> customItem = itemInHand.get();
@@ -57,8 +57,8 @@ public class SlabBlockBehavior extends BukkitBlockBehavior {
boolean upper = context.getClickLocation().y - (double) context.getClickedPos().y() > (double) 0.5F;
Direction clickedFace = context.getClickedFace();
return type == SlabType.BOTTOM ?
clickedFace == Direction.UP || upper && clickedFace.axis().isHorizontal() :
clickedFace == Direction.DOWN || !upper && clickedFace.axis().isHorizontal();
clickedFace == Direction.UP || (upper && clickedFace.axis().isHorizontal()) :
clickedFace == Direction.DOWN || (!upper && clickedFace.axis().isHorizontal());
}
@Override
@@ -119,8 +119,7 @@ public class SlabBlockBehavior extends BukkitBlockBehavior {
@SuppressWarnings("unchecked")
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
Property<SlabType> type = (Property<SlabType>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("type"), "warning.config.block.behavior.trapdoor.missing_type");
Property<SlabType> type = (Property<SlabType>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("type"), "warning.config.block.behavior.slab.missing_type");
return new SlabBlockBehavior(block, type);
}
}

View File

@@ -2,26 +2,17 @@ package net.momirealms.craftengine.bukkit.world;
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.item.behavior.BlockItemBehavior;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MFluids;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.LocationUtils;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.world.BlockInWorld;
import net.momirealms.craftengine.core.world.World;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import java.util.Optional;
public class BukkitBlockInWorld implements BlockInWorld {
private final Block block;

View File

@@ -258,10 +258,11 @@ warning.config.block.behavior.trapdoor.missing_open: "<yellow>Issue found in fil
warning.config.block.behavior.trapdoor.missing_powered: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'powered' property for 'trapdoor_block' behavior.</yellow>"
warning.config.block.behavior.stackable.missing_amount: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'amount' property for 'stackable_block' behavior.</yellow>"
warning.config.block.behavior.stackable.missing_items: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'items' argument for 'stackable_block' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_facing: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'facing' argument for 'fence_gate' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_in_wall: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'in_wall' argument for 'fence_gate' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_open: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'powered' argument for 'fence_gate' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_powered: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'open' argument for 'fence_gate' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_facing: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'facing' argument for 'fence_gate_block' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_in_wall: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'in_wall' argument for 'fence_gate_block' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_open: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'powered' argument for 'fence_gate_block' behavior.</yellow>"
warning.config.block.behavior.fence_gate.missing_powered: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'open' argument for 'fence_gate_block' behavior.</yellow>"
warning.config.block.behavior.trapdoor.missing_type: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'type' property for 'slab_block' behavior.</yellow>"
warning.config.model.generation.missing_parent: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'parent' argument in 'generation' section.</yellow>"
warning.config.model.generation.invalid_display_position: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid display position '<arg:2>' in 'generation.display' section. Allowed display positions: [<arg:3>]</yellow>"
warning.config.model.generation.invalid_gui_light: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid gui-light option '<arg:2>' in 'generation' section. Allowed gui light options: [<arg:3>]</yellow>"

View File

@@ -258,10 +258,11 @@ warning.config.block.behavior.trapdoor.missing_open: "<yellow>在文件 <arg:0>
warning.config.block.behavior.trapdoor.missing_powered: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'trapdoor_block' 行为缺少必需的 'powered' 属性</yellow>"
warning.config.block.behavior.stackable.missing_amount: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'stackable_block' 行为缺少必需的 'amount' 属性</yellow>"
warning.config.block.behavior.stackable.missing_items: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'stackable_block' 行为缺少必需的 'items' 参数</yellow>"
warning.config.block.behavior.fence_gate.missing_facing: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate' 行为缺少必需的 'facing' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_in_wall: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate' 行为缺少必需的 'in_wall' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_open: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate' 行为缺少必需的 'open' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_powered: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate' 行为缺少必需的 'powered' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_facing: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate_block' 行为缺少必需的 'facing' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_in_wall: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate_block' 行为缺少必需的 'in_wall' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_open: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate_block' 行为缺少必需的 'open' 属性</yellow>"
warning.config.block.behavior.fence_gate.missing_powered: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_gate_block' 行为缺少必需的 'powered' 属性</yellow>"
warning.config.block.behavior.slab.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'slab_block' 行为缺少必需的 'type' 属性</yellow>"
warning.config.model.generation.missing_parent: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 的 'generation' 段落缺少必需的 'parent' 参数</yellow>"
warning.config.model.generation.conflict: "<yellow>在文件 <arg:0> 发现问题 - 无法为 '<arg:1>' 生成模型 存在多个配置尝试使用相同路径 '<arg:2>' 生成不同的 JSON 模型</yellow>"
warning.config.model.generation.invalid_display_position: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 在 'generation.display' 区域使用了无效的 display 位置类型 '<arg:2>'. 可用展示类型: [<arg:3>]</yellow>"

View File

@@ -19,6 +19,7 @@ public class BlockPlaceContext extends UseOnContext {
public BlockPlaceContext(World world, Player player, InteractionHand hand, Item<?> stack, BlockHitResult hit) {
super(world, player, hand, stack, hit);
this.relativePos = hit.getBlockPos().relative(hit.getDirection());
this.replaceClicked = true;
this.replaceClicked = world.getBlockAt(hit.getBlockPos()).canBeReplaced(this);
}

View File

@@ -3,8 +3,6 @@ package net.momirealms.craftengine.core.pack.misc;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.item.setting.EquipmentData;
import net.momirealms.craftengine.core.pack.model.tint.Tint;
import net.momirealms.craftengine.core.util.Color;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.NotNull;

View File

@@ -4,11 +4,13 @@ import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
import net.momirealms.craftengine.core.util.VersionHelper;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.nodes.*;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.ScalarNode;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class StringKeyConstructor extends SafeConstructor {