mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 18:09:27 +00:00
添加坚固地板参数
This commit is contained in:
@@ -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<Object> supportTypes;
|
||||
|
||||
public SturdyBaseBlockBehavior(CustomBlock block, int delay, Direction direction, boolean stackable) {
|
||||
public SturdyBaseBlockBehavior(CustomBlock block, int delay, Direction direction, boolean stackable, List<Object> 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<Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user