Look ma, no Bukkit API in the core package

This commit is contained in:
dfsek
2020-12-11 17:30:17 -07:00
parent 7ee1d2c391
commit 5bf699cba9
345 changed files with 1352 additions and 2642 deletions

View File

@@ -0,0 +1,24 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
import com.dfsek.terra.config.builder.biomegrid.SingleGridBuilder;
public class BiomeGridRegistry extends TerraRegistry<BiomeGridBuilder> {
private final BiomeRegistry biomeRegistry;
public BiomeGridRegistry(BiomeRegistry biomeRegistry) {
this.biomeRegistry = biomeRegistry;
}
@Override
public BiomeGridBuilder get(String id) {
if(id.startsWith("BIOME:")) return new SingleGridBuilder(biomeRegistry.get(id.substring(6)));
return super.get(id);
}
@Override
public boolean contains(String name) {
if(name.startsWith("BIOME:")) return biomeRegistry.contains(name.substring(6));
return super.contains(name);
}
}

View File

@@ -0,0 +1,6 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.biome.UserDefinedBiome;
public class BiomeRegistry extends TerraRegistry<UserDefinedBiome> {
}

View File

@@ -0,0 +1,6 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.carving.UserDefinedCarver;
public class CarverRegistry extends TerraRegistry<UserDefinedCarver> {
}

View File

@@ -0,0 +1,48 @@
package com.dfsek.terra.registry;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.debug.Debug;
import java.io.File;
import java.io.IOException;
import java.util.zip.ZipFile;
/**
* Class to hold config packs
*/
public class ConfigRegistry extends TerraRegistry<ConfigPack> {
public void load(File folder, TerraPlugin main) throws ConfigException {
ConfigPack pack = new ConfigPack(folder, main);
add(pack.getTemplate().getID(), pack);
}
public boolean loadAll(TerraPlugin main) {
boolean valid = true;
File packsFolder = new File(main.getDataFolder(), "packs");
for(File dir : packsFolder.listFiles(File::isDirectory)) {
try {
load(dir, main);
} catch(ConfigException e) {
e.printStackTrace();
valid = false;
}
}
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".jar") || file.getName().endsWith(".com.dfsek.terra"))) {
try {
Debug.info("Loading ZIP archive: " + zip.getName());
load(new ZipFile(zip), main);
} catch(IOException | ConfigException e) {
e.printStackTrace();
valid = false;
}
}
return valid;
}
public void load(ZipFile file, TerraPlugin main) throws ConfigException {
ConfigPack pack = new ConfigPack(file, main);
add(pack.getTemplate().getID(), pack);
}
}

View File

@@ -0,0 +1,74 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.api.gaea.world.Flora;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.generation.items.flora.ConstantFlora;
import com.dfsek.terra.util.MaterialSet;
import java.util.Arrays;
import java.util.Collections;
public class FloraRegistry extends TerraRegistry<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")), 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 MaterialData create(String s) {
return main.getWorldHandle().createMaterialData(s);
}
private void addItem(String id, ConstantFlora flora) {
try {
add(id, flora);
} catch(IllegalArgumentException e) {
main.getLogger().warning("Failed to load Flora item: " + id + ": " + e.getMessage());
}
}
private BlockData data(String s) {
return main.getWorldHandle().createBlockData(s);
}
@Override
public Flora get(String id) {
return super.get(id);
}
}

View File

@@ -0,0 +1,6 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.generation.items.ores.Ore;
public class OreRegistry extends TerraRegistry<Ore> {
}

View File

@@ -0,0 +1,21 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.api.gaea.world.palette.Palette;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.biome.palette.SinglePalette;
public class PaletteRegistry extends TerraRegistry<Palette<BlockData>> {
private final TerraPlugin main;
public PaletteRegistry(TerraPlugin main) {
this.main = main;
}
@Override
public Palette<BlockData> get(String id) {
if(id.startsWith("BLOCK:"))
return new SinglePalette<>(main.getWorldHandle().createBlockData(id.substring(6))); // Return single palette for BLOCK: shortcut.
return super.get(id);
}
}

View File

@@ -0,0 +1,6 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.generation.items.TerraStructure;
public class StructureRegistry extends TerraRegistry<TerraStructure> {
}

View File

@@ -0,0 +1,72 @@
package com.dfsek.terra.registry;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
public abstract class TerraRegistry<T> implements TypeLoader<T> {
private final Map<String, T> objects = new HashMap<>();
@Override
public T load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
T obj = get((String) o);
if(obj == null)
throw new LoadException("No such " + type.getTypeName() + " matching \"" + o + "\" was found in this registry.");
return obj;
}
/**
* Add an object to the registry with a name.
*
* @param name Name of the tree.
* @param value Object to add
* @return True if tree was overwritten.
*/
public boolean add(String name, T value) {
boolean exists = objects.containsKey(name);
objects.put(name, value);
return exists;
}
/**
* Check if the registry contains an object.
*
* @param name Name of the object.
* @return Whether the registry contains the object.
*/
public boolean contains(String name) {
return objects.containsKey(name);
}
/**
* Get an object from the registry,
*
* @param id ID of object to get
* @return Object
*/
public T get(String id) {
return objects.get(id);
}
public void forEach(Consumer<T> consumer) {
objects.forEach((id, obj) -> consumer.accept(obj));
}
public Set<T> entries() {
return new HashSet<>(objects.values());
}
/**
* Clears all entries from the registry.
*/
public void clear() {
objects.clear();
}
}

View File

@@ -0,0 +1,9 @@
package com.dfsek.terra.registry;
import com.dfsek.terra.api.gaea.tree.Tree;
public class TreeRegistry extends TerraRegistry<Tree> {
public TreeRegistry() {
}
}