Remove hardcoded flora registry entries

This commit is contained in:
Astrashh 2021-06-24 21:38:07 +10:00
parent 4bac67b8d7
commit cf30f3d067
2 changed files with 1 additions and 65 deletions

View File

@ -44,7 +44,7 @@ public class ConfigTypeRegistry extends OpenRegistryImpl<ConfigType<?, ?>> {
this.callback = callback;
add("PALETTE", new ConfigBuilder<>(new PaletteFactory(), PaletteTemplate::new, Palette.class, () -> new PaletteRegistry(main)));
add("ORE", new ConfigBuilder<>(new OreFactory(), OreTemplate::new, Ore.class, OreRegistry::new));
add("FLORA", new ConfigBuilder<>(new FloraFactory(), FloraTemplate::new, Flora.class, () -> new FloraRegistry(main)));
add("FLORA", new ConfigBuilder<>(new FloraFactory(), FloraTemplate::new, Flora.class, FloraRegistry::new));
add("CARVER", new ConfigBuilder<>(new CarverFactory(pack), CarverTemplate::new, UserDefinedCarver.class, CarverRegistry::new));
add("STRUCTURE", new ConfigBuilder<>(new StructureFactory(), StructureTemplate::new, TerraStructure.class, StructureRegistry::new));
add("TREE", new ConfigBuilder<>(new TreeFactory(), TreeTemplate::new, Tree.class, TreeRegistry::new));

View File

@ -1,71 +1,7 @@
package com.dfsek.terra.registry.config;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.block.BlockData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.Flora;
import com.dfsek.terra.registry.OpenRegistryImpl;
import com.dfsek.terra.world.population.items.flora.ConstantFlora;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.Callable;
public class FloraRegistry extends OpenRegistryImpl<Flora> {
private final TerraPlugin main;
public FloraRegistry(TerraPlugin main) {
this.main = main;
MaterialSet grassy = MaterialSet.get(create("minecraft:grass_block"), create("minecraft:podzol"));
addItem("TALL_GRASS", () -> new ConstantFlora(grassy, Arrays.asList(data("minecraft:tall_grass[half=lower]"), data("minecraft:tall_grass[half=upper]"))));
addItem("TALL_FERN", () -> new ConstantFlora(grassy, Arrays.asList(data("minecraft:large_fern[half=lower]"), data("minecraft:large_fern[half=upper]"))));
addItem("SUNFLOWER", () -> new ConstantFlora(grassy, Arrays.asList(data("minecraft:sunflower[half=lower]"), data("minecraft:sunflower[half=upper]"))));
addItem("ROSE_BUSH", () -> new ConstantFlora(grassy, Arrays.asList(data("minecraft:rose_bush[half=lower]"), data("minecraft:rose_bush[half=upper]"))));
addItem("LILAC", () -> new ConstantFlora(grassy, Arrays.asList(data("minecraft:lilac[half=lower]"), data("minecraft:lilac[half=upper]"))));
addItem("PEONY", () -> new ConstantFlora(grassy, Arrays.asList(data("minecraft:peony[half=lower]"), data("minecraft:peony[half=upper]"))));
addItem("GRASS", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:grass"))));
addItem("FERN", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:fern"))));
addItem("AZURE_BLUET", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:azure_bluet"))));
addItem("LILY_OF_THE_VALLEY", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:lily_of_the_valley"))));
addItem("BLUE_ORCHID", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:blue_orchid"))));
addItem("POPPY", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:poppy"))));
addItem("DANDELION", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:dandelion"))));
addItem("WITHER_ROSE", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:wither_rose"))));
addItem("DEAD_BUSH", () -> new ConstantFlora(MaterialSet.get(create("minecraft:terracotta"), create("minecraft:black_terracotta"),
create("minecraft:blue_terracotta"), create("minecraft:brown_terracotta"), create("minecraft:cyan_terracotta"),
create("minecraft:gray_terracotta"), create("minecraft:green_terracotta"), create("minecraft:light_blue_terracotta"),
create("minecraft:light_gray_terracotta"), create("minecraft:lime_terracotta"), create("minecraft:magenta_terracotta"),
create("minecraft:orange_terracotta"), create("minecraft:pink_terracotta"), create("minecraft:purple_terracotta"),
create("minecraft:red_terracotta"), create("minecraft:white_terracotta"), create("minecraft:yellow_terracotta"),
create("minecraft:red_sand"), create("minecraft:sand"), create("minecraft:coarse_dirt")), Collections.singletonList(data("minecraft:dead_bush"))));
addItem("RED_TULIP", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:red_tulip"))));
addItem("ORANGE_TULIP", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:orange_tulip"))));
addItem("WHITE_TULIP", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:white_tulip"))));
addItem("PINK_TULIP", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:pink_tulip"))));
addItem("OXEYE_DAISY", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:oxeye_daisy"))));
addItem("ALLIUM", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:allium"))));
addItem("CORNFLOWER", () -> new ConstantFlora(grassy, Collections.singletonList(data("minecraft:cornflower"))));
addItem("LILY_PAD", () -> new ConstantFlora(MaterialSet.get(create("minecraft:water")), Collections.singletonList(data("minecraft:lily_pad"))));
MaterialSet mushroom = MaterialSet.get(create("minecraft:grass_block"), create("minecraft:stone"), create("minecraft:podzol"), create("minecraft:netherrack"), create("minecraft:mycelium"));
addItem("RED_MUSHROOM", () -> new ConstantFlora(mushroom, Collections.singletonList(data("minecraft:red_mushroom"))));
addItem("BROWN_MUSHROOM", () -> new ConstantFlora(mushroom, Collections.singletonList(data("minecraft:brown_mushroom"))));
}
private BlockData create(String s) {
return main.getWorldHandle().createBlockData(s);
}
private void addItem(String id, Callable<ConstantFlora> flora) {
try {
Entry<Flora> entry = new Entry<>(flora.call());
entry.getValue(); // Mark as not dead.
add(id, entry);
} catch(Exception e) {
main.logger().warning("Failed to load Flora item: " + id + ": " + e.getMessage());
}
}
private BlockData data(String s) {
return main.getWorldHandle().createBlockData(s);
}
}