9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00
This commit is contained in:
jhqwqmc
2025-11-17 20:43:31 +08:00
parent a435f401f7
commit 3c5aa186dc
6 changed files with 81 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ public class BukkitItemBehaviors extends ItemBehaviors {
public static final Key DOUBLE_HIGH_BLOCK_ITEM = Key.from("craftengine:double_high_block_item"); public static final Key DOUBLE_HIGH_BLOCK_ITEM = Key.from("craftengine:double_high_block_item");
public static final Key WALL_BLOCK_ITEM = Key.from("craftengine:wall_block_item"); public static final Key WALL_BLOCK_ITEM = Key.from("craftengine:wall_block_item");
public static final Key CEILING_BLOCK_ITEM = Key.from("craftengine:ceiling_block_item"); public static final Key CEILING_BLOCK_ITEM = Key.from("craftengine:ceiling_block_item");
public static final Key GROUND_BLOCK_ITEM = Key.from("craftengine:ground_block_item");
public static void init() { public static void init() {
register(EMPTY, EmptyItemBehavior.FACTORY); register(EMPTY, EmptyItemBehavior.FACTORY);
@@ -26,5 +27,6 @@ public class BukkitItemBehaviors extends ItemBehaviors {
register(DOUBLE_HIGH_BLOCK_ITEM, DoubleHighBlockItemBehavior.FACTORY); register(DOUBLE_HIGH_BLOCK_ITEM, DoubleHighBlockItemBehavior.FACTORY);
register(WALL_BLOCK_ITEM, WallBlockItemBehavior.FACTORY); register(WALL_BLOCK_ITEM, WallBlockItemBehavior.FACTORY);
register(CEILING_BLOCK_ITEM, CeilingBlockItemBehavior.FACTORY); register(CEILING_BLOCK_ITEM, CeilingBlockItemBehavior.FACTORY);
register(GROUND_BLOCK_ITEM, GroundBlockItemBehavior.FACTORY);
} }
} }

View File

