Skip to content

Commit 69b88ea

Browse files
authored
Merge pull request #331 from Ultrasquid9/1.21.1-1.1
Fix Roseroot Foliage Placer
2 parents 84954a5 + 4a0380d commit 69b88ea

File tree

1 file changed

+206
-121
lines changed

1 file changed

+206
-121
lines changed
Lines changed: 206 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.razordevs.deep_aether.world.feature.tree.foliage;
22

3+
import java.util.function.Consumer;
4+
35
import com.mojang.serialization.MapCodec;
46
import com.mojang.serialization.codecs.RecordCodecBuilder;
57
import net.minecraft.core.BlockPos;
@@ -10,126 +12,209 @@
1012
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;
1113
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType;
1214

13-
14-
1515
public class RoserootFoliagePlacer extends FoliagePlacer {
16-
public static final MapCodec<RoserootFoliagePlacer> CODEC = RecordCodecBuilder.mapCodec((p2) -> foliagePlacerParts(p2).and(IntProvider.codec(0, 24).fieldOf("trunk_height")
17-
.forGetter((foliagePlacer) -> foliagePlacer.trunkHeight)).apply(p2, RoserootFoliagePlacer::new));
18-
private final IntProvider trunkHeight;
19-
20-
public RoserootFoliagePlacer(IntProvider intProvider, IntProvider intProvider1, IntProvider intProvider2) {
21-
super(intProvider, intProvider1);
22-
this.trunkHeight = intProvider2;
23-
}
24-
25-
protected FoliagePlacerType<?> type() {
26-
return DAFoliagePlacers.ROSEROOT_FOLIAGE_PLACER.get();
27-
}
28-
29-
@Override
30-
protected void createFoliage(LevelSimulatedReader levelSimulatedReader, FoliageSetter foliageSetter, RandomSource randomSource, TreeConfiguration treeConfiguration, int i1, FoliagePlacer.FoliageAttachment foliageAttachment, int foliageMaxHeight, int i2, int i3) {
31-
BlockPos blockpos = foliageAttachment.pos();
32-
for(int l = randomSource.nextInt(1, 4); l >= 0; --l) {
33-
this.placeLeavesRow(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.above(1+l), 0, 1, foliageAttachment.doubleTrunk());
34-
}
35-
int a1 = ((foliageMaxHeight/3)*2) + randomSource.nextInt(-1,1);
36-
int a2 = ((foliageMaxHeight/3)) + randomSource.nextInt(-1,1);
37-
38-
39-
for(int l = foliageMaxHeight; l >= 0; --l) {
40-
if (l == 0) {
41-
this.placeLeavesRow(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos, 1, 1, foliageAttachment.doubleTrunk());
42-
blockpos = blockpos.below(1);
43-
}
44-
else if(l >= a1) {
45-
placeSmallCircle(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos, foliageAttachment);
46-
blockpos = blockpos.below(1);
47-
}
48-
else if (l >= a2) {
49-
this.placeSquare(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos);
50-
blockpos = blockpos.below(1);
51-
}
52-
else {
53-
placeBiggerCircle(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos, foliageAttachment);
54-
blockpos = blockpos.below(1);
55-
}
56-
}
57-
58-
}
59-
public void placeSquare(LevelSimulatedReader levelSimulatedReader, FoliageSetter foliageSetter, RandomSource randomSource, TreeConfiguration treeConfiguration, BlockPos blockpos) {
60-
for (int i = 0; i < 3; ++i) {
61-
for (int ii = 0; ii < 3; ++ii) {
62-
tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(i-1).east(ii-1).above(2));
63-
}
64-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(0).east(2).above(2));
65-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(0).east(-2).above(2));
66-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(2).east(0).above(2));
67-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-2).east(0).above(2));
68-
69-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(1).east(2).above(2));
70-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(1).east(-2).above(2));
71-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-1).east(2).above(2));
72-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-1).east(-2).above(2));
73-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(2).east(1).above(2));
74-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-2).east(1).above(2));
75-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(2).east(-1).above(2));
76-
if(randomSource.nextInt(4) == 1)tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-2).east(-1).above(2));
77-
78-
}
79-
}
80-
public void placeSmallCircle(LevelSimulatedReader levelSimulatedReader, FoliageSetter foliageSetter, RandomSource randomSource, TreeConfiguration treeConfiguration, BlockPos blockpos, FoliagePlacer.FoliageAttachment foliageAttachment) {
81-
this.placeLeavesRow(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos, 1, 2, foliageAttachment.doubleTrunk());
82-
83-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-1).east(-1).above(2));
84-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(1).east(1).above(2));
85-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(0).east(2).above(2));
86-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(0).east(-2).above(2));
87-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(2).east(0).above(2));
88-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-2).east(0).above(2));
89-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-1).east(1).above(2));
90-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(1).east(-1).above(2));
91-
}
92-
public void placeBiggerCircle(LevelSimulatedReader levelSimulatedReader, FoliageSetter foliageSetter, RandomSource randomSource, TreeConfiguration treeConfiguration, BlockPos blockpos, FoliagePlacer.FoliageAttachment foliageAttachment) {
93-
this.placeLeavesRow(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos, 2, 2, foliageAttachment.doubleTrunk());
94-
95-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(0).east(3).above(2));
96-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(0).east(-3).above(2));
97-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(3).east(0).above(2));
98-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-3).east(0).above(2));
99-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(2).east(2).above(2));
100-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-2).east(-2).above(2));
101-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(2).east(-2).above(2));
102-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-2).east(2).above(2));
103-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(1).east(3).above(2));
104-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-1).east(3).above(2));
105-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(1).east(-3).above(2));
106-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-1).east(-3).above(2));
107-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(3).east(1).above(2));
108-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(3).east(-1).above(2));
109-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-3).east(1).above(2));
110-
if(randomSource.nextBoolean())tryPlaceLeaf(levelSimulatedReader, foliageSetter, randomSource, treeConfiguration, blockpos.north(-3).east(-1).above(2));
111-
112-
}
113-
114-
public int foliageHeight(RandomSource randomSource, int i, TreeConfiguration treeConfiguration) {
115-
return Math.max(4, i - this.trunkHeight.sample(randomSource));
116-
}
117-
118-
protected boolean shouldSkipLocation(RandomSource randomSource, int a, int b, int c, int d, boolean b1) {
119-
return a == d && c == d && d > 0;
120-
}
121-
@Override
122-
protected void placeLeavesRow(LevelSimulatedReader simulatedReader, FoliageSetter foliageSetter, RandomSource randomSource, TreeConfiguration configuration, BlockPos blockPos, int i1, int i2, boolean b) {
123-
int i = b ? 1 : 0;
124-
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
125-
126-
for (int j = -i1; j <= i1 + i; ++j) {
127-
for (int k = -i1; k <= i1 + i; ++k) {
128-
if (!shouldSkipLocationSigned(randomSource, j, i2, k, i1, b)) {
129-
blockpos$mutableblockpos.setWithOffset(blockPos, j, i2, k);
130-
tryPlaceLeaf(simulatedReader, foliageSetter, randomSource, configuration, blockpos$mutableblockpos);
131-
}
132-
}
133-
}
134-
}
16+
public static final MapCodec<RoserootFoliagePlacer> CODEC = RecordCodecBuilder.mapCodec(
17+
builder -> foliagePlacerParts(builder)
18+
.and(IntProvider.codec(0, 24).fieldOf("trunk_height").forGetter(f -> f.trunkHeight))
19+
.apply(builder, RoserootFoliagePlacer::new)
20+
);
21+
22+
private final IntProvider trunkHeight;
23+
24+
public RoserootFoliagePlacer(IntProvider radius, IntProvider offset, IntProvider height) {
25+
super(radius, offset);
26+
this.trunkHeight = height;
27+
}
28+
29+
protected FoliagePlacerType<?> type() {
30+
return DAFoliagePlacers.ROSEROOT_FOLIAGE_PLACER.get();
31+
}
32+
33+
@Override
34+
protected void createFoliage(
35+
LevelSimulatedReader reader,
36+
FoliageSetter setter,
37+
RandomSource rand,
38+
TreeConfiguration cfg,
39+
int i1,
40+
FoliagePlacer.FoliageAttachment attachment,
41+
int foliageMaxHeight,
42+
int i2,
43+
int i3
44+
) {
45+
var pos = attachment.pos();
46+
47+
for(int l = rand.nextInt(1, 4); l >= 0; --l) {
48+
this.placeLeavesRow(reader, setter, rand, cfg, pos.above(1+l), 0, 1, attachment.doubleTrunk());
49+
}
50+
int a1 = ((foliageMaxHeight/3)*2) + rand.nextInt(-1,1);
51+
int a2 = ((foliageMaxHeight/3)) + rand.nextInt(-1,1);
52+
53+
for(int l = foliageMaxHeight; l >= 0; --l) {
54+
if (l == 0) {
55+
this.placeLeavesRow(reader, setter, rand, cfg, pos, 1, 1, attachment.doubleTrunk());
56+
pos = pos.below(1);
57+
}
58+
else if(l >= a1) {
59+
placeSmallCircle(reader, setter, rand, cfg, pos, attachment);
60+
pos = pos.below(1);
61+
}
62+
else if (l >= a2) {
63+
this.placeSquare(reader, setter, rand, cfg, pos);
64+
pos = pos.below(1);
65+
}
66+
else {
67+
placeBiggerCircle(reader, setter, rand, cfg, pos, attachment);
68+
pos = pos.below(1);
69+
}
70+
}
71+
72+
}
73+
74+
public void placeSquare(
75+
LevelSimulatedReader reader,
76+
FoliageSetter setter,
77+
RandomSource rand,
78+
TreeConfiguration cfg,
79+
BlockPos blockPos
80+
) {
81+
var pos = blockPos.above(2);
82+
Consumer<BlockPos> placeLeaf = p -> {
83+
if(rand.nextInt(4) == 1) tryPlaceLeaf(reader, setter, rand, cfg, p);
84+
};
85+
86+
for (int i = 0; i < 3; ++i) {
87+
for (int ii = 0; ii < 3; ++ii) {
88+
placeLeaf.accept(pos.north(i-1).east(ii-1));
89+
}
90+
placeLeaf.accept(pos.north(0).east(2));
91+
placeLeaf.accept(pos.north(0).east(-2));
92+
placeLeaf.accept(pos.north(2).east(0));
93+
placeLeaf.accept(pos.north(-2).east(0));
94+
95+
placeLeaf.accept(pos.north(1).east(2));
96+
placeLeaf.accept(pos.north(1).east(-2));
97+
placeLeaf.accept(pos.north(-1).east(2));
98+
placeLeaf.accept(pos.north(-1).east(-2));
99+
placeLeaf.accept(pos.north(2).east(1));
100+
placeLeaf.accept(pos.north(-2).east(1));
101+
placeLeaf.accept(pos.north(2).east(-1));
102+
placeLeaf.accept(pos.north(-2).east(-1));
103+
}
104+
}
105+
106+
public void placeSmallCircle(
107+
LevelSimulatedReader reader,
108+
FoliageSetter setter,
109+
RandomSource rand,
110+
TreeConfiguration cfg,
111+
BlockPos blockPos,
112+
FoliagePlacer.FoliageAttachment attachment
113+
) {
114+
this.placeLeavesRow(reader, setter, rand, cfg, blockPos, 1, 2, attachment.doubleTrunk());
115+
116+
var pos = blockPos.above(2);
117+
Consumer<BlockPos> placeLeaf = p -> {
118+
if(rand.nextInt(4) == 1) tryPlaceLeaf(reader, setter, rand, cfg, p);
119+
};
120+
121+
placeLeaf.accept(pos.north(-1).east(-1));
122+
placeLeaf.accept(pos.north(1).east(1));
123+
placeLeaf.accept(pos.north(0).east(2));
124+
placeLeaf.accept(pos.north(0).east(-2));
125+
placeLeaf.accept(pos.north(2).east(0));
126+
placeLeaf.accept(pos.north(-2).east(0));
127+
placeLeaf.accept(pos.north(-1).east(1));
128+
placeLeaf.accept(pos.north(1).east(-1));
129+
}
130+
131+
public void placeBigCircle(
132+
LevelSimulatedReader reader,
133+
FoliageSetter setter,
134+
RandomSource rand,
135+
TreeConfiguration cfg,
136+
BlockPos blockPos,
137+
FoliagePlacer.FoliageAttachment attachment
138+
) {
139+
this.placeLeavesRow(reader, setter, rand, cfg, blockPos, 2, 2, attachment.doubleTrunk());
140+
141+
var pos = blockPos.above(2);
142+
Consumer<BlockPos> placeLeaf = p -> {
143+
if(rand.nextInt(4) == 1) tryPlaceLeaf(reader, setter, rand, cfg, p);
144+
};
145+
146+
placeLeaf.accept(pos.north(0).east(3));
147+
placeLeaf.accept(pos.north(0).east(-3));
148+
placeLeaf.accept(pos.north(3).east(0));
149+
placeLeaf.accept(pos.north(-3).east(0));
150+
placeLeaf.accept(pos.north(2).east(2));
151+
placeLeaf.accept(pos.north(-2).east(-2));
152+
placeLeaf.accept(pos.north(2).east(-2));
153+
placeLeaf.accept(pos.north(-2).east(2));
154+
}
155+
156+
public void placeBiggerCircle(
157+
LevelSimulatedReader reader,
158+
FoliageSetter setter,
159+
RandomSource rand,
160+
TreeConfiguration cfg,
161+
BlockPos blockPos,
162+
FoliagePlacer.FoliageAttachment attachment
163+
) {
164+
this.placeLeavesRow(reader, setter, rand, cfg, blockPos, 2, 2, attachment.doubleTrunk());
165+
166+
var pos = blockPos.above(2);
167+
Consumer<BlockPos> placeLeaf = p -> {
168+
if(rand.nextInt(4) == 1) tryPlaceLeaf(reader, setter, rand, cfg, p);
169+
};
170+
171+
placeLeaf.accept(pos.north(0).east(3));
172+
placeLeaf.accept(pos.north(0).east(-3));
173+
placeLeaf.accept(pos.north(3).east(0));
174+
placeLeaf.accept(pos.north(-3).east(0));
175+
placeLeaf.accept(pos.north(2).east(2));
176+
placeLeaf.accept(pos.north(-2).east(-2));
177+
placeLeaf.accept(pos.north(2).east(-2));
178+
placeLeaf.accept(pos.north(-2).east(2));
179+
placeLeaf.accept(pos.north(1).east(3));
180+
placeLeaf.accept(pos.north(-1).east(3));
181+
placeLeaf.accept(pos.north(1).east(-3));
182+
placeLeaf.accept(pos.north(-1).east(-3));
183+
placeLeaf.accept(pos.north(3).east(1));
184+
placeLeaf.accept(pos.north(3).east(-1));
185+
placeLeaf.accept(pos.north(-3).east(1));
186+
placeLeaf.accept(pos.north(-3).east(-1));
187+
}
188+
189+
public int foliageHeight(RandomSource rand, int i, TreeConfiguration cfg) {
190+
return Math.max(4, i - this.trunkHeight.sample(rand));
191+
}
192+
193+
protected boolean shouldSkipLocation(RandomSource rand, int a, int b, int c, int d, boolean b1) {
194+
return a == d && c == d && d > 0;
195+
}
196+
197+
@Override
198+
protected void placeLeavesRow(
199+
LevelSimulatedReader reader,
200+
FoliageSetter setter,
201+
RandomSource rand,
202+
TreeConfiguration cfg,
203+
BlockPos blockPos,
204+
int i1,
205+
int i2,
206+
boolean b
207+
) {
208+
int i = b ? 1 : 0;
209+
var pos = new BlockPos.MutableBlockPos();
210+
211+
for (int j = -i1; j <= i1 + i; ++j) {
212+
for (int k = -i1; k <= i1 + i; ++k) {
213+
if (shouldSkipLocationSigned(rand, j, i2, k, i1, b)) continue;
214+
215+
pos.setWithOffset(blockPos, j, i2, k);
216+
tryPlaceLeaf(reader, setter, rand, cfg, pos);
217+
}
218+
}
219+
}
135220
}

0 commit comments

Comments
 (0)