Skip to content

Commit c7c5f1a

Browse files
authored
Merge pull request #127 from TheNextLvl-net/preserve-properties
Preserve block properties when replacing blocks across all patterns
2 parents b4c66af + a7656ef commit c7c5f1a

File tree

9 files changed

+13
-11
lines changed

9 files changed

+13
-11
lines changed

src/main/java/net/thenextlvl/gopaint/brush/pattern/AnglePattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws W
2828
>= Math.tan(Math.toRadians(settings().getAngleHeightDifference()))
2929
) return false;
3030

31-
return set.setBlock(extent, getRandomBlockState());
31+
return set.setBlock(extent, getRandomBlockState().withProperties(block.base().toBlockState()));
3232
}
3333
}

src/main/java/net/thenextlvl/gopaint/brush/pattern/FracturePattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws W
3030
Height.getNearestNonEmptyBlock(block), settings.getFractureStrength()
3131
) < 0.1) return false;
3232

33-
return set.setBlock(extent, getRandomBlockState());
33+
return set.setBlock(extent, getRandomBlockState().withProperties(block.base().toBlockState()));
3434
}
3535
}

src/main/java/net/thenextlvl/gopaint/brush/pattern/GradientPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public record GradientPattern(
2424
@Override
2525
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
2626
if (settings().getRandom().nextDouble() <= getRate(set)) return false;
27-
return set.setBlock(extent, getRandomBlockState(set.y()));
27+
return set.setBlock(extent, getRandomBlockState(set.y()).withProperties(get.getBlock(extent)));
2828
}
2929

3030
public BlockState getRandomBlockState(int altitude) {

src/main/java/net/thenextlvl/gopaint/brush/pattern/OverlayPattern.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public record OverlayPattern(
2020

2121
@Override
2222
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
23-
if (!isOverlay(get, applyBlock(get))) return false;
24-
return set.setBlock(extent, getRandomBlockState());
23+
var block = applyBlock(get);
24+
if (!isOverlay(get, block)) return false;
25+
return set.setBlock(extent, getRandomBlockState().withProperties(block.toBlockState()));
2526
}
2627

2728
private boolean isOverlay(BlockVector3 position, BaseBlock block) {

src/main/java/net/thenextlvl/gopaint/brush/pattern/ShufflePattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public record ShufflePattern(
1919

2020
@Override
2121
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
22-
return set.setBlock(extent, getRandomBlockState());
22+
return set.setBlock(extent, getRandomBlockState().withProperties(get.getBlock(extent)));
2323
}
2424
}

src/main/java/net/thenextlvl/gopaint/brush/pattern/SplatterPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public record SplatterPattern(
2020
@Override
2121
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
2222
if (settings().getRandom().nextDouble() <= getRate(set)) return false;
23-
return set.setBlock(extent, getRandomBlockState());
23+
return set.setBlock(extent, getRandomBlockState().withProperties(get.getBlock(extent)));
2424
}
2525

2626
private double getRate(BlockVector3 position) {

src/main/java/net/thenextlvl/gopaint/brush/pattern/SplinePattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public SplinePattern(EditSession session, BlockVector3 position, Player player,
3131

3232
@Override
3333
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
34-
return set.setBlock(extent, getRandomBlockState());
34+
return set.setBlock(extent, getRandomBlockState().withProperties(get.getBlock(extent)));
3535
}
3636

3737
@Override

src/main/java/net/thenextlvl/gopaint/brush/pattern/SprayPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public record SprayPattern(
2020
@Override
2121
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
2222
if (settings.getRandom().nextInt(100) >= settings.getChance()) return false;
23-
return set.setBlock(extent, getRandomBlockState());
23+
return set.setBlock(extent, getRandomBlockState().withProperties(get.getBlock(extent)));
2424
}
2525
}

src/main/java/net/thenextlvl/gopaint/brush/pattern/UnderlayPattern.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public record UnderlayPattern(
2020

2121
@Override
2222
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
23-
if (!isUnderlay(get, applyBlock(get))) return false;
24-
return set.setBlock(extent, getRandomBlockState());
23+
var block = applyBlock(get);
24+
if (!isUnderlay(get, block)) return false;
25+
return set.setBlock(extent, getRandomBlockState().withProperties(block.toBlockState()));
2526
}
2627

2728
private boolean isUnderlay(BlockVector3 position, BaseBlock block) {

0 commit comments

Comments
 (0)