@@ -27,12 +27,10 @@ public class CeilingBlockItemBehavior extends BlockItemBehavior {
@Override @Override
public InteractionResult place(BlockPlaceContext context) { public InteractionResult place(BlockPlaceContext context) {
for (Direction direction : context.getNearestLookingDirections()) { if (context.getClickedFace() != Direction.DOWN) {
if (direction.axis() != Direction.Axis.Y) continue; return InteractionResult.PASS;
if (direction == Direction.DOWN) break; // 如果最后只能放到地面就直接不放置
super.place(context);
} }
return InteractionResult.PASS; return super.place(context);
} }
public static class Factory implements ItemBehaviorFactory { public static class Factory implements ItemBehaviorFactory {

View File

@@ -0,0 +1,51 @@
package net.momirealms.craftengine.bukkit.item.behavior;
import net.momirealms.craftengine.core.entity.player.InteractionResult;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key;
import java.nio.file.Path;
import java.util.Map;
public class GroundBlockItemBehavior extends BlockItemBehavior {
public static final Factory FACTORY = new Factory();
public GroundBlockItemBehavior(Key ceilingBlockId) {
super(ceilingBlockId);
}
@Override
public InteractionResult useOnBlock(UseOnContext context) {
return this.place(new BlockPlaceContext(context));
}
@Override
public InteractionResult place(BlockPlaceContext context) {
if (context.getClickedFace() != Direction.UP) {
return InteractionResult.PASS;
}
return super.place(context);
}
public static class Factory implements ItemBehaviorFactory {
@Override
public ItemBehavior create(Pack pack, Path path, String node, Key key, Map<String, Object> arguments) {
Object id = arguments.get("block");
if (id == null) {
throw new LocalizedResourceConfigException("warning.config.item.behavior.ground_block.missing_block", new IllegalArgumentException("Missing required parameter 'block' for ground_block_item behavior"));
}
if (id instanceof Map<?, ?> map) {
addPendingSection(pack, path, node, key, map);
return new GroundBlockItemBehavior(key);
} else {
return new GroundBlockItemBehavior(Key.of(id.toString()));
}
}
}
}

View File

@@ -7,16 +7,21 @@ import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.item.context.UseOnContext; import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.Tristate;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Map; import java.util.Map;
public class WallBlockItemBehavior extends BlockItemBehavior { public class WallBlockItemBehavior extends BlockItemBehavior {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
private final Tristate hanging;
public WallBlockItemBehavior(Key wallBlockId) { public WallBlockItemBehavior(Key wallBlockId, Tristate hanging) {
super(wallBlockId); super(wallBlockId);
this.hanging = hanging;
} }
@Override @Override
@@ -29,7 +34,20 @@ public class WallBlockItemBehavior extends BlockItemBehavior {
if (context.getClickedFace().stepY() != 0) { if (context.getClickedFace().stepY() != 0) {
return InteractionResult.PASS; return InteractionResult.PASS;
} }
return super.place(context); if (this.hanging == Tristate.UNDEFINED) {
return super.place(context);
}
for (Direction direction : context.getNearestLookingDirections()) {
if (direction.axis() != Direction.Axis.Y) continue;
if (this.hanging == Tristate.FALSE) {
if (direction == Direction.DOWN) return super.place(context);
if (direction == Direction.UP) break;
} else if (this.hanging == Tristate.TRUE) {
if (direction == Direction.UP) return super.place(context);
if (direction == Direction.DOWN) break;
}
}
return InteractionResult.PASS;
} }
public static class Factory implements ItemBehaviorFactory { public static class Factory implements ItemBehaviorFactory {
@@ -39,11 +57,12 @@ public class WallBlockItemBehavior extends BlockItemBehavior {
if (id == null) { if (id == null) {
throw new LocalizedResourceConfigException("warning.config.item.behavior.wall_block.missing_block", new IllegalArgumentException("Missing required parameter 'block' for wall_block_item behavior")); throw new LocalizedResourceConfigException("warning.config.item.behavior.wall_block.missing_block", new IllegalArgumentException("Missing required parameter 'block' for wall_block_item behavior"));
} }
Tristate hanging = arguments.containsKey("hanging") ? Tristate.of(ResourceConfigUtils.getAsBoolean(arguments.get("hanging"), "hanging")) : Tristate.UNDEFINED;
if (id instanceof Map<?, ?> map) { if (id instanceof Map<?, ?> map) {
addPendingSection(pack, path, node, key, map); addPendingSection(pack, path, node, key, map);
return new WallBlockItemBehavior(key); return new WallBlockItemBehavior(key, hanging);
} else { } else {
return new WallBlockItemBehavior(Key.of(id.toString())); return new WallBlockItemBehavior(Key.of(id.toString()), hanging);
} }
} }
} }

View File

@@ -214,6 +214,7 @@ warning.config.item.behavior.invalid_type: "<yellow>Issue found in file <arg:0>
warning.config.item.behavior.block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'block_item' behavior.</yellow>" warning.config.item.behavior.block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'block_item' behavior.</yellow>"
warning.config.item.behavior.wall_block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'wall_block_item' behavior.</yellow>" warning.config.item.behavior.wall_block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'wall_block_item' behavior.</yellow>"
warning.config.item.behavior.ceiling_block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'ceiling_block_item' behavior.</yellow>" warning.config.item.behavior.ceiling_block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'ceiling_block_item' behavior.</yellow>"
warning.config.item.behavior.ground_block.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'ground_block_item' behavior.</yellow>"
warning.config.item.behavior.furniture.missing_furniture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'furniture' argument for 'furniture_item' behavior.</yellow>" warning.config.item.behavior.furniture.missing_furniture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'furniture' argument for 'furniture_item' behavior.</yellow>"
warning.config.item.behavior.liquid_collision.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'liquid_collision_block_item' behavior.</yellow>" warning.config.item.behavior.liquid_collision.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'liquid_collision_block_item' behavior.</yellow>"
warning.config.item.behavior.double_high.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'double_high_block_item' behavior.</yellow>" warning.config.item.behavior.double_high.missing_block: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'block' argument for 'double_high_block_item' behavior.</yellow>"

View File

@@ -214,6 +214,7 @@ warning.config.item.behavior.invalid_type: "<yellow>在文件 <arg:0> 发现问
warning.config.item.behavior.block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'block_item' 行为缺少必需的 'block' 参数</yellow>" warning.config.item.behavior.block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'block_item' 行为缺少必需的 'block' 参数</yellow>"
warning.config.item.behavior.wall_block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少 'wall_block_item' 行为所需的 'block' 参数</yellow>" warning.config.item.behavior.wall_block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少 'wall_block_item' 行为所需的 'block' 参数</yellow>"
warning.config.item.behavior.ceiling_block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少 'ceiling_block_item' 行为所需的 'block' 参数</yellow>" warning.config.item.behavior.ceiling_block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少 'ceiling_block_item' 行为所需的 'block' 参数</yellow>"
warning.config.item.behavior.ground_block.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 缺少 'ground_block_item' 行为所需的 'block' 参数</yellow>"
warning.config.item.behavior.furniture.missing_furniture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'furniture_item' 行为缺少必需的 'furniture' 参数</yellow>" warning.config.item.behavior.furniture.missing_furniture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'furniture_item' 行为缺少必需的 'furniture' 参数</yellow>"
warning.config.item.behavior.liquid_collision.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'liquid_collision_block_item' 行为缺少必需的 'block' 参数</yellow>" warning.config.item.behavior.liquid_collision.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'liquid_collision_block_item' 行为缺少必需的 'block' 参数</yellow>"
warning.config.item.behavior.double_high.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'double_high_block_item' 行为缺少必需的 'block' 参数</yellow>" warning.config.item.behavior.double_high.missing_block: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'double_high_block_item' 行为缺少必需的 'block' 参数</yellow>"