mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Loot tables
This commit is contained in:
@@ -21,6 +21,7 @@ import com.dfsek.terra.config.files.FolderLoader;
|
||||
import com.dfsek.terra.config.files.Loader;
|
||||
import com.dfsek.terra.config.files.ZIPLoader;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.loaders.LootTableLoader;
|
||||
import com.dfsek.terra.config.loaders.StructureLoader;
|
||||
import com.dfsek.terra.config.templates.AbstractableTemplate;
|
||||
import com.dfsek.terra.config.templates.BiomeGridTemplate;
|
||||
@@ -46,6 +47,7 @@ import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.util.ConfigUtil;
|
||||
import com.dfsek.terra.util.StructureTypeEnum;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
@@ -143,7 +145,8 @@ public class ConfigPack {
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey()).setValue(var.getValue());
|
||||
}
|
||||
abstractConfigLoader.registerLoader(Structure.class, new StructureLoader(loader));
|
||||
abstractConfigLoader.registerLoader(Structure.class, new StructureLoader(loader))
|
||||
.registerLoader(LootTable.class, new LootTableLoader(loader)); // These loaders need access to the Loader instance to get files.
|
||||
loader
|
||||
.open("palettes").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new))).close()
|
||||
.open("ores").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new))).close()
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.config.files.Loader;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class LootTableLoader implements TypeLoader<LootTable> {
|
||||
private final Loader loader;
|
||||
|
||||
public LootTableLoader(Loader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LootTable load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
try(InputStream stream = loader.get("structures/loot/" + o + ".json")) {
|
||||
return new LootTable(IOUtils.toString(stream, StandardCharsets.UTF_8));
|
||||
} catch(IOException | ParseException | NullPointerException e) {
|
||||
throw new LoadException("Unable to load loot", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user