[Fix] Placing Facing Blocks
This commit is contained in:
parent
3f04b85565
commit
e3b3ea7872
4 changed files with 42 additions and 22 deletions
|
@ -348,11 +348,11 @@ public class BCLFeatureBuilder<FC extends FeatureConfiguration, F extends Featur
|
||||||
* @see #findSolidSurface(Direction, int) for Details
|
* @see #findSolidSurface(Direction, int) for Details
|
||||||
*/
|
*/
|
||||||
public BCLFeatureBuilder findSolidSurface(Direction dir, int distance) {
|
public BCLFeatureBuilder findSolidSurface(Direction dir, int distance) {
|
||||||
return modifier(new FindSolidInDirection(dir, distance));
|
return modifier(new FindSolidInDirection(dir, distance, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BCLFeatureBuilder findSolidSurface(List<Direction> dir, int distance, boolean randomSelect) {
|
public BCLFeatureBuilder findSolidSurface(List<Direction> dir, int distance, boolean randomSelect) {
|
||||||
return modifier(new FindSolidInDirection(dir, distance, randomSelect));
|
return modifier(new FindSolidInDirection(dir, distance, randomSelect, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BCLFeatureBuilder heightmap() {
|
public BCLFeatureBuilder heightmap() {
|
||||||
|
|
|
@ -12,14 +12,14 @@ public class FindSolidInDirection extends org.betterx.bclib.api.v3.levelgen.feat
|
||||||
|
|
||||||
|
|
||||||
public FindSolidInDirection(Direction direction, int maxSearchDistance) {
|
public FindSolidInDirection(Direction direction, int maxSearchDistance) {
|
||||||
super(direction, maxSearchDistance);
|
super(direction, maxSearchDistance, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance) {
|
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance) {
|
||||||
super(direction, maxSearchDistance);
|
super(direction, maxSearchDistance, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance, boolean randomSelect) {
|
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance, boolean randomSelect) {
|
||||||
super(direction, maxSearchDistance, randomSelect);
|
super(direction, maxSearchDistance, randomSelect, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,6 @@ public class PlaceFacingBlockConfig extends PlaceBlockFeatureConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
||||||
public boolean placeBlock(
|
public boolean placeBlock(
|
||||||
FeaturePlaceContext<? extends PlaceBlockFeatureConfig> ctx,
|
FeaturePlaceContext<? extends PlaceBlockFeatureConfig> ctx,
|
||||||
WorldGenLevel level,
|
WorldGenLevel level,
|
||||||
|
@ -78,11 +77,11 @@ public class PlaceFacingBlockConfig extends PlaceBlockFeatureConfig {
|
||||||
BlockState lookupState;
|
BlockState lookupState;
|
||||||
BlockPos testPos;
|
BlockPos testPos;
|
||||||
for (Direction dir : directions) {
|
for (Direction dir : directions) {
|
||||||
testPos = pos.relative(dir.getOpposite());
|
testPos = pos.relative(dir);
|
||||||
lookupState = targetState.setValue(HorizontalDirectionalBlock.FACING, dir);
|
lookupState = targetState.setValue(HorizontalDirectionalBlock.FACING, dir);
|
||||||
if (lookupState.canSurvive(level, testPos) && level.getBlockState(testPos).isAir()) {
|
if (level.getBlockState(testPos).isAir() && lookupState.canSurvive(level, testPos)) {
|
||||||
|
lookupState.canSurvive(level, testPos);
|
||||||
BlocksHelper.setWithoutUpdate(level, testPos, lookupState);
|
BlocksHelper.setWithoutUpdate(level, testPos, lookupState);
|
||||||
//BlocksHelper.setWithoutUpdate(level, pos, level.getBlockState(pos.relative(dir.getOpposite())));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,34 +27,42 @@ public class FindSolidInDirection extends PlacementModifier {
|
||||||
.orElse(List.of(Direction.DOWN))
|
.orElse(List.of(Direction.DOWN))
|
||||||
.forGetter(a -> a.direction),
|
.forGetter(a -> a.direction),
|
||||||
Codec.intRange(1, 32).fieldOf("dist").orElse(12).forGetter((p) -> p.maxSearchDistance),
|
Codec.intRange(1, 32).fieldOf("dist").orElse(12).forGetter((p) -> p.maxSearchDistance),
|
||||||
Codec.BOOL.fieldOf("random:select").orElse(true).forGetter(p -> p.randomSelect)
|
Codec.BOOL.fieldOf("random_select").orElse(true).forGetter(p -> p.randomSelect),
|
||||||
|
Codec.INT.fieldOf("offset_in_dir").orElse(0).forGetter(p -> p.offsetInDir)
|
||||||
)
|
)
|
||||||
.apply(
|
.apply(
|
||||||
instance,
|
instance,
|
||||||
FindSolidInDirection::new
|
FindSolidInDirection::new
|
||||||
));
|
));
|
||||||
protected static final FindSolidInDirection DOWN = new FindSolidInDirection(Direction.DOWN, 6);
|
protected static final FindSolidInDirection DOWN = new FindSolidInDirection(Direction.DOWN, 6, 0);
|
||||||
protected static final FindSolidInDirection UP = new FindSolidInDirection(Direction.UP, 6);
|
protected static final FindSolidInDirection UP = new FindSolidInDirection(Direction.UP, 6, 0);
|
||||||
private final List<Direction> direction;
|
private final List<Direction> direction;
|
||||||
private final int maxSearchDistance;
|
private final int maxSearchDistance;
|
||||||
|
|
||||||
|
private final int offsetInDir;
|
||||||
private final boolean randomSelect;
|
private final boolean randomSelect;
|
||||||
private final IntProvider provider;
|
private final IntProvider provider;
|
||||||
|
|
||||||
|
|
||||||
public FindSolidInDirection(Direction direction, int maxSearchDistance) {
|
public FindSolidInDirection(Direction direction, int maxSearchDistance, int offsetInDir) {
|
||||||
this(List.of(direction), maxSearchDistance, false);
|
this(List.of(direction), maxSearchDistance, false, offsetInDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance) {
|
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance, int offsetInDir) {
|
||||||
this(direction, maxSearchDistance, direction.size() > 1);
|
this(direction, maxSearchDistance, direction.size() > 1, offsetInDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FindSolidInDirection(List<Direction> direction, int maxSearchDistance, boolean randomSelect) {
|
public FindSolidInDirection(
|
||||||
|
List<Direction> direction,
|
||||||
|
int maxSearchDistance,
|
||||||
|
boolean randomSelect,
|
||||||
|
int offsetInDir
|
||||||
|
) {
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
this.maxSearchDistance = maxSearchDistance;
|
this.maxSearchDistance = maxSearchDistance;
|
||||||
this.provider = UniformInt.of(0, direction.size() - 1);
|
this.provider = UniformInt.of(0, direction.size() - 1);
|
||||||
this.randomSelect = randomSelect;
|
this.randomSelect = randomSelect;
|
||||||
|
this.offsetInDir = offsetInDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlacementModifier down() {
|
public static PlacementModifier down() {
|
||||||
|
@ -66,13 +74,23 @@ public class FindSolidInDirection extends PlacementModifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlacementModifier down(int dist) {
|
public static PlacementModifier down(int dist) {
|
||||||
if (dist == DOWN.maxSearchDistance) return DOWN;
|
if (dist == DOWN.maxSearchDistance && 0 == DOWN.offsetInDir) return DOWN;
|
||||||
return new FindSolidInDirection(Direction.DOWN, dist);
|
return new FindSolidInDirection(Direction.DOWN, dist, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlacementModifier up(int dist) {
|
public static PlacementModifier up(int dist) {
|
||||||
if (dist == UP.maxSearchDistance) return UP;
|
if (dist == UP.maxSearchDistance && 0 == UP.offsetInDir) return UP;
|
||||||
return new FindSolidInDirection(Direction.UP, dist);
|
return new FindSolidInDirection(Direction.UP, dist, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlacementModifier down(int dist, int offset) {
|
||||||
|
if (dist == DOWN.maxSearchDistance && 0 == DOWN.offsetInDir) return DOWN;
|
||||||
|
return new FindSolidInDirection(Direction.DOWN, dist, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlacementModifier up(int dist, int offset) {
|
||||||
|
if (dist == UP.maxSearchDistance && offset == UP.offsetInDir) return UP;
|
||||||
|
return new FindSolidInDirection(Direction.UP, dist, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction randomDirection(RandomSource random) {
|
public Direction randomDirection(RandomSource random) {
|
||||||
|
@ -123,7 +141,10 @@ public class FindSolidInDirection extends PlacementModifier {
|
||||||
searchDist,
|
searchDist,
|
||||||
BlocksHelper::isTerrain
|
BlocksHelper::isTerrain
|
||||||
)) {
|
)) {
|
||||||
builder.add(POS);
|
if (offsetInDir != 0)
|
||||||
|
builder.add(POS.move(d, offsetInDir));
|
||||||
|
else
|
||||||
|
builder.add(POS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue