rename main parameters/fields to platform

This commit is contained in:
dfsek
2021-09-26 13:22:45 -07:00
parent 8f51707505
commit 4945a3bbfa
117 changed files with 535 additions and 516 deletions
+2 -2
View File
@@ -21,8 +21,8 @@ assignees: ""
- You must be on the LATEST version of Terra to receive any support. There is no support for older versions of Terra. - You must be on the LATEST version of Terra to receive any support. There is no support for older versions of Terra.
- Make sure that this is not a *specific* compatibility issue with another terrain generation mod. - Make sure that this is not a *specific* compatibility issue with another terrain generation mod.
Do not request *specific* compatibility with mods or plugins (e.g. "Compatibility with TechCraft v7"). Do not request *specific* compatibility with mods or plugins (e.g. "Compatibility with TechCraft v7").
That should be implemented in an addon, **not** in the main project. That should be implemented in an addon, **not** in the platform project.
*General* compatibility (e.g. "Ability to pull Vanilla/Modded features from parent biomes") will be considered in the main project. *General* compatibility (e.g. "Ability to pull Vanilla/Modded features from parent biomes") will be considered in the platform project.
- Make sure that there are no already existing issues open with your problem. If you open a duplicate, it will be closed as such. - Make sure that there are no already existing issues open with your problem. If you open a duplicate, it will be closed as such.
- Make sure that it is actually Terra causing the issue, and not another mod/plugin. - Make sure that it is actually Terra causing the issue, and not another mod/plugin.
You can do this by testing to see if you can recreate the issue without Terra installed. You can do this by testing to see if you can recreate the issue without Terra installed.
+6 -6
View File
@@ -114,9 +114,9 @@ please [include as many details as possible](#how-do-i-submit-a-good-bug-report)
- Make sure that this is not a *specific* compatibility issue with another - Make sure that this is not a *specific* compatibility issue with another
terrain generation mod. Do not request *specific* compatibility with mods or terrain generation mod. Do not request *specific* compatibility with mods or
plugins (e.g. "Compatibility with TechCraft v7"). That should be implemented plugins (e.g. "Compatibility with TechCraft v7"). That should be implemented
in an addon, **not** in the main project. in an addon, **not** in the platform project.
*General* compatibility (e.g. "Ability to pull Vanilla/Modded features from *General* compatibility (e.g. "Ability to pull Vanilla/Modded features from
parent biomes") will be considered in the main project. parent biomes") will be considered in the platform project.
- Search for - Search for
any [already existing issues](https://github.com/PolyhedralDev/Terra/issues?q=is%3Aissue+) any [already existing issues](https://github.com/PolyhedralDev/Terra/issues?q=is%3Aissue+)
open with your problem. If you open a duplicate, it will be closed as such. open with your problem. If you open a duplicate, it will be closed as such.
@@ -200,7 +200,7 @@ please [include as many details as possible](#how-do-i-submit-a-good-enhancement
Enhancement suggestions are tracked Enhancement suggestions are tracked
as [GitHub issues](https://guides.github.com/features/issues/). Create an issue as [GitHub issues](https://guides.github.com/features/issues/). Create an issue
on our main repository and provide the following information: on our platform repository and provide the following information:
- **Use a clear and descriptive title** for the issue to identify the - **Use a clear and descriptive title** for the issue to identify the
suggestion. suggestion.
@@ -243,7 +243,7 @@ accepted.
Pull Requests are tracked Pull Requests are tracked
as [GitHub Pull Requests](https://guides.github.com/activities/forking/#making-a-pull-request) as [GitHub Pull Requests](https://guides.github.com/activities/forking/#making-a-pull-request)
. Create a pr on our main repository and provide the following information: . Create a pr on our platform repository and provide the following information:
- **Use a clear and descriptive title** to identify the pull request. - **Use a clear and descriptive title** to identify the pull request.
- **State what this pull request adds/fixes**. - **State what this pull request adds/fixes**.
@@ -347,7 +347,7 @@ TODO
#### General Compatibility #### General Compatibility
General compatibility (example: injection of Vanilla structures/features/carvers General compatibility (example: injection of Vanilla structures/features/carvers
into packs) is acceptable in the main project. into packs) is acceptable in the platform project.
- General compatibility features should be *disabled by default*. Having things - General compatibility features should be *disabled by default*. Having things
auto-injected causes unpredictable behaviour that is annoying to diagnose. auto-injected causes unpredictable behaviour that is annoying to diagnose.
@@ -365,7 +365,7 @@ into packs) is acceptable in the main project.
#### Specific Compatibility #### Specific Compatibility
Specific compatibility should *not* be put in the main project. (Example: Adding Specific compatibility should *not* be put in the platform project. (Example: Adding
the ability to generate TechCraft v7's doo-dads with a TerraScript function) the ability to generate TechCraft v7's doo-dads with a TerraScript function)
Having specific compatibilities leads to tons of extra dependencies to keep Having specific compatibilities leads to tons of extra dependencies to keep
@@ -26,11 +26,11 @@ public class ImageBiomeProviderAddon extends TerraAddon {
}; };
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
@@ -40,17 +40,17 @@ public class BiomePipelineAddon extends TerraAddon {
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() { public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {
}; };
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry( CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(
PROVIDER_REGISTRY_KEY); PROVIDER_REGISTRY_KEY);
providerRegistry.register("PIPELINE", () -> new BiomePipelineTemplate(main)); providerRegistry.register("PIPELINE", () -> new BiomePipelineTemplate(platform));
}) })
.then(event -> { .then(event -> {
CheckedRegistry<Supplier<ObjectTemplate<BiomeSource>>> sourceRegistry = event.getPack().getOrCreateRegistry( CheckedRegistry<Supplier<ObjectTemplate<BiomeSource>>> sourceRegistry = event.getPack().getOrCreateRegistry(
@@ -20,12 +20,12 @@ public class BiomePipelineProvider implements BiomeProvider {
private final NoiseSampler mutator; private final NoiseSampler mutator;
private final double noiseAmp; private final double noiseAmp;
public BiomePipelineProvider(BiomePipeline pipeline, Platform main, int resolution, NoiseSampler mutator, double noiseAmp) { public BiomePipelineProvider(BiomePipeline pipeline, Platform platform, int resolution, NoiseSampler mutator, double noiseAmp) {
this.resolution = resolution; this.resolution = resolution;
this.mutator = mutator; this.mutator = mutator;
this.noiseAmp = noiseAmp; this.noiseAmp = noiseAmp;
holderCache = CacheBuilder.newBuilder() holderCache = CacheBuilder.newBuilder()
.maximumSize(main == null ? 32 : main.getTerraConfig().getProviderCache()) .maximumSize(platform == null ? 32 : platform.getTerraConfig().getProviderCache())
.build( .build(
new CacheLoader<>() { new CacheLoader<>() {
@Override @Override
@@ -16,7 +16,7 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
@SuppressWarnings({ "FieldMayBeFinal", "unused" }) @SuppressWarnings({ "FieldMayBeFinal", "unused" })
public class BiomePipelineTemplate extends BiomeProviderTemplate { public class BiomePipelineTemplate extends BiomeProviderTemplate {
private final Platform main; private final Platform platform;
@Value("pipeline.initial-size") @Value("pipeline.initial-size")
@Default @Default
private @Meta int initialSize = 2; private @Meta int initialSize = 2;
@@ -27,8 +27,8 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
@Value("pipeline.source") @Value("pipeline.source")
private @Meta BiomeSource source; private @Meta BiomeSource source;
public BiomePipelineTemplate(Platform main) { public BiomePipelineTemplate(Platform platform) {
this.main = main; this.platform = platform;
} }
@Override @Override
@@ -36,6 +36,6 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate {
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize); BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize);
stages.forEach(biomePipelineBuilder::addStage); stages.forEach(biomePipelineBuilder::addStage);
BiomePipeline pipeline = biomePipelineBuilder.build(source); BiomePipeline pipeline = biomePipelineBuilder.build(source);
return new BiomePipelineProvider(pipeline, main, resolution, blend, blendAmp); return new BiomePipelineProvider(pipeline, platform, resolution, blend, blendAmp);
} }
} }
@@ -25,11 +25,11 @@ public class SingleBiomeProviderAddon extends TerraAddon {
}; };
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
@@ -23,23 +23,24 @@ import com.dfsek.terra.api.world.generator.ChunkGeneratorProvider;
@Version("1.0.0") @Version("1.0.0")
public class NoiseChunkGenerator3DAddon extends TerraAddon { public class NoiseChunkGenerator3DAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
event.getPack().getOrCreateRegistry(ChunkGeneratorProvider.class).register("NOISE_3D", event.getPack().getOrCreateRegistry(ChunkGeneratorProvider.class).register("NOISE_3D",
pack -> new NoiseChunkGenerator3D(pack, main)); pack -> new NoiseChunkGenerator3D(pack,
platform));
event.getPack() event.getPack()
.applyLoader(SlantHolder.class, new SlantHolderLoader()) .applyLoader(SlantHolder.class, new SlantHolderLoader())
.applyLoader(PaletteHolder.class, new PaletteHolderLoader()); .applyLoader(PaletteHolder.class, new PaletteHolderLoader());
}) })
.failThrough(); .failThrough();
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationLoadEvent.class) .register(this, ConfigurationLoadEvent.class)
.then(event -> { .then(event -> {
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.chunkgenerator.generation.generators; package com.dfsek.terra.addons.chunkgenerator.generation.generators;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -10,7 +12,6 @@ import java.util.Random;
import com.dfsek.terra.addons.chunkgenerator.PaletteUtil; import com.dfsek.terra.addons.chunkgenerator.PaletteUtil;
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D; import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteInfo; import com.dfsek.terra.addons.chunkgenerator.palette.PaletteInfo;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.state.properties.base.Properties; import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.block.state.properties.enums.Direction; import com.dfsek.terra.api.block.state.properties.enums.Direction;
@@ -31,21 +32,21 @@ import com.dfsek.terra.api.util.math.Sampler;
public class NoiseChunkGenerator3D implements ChunkGenerator { public class NoiseChunkGenerator3D implements ChunkGenerator {
private final ConfigPack configPack; private final ConfigPack configPack;
private final Platform main; private final Platform platform;
private final List<GenerationStage> generationStages = new ArrayList<>(); private final List<GenerationStage> generationStages = new ArrayList<>();
private final BlockState air; private final BlockState air;
public NoiseChunkGenerator3D(ConfigPack c, Platform main) { public NoiseChunkGenerator3D(ConfigPack c, Platform platform) {
this.configPack = c; this.configPack = c;
this.main = main; this.platform = platform;
this.air = main.getWorldHandle().air(); this.air = platform.getWorldHandle().air();
c.getStages().forEach(stage -> generationStages.add(stage.newInstance(c))); c.getStages().forEach(stage -> generationStages.add(stage.newInstance(c)));
} }
@SuppressWarnings("try") @SuppressWarnings("try")
static void biomes(@NotNull World world, int chunkX, int chunkZ, @NotNull BiomeGrid biome, Platform main) { static void biomes(@NotNull World world, int chunkX, int chunkZ, @NotNull BiomeGrid biome, Platform platform) {
try(ProfileFrame ignore = main.getProfiler().profile("biomes")) { try(ProfileFrame ignore = platform.getProfiler().profile("biomes")) {
int xOrig = (chunkX << 4); int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4); int zOrig = (chunkZ << 4);
long seed = world.getSeed(); long seed = world.getSeed();
@@ -65,7 +66,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
@Override @Override
@SuppressWarnings("try") @SuppressWarnings("try")
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) { public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_3d")) { try(ProfileFrame ignore = platform.getProfiler().profile("chunk_base_3d")) {
BiomeProvider grid = world.getBiomeProvider(); BiomeProvider grid = world.getBiomeProvider();
int xOrig = (chunkX << 4); int xOrig = (chunkX << 4);
@@ -87,7 +88,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
PaletteInfo paletteInfo = biome.getContext().get(PaletteInfo.class); PaletteInfo paletteInfo = biome.getContext().get(PaletteInfo.class);
if(paletteInfo == null) { if(paletteInfo == null) {
main.logger().info("null palette: " + biome.getID()); platform.logger().info("null palette: " + biome.getID());
} }
GenerationSettings generationSettings = biome.getGenerator(); GenerationSettings generationSettings = biome.getGenerator();
@@ -125,7 +126,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
@Override @Override
public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) { public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) {
biomes(world, chunkX, chunkZ, biome, main); biomes(world, chunkX, chunkZ, biome, platform);
} }
@Override @Override
@@ -139,8 +140,8 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
} }
@Override @Override
public Platform getMain() { public Platform getPlatform() {
return main; return platform;
} }
@Override @Override
@@ -17,11 +17,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@Version("1.0.0") @Version("1.0.0")
public class BiomeAddon extends TerraAddon { public class BiomeAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
@@ -35,8 +35,8 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
} }
@Override @Override
public BiomeTemplate getTemplate(ConfigPack pack, Platform main) { public BiomeTemplate getTemplate(ConfigPack pack, Platform platform) {
return new BiomeTemplate(pack, main); return new BiomeTemplate(pack, platform);
} }
@Override @Override
@@ -14,7 +14,7 @@ public class BiomeFactory implements ConfigFactory<BiomeTemplate, TerraBiome> {
} }
@Override @Override
public TerraBiome build(BiomeTemplate template, Platform main) { public TerraBiome build(BiomeTemplate template, Platform platform) {
UserDefinedGenerationSettings generator = new UserDefinedGenerationSettings(template.getNoiseEquation(), UserDefinedGenerationSettings generator = new UserDefinedGenerationSettings(template.getNoiseEquation(),
template.getElevationEquation(), template.getElevationEquation(),
template.getCarvingEquation(), template.getBiomeNoise(), template.getCarvingEquation(), template.getBiomeNoise(),
@@ -113,7 +113,7 @@ public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTempl
private @Meta Map<String, @Meta Integer> colors = new HashMap<>(); private @Meta Map<String, @Meta Integer> colors = new HashMap<>();
// Plain ol' map, so platforms can decide what to do with colors (if anything). // Plain ol' map, so platforms can decide what to do with colors (if anything).
public BiomeTemplate(ConfigPack pack, Platform main) { public BiomeTemplate(ConfigPack pack, Platform platform) {
this.pack = pack; this.pack = pack;
} }
@@ -1,10 +1,11 @@
package com.dfsek.terra.addons.biome.command.biome; package com.dfsek.terra.addons.biome.command.biome;
import com.dfsek.terra.api.Platform;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.World; import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.TerraBiome;
@@ -23,15 +24,15 @@ public class AsyncBiomeFinder implements Runnable {
protected final int centerX; protected final int centerX;
protected final int centerZ; protected final int centerZ;
protected final World world; protected final World world;
protected final Platform main; protected final Platform platform;
private final Consumer<Vector3> callback; private final Consumer<Vector3> callback;
protected int searchSize = 1; protected int searchSize = 1;
public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius,
Consumer<Vector3> callback, Platform main) { Consumer<Vector3> callback, Platform platform) {
this.provider = provider; this.provider = provider;
this.target = target; this.target = target;
this.main = main; this.platform = platform;
this.startRadius = startRadius; this.startRadius = startRadius;
this.maxRadius = maxRadius; this.maxRadius = maxRadius;
this.centerX = origin.getBlockX(); this.centerX = origin.getBlockX();
@@ -41,7 +42,7 @@ public class AsyncBiomeFinder implements Runnable {
} }
public Vector3 finalizeVector(Vector3 orig) { public Vector3 finalizeVector(Vector3 orig) {
return orig.multiply(main.getTerraConfig().getBiomeSearchResolution()); return orig.multiply(platform.getTerraConfig().getBiomeSearchResolution());
} }
@Override @Override
@@ -90,7 +91,7 @@ public class AsyncBiomeFinder implements Runnable {
* @return TerraBiome at coordinates * @return TerraBiome at coordinates
*/ */
public boolean isValid(int x, int z, TerraBiome target) { public boolean isValid(int x, int z, TerraBiome target) {
int res = main.getTerraConfig().getBiomeSearchResolution(); int res = platform.getTerraConfig().getBiomeSearchResolution();
return getProvider().getBiome(x * res, z * res, world.getSeed()).equals(target); return getProvider().getBiome(x * res, z * res, world.getSeed()).equals(target);
} }
@@ -24,7 +24,7 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
@PlayerCommand @PlayerCommand
public class BiomeCommand implements CommandTemplate { public class BiomeCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
@@ -51,7 +51,7 @@ public class BiomeLocateCommand implements CommandTemplate {
private boolean teleport; private boolean teleport;
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
@@ -59,7 +59,7 @@ public class BiomeLocateCommand implements CommandTemplate {
Player player = (Player) sender; Player player = (Player) sender;
new Thread(new AsyncBiomeFinder(player.world().getBiomeProvider(), biome, new Thread(new AsyncBiomeFinder(player.world().getBiomeProvider(), biome,
player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.position().clone().multiply((1D / platform.getTerraConfig().getBiomeSearchResolution())),
player.world(), 0, radius, location -> { player.world(), 0, radius, location -> {
if(location != null) { if(location != null) {
sender.sendMessage( sender.sendMessage(
@@ -67,11 +67,11 @@ public class BiomeLocateCommand implements CommandTemplate {
location.getBlockX(), location.getBlockZ(), location.getBlockX(), location.getBlockZ(),
location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position()))); location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) { if(teleport) {
main.runPossiblyUnsafeTask( platform.runPossiblyUnsafeTask(
() -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ()))); () -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ())));
} }
} else sender.sendMessage("Unable to locate biome \"" + biome.getID() + "\""); } else sender.sendMessage("Unable to locate biome \"" + biome.getID() + "\"");
}, main), "Biome Location Thread").start(); }, platform), "Biome Location Thread").start();
} }
} }
@@ -10,7 +10,7 @@ import com.dfsek.terra.api.world.biome.TerraBiome;
public class BiomeArgumentParser implements ArgumentParser<TerraBiome> { public class BiomeArgumentParser implements ArgumentParser<TerraBiome> {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public TerraBiome parse(CommandSender sender, String arg) { public TerraBiome parse(CommandSender sender, String arg) {
@@ -13,7 +13,7 @@ import com.dfsek.terra.api.world.biome.TerraBiome;
public class BiomeTabCompleter implements TabCompleter { public class BiomeTabCompleter implements TabCompleter {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public List<String> complete(CommandSender sender) { public List<String> complete(CommandSender sender) {
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.carver; package com.dfsek.terra.addons.carver;
import com.dfsek.terra.api.Platform;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@@ -11,7 +13,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import com.dfsek.terra.addons.carver.carving.Worm; import com.dfsek.terra.addons.carver.carving.Worm;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.util.MathUtil; import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.util.PopulationUtil; import com.dfsek.terra.api.util.PopulationUtil;
import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.util.vector.Vector3;
@@ -25,9 +26,9 @@ public class CarverCache {
private final LoadingCache<Long, List<Worm.WormPoint>> cache; private final LoadingCache<Long, List<Worm.WormPoint>> cache;
private final UserDefinedCarver carver; private final UserDefinedCarver carver;
public CarverCache(World w, Platform main, UserDefinedCarver carver) { public CarverCache(World w, Platform platform, UserDefinedCarver carver) {
this.carver = carver; this.carver = carver;
cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getCarverCacheSize()) cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getCarverCacheSize())
.build(new CacheLoader<>() { .build(new CacheLoader<>() {
@Override @Override
public List<Worm.WormPoint> load(@NotNull Long key) { public List<Worm.WormPoint> load(@NotNull Long key) {
@@ -21,7 +21,7 @@ public class CarverFactory implements ConfigFactory<CarverTemplate, UserDefinedC
} }
@Override @Override
public UserDefinedCarver build(CarverTemplate config, Platform main) throws LoadException { public UserDefinedCarver build(CarverTemplate config, Platform platform) throws LoadException {
double[] start = { config.getStartX(), config.getStartY(), config.getStartZ() }; double[] start = { config.getStartX(), config.getStartY(), config.getStartZ() };
double[] mutate = { config.getMutateX(), config.getMutateY(), config.getMutateZ() }; double[] mutate = { config.getMutateX(), config.getMutateY(), config.getMutateZ() };
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ()); List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
@@ -29,7 +29,7 @@ public class CarverFactory implements ConfigFactory<CarverTemplate, UserDefinedC
UserDefinedCarver carver; UserDefinedCarver carver;
try { try {
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, new Scope(), hash, carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, new Scope(), hash,
config.getCutTop(), config.getCutBottom(), config, main); config.getCutTop(), config.getCutBottom(), config, platform);
} catch(ParseException e) { } catch(ParseException e) {
throw new LoadException("Unable to parse radius equations", e); throw new LoadException("Unable to parse radius equations", e);
} }
@@ -22,16 +22,16 @@ import com.dfsek.terra.api.world.generator.GenerationStage;
public class CavePopulator implements GenerationStage, Chunkified { public class CavePopulator implements GenerationStage, Chunkified {
private static final Map<BlockType, BlockState> shiftStorage = new HashMap<>(); private static final Map<BlockType, BlockState> shiftStorage = new HashMap<>();
// Persist BlockData created for shifts, to avoid re-calculating each time. // Persist BlockData created for shifts, to avoid re-calculating each time.
private final Platform main; private final Platform platform;
public CavePopulator(Platform main) { public CavePopulator(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("try") @SuppressWarnings("try")
@Override @Override
public void populate(@NotNull World world, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Chunk chunk) {
try(ProfileFrame ignore = main.getProfiler().profile("carving")) { try(ProfileFrame ignore = platform.getProfiler().profile("carving")) {
Random random = PopulationUtil.getRandom(chunk); Random random = PopulationUtil.getRandom(chunk);
WorldConfig config = world.getConfig(); WorldConfig config = world.getConfig();
if(config.disableCarving()) return; if(config.disableCarving()) return;
@@ -40,7 +40,7 @@ public class CavePopulator implements GenerationStage, Chunkified {
CarverTemplate template = c.getConfig(); CarverTemplate template = c.getConfig();
Map<Vector3, BlockState> shiftCandidate = new HashMap<>(); Map<Vector3, BlockState> shiftCandidate = new HashMap<>();
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> { c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
try(ProfileFrame ignored = main.getProfiler().profile("carving:" + c.getConfig().getID())) { try(ProfileFrame ignored = platform.getProfiler().profile("carving:" + c.getConfig().getID())) {
BlockState m = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ()); BlockState m = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
BlockType re = m.getBlockType(); BlockType re = m.getBlockType();
switch(type) { switch(type) {
@@ -34,13 +34,13 @@ public class UserDefinedCarver extends Carver {
private final Expression zRad; private final Expression zRad;
private final Map<Long, CarverCache> cacheMap = new ConcurrentHashMap<>(); private final Map<Long, CarverCache> cacheMap = new ConcurrentHashMap<>();
private final Platform main; private final Platform platform;
private double step = 2; private double step = 2;
private Range recalc = new ConstantRange(8, 10); private Range recalc = new ConstantRange(8, 10);
private double recalcMagnitude = 3; private double recalcMagnitude = 3;
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, long hash, public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, long hash,
int topCut, int bottomCut, CarverTemplate config, Platform main) throws ParseException { int topCut, int bottomCut, CarverTemplate config, Platform platform) throws ParseException {
super(height.getMin(), height.getMax()); super(height.getMin(), height.getMax());
this.length = length; this.length = length;
this.start = start; this.start = start;
@@ -49,7 +49,7 @@ public class UserDefinedCarver extends Carver {
this.topCut = topCut; this.topCut = topCut;
this.bottomCut = bottomCut; this.bottomCut = bottomCut;
this.config = config; this.config = config;
this.main = main; this.platform = platform;
Parser p = new Parser(); Parser p = new Parser();
@@ -74,7 +74,7 @@ public class UserDefinedCarver extends Carver {
@Override @Override
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector3, CarvingType> consumer) { public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector3, CarvingType> consumer) {
synchronized(cacheMap) { synchronized(cacheMap) {
CarverCache cache = cacheMap.computeIfAbsent(w.getSeed(), world -> new CarverCache(w, main, this)); CarverCache cache = cacheMap.computeIfAbsent(w.getSeed(), world -> new CarverCache(w, platform, this));
int carvingRadius = getCarvingRadius(); int carvingRadius = getCarvingRadius();
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) { for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) { for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
@@ -31,11 +31,11 @@ public class DistributorAddon extends TerraAddon {
public static final TypeKey<Supplier<ObjectTemplate<Distributor>>> DISTRIBUTOR_TOKEN = new TypeKey<>() { public static final TypeKey<Supplier<ObjectTemplate<Distributor>>> DISTRIBUTOR_TOKEN = new TypeKey<>() {
}; };
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
@@ -15,11 +15,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@Author("Terra") @Author("Terra")
public class FeatureAddon extends TerraAddon { public class FeatureAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack().registerConfigType(new FeatureConfigType(), "FEATURE", 3)) .then(event -> event.getPack().registerConfigType(new FeatureConfigType(), "FEATURE", 3))
@@ -23,7 +23,7 @@ public class FeatureConfigType implements ConfigType<FeatureTemplate, Feature> {
} }
@Override @Override
public FeatureTemplate getTemplate(ConfigPack pack, Platform main) { public FeatureTemplate getTemplate(ConfigPack pack, Platform platform) {
return new FeatureTemplate(); return new FeatureTemplate();
} }
@@ -9,7 +9,7 @@ import com.dfsek.terra.api.structure.feature.Feature;
public class FeatureFactory implements ConfigFactory<FeatureTemplate, Feature> { public class FeatureFactory implements ConfigFactory<FeatureTemplate, Feature> {
@Override @Override
public Feature build(FeatureTemplate config, Platform main) throws LoadException { public Feature build(FeatureTemplate config, Platform platform) throws LoadException {
return new ConfiguredFeature(config.getStructures(), config.getStructureNoise(), config.getDistributor(), config.getLocator()); return new ConfiguredFeature(config.getStructures(), config.getStructureNoise(), config.getDistributor(), config.getLocator());
} }
} }
@@ -17,11 +17,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@Version("0.1.0") @Version("0.1.0")
public class FloraAddon extends TerraAddon { public class FloraAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
@@ -22,7 +22,7 @@ public class FloraConfigType implements ConfigType<FloraTemplate, Structure> {
} }
@Override @Override
public FloraTemplate getTemplate(ConfigPack pack, Platform main) { public FloraTemplate getTemplate(ConfigPack pack, Platform platform) {
return new FloraTemplate(); return new FloraTemplate();
} }
@@ -8,7 +8,7 @@ import com.dfsek.terra.api.structure.Structure;
public class FloraFactory implements ConfigFactory<FloraTemplate, Structure> { public class FloraFactory implements ConfigFactory<FloraTemplate, Structure> {
@Override @Override
public TerraFlora build(FloraTemplate config, Platform main) { public TerraFlora build(FloraTemplate config, Platform platform) {
return new TerraFlora(config.getLayers(), config.doPhysics(), config.isCeiling(), return new TerraFlora(config.getLayers(), config.doPhysics(), config.isCeiling(),
config.getRotatable(), config.getRotatable(),
config.getNoiseDistribution(), config.getID()); config.getNoiseDistribution(), config.getID());
@@ -42,16 +42,16 @@ public class LocatorAddon extends TerraAddon {
public static final TypeKey<Supplier<ObjectTemplate<Pattern>>> PATTERN_TOKEN = new TypeKey<>() { public static final TypeKey<Supplier<ObjectTemplate<Pattern>>> PATTERN_TOKEN = new TypeKey<>() {
}; };
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
CheckedRegistry<Supplier<ObjectTemplate<Locator>>> locatorRegistry = event.getPack().getOrCreateRegistry(LOCATOR_TOKEN); CheckedRegistry<Supplier<ObjectTemplate<Locator>>> locatorRegistry = event.getPack().getOrCreateRegistry(LOCATOR_TOKEN);
locatorRegistry.register("SURFACE", () -> new SurfaceLocatorTemplate(main)); locatorRegistry.register("SURFACE", () -> new SurfaceLocatorTemplate(platform));
locatorRegistry.register("RANDOM", RandomLocatorTemplate::new); locatorRegistry.register("RANDOM", RandomLocatorTemplate::new);
locatorRegistry.register("PATTERN", PatternLocatorTemplate::new); locatorRegistry.register("PATTERN", PatternLocatorTemplate::new);
locatorRegistry.register("NOISE", NoiseLocatorTemplate::new); locatorRegistry.register("NOISE", NoiseLocatorTemplate::new);
@@ -11,17 +11,17 @@ import com.dfsek.terra.api.util.Range;
public class SurfaceLocatorTemplate implements ObjectTemplate<Locator> { public class SurfaceLocatorTemplate implements ObjectTemplate<Locator> {
private final Platform main; private final Platform platform;
@Value("range") @Value("range")
private @Meta Range range; private @Meta Range range;
public SurfaceLocatorTemplate(Platform main) { public SurfaceLocatorTemplate(Platform platform) {
this.main = main; this.platform = platform;
} }
@Override @Override
public Locator get() { public Locator get() {
return new SurfaceLocator(range, main); return new SurfaceLocator(range, platform);
} }
} }
@@ -13,9 +13,9 @@ public class SurfaceLocator implements Locator {
private final BlockState air; private final BlockState air;
public SurfaceLocator(Range search, Platform main) { public SurfaceLocator(Range search, Platform platform) {
this.search = search; this.search = search;
this.air = main.getWorldHandle().air(); this.air = platform.getWorldHandle().air();
} }
@Override @Override
@@ -16,16 +16,16 @@ import com.dfsek.terra.api.world.generator.GenerationStageProvider;
@Version("1.0.0") @Version("1.0.0")
public class OreAddon extends TerraAddon { public class OreAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
event.getPack().registerConfigType(new OreConfigType(), "ORE", 1); event.getPack().registerConfigType(new OreConfigType(), "ORE", 1);
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("ORE", pack -> new OrePopulator(main)); event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("ORE", pack -> new OrePopulator(platform));
}) })
.failThrough(); .failThrough();
} }
@@ -22,7 +22,7 @@ public class OreConfigType implements ConfigType<OreTemplate, Ore> {
} }
@Override @Override
public OreTemplate getTemplate(ConfigPack pack, Platform main) { public OreTemplate getTemplate(ConfigPack pack, Platform platform) {
return new OreTemplate(); return new OreTemplate();
} }
@@ -9,8 +9,8 @@ import com.dfsek.terra.api.config.ConfigFactory;
public class OreFactory implements ConfigFactory<OreTemplate, Ore> { public class OreFactory implements ConfigFactory<OreTemplate, Ore> {
@Override @Override
public Ore build(OreTemplate config, Platform main) { public Ore build(OreTemplate config, Platform platform) {
BlockState m = config.getMaterial(); BlockState m = config.getMaterial();
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main, config.getMaterialOverrides()); return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), platform, config.getMaterialOverrides());
} }
} }
@@ -14,16 +14,16 @@ import com.dfsek.terra.api.world.generator.GenerationStage;
public class OrePopulator implements GenerationStage { public class OrePopulator implements GenerationStage {
private final Platform main; private final Platform platform;
public OrePopulator(Platform main) { public OrePopulator(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("try") @SuppressWarnings("try")
@Override @Override
public void populate(@NotNull World world, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Chunk chunk) {
try(ProfileFrame ignore = main.getProfiler().profile("ore")) { try(ProfileFrame ignore = platform.getProfiler().profile("ore")) {
if(world.getConfig().disableOres()) return; if(world.getConfig().disableOres()) return;
for(int cx = -1; cx <= 1; cx++) { for(int cx = -1; cx <= 1; cx++) {
@@ -17,13 +17,13 @@ public abstract class Ore {
private final MaterialSet replaceable; private final MaterialSet replaceable;
private final boolean applyGravity; private final boolean applyGravity;
private final Map<BlockType, BlockState> materials; private final Map<BlockType, BlockState> materials;
protected Platform main; protected Platform platform;
public Ore(BlockState material, MaterialSet replaceable, boolean applyGravity, Platform main, Map<BlockType, BlockState> materials) { public Ore(BlockState material, MaterialSet replaceable, boolean applyGravity, Platform platform, Map<BlockType, BlockState> materials) {
this.material = material; this.material = material;
this.replaceable = replaceable; this.replaceable = replaceable;
this.applyGravity = applyGravity; this.applyGravity = applyGravity;
this.main = main; this.platform = platform;
this.materials = materials; this.materials = materials;
} }
@@ -1,11 +1,12 @@
package com.dfsek.terra.addons.ore.ores; package com.dfsek.terra.addons.ore.ores;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.block.BlockType; import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.util.Range; import com.dfsek.terra.api.util.Range;
@@ -17,9 +18,9 @@ import com.dfsek.terra.api.world.Chunk;
public class VanillaOre extends Ore { public class VanillaOre extends Ore {
private final Range sizeRange; private final Range sizeRange;
public VanillaOre(BlockState material, MaterialSet replaceable, boolean applyGravity, Range size, Platform main, public VanillaOre(BlockState material, MaterialSet replaceable, boolean applyGravity, Range size, Platform platform,
Map<BlockType, BlockState> materials) { Map<BlockType, BlockState> materials) {
super(material, replaceable, applyGravity, main, materials); super(material, replaceable, applyGravity, platform, materials);
this.sizeRange = size; this.sizeRange = size;
} }
@@ -17,15 +17,15 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@Version("1.0.0") @Version("1.0.0")
public class PaletteAddon extends TerraAddon { public class PaletteAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
event.getPack().registerConfigType(new PaletteConfigType(main), "PALETTE", 2); event.getPack().registerConfigType(new PaletteConfigType(platform), "PALETTE", 2);
event.getPack().applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader()); event.getPack().applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader());
}) })
.failThrough(); .failThrough();
@@ -19,10 +19,10 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>() { public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>() {
}; };
private final PaletteFactory factory = new PaletteFactory(); private final PaletteFactory factory = new PaletteFactory();
private final Platform main; private final Platform platform;
public PaletteConfigType(Platform main) { public PaletteConfigType(Platform platform) {
this.main = main; this.platform = platform;
} }
@Override @Override
@@ -30,7 +30,7 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<Palette>) (t, c, loader) -> { return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<Palette>) (t, c, loader) -> {
if(((String) c).startsWith("BLOCK:")) if(((String) c).startsWith("BLOCK:"))
return new PaletteImpl.Singleton( return new PaletteImpl.Singleton(
main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut. platform.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
Palette obj = registry.get((String) c); Palette obj = registry.get((String) c);
if(obj == null) if(obj == null)
throw new LoadException("No such " + t.getType().getTypeName() + " matching \"" + c + "\" was found in this registry."); throw new LoadException("No such " + t.getType().getTypeName() + " matching \"" + c + "\" was found in this registry.");
@@ -39,7 +39,7 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
} }
@Override @Override
public PaletteTemplate getTemplate(ConfigPack pack, Platform main) { public PaletteTemplate getTemplate(ConfigPack pack, Platform platform) {
return new PaletteTemplate(); return new PaletteTemplate();
} }
@@ -9,7 +9,7 @@ import com.dfsek.terra.api.world.generator.Palette;
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> { public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> {
@Override @Override
public Palette build(PaletteTemplate config, Platform main) { public Palette build(PaletteTemplate config, Platform platform) {
NoisePalette palette = new NoisePalette(config.getNoise()); NoisePalette palette = new NoisePalette(config.getNoise());
for(PaletteLayerHolder layer : config.getPalette()) { for(PaletteLayerHolder layer : config.getPalette()) {
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler()); palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
@@ -16,11 +16,11 @@ import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
@Author("Terra") @Author("Terra")
public class StructureAddon extends TerraAddon { public class StructureAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack().applyLoader(ConfiguredStructure.class, (t, o, l) -> null)) .then(event -> event.getPack().applyLoader(ConfiguredStructure.class, (t, o, l) -> null))
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
public class StructureFactory implements ConfigFactory<StructureTemplate, ConfiguredStructure> { public class StructureFactory implements ConfigFactory<StructureTemplate, ConfiguredStructure> {
@Override @Override
public ConfiguredStructure build(StructureTemplate config, Platform main) { public ConfiguredStructure build(StructureTemplate config, Platform platform) {
return new TerraStructure(config.getStructures(), config.getY(), config.getSpawn()); return new TerraStructure(config.getStructures(), config.getY(), config.getSpawn());
} }
} }
@@ -1,11 +1,12 @@
package com.dfsek.terra.addons.structure; package com.dfsek.terra.addons.structure;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Random; import java.util.Random;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.config.WorldConfig; import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.profiler.ProfileFrame; import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure; import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
@@ -20,16 +21,16 @@ import com.dfsek.terra.api.world.generator.GenerationStage;
public class StructurePopulator implements GenerationStage, Chunkified { public class StructurePopulator implements GenerationStage, Chunkified {
private final Platform main; private final Platform platform;
public StructurePopulator(Platform main) { public StructurePopulator(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("try") @SuppressWarnings("try")
@Override @Override
public void populate(@NotNull World world, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Chunk chunk) {
try(ProfileFrame ignore = main.getProfiler().profile("structure")) { try(ProfileFrame ignore = platform.getProfiler().profile("structure")) {
if(world.getConfig().disableStructures()) return; if(world.getConfig().disableStructures()) return;
int cx = (chunk.getX() << 4); int cx = (chunk.getX() << 4);
@@ -1,10 +1,11 @@
package com.dfsek.terra.addons.structure.command; package com.dfsek.terra.addons.structure.command;
import com.dfsek.terra.api.Platform;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure; import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.World; import com.dfsek.terra.api.world.World;
@@ -19,16 +20,16 @@ public class AsyncStructureFinder implements Runnable {
protected final int centerX; protected final int centerX;
protected final int centerZ; protected final int centerZ;
protected final World world; protected final World world;
protected final Platform main; protected final Platform platform;
private final Consumer<Vector3> callback; private final Consumer<Vector3> callback;
protected int searchSize = 1; protected int searchSize = 1;
public AsyncStructureFinder(BiomeProvider provider, ConfiguredStructure target, @NotNull Vector3 origin, World world, int startRadius, public AsyncStructureFinder(BiomeProvider provider, ConfiguredStructure target, @NotNull Vector3 origin, World world, int startRadius,
int maxRadius, Consumer<Vector3> callback, Platform main) { int maxRadius, Consumer<Vector3> callback, Platform platform) {
//setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation()); //setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
this.provider = provider; this.provider = provider;
this.target = target; this.target = target;
this.main = main; this.platform = platform;
this.startRadius = startRadius; this.startRadius = startRadius;
this.maxRadius = maxRadius; this.maxRadius = maxRadius;
this.centerX = origin.getBlockX(); this.centerX = origin.getBlockX();
@@ -29,7 +29,7 @@ import com.dfsek.terra.api.util.vector.Vector3;
@Command(arguments = @Argument("id"), usage = "/terra structure export <ID>") @Command(arguments = @Argument("id"), usage = "/terra structure export <ID>")
public class StructureExportCommand implements CommandTemplate { public class StructureExportCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@ArgumentTarget("id") @ArgumentTarget("id")
private String id; private String id;
@@ -38,7 +38,7 @@ public class StructureExportCommand implements CommandTemplate {
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
Pair<Vector3, Vector3> l = main.getWorldHandle().getSelectedLocation(player); Pair<Vector3, Vector3> l = platform.getWorldHandle().getSelectedLocation(player);
Vector3 l1 = l.getLeft(); Vector3 l1 = l.getLeft();
Vector3 l2 = l.getRight(); Vector3 l2 = l.getRight();
@@ -75,7 +75,7 @@ public class StructureExportCommand implements CommandTemplate {
if(state instanceof Sign) { if(state instanceof Sign) {
Sign sign = (Sign) state; Sign sign = (Sign) state;
if(sign.getLine(0).equals("[TERRA]")) { if(sign.getLine(0).equals("[TERRA]")) {
data = main.getWorldHandle().createBlockData(sign.getLine(2) + sign.getLine(3)); data = platform.getWorldHandle().createBlockData(sign.getLine(2) + sign.getLine(3));
} }
} }
if(!data.isStructureVoid()) { if(!data.isStructureVoid()) {
@@ -88,7 +88,7 @@ public class StructureExportCommand implements CommandTemplate {
} }
} }
File file = new File(main.getDataFolder() + File.separator + "export" + File.separator + "structures", id + ".tesf"); File file = new File(platform.getDataFolder() + File.separator + "export" + File.separator + "structures", id + ".tesf");
try { try {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
file.createNewFile(); file.createNewFile();
@@ -54,7 +54,7 @@ public class StructureLoadCommand implements CommandTemplate {
private Structure script; private Structure script;
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
@@ -42,7 +42,7 @@ import com.dfsek.terra.api.util.vector.Vector3;
)) ))
public class StructureLocateCommand implements CommandTemplate { public class StructureLocateCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@ArgumentTarget("structure") @ArgumentTarget("structure")
private ConfiguredStructure structure; private ConfiguredStructure structure;
@@ -58,7 +58,7 @@ public class StructureLocateCommand implements CommandTemplate {
Player player = (Player) sender; Player player = (Player) sender;
new Thread(new AsyncStructureFinder(player.world().getBiomeProvider(), structure, new Thread(new AsyncStructureFinder(player.world().getBiomeProvider(), structure,
player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.position().clone().multiply((1D / platform.getTerraConfig().getBiomeSearchResolution())),
player.world(), 0, radius, location -> { player.world(), 0, radius, location -> {
if(location != null) { if(location != null) {
sender.sendMessage( sender.sendMessage(
@@ -66,10 +66,10 @@ public class StructureLocateCommand implements CommandTemplate {
location.getBlockX(), location.getBlockZ(), location.getBlockX(), location.getBlockZ(),
location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position()))); location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) { if(teleport) {
main.runPossiblyUnsafeTask( platform.runPossiblyUnsafeTask(
() -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ()))); () -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ())));
} }
} //else LangUtil.send("command.biome.unable-to-locate", sender); } //else LangUtil.send("command.biome.unable-to-locate", sender);
}, main), "Biome Location Thread").start(); }, platform), "Biome Location Thread").start();
} }
} }
@@ -10,7 +10,7 @@ import com.dfsek.terra.api.structure.Structure;
public class ScriptArgumentParser implements ArgumentParser<Structure> { public class ScriptArgumentParser implements ArgumentParser<Structure> {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public Structure parse(CommandSender sender, String arg) { public Structure parse(CommandSender sender, String arg) {
@@ -10,7 +10,7 @@ import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
public class StructureArgumentParser implements ArgumentParser<ConfiguredStructure> { public class StructureArgumentParser implements ArgumentParser<ConfiguredStructure> {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public ConfiguredStructure parse(CommandSender sender, String arg) { public ConfiguredStructure parse(CommandSender sender, String arg) {
@@ -13,7 +13,7 @@ import com.dfsek.terra.api.structure.Structure;
public class ScriptCompleter implements TabCompleter { public class ScriptCompleter implements TabCompleter {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public List<String> complete(CommandSender sender) { public List<String> complete(CommandSender sender) {
@@ -13,7 +13,7 @@ import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
public class StructureCompleter implements TabCompleter { public class StructureCompleter implements TabCompleter {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public List<String> complete(CommandSender sender) { public List<String> complete(CommandSender sender) {
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.structure.structures.loot; package com.dfsek.terra.addons.structure.structures.loot;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@@ -12,7 +14,6 @@ import com.dfsek.terra.addons.structure.structures.loot.functions.AmountFunction
import com.dfsek.terra.addons.structure.structures.loot.functions.DamageFunction; import com.dfsek.terra.addons.structure.structures.loot.functions.DamageFunction;
import com.dfsek.terra.addons.structure.structures.loot.functions.EnchantFunction; import com.dfsek.terra.addons.structure.structures.loot.functions.EnchantFunction;
import com.dfsek.terra.addons.structure.structures.loot.functions.LootFunction; import com.dfsek.terra.addons.structure.structures.loot.functions.LootFunction;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.inventory.Item; import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.ItemStack; import com.dfsek.terra.api.inventory.ItemStack;
@@ -30,9 +31,9 @@ public class Entry {
* *
* @param entry The JSON Object to instantiate from. * @param entry The JSON Object to instantiate from.
*/ */
public Entry(JSONObject entry, Platform main) { public Entry(JSONObject entry, Platform platform) {
String id = entry.get("name").toString(); String id = entry.get("name").toString();
this.item = main.getItemHandle().createItem(id); this.item = platform.getItemHandle().createItem(id);
long weight1; long weight1;
try { try {
@@ -69,7 +70,7 @@ public class Entry {
if(((JSONObject) function).containsKey("disabled_enchants")) if(((JSONObject) function).containsKey("disabled_enchants"))
disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants"); disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants");
functions.add( functions.add(
new EnchantFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled, main)); new EnchantFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled, platform));
} }
} }
} }
@@ -27,12 +27,12 @@ public class LootTableImpl implements com.dfsek.terra.api.structure.LootTable {
* *
* @throws ParseException if malformed JSON is passed. * @throws ParseException if malformed JSON is passed.
*/ */
public LootTableImpl(String json, Platform main) throws ParseException { public LootTableImpl(String json, Platform platform) throws ParseException {
JSONParser jsonParser = new JSONParser(); JSONParser jsonParser = new JSONParser();
Object tableJSON = jsonParser.parse(json); Object tableJSON = jsonParser.parse(json);
JSONArray poolArray = (JSONArray) ((JSONObject) tableJSON).get("pools"); JSONArray poolArray = (JSONArray) ((JSONObject) tableJSON).get("pools");
for(Object pool : poolArray) { for(Object pool : poolArray) {
pools.add(new Pool((JSONObject) pool, main)); pools.add(new Pool((JSONObject) pool, platform));
} }
} }
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.structure.structures.loot; package com.dfsek.terra.addons.structure.structures.loot;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@@ -8,7 +10,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.inventory.ItemStack; import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.util.collection.ProbabilityCollection; import com.dfsek.terra.api.util.collection.ProbabilityCollection;
@@ -26,7 +27,7 @@ public class Pool {
* *
* @param pool The JSON Object to instantiate from. * @param pool The JSON Object to instantiate from.
*/ */
public Pool(JSONObject pool, Platform main) { public Pool(JSONObject pool, Platform platform) {
entries = new ProbabilityCollection<>(); entries = new ProbabilityCollection<>();
Object amount = pool.get("rolls"); Object amount = pool.get("rolls");
if(amount instanceof Long) { if(amount instanceof Long) {
@@ -38,7 +39,7 @@ public class Pool {
} }
for(Object entryJSON : (JSONArray) pool.get("entries")) { for(Object entryJSON : (JSONArray) pool.get("entries")) {
Entry entry = new Entry((JSONObject) entryJSON, main); Entry entry = new Entry((JSONObject) entryJSON, platform);
entries.add(entry, FastMath.toIntExact(entry.getWeight())); entries.add(entry, FastMath.toIntExact(entry.getWeight()));
} }
} }
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.structure.structures.loot.functions; package com.dfsek.terra.addons.structure.structures.loot.functions;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
@@ -8,7 +10,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.inventory.ItemStack; import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment; import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta; import com.dfsek.terra.api.inventory.item.ItemMeta;
@@ -18,14 +19,14 @@ public class EnchantFunction implements LootFunction {
private final int min; private final int min;
private final int max; private final int max;
private final JSONArray disabled; private final JSONArray disabled;
private final Platform main; private final Platform platform;
public EnchantFunction(int min, int max, JSONArray disabled, Platform main) { public EnchantFunction(int min, int max, JSONArray disabled, Platform platform) {
this.max = max; this.max = max;
this.min = min; this.min = min;
this.disabled = disabled; this.disabled = disabled;
this.main = main; this.platform = platform;
} }
/** /**
@@ -42,7 +43,7 @@ public class EnchantFunction implements LootFunction {
double enchant = (r.nextDouble() * (max - min)) + min; double enchant = (r.nextDouble() * (max - min)) + min;
List<Enchantment> possible = new ArrayList<>(); List<Enchantment> possible = new ArrayList<>();
for(Enchantment ench : main.getItemHandle().getEnchantments()) { for(Enchantment ench : platform.getItemHandle().getEnchantments()) {
if(ench.canEnchantItem(original) && (disabled == null || !this.disabled.contains(ench.getID()))) { if(ench.canEnchantItem(original) && (disabled == null || !this.disabled.contains(ench.getID()))) {
possible.add(ench); possible.add(ench);
} }
@@ -60,7 +61,7 @@ public class EnchantFunction implements LootFunction {
try { try {
meta.addEnchantment(chosen, FastMath.max(lvl, 1)); meta.addEnchantment(chosen, FastMath.max(lvl, 1));
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
main.logger().warning( platform.logger().warning(
"Attempted to enchant " + original.getType() + " with " + chosen + " at level " + FastMath.max(lvl, 1) + "Attempted to enchant " + original.getType() + " with " + chosen + " at level " + FastMath.max(lvl, 1) +
", but an unexpected exception occurred! Usually this is caused by a misbehaving enchantment plugin."); ", but an unexpected exception occurred! Usually this is caused by a misbehaving enchantment plugin.");
} }
@@ -19,19 +19,19 @@ import com.dfsek.terra.api.world.generator.GenerationStageProvider;
@Author("Terra") @Author("Terra")
public class FeatureGenerationAddon extends TerraAddon { public class FeatureGenerationAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack() .then(event -> event.getPack()
.getOrCreateRegistry(GenerationStageProvider.class) .getOrCreateRegistry(GenerationStageProvider.class)
.register("FEATURE", pack -> new FeatureGenerationStage(main))) .register("FEATURE", pack -> new FeatureGenerationStage(platform)))
.failThrough(); .failThrough();
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationLoadEvent.class) .register(this, ConfigurationLoadEvent.class)
.then(event -> { .then(event -> {
@@ -12,16 +12,16 @@ import com.dfsek.terra.api.world.generator.GenerationStage;
public class FeatureGenerationStage implements GenerationStage { public class FeatureGenerationStage implements GenerationStage {
private final Platform main; private final Platform platform;
public FeatureGenerationStage(Platform main) { public FeatureGenerationStage(Platform platform) {
this.main = main; this.platform = platform;
} }
@Override @Override
@SuppressWarnings("try") @SuppressWarnings("try")
public void populate(World world, Chunk chunk) { public void populate(World world, Chunk chunk) {
try(ProfileFrame ignore = main.getProfiler().profile("feature")) { try(ProfileFrame ignore = platform.getProfiler().profile("feature")) {
int cx = chunk.getX() << 4; int cx = chunk.getX() << 4;
int cz = chunk.getZ() << 4; int cz = chunk.getZ() << 4;
long seed = world.getSeed(); long seed = world.getSeed();
@@ -17,15 +17,15 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@Author("Terra") @Author("Terra")
public class YamlAddon extends TerraAddon { public class YamlAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigurationDiscoveryEvent.class) .register(this, ConfigurationDiscoveryEvent.class)
.then(event -> event.getLoader().open("", ".yml").thenEntries(entries -> entries.forEach(entry -> { .then(event -> event.getLoader().open("", ".yml").thenEntries(entries -> entries.forEach(entry -> {
main.getDebugLogger().info("Discovered config " + entry.getKey()); platform.getDebugLogger().info("Discovered config " + entry.getKey());
event.register(entry.getKey(), new YamlConfiguration(entry.getValue(), entry.getKey())); event.register(entry.getKey(), new YamlConfiguration(entry.getValue(), entry.getKey()));
}))) })))
.failThrough(); .failThrough();
@@ -25,11 +25,11 @@ import com.dfsek.terra.api.structure.Structure;
@Version("1.0.0") @Version("1.0.0")
public class TerraScriptAddon extends TerraAddon { public class TerraScriptAddon extends TerraAddon {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void initialize() { public void initialize() {
main.getEventManager() platform.getEventManager()
.getHandler(FunctionalEventHandler.class) .getHandler(FunctionalEventHandler.class)
.register(this, ConfigPackPreLoadEvent.class) .register(this, ConfigPackPreLoadEvent.class)
.then(event -> { .then(event -> {
@@ -38,7 +38,7 @@ public class TerraScriptAddon extends TerraAddon {
event.getPack().getLoader().open("", ".tesf").thenEntries(entries -> { event.getPack().getLoader().open("", ".tesf").thenEntries(entries -> {
for(Map.Entry<String, InputStream> entry : entries) { for(Map.Entry<String, InputStream> entry : entries) {
try { try {
StructureScript structureScript = new StructureScript(entry.getValue(), main, structureRegistry, lootRegistry, StructureScript structureScript = new StructureScript(entry.getValue(), platform, structureRegistry, lootRegistry,
event.getPack().getRegistryFactory().create()); event.getPack().getRegistryFactory().create());
structureRegistry.register(structureScript.getID(), structureScript); structureRegistry.register(structureScript.getID(), structureScript);
} catch(ParseException e) { } catch(ParseException e) {
@@ -11,13 +11,13 @@ import com.dfsek.terra.api.world.World;
public class BufferedBlock implements BufferedItem { public class BufferedBlock implements BufferedItem {
private final BlockState data; private final BlockState data;
private final boolean overwrite; private final boolean overwrite;
private final Platform main; private final Platform platform;
private final boolean waterlog; private final boolean waterlog;
public BufferedBlock(BlockState data, boolean overwrite, Platform main, boolean waterlog) { public BufferedBlock(BlockState data, boolean overwrite, Platform platform, boolean waterlog) {
this.data = data; this.data = data;
this.overwrite = overwrite; this.overwrite = overwrite;
this.main = main; this.platform = platform;
this.waterlog = waterlog; this.waterlog = waterlog;
} }
@@ -32,8 +32,8 @@ public class BufferedBlock implements BufferedItem {
world.setBlockData(origin, data); world.setBlockData(origin, data);
} }
} catch(RuntimeException e) { } catch(RuntimeException e) {
main.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage()); platform.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage());
main.getDebugLogger().stack(e); platform.getDebugLogger().stack(e);
} }
} }
} }
@@ -12,16 +12,16 @@ import com.dfsek.terra.api.world.World;
public class BufferedEntity implements BufferedItem { public class BufferedEntity implements BufferedItem {
private final EntityType type; private final EntityType type;
private final Platform main; private final Platform platform;
public BufferedEntity(EntityType type, Platform main) { public BufferedEntity(EntityType type, Platform platform) {
this.type = type; this.type = type;
this.main = main; this.platform = platform;
} }
@Override @Override
public void paste(Vector3 origin, World world) { public void paste(Vector3 origin, World world) {
Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5), type); Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5), type);
main.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getConfig().getPack(), entity)); platform.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getConfig().getPack(), entity));
} }
} }
@@ -15,12 +15,12 @@ import com.dfsek.terra.api.world.World;
public class BufferedLootApplication implements BufferedItem { public class BufferedLootApplication implements BufferedItem {
private final LootTable table; private final LootTable table;
private final Platform main; private final Platform platform;
private final StructureScript structure; private final StructureScript structure;
public BufferedLootApplication(LootTable table, Platform main, StructureScript structure) { public BufferedLootApplication(LootTable table, Platform platform, StructureScript structure) {
this.table = table; this.table = table;
this.main = main; this.platform = platform;
this.structure = structure; this.structure = structure;
} }
@@ -29,19 +29,19 @@ public class BufferedLootApplication implements BufferedItem {
try { try {
BlockEntity data = world.getBlockState(origin); BlockEntity data = world.getBlockState(origin);
if(!(data instanceof Container)) { if(!(data instanceof Container)) {
main.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container."); platform.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container.");
return; return;
} }
Container container = (Container) data; Container container = (Container) data;
LootPopulateEvent event = new LootPopulateEvent(container, table, world.getConfig().getPack(), structure); LootPopulateEvent event = new LootPopulateEvent(container, table, world.getConfig().getPack(), structure);
main.getEventManager().callEvent(event); platform.getEventManager().callEvent(event);
if(event.isCancelled()) return; if(event.isCancelled()) return;
event.getTable().fillInventory(container.getInventory(), new Random(origin.hashCode())); event.getTable().fillInventory(container.getInventory(), new Random(origin.hashCode()));
data.update(false); data.update(false);
} catch(Exception e) { } catch(Exception e) {
main.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage()); platform.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -8,11 +8,11 @@ import com.dfsek.terra.api.world.World;
public class BufferedStateManipulator implements BufferedItem { public class BufferedStateManipulator implements BufferedItem {
private final Platform main; private final Platform platform;
private final String data; private final String data;
public BufferedStateManipulator(Platform main, String state) { public BufferedStateManipulator(Platform platform, String state) {
this.main = main; this.platform = platform;
this.data = state; this.data = state;
} }
@@ -23,7 +23,7 @@ public class BufferedStateManipulator implements BufferedItem {
state.applyState(data); state.applyState(data);
state.update(false); state.update(false);
} catch(Exception e) { } catch(Exception e) {
main.logger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage()); platform.logger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -52,10 +52,10 @@ public class StructureScript implements Structure {
private final Block block; private final Block block;
private final String id; private final String id;
private final Cache<Vector3, StructureBuffer> cache; private final Cache<Vector3, StructureBuffer> cache;
private final Platform main; private final Platform platform;
private String tempID; private String tempID;
public StructureScript(InputStream inputStream, Platform main, Registry<Structure> registry, Registry<LootTable> lootRegistry, public StructureScript(InputStream inputStream, Platform platform, Registry<Structure> registry, Registry<LootTable> lootRegistry,
Registry<FunctionBuilder<?>> functionRegistry) throws ParseException { Registry<FunctionBuilder<?>> functionRegistry) throws ParseException {
Parser parser; Parser parser;
try { try {
@@ -67,20 +67,20 @@ public class StructureScript implements Structure {
functionRegistry.forEach(parser::registerFunction); // Register registry functions. functionRegistry.forEach(parser::registerFunction); // Register registry functions.
parser parser
.registerFunction("block", new BlockFunctionBuilder(main)) .registerFunction("block", new BlockFunctionBuilder(platform))
.registerFunction("debugBlock", new BlockFunctionBuilder(main)) .registerFunction("debugBlock", new BlockFunctionBuilder(platform))
.registerFunction("check", new CheckFunctionBuilder(main)) .registerFunction("check", new CheckFunctionBuilder(platform))
.registerFunction("structure", new StructureFunctionBuilder(registry, main)) .registerFunction("structure", new StructureFunctionBuilder(registry, platform))
.registerFunction("randomInt", new RandomFunctionBuilder()) .registerFunction("randomInt", new RandomFunctionBuilder())
.registerFunction("recursions", new RecursionsFunctionBuilder()) .registerFunction("recursions", new RecursionsFunctionBuilder())
.registerFunction("setMark", new SetMarkFunctionBuilder()) .registerFunction("setMark", new SetMarkFunctionBuilder())
.registerFunction("getMark", new GetMarkFunctionBuilder()) .registerFunction("getMark", new GetMarkFunctionBuilder())
.registerFunction("pull", new PullFunctionBuilder(main)) .registerFunction("pull", new PullFunctionBuilder(platform))
.registerFunction("loot", new LootFunctionBuilder(main, lootRegistry, this)) .registerFunction("loot", new LootFunctionBuilder(platform, lootRegistry, this))
.registerFunction("entity", new EntityFunctionBuilder(main)) .registerFunction("entity", new EntityFunctionBuilder(platform))
.registerFunction("getBiome", new BiomeFunctionBuilder(main)) .registerFunction("getBiome", new BiomeFunctionBuilder(platform))
.registerFunction("getBlock", new CheckBlockFunctionBuilder()) .registerFunction("getBlock", new CheckBlockFunctionBuilder())
.registerFunction("state", new StateFunctionBuilder(main)) .registerFunction("state", new StateFunctionBuilder(platform))
.registerFunction("setWaterlog", new UnaryBooleanFunctionBuilder((waterlog, args) -> args.setWaterlog(waterlog))) .registerFunction("setWaterlog", new UnaryBooleanFunctionBuilder((waterlog, args) -> args.setWaterlog(waterlog)))
.registerFunction("originX", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getBuffer().getOrigin().getX(), .registerFunction("originX", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getBuffer().getOrigin().getX(),
Returnable.ReturnType.NUMBER)) Returnable.ReturnType.NUMBER))
@@ -93,7 +93,7 @@ public class StructureScript implements Structure {
.registerFunction("rotationDegrees", new ZeroArgFunctionBuilder<>(arguments -> arguments.getRotation().getDegrees(), .registerFunction("rotationDegrees", new ZeroArgFunctionBuilder<>(arguments -> arguments.getRotation().getDegrees(),
Returnable.ReturnType.NUMBER)) Returnable.ReturnType.NUMBER))
.registerFunction("print", .registerFunction("print",
new UnaryStringFunctionBuilder(string -> main.getDebugLogger().info("[" + tempID + "] " + string))) new UnaryStringFunctionBuilder(string -> platform.getDebugLogger().info("[" + tempID + "] " + string)))
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue()))) .registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
.registerFunction("pow", new BinaryNumberFunctionBuilder( .registerFunction("pow", new BinaryNumberFunctionBuilder(
(number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue()))) (number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue())))
@@ -113,21 +113,21 @@ public class StructureScript implements Structure {
.registerFunction("min", new BinaryNumberFunctionBuilder( .registerFunction("min", new BinaryNumberFunctionBuilder(
(number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue()))); (number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue())));
if(!main.getTerraConfig().isDebugScript()) { if(!platform.getTerraConfig().isDebugScript()) {
parser.ignoreFunction("debugBlock"); parser.ignoreFunction("debugBlock");
} }
block = parser.parse(); block = parser.parse();
this.id = parser.getID(); this.id = parser.getID();
tempID = id; tempID = id;
this.main = main; this.platform = platform;
this.cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getStructureCache()).build(); this.cache = CacheBuilder.newBuilder().maximumSize(platform.getTerraConfig().getStructureCache()).build();
} }
@Override @Override
@SuppressWarnings("try") @SuppressWarnings("try")
public boolean generate(Vector3 location, World world, Chunk chunk, Random random, Rotation rotation) { public boolean generate(Vector3 location, World world, Chunk chunk, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_chunk:" + id)) { try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_chunk:" + id)) {
StructureBuffer buffer = computeBuffer(location, world, random, rotation); StructureBuffer buffer = computeBuffer(location, world, random, rotation);
buffer.paste(location, chunk); buffer.paste(location, chunk);
return buffer.succeeded(); return buffer.succeeded();
@@ -137,7 +137,7 @@ public class StructureScript implements Structure {
@Override @Override
@SuppressWarnings("try") @SuppressWarnings("try")
public boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions) { public boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_recursive:" + id)) { try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_recursive:" + id)) {
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, recursions)); return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, recursions));
} }
} }
@@ -145,7 +145,7 @@ public class StructureScript implements Structure {
@Override @Override
@SuppressWarnings("try") @SuppressWarnings("try")
public boolean generate(Vector3 location, World world, Random random, Rotation rotation) { public boolean generate(Vector3 location, World world, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_direct:" + id)) { try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_direct:" + id)) {
DirectBuffer buffer = new DirectBuffer(location, world); DirectBuffer buffer = new DirectBuffer(location, world);
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, 0)); return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, 0));
} }
@@ -153,7 +153,7 @@ public class StructureScript implements Structure {
@SuppressWarnings("try") @SuppressWarnings("try")
public boolean test(Vector3 location, World world, Random random, Rotation rotation) { public boolean test(Vector3 location, World world, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_test:" + id)) { try(ProfileFrame ignore = platform.getProfiler().profile("terrascript_test:" + id)) {
StructureBuffer buffer = computeBuffer(location, world, random, rotation); StructureBuffer buffer = computeBuffer(location, world, random, rotation);
return buffer.succeeded(); return buffer.succeeded();
} }
@@ -175,8 +175,8 @@ public class StructureScript implements Structure {
try { try {
return block.apply(arguments).getLevel() != Block.ReturnLevel.FAIL; return block.apply(arguments).getLevel() != Block.ReturnLevel.FAIL;
} catch(RuntimeException e) { } catch(RuntimeException e) {
main.logger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage()); platform.logger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage());
main.getDebugLogger().stack(e); platform.getDebugLogger().stack(e);
return false; return false;
} }
} }
@@ -10,16 +10,16 @@ import com.dfsek.terra.api.Platform;
public class BiomeFunctionBuilder implements FunctionBuilder<BiomeFunction> { public class BiomeFunctionBuilder implements FunctionBuilder<BiomeFunction> {
private final Platform main; private final Platform platform;
public BiomeFunctionBuilder(Platform main) { public BiomeFunctionBuilder(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public BiomeFunction build(List<Returnable<?>> argumentList, Position position) { public BiomeFunction build(List<Returnable<?>> argumentList, Position position) {
return new BiomeFunction(main, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new BiomeFunction(platform, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), position); (Returnable<Number>) argumentList.get(2), position);
} }
@@ -13,10 +13,10 @@ import com.dfsek.terra.api.Platform;
public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> { public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
private final Platform main; private final Platform platform;
public BlockFunctionBuilder(Platform main) { public BlockFunctionBuilder(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -28,11 +28,11 @@ public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
if(argumentList.get(3) instanceof StringConstant) { if(argumentList.get(3) instanceof StringConstant) {
return new BlockFunction.Constant((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new BlockFunction.Constant((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (StringConstant) argumentList.get(3), (Returnable<Number>) argumentList.get(2), (StringConstant) argumentList.get(3),
booleanReturnable, main, position); booleanReturnable, platform, position);
} }
return new BlockFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new BlockFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), booleanReturnable, (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), booleanReturnable,
main, position); platform, position);
} }
@Override @Override
@@ -11,16 +11,16 @@ import com.dfsek.terra.api.Platform;
public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> { public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> {
private final Platform main; private final Platform platform;
public CheckFunctionBuilder(Platform main) { public CheckFunctionBuilder(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public CheckFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public CheckFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
return new CheckFunction(main, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new CheckFunction(platform, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), position); (Returnable<Number>) argumentList.get(2), position);
} }
@@ -11,17 +11,17 @@ import com.dfsek.terra.api.Platform;
public class EntityFunctionBuilder implements FunctionBuilder<EntityFunction> { public class EntityFunctionBuilder implements FunctionBuilder<EntityFunction> {
private final Platform main; private final Platform platform;
public EntityFunctionBuilder(Platform main) { public EntityFunctionBuilder(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public EntityFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public EntityFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
return new EntityFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new EntityFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), main, position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position);
} }
@Override @Override
@@ -13,12 +13,12 @@ import com.dfsek.terra.api.structure.LootTable;
public class LootFunctionBuilder implements FunctionBuilder<LootFunction> { public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
private final Platform main; private final Platform platform;
private final Registry<LootTable> registry; private final Registry<LootTable> registry;
private final StructureScript script; private final StructureScript script;
public LootFunctionBuilder(Platform main, Registry<LootTable> registry, StructureScript script) { public LootFunctionBuilder(Platform platform, Registry<LootTable> registry, StructureScript script) {
this.main = main; this.platform = platform;
this.registry = registry; this.registry = registry;
this.script = script; this.script = script;
} }
@@ -27,7 +27,7 @@ public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
@Override @Override
public LootFunction build(List<Returnable<?>> argumentList, Position position) { public LootFunction build(List<Returnable<?>> argumentList, Position position) {
return new LootFunction(registry, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new LootFunction(registry, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), main, position, script); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position, script);
} }
@Override @Override
@@ -11,17 +11,17 @@ import com.dfsek.terra.api.Platform;
public class PullFunctionBuilder implements FunctionBuilder<PullFunction> { public class PullFunctionBuilder implements FunctionBuilder<PullFunction> {
private final Platform main; private final Platform platform;
public PullFunctionBuilder(Platform main) { public PullFunctionBuilder(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public PullFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public PullFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
return new PullFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new PullFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), main, position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position);
} }
@Override @Override
@@ -11,10 +11,10 @@ import com.dfsek.terra.api.Platform;
public class StateFunctionBuilder implements FunctionBuilder<StateFunction> { public class StateFunctionBuilder implements FunctionBuilder<StateFunction> {
private final Platform main; private final Platform platform;
public StateFunctionBuilder(Platform main) { public StateFunctionBuilder(Platform platform) {
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -22,7 +22,7 @@ public class StateFunctionBuilder implements FunctionBuilder<StateFunction> {
public StateFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public StateFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException {
if(argumentList.size() < 4) throw new ParseException("Expected data", position); if(argumentList.size() < 4) throw new ParseException("Expected data", position);
return new StateFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new StateFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), main, position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position);
} }
@Override @Override
@@ -15,11 +15,11 @@ import com.dfsek.terra.api.structure.Structure;
public class StructureFunctionBuilder implements FunctionBuilder<StructureFunction> { public class StructureFunctionBuilder implements FunctionBuilder<StructureFunction> {
private final Registry<Structure> registry; private final Registry<Structure> registry;
private final Platform main; private final Platform platform;
public StructureFunctionBuilder(Registry<Structure> registry, Platform main) { public StructureFunctionBuilder(Registry<Structure> registry, Platform platform) {
this.registry = registry; this.registry = registry;
this.main = main; this.platform = platform;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -30,7 +30,7 @@ public class StructureFunctionBuilder implements FunctionBuilder<StructureFuncti
return new StructureFunction((Returnable<Number>) argumentList.remove(0), (Returnable<Number>) argumentList.remove(0), return new StructureFunction((Returnable<Number>) argumentList.remove(0), (Returnable<Number>) argumentList.remove(0),
(Returnable<Number>) argumentList.remove(0), (Returnable<String>) argumentList.remove(0), (Returnable<Number>) argumentList.remove(0), (Returnable<String>) argumentList.remove(0),
argumentList.stream().map(item -> ((Returnable<String>) item)).collect(Collectors.toList()), registry, argumentList.stream().map(item -> ((Returnable<String>) item)).collect(Collectors.toList()), registry,
position, main); position, platform);
} }
@Override @Override
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.terrascript.script.functions; package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.Map; import java.util.Map;
@@ -10,7 +12,6 @@ import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable; import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments; import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.util.RotationUtil; import com.dfsek.terra.api.util.RotationUtil;
import com.dfsek.terra.api.util.vector.Vector2; import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.util.vector.Vector3;
@@ -18,13 +19,13 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
public class BiomeFunction implements Function<String> { public class BiomeFunction implements Function<String> {
private final Platform main; private final Platform platform;
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
public BiomeFunction(Platform main, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) { public BiomeFunction(Platform platform, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) {
this.main = main; this.platform = platform;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.terrascript.script.functions; package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.HashMap; import java.util.HashMap;
@@ -13,7 +15,6 @@ import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable; import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments; import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.util.RotationUtil; import com.dfsek.terra.api.util.RotationUtil;
import com.dfsek.terra.api.util.vector.Vector2; import com.dfsek.terra.api.util.vector.Vector2;
@@ -23,19 +24,19 @@ import com.dfsek.terra.api.util.vector.Vector3;
public class BlockFunction implements Function<Void> { public class BlockFunction implements Function<Void> {
protected final Returnable<Number> x, y, z; protected final Returnable<Number> x, y, z;
protected final Returnable<String> blockData; protected final Returnable<String> blockData;
protected final Platform main; protected final Platform platform;
private final Map<String, BlockState> data = new HashMap<>(); private final Map<String, BlockState> data = new HashMap<>();
private final Returnable<Boolean> overwrite; private final Returnable<Boolean> overwrite;
private final Position position; private final Position position;
public BlockFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> blockData, public BlockFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> blockData,
Returnable<Boolean> overwrite, Platform main, Position position) { Returnable<Boolean> overwrite, Platform platform, Position position) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.blockData = blockData; this.blockData = blockData;
this.overwrite = overwrite; this.overwrite = overwrite;
this.main = main; this.platform = platform;
this.position = position; this.position = position;
} }
@@ -66,13 +67,13 @@ public class BlockFunction implements Function<Void> {
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse()); RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
arguments.getBuffer().addItem( arguments.getBuffer().addItem(
new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap), main, arguments.isWaterlog()), new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap), platform, arguments.isWaterlog()),
new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(),
FastMath.roundToInt(xz.getZ()))); FastMath.roundToInt(xz.getZ())));
} }
protected BlockState getBlockState(ImplementationArguments arguments, Map<String, Variable<?>> variableMap) { protected BlockState getBlockState(ImplementationArguments arguments, Map<String, Variable<?>> variableMap) {
return data.computeIfAbsent(blockData.apply(arguments, variableMap), main.getWorldHandle()::createBlockData); return data.computeIfAbsent(blockData.apply(arguments, variableMap), platform.getWorldHandle()::createBlockData);
} }
@@ -80,9 +81,9 @@ public class BlockFunction implements Function<Void> {
private final BlockState state; private final BlockState state;
public Constant(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, StringConstant blockData, public Constant(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, StringConstant blockData,
Returnable<Boolean> overwrite, Platform main, Position position) { Returnable<Boolean> overwrite, Platform platform, Position position) {
super(x, y, z, blockData, overwrite, main, position); super(x, y, z, blockData, overwrite, platform, position);
this.state = main.getWorldHandle().createBlockData(blockData.getConstant()); this.state = platform.getWorldHandle().createBlockData(blockData.getConstant());
} }
@Override @Override
@@ -19,12 +19,12 @@ import com.dfsek.terra.api.world.generator.SamplerCache;
public class CheckFunction implements Function<String> { public class CheckFunction implements Function<String> {
private final Platform main; private final Platform platform;
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
public CheckFunction(Platform main, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) { public CheckFunction(Platform platform, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) {
this.main = main; this.platform = platform;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@@ -22,15 +22,15 @@ public class EntityFunction implements Function<Void> {
private final EntityType data; private final EntityType data;
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
private final Platform main; private final Platform platform;
public EntityFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform main, public EntityFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform,
Position position) throws ParseException { Position position) throws ParseException {
this.position = position; this.position = position;
this.main = main; this.platform = platform;
if(!(data instanceof ConstantExpression)) throw new ParseException("Entity data must be constant", data.getPosition()); if(!(data instanceof ConstantExpression)) throw new ParseException("Entity data must be constant", data.getPosition());
this.data = main.getWorldHandle().getEntity(((ConstantExpression<String>) data).getConstant()); this.data = platform.getWorldHandle().getEntity(((ConstantExpression<String>) data).getConstant());
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@@ -44,7 +44,7 @@ public class EntityFunction implements Function<Void> {
RotationUtil.rotateVector(xz, arguments.getRotation()); RotationUtil.rotateVector(xz, arguments.getRotation());
arguments.getBuffer().addItem(new BufferedEntity(data, main), arguments.getBuffer().addItem(new BufferedEntity(data, platform),
new Vector3(xz.getX(), y.apply(implementationArguments, variableMap).doubleValue(), xz.getZ())); new Vector3(xz.getX(), y.apply(implementationArguments, variableMap).doubleValue(), xz.getZ()));
return null; return null;
} }
@@ -25,18 +25,18 @@ public class LootFunction implements Function<Void> {
private final Returnable<String> data; private final Returnable<String> data;
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
private final Platform main; private final Platform platform;
private final StructureScript script; private final StructureScript script;
public LootFunction(Registry<LootTable> registry, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, public LootFunction(Registry<LootTable> registry, Returnable<Number> x, Returnable<Number> y, Returnable<Number> z,
Returnable<String> data, Platform main, Position position, StructureScript script) { Returnable<String> data, Platform platform, Position position, StructureScript script) {
this.registry = registry; this.registry = registry;
this.position = position; this.position = position;
this.data = data; this.data = data;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.main = main; this.platform = platform;
this.script = script; this.script = script;
} }
@@ -52,11 +52,11 @@ public class LootFunction implements Function<Void> {
LootTable table = registry.get(id); LootTable table = registry.get(id);
if(table == null) { if(table == null) {
main.logger().severe("No such loot table " + id); platform.logger().severe("No such loot table " + id);
return null; return null;
} }
arguments.getBuffer().addItem(new BufferedLootApplication(table, main, script), arguments.getBuffer().addItem(new BufferedLootApplication(table, platform, script),
new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ()))); FastMath.roundToInt(xz.getZ())));
return null; return null;
@@ -25,12 +25,12 @@ public class PullFunction implements Function<Void> {
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
public PullFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform main, public PullFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform,
Position position) throws ParseException { Position position) throws ParseException {
this.position = position; this.position = position;
if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition()); if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition());
this.data = main.getWorldHandle().createBlockData(((ConstantExpression<String>) data).getConstant()); this.data = platform.getWorldHandle().createBlockData(((ConstantExpression<String>) data).getConstant());
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
@@ -21,12 +21,12 @@ public class StateFunction implements Function<Void> {
private final Returnable<String> data; private final Returnable<String> data;
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
private final Platform main; private final Platform platform;
public StateFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform main, public StateFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform,
Position position) { Position position) {
this.position = position; this.position = position;
this.main = main; this.platform = platform;
this.data = data; this.data = data;
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -40,7 +40,7 @@ public class StateFunction implements Function<Void> {
z.apply(implementationArguments, variableMap).doubleValue()); z.apply(implementationArguments, variableMap).doubleValue());
RotationUtil.rotateVector(xz, arguments.getRotation()); RotationUtil.rotateVector(xz, arguments.getRotation());
arguments.getBuffer().addItem(new BufferedStateManipulator(main, data.apply(implementationArguments, variableMap)), arguments.getBuffer().addItem(new BufferedStateManipulator(platform, data.apply(implementationArguments, variableMap)),
new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ()))); FastMath.roundToInt(xz.getZ())));
return null; return null;
@@ -26,18 +26,18 @@ public class StructureFunction implements Function<Boolean> {
private final Returnable<String> id; private final Returnable<String> id;
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
private final Platform main; private final Platform platform;
private final List<Returnable<String>> rotations; private final List<Returnable<String>> rotations;
public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id, public StructureFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> id,
List<Returnable<String>> rotations, Registry<Structure> registry, Position position, Platform main) { List<Returnable<String>> rotations, Registry<Structure> registry, Position position, Platform platform) {
this.registry = registry; this.registry = registry;
this.id = id; this.id = id;
this.position = position; this.position = position;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.main = main; this.platform = platform;
this.rotations = rotations; this.rotations = rotations;
} }
@@ -50,7 +50,7 @@ public class StructureFunction implements Function<Boolean> {
public Boolean apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) { public Boolean apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments; TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
if(arguments.getRecursions() > main.getTerraConfig().getMaxRecursion()) if(arguments.getRecursions() > platform.getTerraConfig().getMaxRecursion())
throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions()); throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions());
Vector2 xz = new Vector2(x.apply(implementationArguments, variableMap).doubleValue(), Vector2 xz = new Vector2(x.apply(implementationArguments, variableMap).doubleValue(),
@@ -61,7 +61,7 @@ public class StructureFunction implements Function<Boolean> {
String app = id.apply(implementationArguments, variableMap); String app = id.apply(implementationArguments, variableMap);
Structure script = registry.get(app); Structure script = registry.get(app);
if(script == null) { if(script == null) {
main.logger().severe("No such structure " + app); platform.logger().severe("No such structure " + app);
return null; return null;
} }
@@ -70,7 +70,7 @@ public class StructureFunction implements Function<Boolean> {
try { try {
rotation1 = Rotation.valueOf(rotString); rotation1 = Rotation.valueOf(rotString);
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
main.logger().severe("Invalid rotation " + rotString); platform.logger().severe("Invalid rotation " + rotString);
return null; return null;
} }
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
public interface AddonLoader { public interface AddonLoader {
/** /**
* Load all addons. * Load all addons.
* @param main TerraPlugin instance. * @param platform TerraPlugin instance.
*/ */
void load(Platform main, CheckedRegistry<Addon> addons); void load(Platform platform, CheckedRegistry<Addon> addons);
} }
@@ -7,5 +7,5 @@ import com.dfsek.terra.api.Platform;
public interface ConfigFactory<C extends ConfigTemplate, O> { public interface ConfigFactory<C extends ConfigTemplate, O> {
O build(C config, Platform main) throws LoadException; O build(C config, Platform platform) throws LoadException;
} }
@@ -10,7 +10,7 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
public interface ConfigType<T extends AbstractableTemplate, R> { public interface ConfigType<T extends AbstractableTemplate, R> {
Supplier<OpenRegistry<R>> registrySupplier(ConfigPack pack); Supplier<OpenRegistry<R>> registrySupplier(ConfigPack pack);
T getTemplate(ConfigPack pack, Platform main); T getTemplate(ConfigPack pack, Platform platform);
ConfigFactory<T, R> getFactory(); ConfigFactory<T, R> getFactory();
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.Platform;
public interface PluginConfig { public interface PluginConfig {
void load(Platform main); void load(Platform platform);
boolean dumpDefaultConfig(); boolean dumpDefaultConfig();
@@ -24,7 +24,7 @@ public interface ChunkGenerator {
ConfigPack getConfigPack(); ConfigPack getConfigPack();
Platform getMain(); Platform getPlatform();
List<GenerationStage> getGenerationStages(); List<GenerationStage> getGenerationStages();
@@ -1,6 +1,9 @@
package com.dfsek.terra; package com.dfsek.terra;
import com.dfsek.tectonic.loading.TypeRegistry; import com.dfsek.tectonic.loading.TypeRegistry;
import com.dfsek.terra.api.Platform;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@@ -17,7 +20,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import com.dfsek.terra.api.util.Logger; import com.dfsek.terra.api.util.Logger;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.TerraAddon; import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.api.command.exception.MalformedCommandException;
@@ -12,12 +12,12 @@ import com.dfsek.terra.api.inject.annotations.Inject;
) )
public class AddonsCommand implements CommandTemplate { public class AddonsCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
sender.sendMessage("Installed Addons:"); sender.sendMessage("Installed Addons:");
main.getAddons().forEach( platform.getAddons().forEach(
addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor())); addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor()));
} }
} }
@@ -19,7 +19,7 @@ import com.dfsek.terra.api.inject.annotations.Inject;
) )
public class GetBlockCommand implements CommandTemplate { public class GetBlockCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
@@ -15,11 +15,11 @@ import com.dfsek.terra.config.lang.LangUtil;
) )
public class PacksCommand implements CommandTemplate { public class PacksCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
CheckedRegistry<ConfigPack> registry = main.getConfigRegistry(); CheckedRegistry<ConfigPack> registry = platform.getConfigRegistry();
if(registry.entries().size() == 0) { if(registry.entries().size() == 0) {
LangUtil.send("command.packs.none", sender); LangUtil.send("command.packs.none", sender);
@@ -13,11 +13,11 @@ import com.dfsek.terra.config.lang.LangUtil;
) )
public class ReloadCommand implements CommandTemplate { public class ReloadCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
if(!main.reload()) { if(!platform.reload()) {
LangUtil.send("command.reload-error", sender); LangUtil.send("command.reload-error", sender);
} else { } else {
LangUtil.send("command.reload", sender); LangUtil.send("command.reload", sender);
@@ -1,5 +1,7 @@
package com.dfsek.terra.commands; package com.dfsek.terra.commands;
import com.dfsek.terra.api.Platform;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@@ -12,7 +14,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.CommandTemplate;
import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Argument;
@@ -41,11 +42,11 @@ import com.dfsek.terra.inject.InjectorImpl;
public class TerraCommandManager implements CommandManager { public class TerraCommandManager implements CommandManager {
private final Map<String, CommandHolder> commands = new HashMap<>(); private final Map<String, CommandHolder> commands = new HashMap<>();
private final InjectorImpl<Platform> pluginInjector; private final InjectorImpl<Platform> pluginInjector;
private final Platform main; private final Platform platform;
public TerraCommandManager(Platform main) { public TerraCommandManager(Platform platform) {
this.main = main; this.platform = platform;
this.pluginInjector = new InjectorImpl<>(main); this.pluginInjector = new InjectorImpl<>(platform);
pluginInjector.addExplicitTarget(Platform.class); pluginInjector.addExplicitTarget(Platform.class);
} }
@@ -81,7 +82,7 @@ public class TerraCommandManager implements CommandManager {
private void execute(CommandHolder commandHolder, CommandSender sender, List<String> args) throws CommandException { private void execute(CommandHolder commandHolder, CommandSender sender, List<String> args) throws CommandException {
Class<? extends CommandTemplate> commandClass = commandHolder.clazz; Class<? extends CommandTemplate> commandClass = commandHolder.clazz;
if(commandClass.isAnnotationPresent(DebugCommand.class) && !main.getTerraConfig().isDebugCommands()) { if(commandClass.isAnnotationPresent(DebugCommand.class) && !platform.getTerraConfig().isDebugCommands()) {
sender.sendMessage("Command must be executed with debug commands enabled."); sender.sendMessage("Command must be executed with debug commands enabled.");
return; return;
} }
@@ -13,11 +13,11 @@ import com.dfsek.terra.config.lang.LangUtil;
) )
public class VersionCommand implements CommandTemplate { public class VersionCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
String terraVersion = main.getVersion(); String terraVersion = platform.getVersion();
LangUtil.send("command.version", sender, terraVersion, main.platformName()); LangUtil.send("command.version", sender, terraVersion, platform.platformName());
} }
} }
@@ -12,13 +12,13 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand @DebugCommand
public class ProfileQueryCommand implements CommandTemplate { public class ProfileQueryCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
StringBuilder data = new StringBuilder("Terra Profiler data dump: \n"); StringBuilder data = new StringBuilder("Terra Profiler data dump: \n");
main.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n')); platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
main.logger().info(data.toString()); platform.logger().info(data.toString());
sender.sendMessage("Profiler data dumped to console."); sender.sendMessage("Profiler data dumped to console.");
} }
} }
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand @DebugCommand
public class ProfileResetCommand implements CommandTemplate { public class ProfileResetCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
main.getProfiler().reset(); platform.getProfiler().reset();
sender.sendMessage("Profiler reset."); sender.sendMessage("Profiler reset.");
} }
} }
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand @DebugCommand
public class ProfileStartCommand implements CommandTemplate { public class ProfileStartCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
main.getProfiler().start(); platform.getProfiler().start();
sender.sendMessage("Profiling enabled."); sender.sendMessage("Profiling enabled.");
} }
} }
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.inject.annotations.Inject;
@DebugCommand @DebugCommand
public class ProfileStopCommand implements CommandTemplate { public class ProfileStopCommand implements CommandTemplate {
@Inject @Inject
private Platform main; private Platform platform;
@Override @Override
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
main.getProfiler().stop(); platform.getProfiler().stop();
sender.sendMessage("Profiling disabled."); sender.sendMessage("Profiling disabled.");
} }
} }
@@ -19,10 +19,10 @@ import com.dfsek.terra.config.loaders.RangeLoader;
public class GenericLoaders implements LoaderRegistrar { public class GenericLoaders implements LoaderRegistrar {
private final Platform main; private final Platform platform;
public GenericLoaders(Platform main) { public GenericLoaders(Platform platform) {
this.main = main; this.platform = platform;
} }
@Override @Override
@@ -32,11 +32,11 @@ public class GenericLoaders implements LoaderRegistrar {
.registerLoader(MaterialSet.class, new MaterialSetLoader()) .registerLoader(MaterialSet.class, new MaterialSetLoader())
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader()); .registerLoader(LinkedHashMap.class, new LinkedHashMapLoader());
if(main != null) { if(platform != null) {
registry.registerLoader(TerraAddon.class, main.getAddons()) registry.registerLoader(TerraAddon.class, platform.getAddons())
.registerLoader(BlockType.class, .registerLoader(BlockType.class,
(t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType()) (t, object, cf) -> platform.getWorldHandle().createBlockData((String) object).getBlockType())
.registerLoader(BlockState.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object)); .registerLoader(BlockState.class, (t, object, cf) -> platform.getWorldHandle().createBlockData((String) object));
} }
} }
} }
@@ -76,10 +76,10 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
private int maxRecursion = 1000; private int maxRecursion = 1000;
@Override @Override
public void load(Platform main) { public void load(Platform platform) {
Logger logger = main.logger(); Logger logger = platform.logger();
logger.info("Loading config values"); logger.info("Loading config values");
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) { try(FileInputStream file = new FileInputStream(new File(platform.getDataFolder(), "config.yml"))) {
ConfigLoader loader = new ConfigLoader(); ConfigLoader loader = new ConfigLoader();
loader.load(this, new YamlConfiguration(file, "config.yml")); loader.load(this, new YamlConfiguration(file, "config.yml"));
} catch(ConfigException | IOException | UncheckedIOException e) { } catch(ConfigException | IOException | UncheckedIOException e) {
@@ -12,9 +12,9 @@ import com.dfsek.terra.api.lang.Language;
public final class LangUtil { public final class LangUtil {
private static Language language; private static Language language;
public static void load(String langID, Platform main) { public static void load(String langID, Platform platform) {
Logger logger = main.logger(); Logger logger = platform.logger();
File file = new File(main.getDataFolder(), "lang"); File file = new File(platform.getDataFolder(), "lang");
try { try {
File file1 = new File(file, langID + ".yml"); File file1 = new File(file, langID + ".yml");
logger.info(file1.getAbsolutePath()); logger.info(file1.getAbsolutePath());

Some files were not shown because too many files have changed in this diff Show More