mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 22:30:00 +00:00
Merge pull request #145 from PolyhedralDev/dev/forge
Forge implementation
This commit is contained in:
@@ -17,7 +17,7 @@ dependencies {
|
||||
"shadedApi"("commons-io:commons-io:2.4")
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.2.3")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.3.1")
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
"shadedApi"("org.ow2.asm:asm:9.0")
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
@@ -16,6 +17,9 @@ import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* Represents a Terra mod/plugin instance.
|
||||
@@ -67,4 +71,8 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
}
|
||||
|
||||
Profiler getProfiler();
|
||||
|
||||
default JarFile getModJar() throws URISyntaxException, IOException {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,12 @@ public interface World extends Handle {
|
||||
|
||||
String getName();
|
||||
|
||||
UUID getUID();
|
||||
|
||||
boolean isChunkGenerated(int x, int z);
|
||||
|
||||
Chunk getChunkAt(int x, int z);
|
||||
|
||||
default Chunk getChunkAt(Location location) {
|
||||
return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
}
|
||||
|
||||
File getWorldFolder();
|
||||
|
||||
Block getBlockAt(int x, int y, int z);
|
||||
|
||||
default Block getBlockAt(Location l) {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
@@ -32,4 +36,12 @@ public class JarUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static JarFile getJarFile() throws URISyntaxException, IOException {
|
||||
return new JarFile(new File(getJarURL().toURI()));
|
||||
}
|
||||
|
||||
public static URL getJarURL() {
|
||||
return TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public class PluginConfig implements ConfigTemplate {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.load(this, file);
|
||||
if(dumpDefaultConfig) { // Don't dump default config if already loaded.
|
||||
try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
try(JarFile jar = main.getModJar()) {
|
||||
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
main.getDebugLogger().error("Failed to dump default config files!");
|
||||
e.printStackTrace();
|
||||
main.getDebugLogger().error("Report this to Terra!");
|
||||
main.getDebugLogger().error("Either you're on Forge, or this is a bug. If it's the latter, report this to Terra!");
|
||||
}
|
||||
}
|
||||
} catch(ConfigException | IOException e) {
|
||||
|
||||
@@ -9,9 +9,6 @@ import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DummyWorld implements World {
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
@@ -38,26 +35,11 @@ public class DummyWorld implements World {
|
||||
return "DUMMY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUID() {
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkGenerated(int x, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
throw new UnsupportedOperationException("Cannot get chunk in DummyWorld");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorldFolder() {
|
||||
throw new UnsupportedOperationException("Cannot get folder of DummyWorld");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException("Cannot get block in DummyWorld");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
|
||||
@@ -18,8 +19,12 @@ public abstract class Loader {
|
||||
*
|
||||
* @param consumer Something to do with the streams.
|
||||
*/
|
||||
public Loader then(ExceptionalConsumer<List<InputStream>> consumer) throws ConfigException {
|
||||
consumer.accept(new GlueList<>(streams.values()));
|
||||
public Loader then(ExceptionalConsumer<List<Configuration>> consumer) throws ConfigException {
|
||||
List<Configuration> list = new GlueList<>();
|
||||
streams.forEach((id, stream) -> {
|
||||
list.add(new Configuration(stream, id));
|
||||
});
|
||||
consumer.accept(list);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public final class LangUtil {
|
||||
public static void load(String langID, TerraPlugin main) {
|
||||
Logger logger = main.logger();
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
try(JarFile jar = main.getModJar()) {
|
||||
copyResourcesToDirectory(jar, "lang", file.toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
main.getDebugLogger().error("Failed to dump language files!");
|
||||
|
||||
@@ -237,13 +237,13 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
}).close();
|
||||
|
||||
loader
|
||||
.open("carving", ".yml").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("palettes", ".yml").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores", ".yml").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("structures/trees", ".yml").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
|
||||
.open("structures/structures", ".yml").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new), main)).close()
|
||||
.open("flora", ".yml").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
.open("carving", ".yml").then(configs -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.loadConfigs(configs, CarverTemplate::new), main)).close()
|
||||
.open("palettes", ".yml").then(configs -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.loadConfigs(configs, PaletteTemplate::new), main)).close()
|
||||
.open("ores", ".yml").then(configs -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.loadConfigs(configs, OreTemplate::new), main)).close()
|
||||
.open("structures/trees", ".yml").then(configs -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.loadConfigs(configs, TreeTemplate::new), main)).close()
|
||||
.open("structures/structures", ".yml").then(configs -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.loadConfigs(configs, StructureTemplate::new), main)).close()
|
||||
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this));
|
||||
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
|
||||
|
||||
@@ -65,7 +65,9 @@ public class OpenRegistry<T> implements Registry<T> {
|
||||
|
||||
@Override
|
||||
public T get(String identifier) {
|
||||
return objects.get(identifier).getValue();
|
||||
Entry<T> entry = objects.get(identifier);
|
||||
if(entry == null) return null;
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,10 +68,4 @@ public class FloraRegistry extends OpenRegistry<Flora> {
|
||||
private BlockData data(String s) {
|
||||
return main.getWorldHandle().createBlockData(s);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Flora get(String identifier) {
|
||||
return super.get(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,10 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
|
||||
@Override
|
||||
@SuppressWarnings({"try"})
|
||||
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
BiomeProvider grid = tw.getBiomeProvider();
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_3d")) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
BiomeProvider grid = tw.getBiomeProvider();
|
||||
|
||||
if(!tw.isSafe()) return chunk;
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
@@ -119,7 +120,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
|
||||
int cx = xOrig + x;
|
||||
int cz = zOrig + z;
|
||||
|
||||
TerraBiome b = grid.getBiome(xOrig + x, zOrig + z);
|
||||
TerraBiome b = grid.getBiome(cx, cz);
|
||||
BiomeTemplate c = ((UserDefinedBiome) b).getConfig();
|
||||
|
||||
int sea = c.getSeaLevel();
|
||||
|
||||
@@ -159,7 +159,7 @@ public class DistributionTest {
|
||||
new GenericLoaders(MAIN).register(loader);
|
||||
|
||||
BiomeRegistry biomeRegistry = new BiomeRegistry();
|
||||
folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.load(inputStreams, TestBiome::new), MAIN));
|
||||
folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.loadConfigs(inputStreams, TestBiome::new), MAIN));
|
||||
|
||||
BiomeProviderTemplate template = new BiomeProviderTemplate();
|
||||
ConfigLoader pipeLoader = new ConfigLoader()
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ImageTest {
|
||||
|
||||
OpenRegistry<TerraBiome> biomeRegistry = new OpenRegistry<TerraBiome>() {
|
||||
};
|
||||
folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.load(inputStreams, TestBiome::new), null));
|
||||
folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.loadConfigs(inputStreams, TestBiome::new), null));
|
||||
|
||||
return new ImageBiomeProvider(biomeRegistry.entries(), ImageIO.read(ImageTest.class.getResourceAsStream("/map.jpg")), 1, ImageBiomeProvider.Align.CENTER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user