mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
property-ify flora
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package com.dfsek.terra.addons.flora;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.flora.flora.FloraLayer;
|
||||||
|
import com.dfsek.terra.api.properties.Properties;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BiomeFlora implements Properties {
|
||||||
|
private final List<FloraLayer> layers;
|
||||||
|
|
||||||
|
public BiomeFlora(List<FloraLayer> layers) {
|
||||||
|
this.layers = layers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FloraLayer> getLayers() {
|
||||||
|
return layers;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-3
@@ -3,17 +3,19 @@ package com.dfsek.terra.addons.flora;
|
|||||||
import com.dfsek.tectonic.annotations.Default;
|
import com.dfsek.tectonic.annotations.Default;
|
||||||
import com.dfsek.tectonic.annotations.Value;
|
import com.dfsek.tectonic.annotations.Value;
|
||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
import com.dfsek.terra.addons.flora.flora.FloraLayer;
|
import com.dfsek.terra.addons.flora.flora.FloraLayer;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BiomeFloraTemplate implements ConfigTemplate {
|
public class BiomeFloraTemplate implements ObjectTemplate<BiomeFlora> {
|
||||||
@Value("flora")
|
@Value("flora")
|
||||||
@Default
|
@Default
|
||||||
private List<FloraLayer> flora = Collections.emptyList();
|
private List<FloraLayer> flora = Collections.emptyList();
|
||||||
|
|
||||||
public List<FloraLayer> getFlora() {
|
@Override
|
||||||
return flora;
|
public BiomeFlora get() {
|
||||||
|
return new BiomeFlora(flora);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-14
@@ -14,14 +14,8 @@ import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
|||||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||||
import com.dfsek.terra.api.util.seeded.BiomeBuilder;
|
import com.dfsek.terra.api.util.seeded.BiomeBuilder;
|
||||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
|
||||||
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Addon("config-flora")
|
@Addon("config-flora")
|
||||||
@Author("Terra")
|
@Author("Terra")
|
||||||
@Version("0.1.0")
|
@Version("0.1.0")
|
||||||
@@ -29,8 +23,6 @@ public class FloraAddon extends TerraAddon implements EventListener {
|
|||||||
@Inject
|
@Inject
|
||||||
private TerraPlugin main;
|
private TerraPlugin main;
|
||||||
|
|
||||||
private final Map<String, List<FloraLayer>> flora = new HashMap<>(); // store Flora layers per biome by biome ID
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
main.getEventManager().registerListener(this, this);
|
main.getEventManager().registerListener(this, this);
|
||||||
@@ -38,18 +30,14 @@ public class FloraAddon extends TerraAddon implements EventListener {
|
|||||||
|
|
||||||
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
|
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
|
||||||
event.getPack().registerConfigType(new FloraConfigType(event.getPack()), "FLORA", 2);
|
event.getPack().registerConfigType(new FloraConfigType(event.getPack()), "FLORA", 2);
|
||||||
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("FLORA", pack -> new FloraPopulator(main, this));
|
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("FLORA", pack -> new FloraPopulator(main));
|
||||||
event.getPack().applyLoader(FloraLayer.class, FloraLayerLoader::new)
|
event.getPack().applyLoader(FloraLayer.class, FloraLayerLoader::new)
|
||||||
.applyLoader(BlockLayer.class, BlockLayerTemplate::new);
|
.applyLoader(BlockLayer.class, BlockLayerTemplate::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBiomeLoad(ConfigurationLoadEvent event) {
|
public void onBiomeLoad(ConfigurationLoadEvent event) {
|
||||||
if(BiomeBuilder.class.isAssignableFrom(event.getType().getTypeClass())) {
|
if(BiomeBuilder.class.isAssignableFrom(event.getType().getTypeClass())) {
|
||||||
flora.put(event.getConfiguration().getID(), event.load(new BiomeFloraTemplate()).getFlora());
|
event.getLoadedObject(BiomeBuilder.class).getContext().put(event.load(new BiomeFloraTemplate()).get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FloraLayer> getFlora(TerraBiome biome) {
|
|
||||||
return flora.getOrDefault(biome.getID(), Collections.emptyList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -23,11 +23,9 @@ import java.util.Random;
|
|||||||
*/
|
*/
|
||||||
public class FloraPopulator implements TerraGenerationStage {
|
public class FloraPopulator implements TerraGenerationStage {
|
||||||
private final TerraPlugin main;
|
private final TerraPlugin main;
|
||||||
private final FloraAddon floraAddon;
|
|
||||||
|
|
||||||
public FloraPopulator(TerraPlugin main, FloraAddon floraAddon) {
|
public FloraPopulator(TerraPlugin main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
this.floraAddon = floraAddon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
@@ -42,7 +40,7 @@ public class FloraPopulator implements TerraGenerationStage {
|
|||||||
for(int x = 0; x < 16; x++) {
|
for(int x = 0; x < 16; x++) {
|
||||||
for(int z = 0; z < 16; z++) {
|
for(int z = 0; z < 16; z++) {
|
||||||
Vector2 l = new Vector2(x, z);
|
Vector2 l = new Vector2(x, z);
|
||||||
layers.put(l, floraAddon.getFlora(provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z)));
|
layers.put(l, provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z).getContext().get(BiomeFlora.class).getLayers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user