9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 17:09:19 +00:00
This commit is contained in:
jhqwqmc
2025-09-20 02:46:42 +08:00
parent ea1b684982
commit 150444819c
5 changed files with 19 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.block.state.properties.AttachFace;
import net.momirealms.craftengine.core.block.state.properties.AnchorType;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.HorizontalDirection;
@@ -27,7 +27,7 @@ import java.util.concurrent.Callable;
public class FaceAttachedHorizontalDirectionalBlockBehavior extends BukkitBlockBehavior {
public static final Factory FACTORY = new Factory();
private final Property<AttachFace> attachFaceProperty;
private final Property<AnchorType> anchorTypeProperty;
private final Property<HorizontalDirection> facingProperty;
private final List<Object> tagsCanSurviveOn;
private final Set<Object> blockStatesCanSurviveOn;
@@ -39,14 +39,14 @@ public class FaceAttachedHorizontalDirectionalBlockBehavior extends BukkitBlockB
List<Object> tagsCanSurviveOn,
Set<Object> blockStatesCanSurviveOn,
Set<String> customBlocksCansSurviveOn,
Property<AttachFace> attachFace,
Property<AnchorType> anchorType,
Property<HorizontalDirection> facing) {
super(customBlock);
this.tagsCanSurviveOn = tagsCanSurviveOn;
this.blockStatesCanSurviveOn = blockStatesCanSurviveOn;
this.customBlocksCansSurviveOn = customBlocksCansSurviveOn;
this.blacklistMode = blacklist;
this.attachFaceProperty = attachFace;
this.anchorTypeProperty = anchorType;
this.facingProperty = facing;
}
@@ -64,16 +64,16 @@ public class FaceAttachedHorizontalDirectionalBlockBehavior extends BukkitBlockB
@SuppressWarnings("unchecked")
@Override
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
Property<AttachFace> face = (Property<AttachFace>) state.owner().value().getProperty("face");
Property<AnchorType> face = (Property<AnchorType>) state.owner().value().getProperty("face");
Property<HorizontalDirection> facing = (Property<HorizontalDirection>) state.owner().value().getProperty("facing");
if (face == null || facing == null) return null;
for (Direction direction : context.getNearestLookingDirections()) {
if (direction.axis() == Direction.Axis.Y) {
state = state
.with(face, direction == Direction.UP ? AttachFace.CEILING : AttachFace.FLOOR)
.with(face, direction == Direction.UP ? AnchorType.CEILING : AnchorType.FLOOR)
.with(facing, context.getHorizontalDirection().toHorizontalDirection());
} else {
state = state.with(face, AttachFace.WALL).with(facing, direction.opposite().toHorizontalDirection());
state = state.with(face, AnchorType.WALL).with(facing, direction.opposite().toHorizontalDirection());
}
if (FastNMS.INSTANCE.method$BlockStateBase$canSurvive(state.customBlockState().literalObject(), context.getLevel().serverWorld(), LocationUtils.toBlockPos(context.getClickedPos()))) {
return state;
@@ -128,7 +128,7 @@ public class FaceAttachedHorizontalDirectionalBlockBehavior extends BukkitBlockB
if (state == null) return null;
FaceAttachedHorizontalDirectionalBlockBehavior behavior = state.behavior().getAs(FaceAttachedHorizontalDirectionalBlockBehavior.class).orElse(null);
if (behavior == null) return null;
return switch (state.get(behavior.attachFaceProperty)) {
return switch (state.get(behavior.anchorTypeProperty)) {
case CEILING -> Direction.DOWN;
case FLOOR -> Direction.UP;
default -> state.get(behavior.facingProperty).toDirection();
@@ -140,11 +140,11 @@ public class FaceAttachedHorizontalDirectionalBlockBehavior extends BukkitBlockB
@SuppressWarnings("unchecked")
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
Property<AttachFace> attachFace = (Property<AttachFace>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("face"), "warning.config.block.behavior.face_attached_horizontal_directional.missing_face");
Property<AnchorType> anchorType = (Property<AnchorType>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("face"), "warning.config.block.behavior.face_attached_horizontal_directional.missing_face");
Property<HorizontalDirection> facing = (Property<HorizontalDirection>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("facing"), "warning.config.block.behavior.face_attached_horizontal_directional.missing_facing");
Tuple<List<Object>, Set<Object>, Set<String>> tuple = DirectionalAttachedBlockBehavior.readTagsAndState(arguments);
boolean blacklistMode = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("blacklist", true), "blacklist");
return new FaceAttachedHorizontalDirectionalBlockBehavior(block, blacklistMode, tuple.left(), tuple.mid(), tuple.right(), attachFace, facing);
return new FaceAttachedHorizontalDirectionalBlockBehavior(block, blacklistMode, tuple.left(), tuple.mid(), tuple.right(), anchorType, facing);
}
}
}

