-
Notifications
You must be signed in to change notification settings - Fork 81
/
NaturaStructures.java
284 lines (234 loc) · 15.6 KB
/
NaturaStructures.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package com.progwml6.natura.world;
import com.google.common.collect.ImmutableList;
import com.progwml6.natura.common.NaturaModule;
import com.progwml6.natura.common.config.Config;
import com.progwml6.natura.library.Util;
import com.progwml6.natura.world.block.RedwoodType;
import com.progwml6.natura.world.block.TreeType;
import com.progwml6.natura.world.config.FeatureType;
import com.progwml6.natura.world.worldgen.helper.ChanceRandomFeature;
import com.progwml6.natura.world.worldgen.helper.ChanceRandomFeatureConfig;
import com.progwml6.natura.world.worldgen.helper.DisableableConfiguredFeature;
import com.progwml6.natura.world.worldgen.trees.SupplierBlockStateProvider;
import com.progwml6.natura.world.worldgen.trees.config.BaseOverworldTreeFeatureConfig;
import com.progwml6.natura.world.worldgen.trees.config.RedwoodTreeFeatureConfig;
import com.progwml6.natura.world.worldgen.trees.feature.EucalyptusTreeFeature;
import com.progwml6.natura.world.worldgen.trees.feature.HopseedTreeFeature;
import com.progwml6.natura.world.worldgen.trees.feature.OverworldTreeFeature;
import com.progwml6.natura.world.worldgen.trees.feature.RedwoodTreeFeature;
import com.progwml6.natura.world.worldgen.trees.feature.WillowTreeFeature;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.blockstateprovider.BlockStateProviderType;
import net.minecraft.world.gen.feature.BaseTreeFeatureConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureSpread;
import net.minecraft.world.gen.feature.Features;
import net.minecraft.world.gen.feature.TwoLayerFeature;
import net.minecraft.world.gen.foliageplacer.BlobFoliagePlacer;
import net.minecraft.world.gen.foliageplacer.FancyFoliagePlacer;
import net.minecraft.world.gen.placement.AtSurfaceWithExtraConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.trunkplacer.FancyTrunkPlacer;
import net.minecraft.world.gen.trunkplacer.StraightTrunkPlacer;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nonnull;
import java.util.OptionalInt;
/**
* Contains any logic relevant to structure generation, including trees
*/
@SuppressWarnings("unused")
public final class NaturaStructures extends NaturaModule {
static final Logger log = Util.getLogger("natura_structures");
/*
* Misc
*/
public static final RegistryObject<BlockStateProviderType<SupplierBlockStateProvider>> supplierBlockstateProvider = BLOCK_STATE_PROVIDER_TYPES
.register("supplier_state_provider", () -> new BlockStateProviderType<>(SupplierBlockStateProvider.CODEC));
/*
* Features
*/
public static final RegistryObject<Feature<BaseTreeFeatureConfig>> OVERWORLD_TREE_FEATURE = FEATURES
.register("overworld_tree", () -> new OverworldTreeFeature(BaseTreeFeatureConfig.CODEC));
public static final RegistryObject<Feature<BaseOverworldTreeFeatureConfig>> WILLOW_TREE_FEATURE = FEATURES
.register("willow_tree", () -> new WillowTreeFeature(BaseOverworldTreeFeatureConfig.CODEC));
public static final RegistryObject<Feature<BaseOverworldTreeFeatureConfig>> EUCALYPTUS_TREE_FEATURE = FEATURES
.register("eucalyptus_tree", () -> new EucalyptusTreeFeature(BaseOverworldTreeFeatureConfig.CODEC));
public static final RegistryObject<Feature<BaseOverworldTreeFeatureConfig>> HOPSEED_TREE_FEATURE = FEATURES
.register("hopseed_tree", () -> new HopseedTreeFeature(BaseOverworldTreeFeatureConfig.CODEC));
public static final RegistryObject<Feature<RedwoodTreeFeatureConfig>> REDWOOD_TREE_FEATURE = FEATURES
.register("redwood_tree", () -> new RedwoodTreeFeature(RedwoodTreeFeatureConfig.CODEC));
public static final RegistryObject<Feature<ChanceRandomFeatureConfig>> CHANCE_FEATURE = FEATURES
.register("chance_feature", () -> new ChanceRandomFeature(ChanceRandomFeatureConfig.CODEC));
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> MAPLE_TREE;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> SILVERBELL_TREE;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> AMARANTH_TREE;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> TIGER_TREE;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> SAKURA_TREE;
public static ConfiguredFeature<BaseOverworldTreeFeatureConfig, ?> WILLOW_TREE;
public static ConfiguredFeature<BaseOverworldTreeFeatureConfig, ?> EUCALYPTUS_TREE;
public static ConfiguredFeature<BaseOverworldTreeFeatureConfig, ?> HOPSEED_TREE;
public static ConfiguredFeature<RedwoodTreeFeatureConfig, ?> REDWOOD_TREE;
// Bee Trees!
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> MAPLE_TREE_005;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> SILVERBELL_TREE_005;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> AMARANTH_TREE_005;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> TIGER_TREE_005;
public static ConfiguredFeature<BaseTreeFeatureConfig, ?> SAKURA_TREE_005;
public static ConfiguredFeature<BaseOverworldTreeFeatureConfig, ?> WILLOW_TREE_005;
public static ConfiguredFeature<BaseOverworldTreeFeatureConfig, ?> EUCALYPTUS_TREE_005;
public static ConfiguredFeature<BaseOverworldTreeFeatureConfig, ?> HOPSEED_TREE_005;
public static ConfiguredFeature<?, ?> MAPLE_TREE_GEN;
public static ConfiguredFeature<?, ?> SILVERBELL_TREE_GEN;
public static ConfiguredFeature<?, ?> AMARANTH_TREE_GEN;
public static ConfiguredFeature<?, ?> TIGER_TREE_GEN;
public static ConfiguredFeature<?, ?> WILLOW_TREE_GEN;
public static ConfiguredFeature<?, ?> WILLOW_TREE_3_GEN;
public static ConfiguredFeature<?, ?> EUCALYPTUS_TREE_GEN;
public static ConfiguredFeature<?, ?> EUCALYPTUS_PLAINS_TREE_GEN;
public static ConfiguredFeature<?, ?> SAKURA_TREE_GEN;
public static ConfiguredFeature<?, ?> SAKURA_FOREST_TREE_GEN;
public static ConfiguredFeature<?, ?> HOPSEED_TREE_GEN;
public static ConfiguredFeature<?, ?> REDWOOD_TREE_GEN;
/**
* Feature configuration
*
* PLACEMENT MOVED TO WorldEvents#onBiomeLoad
*/
@SubscribeEvent
void commonSetup(FMLCommonSetupEvent event) {
MAPLE_TREE = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("maple_tree"), OVERWORLD_TREE_FEATURE.get().withConfiguration(
(new BaseTreeFeatureConfig.Builder(new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.MAPLE).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.MAPLE).getDefaultState()),
new BlobFoliagePlacer(FeatureSpread.func_242252_a(2), FeatureSpread.func_242252_a(0), 3),
new StraightTrunkPlacer(4, 2, 0),
new TwoLayerFeature(1, 0, 1)))
.setIgnoreVines().build())
);
SILVERBELL_TREE = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("silverbell_tree"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(
(new BaseTreeFeatureConfig.Builder(new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.SILVERBELL).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.SILVERBELL).getDefaultState()),
new BlobFoliagePlacer(FeatureSpread.func_242252_a(2), FeatureSpread.func_242252_a(0), 3),
new StraightTrunkPlacer(4, 2, 0),
new TwoLayerFeature(1, 0, 1)))
.setIgnoreVines().build())
);
AMARANTH_TREE = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("amaranth_tree"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(
(new BaseTreeFeatureConfig.Builder(new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.AMARANTH).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.AMARANTH).getDefaultState()),
new BlobFoliagePlacer(FeatureSpread.func_242252_a(2), FeatureSpread.func_242252_a(0), 3),
new StraightTrunkPlacer(9, 8, 0),
new TwoLayerFeature(1, 0, 1)))
.setIgnoreVines().build())
);
TIGER_TREE = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("tiger_tree"), OVERWORLD_TREE_FEATURE.get().withConfiguration(
(new BaseTreeFeatureConfig.Builder(new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.TIGER).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.TIGER).getDefaultState()),
new BlobFoliagePlacer(FeatureSpread.func_242252_a(2), FeatureSpread.func_242252_a(0), 3),
new StraightTrunkPlacer(6, 4, 0),
new TwoLayerFeature(1, 0, 1)))
.setIgnoreVines().build())
);
WILLOW_TREE = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("willow_tree"), WILLOW_TREE_FEATURE.get().withConfiguration((
new BaseOverworldTreeFeatureConfig.Builder(
new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.WILLOW).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.WILLOW).getDefaultState()),
5,
4))
.build())
);
EUCALYPTUS_TREE = Registry
.register(WorldGenRegistries.CONFIGURED_FEATURE, location("eucalyptus_tree"), EUCALYPTUS_TREE_FEATURE.get().withConfiguration((
new BaseOverworldTreeFeatureConfig.Builder(
new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.EUCALYPTUS).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.EUCALYPTUS).getDefaultState()),
6,
3))
.build())
);
HOPSEED_TREE = Registry
.register(WorldGenRegistries.CONFIGURED_FEATURE, location("hopseed_tree"), HOPSEED_TREE_FEATURE.get().withConfiguration((
new BaseOverworldTreeFeatureConfig.Builder(
new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.HOPSEED).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.HOPSEED).getDefaultState()),
2,
3))
.build())
);
SAKURA_TREE = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("sakura_tree"), OVERWORLD_TREE_FEATURE.get().withConfiguration(
(new BaseTreeFeatureConfig.Builder(new SupplierBlockStateProvider(() -> NaturaWorld.logs.get(TreeType.SAKURA).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.leaves.get(TreeType.SAKURA).getDefaultState()),
new FancyFoliagePlacer(FeatureSpread.func_242252_a(2), FeatureSpread.func_242252_a(4), 4),
new FancyTrunkPlacer(3, 11, 0),
new TwoLayerFeature(0, 0, 0, OptionalInt.of(4))))
.setIgnoreVines().func_236702_a_(Heightmap.Type.MOTION_BLOCKING).build())
);
REDWOOD_TREE = Registry
.register(WorldGenRegistries.CONFIGURED_FEATURE, location("redwood_tree"), REDWOOD_TREE_FEATURE.get().withConfiguration((
new RedwoodTreeFeatureConfig.Builder(
new SupplierBlockStateProvider(() -> NaturaWorld.redwood.get(RedwoodType.BARK).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.redwood.get(RedwoodType.HEART).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.redwood.get(RedwoodType.ROOT).getDefaultState()),
new SupplierBlockStateProvider(() -> NaturaWorld.redwood_leaves.get().getDefaultState()),
80,
60,
12,
4,
0.618D,
0.381D,
1.0D,
1.0D))
.build())
);
// Bee Trees
MAPLE_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("maple_tree_005"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(MAPLE_TREE.getConfig().func_236685_a_(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
SILVERBELL_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("silverbell_tree_005"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(SILVERBELL_TREE.getConfig().func_236685_a_(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
AMARANTH_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("amaranth_tree_005"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(AMARANTH_TREE.getConfig().func_236685_a_(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
TIGER_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("tiger_tree_005"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(TIGER_TREE.getConfig().func_236685_a_(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
SAKURA_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("sakura_tree_005"), OVERWORLD_TREE_FEATURE.get()
.withConfiguration(SAKURA_TREE.getConfig().func_236685_a_(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
WILLOW_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("willow_tree_005"),
WILLOW_TREE_FEATURE.get().withConfiguration(WILLOW_TREE.getConfig().withDecorators(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
EUCALYPTUS_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("eucalyptus_tree_005"), EUCALYPTUS_TREE_FEATURE.get()
.withConfiguration(EUCALYPTUS_TREE.getConfig().withDecorators(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
HOPSEED_TREE_005 = Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location("hopseed_tree_005"), HOPSEED_TREE_FEATURE.get()
.withConfiguration(HOPSEED_TREE.getConfig().withDecorators(ImmutableList.of(Features.Placements.BEES_005_PLACEMENT))));
// World Gen
MAPLE_TREE_GEN = getFeature(FeatureType.MAPLE, CHANCE_FEATURE.get(), MAPLE_TREE, 1);
SILVERBELL_TREE_GEN = getFeature(FeatureType.SIVERBELL, CHANCE_FEATURE.get(), SILVERBELL_TREE, 1);
AMARANTH_TREE_GEN = getFeature(FeatureType.AMARANTH, CHANCE_FEATURE.get(), AMARANTH_TREE, 1);
TIGER_TREE_GEN = getFeature(FeatureType.TIGER, CHANCE_FEATURE.get(), TIGER_TREE, 1);
WILLOW_TREE_GEN = getFeature(FeatureType.WILLOW, CHANCE_FEATURE.get(), WILLOW_TREE, 1);
WILLOW_TREE_3_GEN = getFeature(FeatureType.WILLOW, CHANCE_FEATURE.get(), WILLOW_TREE, 3);
EUCALYPTUS_TREE_GEN = getFeature(FeatureType.EUCALYPTUS, CHANCE_FEATURE.get(), EUCALYPTUS_TREE, 1);
EUCALYPTUS_PLAINS_TREE_GEN = getFeature(FeatureType.EUCALYPTUS_PLAINS, CHANCE_FEATURE.get(), EUCALYPTUS_TREE, 1);
HOPSEED_TREE_GEN = getFeature(FeatureType.HOPSEED, CHANCE_FEATURE.get(), HOPSEED_TREE, 1);
SAKURA_TREE_GEN = getFeature(FeatureType.SAKURA, CHANCE_FEATURE.get(), SAKURA_TREE, 3);
SAKURA_FOREST_TREE_GEN = getFeature(FeatureType.SAKURA_FOREST, CHANCE_FEATURE.get(), SAKURA_TREE, 3);
REDWOOD_TREE_GEN = getFeature(FeatureType.REDWOOD, CHANCE_FEATURE.get(), REDWOOD_TREE, 1);
}
@Nonnull
private static ConfiguredFeature<?, ?> getFeature(FeatureType type, Feature<ChanceRandomFeatureConfig> feature,
ConfiguredFeature<?, ?> actualFeature, int count) {
Config.FeatureConfig featureConfig = Config.features.get(type);
ConfiguredFeature<?, ?> configuredFeature = new DisableableConfiguredFeature<>(feature,
new ChanceRandomFeatureConfig(actualFeature, type, featureConfig.chance), featureConfig.shouldGenerate)
.withPlacement(Features.Placements.HEIGHTMAP_PLACEMENT)
.withPlacement(Placement.COUNT_EXTRA.configure(new AtSurfaceWithExtraConfig(count, 0.1F, 1)));
//Register the configured feature
String name = type.getType() + "_" + type.getName();
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, location(name), configuredFeature);
return configuredFeature;
}
}