-
Notifications
You must be signed in to change notification settings - Fork 81
/
EucalyptusTreeFeature.java
222 lines (174 loc) · 8.4 KB
/
EucalyptusTreeFeature.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package com.progwml6.natura.world.worldgen.trees.feature;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.mojang.serialization.Codec;
import com.progwml6.natura.world.NaturaWorld;
import com.progwml6.natura.world.worldgen.trees.config.BaseOverworldTreeFeatureConfig;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.util.math.shapes.BitSetVoxelShapePart;
import net.minecraft.util.math.shapes.VoxelShapePart;
import net.minecraft.util.math.vector.Vector3i;
import net.minecraft.world.ISeedReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldWriter;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.IWorldGenerationBaseReader;
import net.minecraft.world.gen.IWorldGenerationReader;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.template.Template;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.Set;
public class EucalyptusTreeFeature extends GenericOverworldTreeFeature {
public EucalyptusTreeFeature(Codec<BaseOverworldTreeFeatureConfig> codec) {
super(codec);
}
@Override
public void place(IWorldGenerationReader generationReader, Random rand, int height, BlockPos position, Set<BlockPos> logPositions, Set<BlockPos> foliagePositions, MutableBoundingBox boundingBoxIn, BaseOverworldTreeFeatureConfig configIn) {
setDirt(generationReader, position.down());
this.placeTrunk(generationReader, rand, height, position, logPositions, boundingBoxIn, configIn);
this.placeBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.NORTH);
this.placeBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.SOUTH);
this.placeBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.EAST);
this.placeBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.WEST);
this.placeStraightBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.NORTH);
this.placeStraightBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.SOUTH);
this.placeStraightBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.EAST);
this.placeStraightBranch(generationReader, rand, height, position, logPositions, foliagePositions, boundingBoxIn, configIn, BranchDirection.WEST);
this.placeNode(generationReader, rand, position.up(height), logPositions, foliagePositions, boundingBoxIn, configIn);
}
protected void placeTrunk(IWorldGenerationReader worldIn, Random randomIn, int treeHeight, BlockPos blockPos, Set<BlockPos> logPositions, MutableBoundingBox mutableBoundingBoxIn, BaseOverworldTreeFeatureConfig treeFeatureConfigIn) {
while (treeHeight > 0) {
addLogWithCheck(worldIn, randomIn, blockPos, logPositions, mutableBoundingBoxIn, treeFeatureConfigIn);
blockPos = blockPos.up();
treeHeight--;
}
}
protected void placeBranch(IWorldGenerationReader worldIn, Random randomIn, int treeHeight, BlockPos blockPos, Set<BlockPos> logPositions, Set<BlockPos> foliagePositions, MutableBoundingBox mutableBoundingBoxIn, BaseOverworldTreeFeatureConfig treeFeatureConfigIn, BranchDirection direction) {
int posX = blockPos.getX();
int posY = blockPos.getY() + treeHeight - 3;
int posZ = blockPos.getZ();
byte byte0 = 0;
byte byte1 = 0;
switch (direction) {
case NORTH:
byte0 = 1;
byte1 = 1;
break;
case SOUTH:
byte0 = -1;
byte1 = 1;
break;
case EAST:
byte0 = 1;
byte1 = -1;
break;
case WEST:
byte0 = -1;
byte1 = -1;
break;
}
int heightShift = randomIn.nextInt(6);
for (int bIter = 4; bIter > 0; bIter--) {
if (heightShift % 3 != 0) {
posX += byte0;
}
if (heightShift % 3 != 1) {
posZ += byte1;
}
int branch = heightShift % 3;
posY += branch;
BlockPos blockPos1 = new BlockPos(posX, posY, posZ);
if (branch == 2) {
addLogWithCheck(worldIn, randomIn, blockPos1.down(), logPositions, mutableBoundingBoxIn, treeFeatureConfigIn);
}
addLogWithCheck(worldIn, randomIn, blockPos1, logPositions, mutableBoundingBoxIn, treeFeatureConfigIn);
if (bIter == 1) {
this.placeNode(worldIn, randomIn, blockPos1, logPositions, foliagePositions, mutableBoundingBoxIn, treeFeatureConfigIn);
}
heightShift = randomIn.nextInt(6);
}
}
protected void placeStraightBranch(IWorldGenerationReader worldIn, Random randomIn, int treeHeight, BlockPos blockPos, Set<BlockPos> logPositions, Set<BlockPos> foliagePositions, MutableBoundingBox mutableBoundingBoxIn, BaseOverworldTreeFeatureConfig treeFeatureConfigIn, BranchDirection direction) {
int posX = blockPos.getX();
int posY = blockPos.getY() + treeHeight - 3;
int posZ = blockPos.getZ();
byte xShift = 0;
byte zShift = 0;
switch (direction) {
case NORTH:
xShift = 1;
zShift = 0;
break;
case SOUTH:
xShift = 0;
zShift = 1;
break;
case EAST:
xShift = -1;
zShift = 0;
break;
case WEST:
xShift = 0;
zShift = -1;
break;
}
int heightShift = randomIn.nextInt(6);
for (int j2 = 4; j2 > 0; j2--) {
if (xShift == 0) {
posX = (posX + randomIn.nextInt(3)) - 1;
posZ += zShift;
}
if (zShift == 0) {
posX += xShift;
posZ = (posZ + randomIn.nextInt(3)) - 1;
}
int branch = heightShift % 3;
posY += branch;
BlockPos blockPos1 = new BlockPos(posX, posY, posZ);
if (branch == 2) {
addLogWithCheck(worldIn, randomIn, blockPos1.down(), logPositions, mutableBoundingBoxIn, treeFeatureConfigIn);
}
addLogWithCheck(worldIn, randomIn, blockPos1, logPositions, mutableBoundingBoxIn, treeFeatureConfigIn);
if (j2 == 1) {
this.placeNode(worldIn, randomIn, blockPos1, logPositions, foliagePositions, mutableBoundingBoxIn, treeFeatureConfigIn);
}
heightShift = randomIn.nextInt(6);
}
}
protected void placeNode(IWorldGenerationReader worldIn, Random randomIn, BlockPos blockPos, Set<BlockPos> logPositions, Set<BlockPos> foliagePositions, MutableBoundingBox mutableBoundingBoxIn, BaseOverworldTreeFeatureConfig treeFeatureConfigIn) {
addLogWithCheck(worldIn, randomIn, blockPos, logPositions, mutableBoundingBoxIn, treeFeatureConfigIn);
placeNode(worldIn, randomIn, blockPos, foliagePositions, mutableBoundingBoxIn, treeFeatureConfigIn, 2, 1);
placeNode(worldIn, randomIn, blockPos, foliagePositions, mutableBoundingBoxIn, treeFeatureConfigIn, 1, 2);
for (int xIter = blockPos.getX() - 1; xIter <= blockPos.getX() + 1; xIter++) {
for (int zIter = blockPos.getZ() - 1; zIter <= blockPos.getZ() + 1; zIter++) {
BlockPos newPos = new BlockPos(xIter, blockPos.getY() + 1, zIter);
addLeafWithCheck(worldIn, randomIn, newPos, foliagePositions, mutableBoundingBoxIn, treeFeatureConfigIn);
}
}
}
private void placeNode(IWorldGenerationReader worldIn, Random randomIn, BlockPos blockPos, Set<BlockPos> foliagePositions, MutableBoundingBox mutableBoundingBoxIn, BaseOverworldTreeFeatureConfig treeFeatureConfigIn, int i, int i2) {
for (int xIter = blockPos.getX() - i; xIter <= blockPos.getX() + i; xIter++) {
for (int zIter = blockPos.getZ() - i2; zIter <= blockPos.getZ() + i2; zIter++) {
BlockPos newPos = new BlockPos(xIter, blockPos.getY(), zIter);
addLeafWithCheck(worldIn, randomIn, newPos, foliagePositions, mutableBoundingBoxIn, treeFeatureConfigIn);
}
}
}
public enum BranchDirection {
NORTH,
SOUTH,
EAST,
WEST
}
}