View File

@@ -325,6 +325,9 @@ warning.config.block.behavior.fence.missing_north: "<yellow>Issue found in file
warning.config.block.behavior.fence.missing_east: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'east' property for 'fence_block' behavior.</yellow>"
warning.config.block.behavior.fence.missing_south: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'south' property for 'fence_block' behavior.</yellow>"
warning.config.block.behavior.fence.missing_west: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'west' property for 'fence_block' behavior.</yellow>"
warning.config.block.behavior.face_attached_horizontal_directional.missing_face: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'face' property for 'face_attached_horizontal_directional_block' behavior.</yellow>"
warning.config.block.behavior.face_attached_horizontal_directional.missing_facing: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'facing' property for 'face_attached_horizontal_directional_block' behavior.</yellow>"
warning.config.block.behavior.button.missing_powered: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'powered' property for 'button_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.conflict: "<yellow>Issue found in file <arg:0> - Failed to generate model for '<arg:1>' as two or more configurations attempt to generate different json models with the same path: '<arg:2>'.</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>"

View File

@@ -319,6 +319,9 @@ warning.config.block.behavior.fence.missing_north: "<yellow>在文件 <arg:0>
warning.config.block.behavior.fence.missing_east: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_block' 行为缺少必需的 'east' 属性</yellow>"
warning.config.block.behavior.fence.missing_south: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_block' 行为缺少必需的 'south' 属性</yellow>"
warning.config.block.behavior.fence.missing_west: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'fence_block' 行为缺少必需的 'west' 属性</yellow>"
warning.config.block.behavior.face_attached_horizontal_directional.missing_face: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'face_attached_horizontal_directional_block' 行为缺少必需的 'face' 属性</yellow>"
warning.config.block.behavior.face_attached_horizontal_directional.missing_facing: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'face_attached_horizontal_directional_block' 行为缺少必需的 'facing' 属性</yellow>"
warning.config.block.behavior.button.missing_powered: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'button_block' 行为缺少必需的 'powered' 属性</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

@@ -22,7 +22,7 @@ public final class Properties {
public static final Key STAIRS_SHAPE = Key.of("craftengine:stairs_shape");
public static final Key SLAB_TYPE = Key.of("craftengine:slab_type");
public static final Key SOFA_SHAPE = Key.of("craftengine:sofa_shape");
public static final Key ATTACH_FACE = Key.of("craftengine:attach_face");
public static final Key ANCHOR_TYPE = Key.of("craftengine:anchor_type");
static {
register(BOOLEAN, BooleanProperty.FACTORY);
@@ -39,7 +39,7 @@ public final class Properties {
register(STAIRS_SHAPE, new EnumProperty.Factory<>(StairsShape.class));
register(SLAB_TYPE, new EnumProperty.Factory<>(SlabType.class));
register(SOFA_SHAPE, new EnumProperty.Factory<>(SofaShape.class));
register(ATTACH_FACE, new EnumProperty.Factory<>(AttachFace.class));
register(ANCHOR_TYPE, new EnumProperty.Factory<>(AnchorType.class));
}

View File

@@ -1,6 +1,6 @@
package net.momirealms.craftengine.core.block.state.properties;
public enum AttachFace {
public enum AnchorType {
FLOOR,
WALL,
CEILING