diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SturdyBaseBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SturdyBaseBlockBehavior.java index aca8e0baf..6ec63efb4 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SturdyBaseBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SturdyBaseBlockBehavior.java @@ -10,20 +10,26 @@ 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.util.Direction; +import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.ResourceConfigUtils; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; public class SturdyBaseBlockBehavior extends AbstractCanSurviveBlockBehavior { public static final Factory FACTORY = new Factory(); private final Direction direction; private final boolean stackable; + private final List supportTypes; - public SturdyBaseBlockBehavior(CustomBlock block, int delay, Direction direction, boolean stackable) { + public SturdyBaseBlockBehavior(CustomBlock block, int delay, Direction direction, boolean stackable, List supportTypes) { super(block, delay); this.direction = direction; this.stackable = stackable; + this.supportTypes = supportTypes; } @Override @@ -33,11 +39,13 @@ public class SturdyBaseBlockBehavior extends AbstractCanSurviveBlockBehavior { int z = FastNMS.INSTANCE.field$Vec3i$z(blockPos) + this.direction.stepZ(); Object targetPos = FastNMS.INSTANCE.constructor$BlockPos(x, y, z); Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, targetPos); - if ((boolean) CoreReflections.method$BlockStateBase$isFaceSturdy.invoke( - blockState, world, targetPos, DirectionUtils.toNMSDirection(this.direction.opposite()), - CoreReflections.instance$SupportType$FULL - )) { - return true; + for (Object supportType : this.supportTypes) { + if ((boolean) CoreReflections.method$BlockStateBase$isFaceSturdy.invoke( + blockState, world, targetPos, DirectionUtils.toNMSDirection(this.direction.opposite()), + supportType + )) { + return true; + } } if (!this.stackable) { return false; @@ -54,7 +62,22 @@ public class SturdyBaseBlockBehavior extends AbstractCanSurviveBlockBehavior { int delay = ResourceConfigUtils.getAsInt(arguments.getOrDefault("delay", 0), "delay"); Direction direction = Direction.valueOf(arguments.getOrDefault("direction", "down").toString().toUpperCase(Locale.ENGLISH)); boolean stackable = (boolean) arguments.getOrDefault("stackable", false); - return new SturdyBaseBlockBehavior(block, delay, direction, stackable); + List supportTypes = MiscUtils.getAsStringList(arguments.getOrDefault("support-types", List.of("full"))) + .stream() + .map(it -> { + if (it.equalsIgnoreCase("full")) { + return CoreReflections.instance$SupportType$FULL; + } else if (it.equalsIgnoreCase("rigid")) { + return CoreReflections.instance$SupportType$RIGID; + } else if (it.equalsIgnoreCase("center")) { + return CoreReflections.instance$SupportType$CENTER; + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toList(); + return new SturdyBaseBlockBehavior(block, delay, direction, stackable, supportTypes); } } }