reformat all code

This commit is contained in:
dfsek
2022-03-30 14:43:50 -07:00
parent d79c37fc49
commit 4a3c22a8d6
201 changed files with 925 additions and 1040 deletions
@@ -19,7 +19,7 @@ import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
public class ApiAddonLoader implements BootstrapBaseAddon<BaseAddon> {
private static final Version VERSION = Versions.getVersion(1, 0, 0);
@Override
public Iterable<BaseAddon> loadAddons(Path addonsFolder, ClassLoader parent) {
return Collections.emptySet();
@@ -41,7 +41,8 @@ public class ImageBiomeProviderAddon implements AddonInitializer {
.then(event -> {
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(
PROVIDER_REGISTRY_KEY);
providerRegistry.register(addon.key("IMAGE"), () -> new ImageProviderTemplate(event.getPack().getRegistry(Biome.class)));
providerRegistry.register(addon.key("IMAGE"),
() -> new ImageProviderTemplate(event.getPack().getRegistry(Biome.class)));
})
.failThrough();
}
@@ -1,6 +1,5 @@
package com.dfsek.terra.addons.biome.pipeline.api.delegate;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -4,7 +4,6 @@ import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.AnnotatedType;
@@ -22,7 +21,8 @@ public class BiomeDelegateLoader implements TypeLoader<BiomeDelegate> {
}
@Override
public BiomeDelegate load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker) throws LoadException {
public BiomeDelegate load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker)
throws LoadException {
if(c.equals("SELF")) return BiomeDelegate.self();
return biomeRegistry
.getByID((String) c)
@@ -21,10 +21,10 @@ public abstract class BiomeProviderTemplate implements ObjectTemplate<BiomeProvi
@Value("resolution")
@Default
@Description("""
The resolution at which to sample biomes.
Larger values are quadratically faster, but produce lower quality results.
For example, a value of 3 would sample every 3 blocks.""")
The resolution at which to sample biomes.
Larger values are quadratically faster, but produce lower quality results.
For example, a value of 3 would sample every 3 blocks.""")
protected @Meta int resolution = 1;
@Value("blend.sampler")
@Default
@@ -8,8 +8,6 @@
package com.dfsek.terra.addons.chunkgenerator.generation;
import com.dfsek.terra.api.world.info.WorldProperties;
import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull;
@@ -26,6 +24,7 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
import com.dfsek.terra.api.world.info.WorldProperties;
public class NoiseChunkGenerator3D implements ChunkGenerator {
@@ -87,7 +86,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
if(sampler.sample(x, y, z) > 0) {
if(carver.sample(x, y, z) <= 0) {
data = PaletteUtil.getPalette(x, y, z, sampler, paletteInfo, paletteLevel).get(paletteLevel, cx, y, cz,
seed);
seed);
chunk.setBlock(x, y, z, data);
}
@@ -56,8 +56,8 @@ public class ChunkInterpolator {
for(int x = 0; x < 5; x++) {
for(int z = 0; z < 5; z++) {
BiomeNoiseProperties generationSettings = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2), seed)
.getContext()
.get(BiomeNoiseProperties.class);
.getContext()
.get(BiomeNoiseProperties.class);
Map<BiomeNoiseProperties, MutableInteger> genMap = new HashMap<>();
int step = generationSettings.blendStep();
@@ -8,12 +8,8 @@
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import java.util.HashSet;
import java.util.Set;
public class ElevationInterpolator {
private final double[][] values = new double[18][18];
@@ -39,10 +35,11 @@ public class ElevationInterpolator {
BiomeNoiseProperties center = gens[x + 1 + smooth][z + 1 + smooth];
boolean same = true;
for(int xi = -smooth; xi <= smooth; xi++) {
for(int zi = -smooth; zi <= smooth; zi++) {
if(gens[x + 1 + smooth + xi][z + 1 + smooth + zi] != center) { // test referential equality because thats all we need to know
if(gens[x + 1 + smooth + xi][z + 1 + smooth + zi] !=
center) { // test referential equality because thats all we need to know
same = false;
break;
}
@@ -17,23 +17,16 @@
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
import com.dfsek.terra.api.world.info.WorldProperties;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.jafama.FastMath;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import java.util.concurrent.ExecutionException;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.info.WorldProperties;
public class SamplerProvider {
private final Cache<WorldContext, Sampler3D> cache;
@@ -53,8 +46,9 @@ public class SamplerProvider {
public Sampler3D getChunk(int cx, int cz, WorldProperties world, BiomeProvider provider) {
WorldContext context = new WorldContext(cx, cz, world.getSeed(), world.getMinHeight(), world.getMaxHeight());
try {
return cache.get(context, () -> new Sampler3D(context.cx, context.cz, context.seed, context.minHeight, context.maxHeight, provider,
elevationSmooth));
return cache.get(context,
() -> new Sampler3D(context.cx, context.cz, context.seed, context.minHeight, context.maxHeight, provider,
elevationSmooth));
} catch(ExecutionException e) {
throw new RuntimeException(e);
}
@@ -6,16 +6,12 @@ import cloud.commandframework.CommandManager;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.inject.annotations.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AddonsCommandAddon implements AddonInitializer {
@Inject
@@ -32,7 +28,7 @@ public class AddonsCommandAddon implements AddonInitializer {
.register(addon, CommandRegistrationEvent.class)
.then(event -> {
CommandManager<CommandSender> manager = event.getCommandManager();
manager.command(
manager.commandBuilder("addons", ArgumentDescription.of("List installed Terra addons"))
.permission("terra.addons")
@@ -55,9 +51,9 @@ public class AddonsCommandAddon implements AddonInitializer {
.handler(context -> {
BaseAddon addon = context.get("addon");
StringBuilder addonInfo = new StringBuilder("Addon ").append(addon.getID()).append('\n');
addonInfo.append("Version: ").append(addon.getVersion().getFormatted()).append('\n');
addonInfo.append("Dependencies:\n");
addon.getDependencies().forEach((id, versions) -> addonInfo
.append(" - ")
@@ -2,30 +2,18 @@ package com.dfsek.terra.addons.commands.packs;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.EnumArgument;
import cloud.commandframework.arguments.standard.LongArgument;
import cloud.commandframework.context.CommandContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.inject.annotations.Inject;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.reflection.TypeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Random;
public class PacksCommandAddon implements AddonInitializer {
@@ -45,7 +33,7 @@ public class PacksCommandAddon implements AddonInitializer {
.register(addon, CommandRegistrationEvent.class)
.then(event -> {
CommandManager<CommandSender> manager = event.getCommandManager();
manager.command(
manager.commandBuilder("packs", ArgumentDescription.of("List installed config packs"))
.permission("terra.packs")
@@ -66,10 +54,10 @@ public class PacksCommandAddon implements AddonInitializer {
.handler(context -> {
ConfigPack pack = context.get("pack");
StringBuilder packInfo = new StringBuilder("Pack ").append(pack.getID()).append('\n');
packInfo.append("Version: ").append(pack.getVersion().getFormatted()).append('\n');
packInfo.append("Author: ").append(pack.getAuthor()).append('\n');
packInfo.append("Addon Dependencies:\n");
pack.addons().forEach((id, versions) -> packInfo
.append(" - ")
@@ -2,19 +2,17 @@ package com.dfsek.terra.addons.commands.profiler;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
import com.dfsek.terra.api.inject.annotations.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProfilerCommandAddon implements AddonInitializer {
private static final Logger logger = LoggerFactory.getLogger(ProfilerCommandAddon.class);
@@ -2,16 +2,17 @@ package com.dfsek.terra.addons.commands.structure;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.EnumArgument;
import cloud.commandframework.arguments.standard.LongArgument;
import cloud.commandframework.context.CommandContext;
import java.util.Random;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.command.arguments.RegistryArgument;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
@@ -21,8 +22,6 @@ import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.reflection.TypeKey;
import java.util.Random;
public class StructureCommandAddon implements AddonInitializer {
@Inject
@@ -31,6 +30,9 @@ public class StructureCommandAddon implements AddonInitializer {
@Inject
private BaseAddon addon;
private static Registry<Structure> getStructureRegistry(CommandContext<CommandSender> sender) {
return sender.getSender().getEntity().orElseThrow().world().getPack().getRegistry(Structure.class);
}
@Override
public void initialize() {
@@ -39,31 +41,27 @@ public class StructureCommandAddon implements AddonInitializer {
.register(addon, CommandRegistrationEvent.class)
.then(event -> {
CommandManager<CommandSender> manager = event.getCommandManager();
manager.command(
manager.commandBuilder("structures", ArgumentDescription.of("Manage or generate structures"))
.literal("generate")
.argument(RegistryArgument.builder("structure",
StructureCommandAddon::getStructureRegistry,
TypeKey.of(Structure.class)))
.argument(LongArgument.optional("seed", 0))
.argument(EnumArgument.optional(Rotation.class, "rotation", Rotation.NONE))
.handler(context -> {
Structure structure = context.get("structure");
Entity sender = context.getSender().getEntity().orElseThrow();
structure.generate(
sender.position().toInt(),
sender.world(),
((Long) context.get("seed") == 0) ? new Random() : new Random(context.get("seed")),
context.get("rotation")
);
})
.permission("terra.structures.generate")
.literal("generate")
.argument(RegistryArgument.builder("structure",
StructureCommandAddon::getStructureRegistry,
TypeKey.of(Structure.class)))
.argument(LongArgument.optional("seed", 0))
.argument(EnumArgument.optional(Rotation.class, "rotation", Rotation.NONE))
.handler(context -> {
Structure structure = context.get("structure");
Entity sender = context.getSender().getEntity().orElseThrow();
structure.generate(
sender.position().toInt(),
sender.world(),
((Long) context.get("seed") == 0) ? new Random() : new Random(context.get("seed")),
context.get("rotation")
);
})
.permission("terra.structures.generate")
);
});
}
private static Registry<Structure> getStructureRegistry(CommandContext<CommandSender> sender) {
return sender.getSender().getEntity().orElseThrow().world().getPack().getRegistry(Structure.class);
}
}
@@ -13,10 +13,8 @@ import com.dfsek.tectonic.api.config.template.annotations.Final;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.dfsek.terra.api.Platform;
@@ -11,6 +11,7 @@ import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.AnnotatedType;
import java.util.List;
@@ -18,13 +19,12 @@ import java.util.Map;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
import org.jetbrains.annotations.NotNull;
public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
@SuppressWarnings("unchecked")
@Override
public PaletteHolder load(@NotNull AnnotatedType type, @NotNull Object o, @NotNull ConfigLoader configLoader, DepthTracker depthTracker) throws LoadException {
public PaletteHolder load(@NotNull AnnotatedType type, @NotNull Object o, @NotNull ConfigLoader configLoader, DepthTracker depthTracker)
throws LoadException {
List<Map<String, Integer>> palette = (List<Map<String, Integer>>) o;
PaletteHolderBuilder builder = new PaletteHolderBuilder();
for(Map<String, Integer> layer : palette) {
@@ -13,10 +13,10 @@ import java.util.function.Supplier;
import com.dfsek.terra.addons.feature.distributor.config.AndDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.NoDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.PaddedGridDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.SamplerDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.OrDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.PaddedGridDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.PointSetDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.SamplerDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.XorDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.config.YesDistributorTemplate;
import com.dfsek.terra.addons.feature.distributor.util.Point;
@@ -50,7 +50,7 @@ public class DistributorAddon implements AddonInitializer {
CheckedRegistry<Supplier<ObjectTemplate<Distributor>>> distributorRegistry = event
.getPack()
.getOrCreateRegistry(DISTRIBUTOR_TOKEN);
distributorRegistry.register(addon.key("SAMPLER"), SamplerDistributorTemplate::new);
distributorRegistry.register(addon.key("POINTS"), PointSetDistributorTemplate::new);
distributorRegistry.register(addon.key("PADDED_GRID"), PaddedGridDistributorTemplate::new);
@@ -12,11 +12,11 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.tectonic.api.exception.ValidationException;
import java.util.List;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.structure.feature.Distributor;
import java.util.List;
public class XorDistributorTemplate implements ObjectTemplate<Distributor>, ValidatedConfigTemplate {
@Value("distributors")
@@ -1,13 +1,12 @@
package com.dfsek.terra.addons.feature.distributor.distributors;
import com.dfsek.terra.api.structure.feature.Distributor;
import com.dfsek.terra.api.util.MathUtil;
import net.jafama.FastMath;
import java.util.Random;
import com.dfsek.terra.api.structure.feature.Distributor;
import com.dfsek.terra.api.util.MathUtil;
public class PaddedGridDistributor implements Distributor {
private final int width;
@@ -22,19 +21,6 @@ public class PaddedGridDistributor implements Distributor {
this.cellWidth = width + padding;
}
@Override
public boolean matches(int x, int z, long seed) {
int cellX = FastMath.floorDiv(x, cellWidth);
int cellZ = FastMath.floorDiv(z, cellWidth);
Random random = new Random((murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
int pointX = random.nextInt(width) + cellX * cellWidth;
int pointZ = random.nextInt(width) + cellZ * cellWidth;
return x == pointX && z == pointZ;
}
private static long murmur64(long h) {
h ^= h >>> 33;
h *= 0xff51afd7ed558ccdL;
@@ -43,4 +29,17 @@ public class PaddedGridDistributor implements Distributor {
h ^= h >>> 33;
return h;
}
@Override
public boolean matches(int x, int z, long seed) {
int cellX = FastMath.floorDiv(x, cellWidth);
int cellZ = FastMath.floorDiv(z, cellWidth);
Random random = new Random((murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
int pointX = random.nextInt(width) + cellX * cellWidth;
int pointZ = random.nextInt(width) + cellZ * cellWidth;
return x == pointX && z == pointZ;
}
}
@@ -7,8 +7,6 @@
package com.dfsek.terra.addons.flora.flora.gen;
import com.dfsek.terra.api.util.vector.Vector3Int;
import net.jafama.FastMath;
import java.util.ArrayList;
@@ -24,6 +22,7 @@ import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.collection.MaterialSet;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;
@@ -14,11 +14,11 @@ import java.util.function.Supplier;
import com.dfsek.terra.addons.feature.locator.config.AdjacentPatternLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.AndLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.GaussianRandomLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.Sampler3DLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.SamplerLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.OrLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.PatternLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.RandomLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.Sampler3DLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.SamplerLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.SurfaceLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.TopLocatorTemplate;
import com.dfsek.terra.addons.feature.locator.config.XorLocatorTemplate;
@@ -63,13 +63,13 @@ public class LocatorAddon implements AddonInitializer {
CheckedRegistry<Supplier<ObjectTemplate<Locator>>> locatorRegistry = event.getPack().getOrCreateRegistry(LOCATOR_TOKEN);
locatorRegistry.register(addon.key("SURFACE"), SurfaceLocatorTemplate::new);
locatorRegistry.register(addon.key("TOP"), TopLocatorTemplate::new);
locatorRegistry.register(addon.key("RANDOM"), RandomLocatorTemplate::new);
locatorRegistry.register(addon.key("GAUSSIAN_RANDOM"), GaussianRandomLocatorTemplate::new);
locatorRegistry.register(addon.key("PATTERN"), PatternLocatorTemplate::new);
locatorRegistry.register(addon.key("ADJACENT_PATTERN"), AdjacentPatternLocatorTemplate::new);
locatorRegistry.register(addon.key("SAMPLER"), SamplerLocatorTemplate::new);
locatorRegistry.register(addon.key("SAMPLER_3D"), Sampler3DLocatorTemplate::new);
@@ -11,7 +11,6 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.terra.addons.feature.locator.locators.SurfaceLocator;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.util.Range;
@@ -10,9 +10,7 @@ package com.dfsek.terra.addons.feature.locator.config;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.terra.addons.feature.locator.locators.SurfaceLocator;
import com.dfsek.terra.addons.feature.locator.locators.TopLocator;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.util.Range;
@@ -12,11 +12,11 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.tectonic.api.exception.ValidationException;
import java.util.List;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.structure.feature.Locator;
import java.util.List;
public class XorLocatorTemplate implements ObjectTemplate<Locator>, ValidatedConfigTemplate {
@Value("locators")
@@ -12,11 +12,11 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.tectonic.api.exception.ValidationException;
import java.util.List;
import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
import com.dfsek.terra.api.config.meta.Meta;
import java.util.List;
public class XorPatternTemplate implements ObjectTemplate<Pattern>, ValidatedConfigTemplate {
@Value("patterns")
@@ -7,14 +7,14 @@
package com.dfsek.terra.addons.feature.locator.locators;
import java.util.Random;
import com.dfsek.terra.api.structure.feature.BinaryColumn;
import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.world.chunk.generation.util.Column;
import com.dfsek.terra.api.world.chunk.generation.util.Column.BinaryColumnBuilder;
import java.util.Random;
public class GaussianRandomLocator implements Locator {
private final double mean;
@@ -7,8 +7,6 @@
package com.dfsek.terra.addons.feature.locator.locators;
import com.dfsek.terra.api.world.chunk.generation.util.Column.BinaryColumnBuilder;
import net.jafama.FastMath;
import java.util.List;
@@ -17,6 +15,7 @@ import com.dfsek.terra.api.noise.NoiseSampler;
import com.dfsek.terra.api.structure.feature.BinaryColumn;
import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.world.chunk.generation.util.Column;
import com.dfsek.terra.api.world.chunk.generation.util.Column.BinaryColumnBuilder;
public class SamplerLocator implements Locator {
@@ -24,7 +24,7 @@ public class TopLocator implements Locator {
public BinaryColumn getSuitableCoordinates(Column<?> column) {
for(int y : search) {
if(column.getBlock(y).isAir() && !column.getBlock(y - 1).isAir()) {
return new BinaryColumn(y, y+1, yi -> true);
return new BinaryColumn(y, y + 1, yi -> true);
}
}
return BinaryColumn.getNull();
@@ -2,12 +2,12 @@ package com.dfsek.terra.addons.noise.config.templates;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import java.util.function.BiFunction;
import com.dfsek.terra.addons.noise.samplers.arithmetic.BinaryArithmeticSampler;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.noise.NoiseSampler;
import java.util.function.BiFunction;
public class BinaryArithmeticTemplate<T extends BinaryArithmeticSampler> extends SamplerTemplate<T> {
private final BiFunction<NoiseSampler, NoiseSampler, T> function;
@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.noise.samplers.arithmetic;
import com.dfsek.terra.api.noise.NoiseSampler;
public class AdditionSampler extends BinaryArithmeticSampler{
public class AdditionSampler extends BinaryArithmeticSampler {
public AdditionSampler(NoiseSampler left, NoiseSampler right) {
super(left, right);
}
@@ -14,7 +14,7 @@ public abstract class BinaryArithmeticSampler implements NoiseSampler {
@Override
public double noise(long seed, double x, double y) {
return operate(left.noise(seed, x, y),right.noise(seed, x, y));
return operate(left.noise(seed, x, y), right.noise(seed, x, y));
}
@Override
@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.noise.samplers.arithmetic;
import com.dfsek.terra.api.noise.NoiseSampler;
public class DivisionSampler extends BinaryArithmeticSampler{
public class DivisionSampler extends BinaryArithmeticSampler {
public DivisionSampler(NoiseSampler left, NoiseSampler right) {
super(left, right);
}
@@ -1,11 +1,11 @@
package com.dfsek.terra.addons.noise.samplers.arithmetic;
import com.dfsek.terra.api.noise.NoiseSampler;
import net.jafama.FastMath;
import com.dfsek.terra.api.noise.NoiseSampler;
public class MaxSampler extends BinaryArithmeticSampler{
public class MaxSampler extends BinaryArithmeticSampler {
public MaxSampler(NoiseSampler left, NoiseSampler right) {
super(left, right);
}
@@ -1,11 +1,11 @@
package com.dfsek.terra.addons.noise.samplers.arithmetic;
import com.dfsek.terra.api.noise.NoiseSampler;
import net.jafama.FastMath;
import com.dfsek.terra.api.noise.NoiseSampler;
public class MinSampler extends BinaryArithmeticSampler{
public class MinSampler extends BinaryArithmeticSampler {
public MinSampler(NoiseSampler left, NoiseSampler right) {
super(left, right);
}
@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.noise.samplers.arithmetic;
import com.dfsek.terra.api.noise.NoiseSampler;
public class MultiplicationSampler extends BinaryArithmeticSampler{
public class MultiplicationSampler extends BinaryArithmeticSampler {
public MultiplicationSampler(NoiseSampler left, NoiseSampler right) {
super(left, right);
}
@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.noise.samplers.arithmetic;
import com.dfsek.terra.api.noise.NoiseSampler;
public class SubtractionSampler extends BinaryArithmeticSampler{
public class SubtractionSampler extends BinaryArithmeticSampler {
public SubtractionSampler(NoiseSampler left, NoiseSampler right) {
super(left, right);
}
@@ -18,10 +18,10 @@ public class GaborNoiseSampler extends NoiseFunction {
private double a = 0.1;
private double f0 = 0.625;
private double kernelRadius = (FastMath.sqrt(-FastMath.log(0.05) / Math.PI) / a);
private double impulsesPerKernel = 64d;
private double impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius));
private double impulsesPerCell = impulseDensity * kernelRadius * kernelRadius;
private double g = FastMath.exp(-impulsesPerCell);
private double impulsesPerKernel = 64d;
private double omega0 = Math.PI * 0.25;
private boolean isotropic = true;
@@ -7,9 +7,6 @@
package com.dfsek.terra.addons.noise.samplers.noise.random;
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
/**
* NoiseSampler implementation to produce random, uniformly distributed (white) noise.
*/
@@ -18,6 +18,7 @@ public class OreFactory implements ConfigFactory<OreTemplate, Structure> {
@Override
public VanillaOre build(OreTemplate config, Platform platform) {
BlockState m = config.getMaterial();
return new VanillaOre(m, config.getSize(), config.getReplaceable(), config.doPhysics(), config.isExposed(), config.getMaterialOverrides());
return new VanillaOre(m, config.getSize(), config.getReplaceable(), config.doPhysics(), config.isExposed(),
config.getMaterialOverrides());
}
}
@@ -7,8 +7,6 @@
package com.dfsek.terra.addons.ore.ores;
import com.dfsek.terra.api.util.vector.Vector3Int;
import net.jafama.FastMath;
import java.util.Map;
@@ -19,6 +17,7 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.collection.MaterialSet;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;
@@ -47,36 +46,36 @@ public class VanillaOre implements Structure {
int centerX = location.getX();
int centerZ = location.getZ();
int centerY = location.getY();
float f = random.nextFloat() * (float) Math.PI;
double d1 = centerX + 8 + FastMath.sin(f) * size / 8.0F;
double d2 = centerX + 8 - FastMath.sin(f) * size / 8.0F;
double d3 = centerZ + 8 + FastMath.cos(f) * size / 8.0F;
double d4 = centerZ + 8 - FastMath.cos(f) * size / 8.0F;
double d5 = centerY + random.nextInt(3) - 2D;
double d6 = centerY + random.nextInt(3) - 2D;
for(int i = 0; i < size; i++) {
float iFactor = (float) i / (float) size;
double d10 = random.nextDouble() * size / 16.0D;
double d11 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
double d12 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
int xStart = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor - d11 / 2.0D));
int yStart = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor - d12 / 2.0D));
int zStart = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor - d11 / 2.0D));
int xEnd = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor + d11 / 2.0D));
int yEnd = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor + d12 / 2.0D));
int zEnd = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor + d11 / 2.0D));
for(int x = xStart; x <= xEnd; x++) {
double d13 = (x + 0.5D - (d1 + (d2 - d1) * iFactor)) / (d11 / 2.0D);
if(d13 * d13 < 1.0D) {
for(int y = yStart; y <= yEnd; y++) {
double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d12 / 2.0D);
@@ -87,11 +86,11 @@ public class VanillaOre implements Structure {
BlockType block = world.getBlockState(x, y, z).getBlockType();
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block)) {
if(exposed > random.nextDouble() || !(world.getBlockState(x, y, z - 1).isAir() ||
world.getBlockState(x, y, z + 1).isAir() ||
world.getBlockState(x, y - 1, z).isAir() ||
world.getBlockState(x, y + 1, z).isAir() ||
world.getBlockState(x - 1, y, z).isAir() ||
world.getBlockState(x + 1, y, z).isAir())) {
world.getBlockState(x, y, z + 1).isAir() ||
world.getBlockState(x, y - 1, z).isAir() ||
world.getBlockState(x, y + 1, z).isAir() ||
world.getBlockState(x - 1, y, z).isAir() ||
world.getBlockState(x + 1, y, z).isAir())) {
world.setBlockState(x, y, z, getMaterial(block), isApplyGravity());
}
}
@@ -7,17 +7,10 @@
package com.dfsek.terra.addons.palette;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import java.util.function.Supplier;
import com.dfsek.terra.addons.palette.palette.PaletteImpl;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.config.ConfigFactory;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.ConfigType;
import com.dfsek.terra.api.registry.OpenRegistry;
import com.dfsek.terra.api.util.reflection.TypeKey;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
@@ -7,14 +7,14 @@
package com.dfsek.terra.addons.palette.palette;
import java.util.ArrayList;
import java.util.List;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.noise.NoiseSampler;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
import java.util.ArrayList;
import java.util.List;
/**
* A class representation of a "slice" of the world.
@@ -10,20 +10,11 @@ package com.dfsek.terra.addons.palette.palette;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.tectonic.api.depth.DepthTracker;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import java.lang.reflect.AnnotatedType;
import java.util.Map;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.noise.NoiseSampler;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
import org.jetbrains.annotations.NotNull;
public class PaletteLayerLoader implements ObjectTemplate<PaletteLayerHolder> {
@Value("materials")
@@ -13,8 +13,8 @@ import java.util.Random;
import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
@@ -38,6 +38,6 @@ public class StructureGenerationAddon implements AddonInitializer {
}
})
.failThrough();
}
}
@@ -12,6 +12,6 @@ public class StructureGenerationStage implements GenerationStage {
@Override
public void populate(ProtoWorld world) {
}
}
@@ -9,9 +9,6 @@ package com.dfsek.terra.addons.manifest.impl;
import ca.solostudios.strata.version.Version;
import ca.solostudios.strata.version.VersionRange;
import com.dfsek.terra.api.inject.impl.InjectorImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,7 +21,8 @@ import java.lang.reflect.AnnotatedType;
public class VersionLoader implements TypeLoader<Version> {
@Override
public Version load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker) throws LoadException {
public Version load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker)
throws LoadException {
try {
return Versions.parseVersion((String) c);
} catch(ParseException e) {
@@ -21,7 +21,8 @@ import java.lang.reflect.AnnotatedType;
public class VersionRangeLoader implements TypeLoader<VersionRange> {
@Override
public VersionRange load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker) throws LoadException {
public VersionRange load(@NotNull AnnotatedType t, @NotNull Object c, @NotNull ConfigLoader loader, DepthTracker depthTracker)
throws LoadException {
try {
return Versions.parseVersionRange((String) c);
} catch(ParseException e) {
@@ -22,8 +22,9 @@ public class PaletteBlockShortcutAddon implements AddonInitializer {
.getHandler(FunctionalEventHandler.class)
.register(addon, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack()
.registerShortcut(Palette.class, "BLOCK",
(configLoader, input, tracker) -> new SingletonPalette(configLoader.loadType(BlockState.class, input, tracker))))
.registerShortcut(Palette.class, "BLOCK",
(configLoader, input, tracker) -> new SingletonPalette(
configLoader.loadType(BlockState.class, input, tracker))))
.failThrough();
}
}
@@ -1,14 +1,13 @@
package com.dfsek.terra.addons.palette.shortcut.block;
import java.util.Random;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;
import java.util.Random;
public class SingletonStructure implements Structure {
private final BlockState blockState;
@@ -22,9 +22,10 @@ public class StructureBlockShortcutAddon implements AddonInitializer {
.getHandler(FunctionalEventHandler.class)
.register(addon, ConfigPackPreLoadEvent.class)
.then(event -> event.getPack()
.registerShortcut(Structure.class, "BLOCK",
(configLoader, input, tracker) -> new SingletonStructure(configLoader.loadType(BlockState.class, input, tracker)
)))
.registerShortcut(Structure.class, "BLOCK",
(configLoader, input, tracker) -> new SingletonStructure(
configLoader.loadType(BlockState.class, input, tracker)
)))
.failThrough();
}
}
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.structure.mutator;
import java.util.Random;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.structure.Structure;
@@ -9,8 +11,6 @@ import com.dfsek.terra.api.world.WritableWorld;
import com.dfsek.terra.api.world.util.ReadInterceptor;
import com.dfsek.terra.api.world.util.WriteInterceptor;
import java.util.Random;
public class MutatedStructure implements Structure, Keyed<MutatedStructure> {
private final RegistryKey key;
@@ -1,7 +1,5 @@
package com.dfsek.terra.addons.structure.mutator.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.api.config.AbstractableTemplate;
@@ -3,7 +3,7 @@ contributors:
- Terra contributors
id: structure-mutator
version: @VERSION@
entrypoints: []
entrypoints: [ ]
website:
issues: https://github.com/PolyhedralDev/Terra/issues
source: https://github.com/PolyhedralDev/Terra
@@ -7,8 +7,6 @@
package com.dfsek.terra.addons.terrascript;
import com.dfsek.tectonic.api.exception.LoadException;
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
@@ -1,10 +1,10 @@
package com.dfsek.terra.addons.terrascript.parser.lang;
import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable;
import java.util.HashMap;
import java.util.Map;
import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable;
public class Scope {
private static final Scope NULL = new Scope() {
@@ -12,7 +12,7 @@ public class Scope {
public Variable<?> get(String id) {
throw new IllegalStateException("Cannot get variable from null scope: " + id);
}
@Override
public void put(String id, Variable<?> variable) {
throw new IllegalStateException("Cannot set variable in null scope: " + id);
@@ -38,7 +38,7 @@ public class Scope {
public void put(String id, Variable<?> variable) {
variableMap.put(id, variable);
}
public Scope sub() {
return new Scope(this);
@@ -7,11 +7,15 @@
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
import com.dfsek.terra.addons.terrascript.parser.lang.*;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -7,7 +7,11 @@
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
import com.dfsek.terra.addons.terrascript.parser.lang.*;
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -7,10 +7,6 @@
package com.dfsek.terra.addons.terrascript.script;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.vector.Vector3Int;
import net.jafama.FastMath;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
@@ -45,9 +41,12 @@ import com.dfsek.terra.addons.terrascript.script.builders.ZeroArgFunctionBuilder
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.structure.LootTable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;
@@ -68,7 +67,7 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
throw new RuntimeException(e);
}
this.id = id;
//noinspection unchecked
functionRegistry.forEach((key, function) -> parser.registerFunction(key.getID(), function)); // Register registry functions.
@@ -24,8 +24,8 @@ public class TerraImplementationArguments implements ImplementationArguments {
private final WritableWorld world;
private final Map<Vector3, String> marks = new HashMap<>();
private final int recursions;
private boolean waterlog = false;
private final Vector3Int origin;
private boolean waterlog = false;
public TerraImplementationArguments(Vector3Int origin, Rotation rotation, Random random, WritableWorld world, int recursions) {
this.rotation = rotation;
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -7,30 +7,27 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import net.jafama.FastMath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.constants.StringConstant;
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.script.TerraImplementationArguments;
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.properties.base.Properties;
import com.dfsek.terra.api.util.RotationUtil;
import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BlockFunction implements Function<Void> {
private static final Logger logger = LoggerFactory.getLogger(BlockFunction.class);
@@ -74,13 +71,13 @@ public class BlockFunction implements Function<Void> {
TerraImplementationArguments arguments, BlockState rot) {
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
rot = RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
try {
Vector3.Mutable set = Vector3.of(FastMath.roundToInt(xz.getX()),
y.apply(implementationArguments, scope).doubleValue(),
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
y.apply(implementationArguments, scope).doubleValue(),
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
BlockState current = arguments.getWorld().getBlockState(set);
if(overwrite.apply(implementationArguments, scope) || current.isAir()) {
if(arguments.isWaterlog() && current.has(Properties.WATERLOGGED) && current.getBlockType().isWater()) {
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -47,8 +47,13 @@ public class EntityFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.apply(implementationArguments, scope).doubleValue(), xz.getZ()).mutable().add(arguments.getOrigin()).add(0.5, 0, 0.5).immutable(), data);
Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.apply(implementationArguments, scope).doubleValue(),
xz.getZ())
.mutable()
.add(arguments.getOrigin())
.add(0.5, 0, 0.5)
.immutable(), data);
platform.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getPack(), entity));
return null;
}
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -36,9 +36,13 @@ public class GetMarkFunction implements Function<String> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(
y.apply(implementationArguments, scope).doubleValue()), FastMath.floorToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable());
y.apply(implementationArguments, scope).doubleValue()),
FastMath.floorToInt(xz.getZ()))
.mutable()
.add(arguments.getOrigin())
.immutable());
return mark == null ? "" : mark;
}
@@ -7,14 +7,6 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.entity.Container;
import com.dfsek.terra.api.event.events.world.generation.LootPopulateEvent;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.vector.Vector3;
import net.jafama.FastMath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,15 +15,21 @@ import java.util.Random;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.StructureScript;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.block.entity.Container;
import com.dfsek.terra.api.event.events.world.generation.LootPopulateEvent;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.structure.LootTable;
import com.dfsek.terra.api.util.RotationUtil;
import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3;
public class LootFunction implements Function<Void> {
@@ -7,12 +7,12 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.constants.ConstantExpression;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
@@ -45,11 +45,11 @@ public class PullFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
BlockState rot = RotationUtil.rotateBlockData(data, arguments.getRotation().inverse());
Vector3.Mutable mutable = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(),
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
while(mutable.getY() > arguments.getWorld().getMinHeight()) {
if(!arguments.getWorld().getBlockState(mutable).isAir()) {
arguments.getWorld().setBlockState(mutable, rot);
@@ -7,11 +7,11 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -38,12 +38,13 @@ public class SetMarkFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
arguments.setMark(Vector3.of(FastMath.floorToInt(xz.getX()),
FastMath.floorToInt(
y.apply(implementationArguments, scope).doubleValue()),
FastMath.floorToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable(), mark.apply(implementationArguments, scope));
FastMath.floorToInt(
y.apply(implementationArguments, scope).doubleValue()),
FastMath.floorToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable(),
mark.apply(implementationArguments, scope));
return null;
}
@@ -7,23 +7,21 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.api.block.entity.BlockEntity;
import net.jafama.FastMath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.block.entity.BlockEntity;
import com.dfsek.terra.api.util.RotationUtil;
import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StateFunction implements Function<Void> {
private static final Logger LOGGER = LoggerFactory.getLogger(StateFunction.class);
@@ -45,10 +43,10 @@ public class StateFunction implements Function<Void> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
Vector3 origin = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(),
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
try {
BlockEntity state = arguments.getWorld().getBlockEntity(origin);
state.applyState(data.apply(implementationArguments, scope));
@@ -7,9 +7,6 @@
package com.dfsek.terra.addons.terrascript.script.functions;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.script.StructureScript;
import net.jafama.FastMath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,7 +15,9 @@ import java.util.List;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.StructureScript;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.Platform;
@@ -61,11 +60,11 @@ public class StructureFunction implements Function<Boolean> {
if(arguments.getRecursions() > platform.getTerraConfig().getMaxRecursion())
throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions());
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
String app = id.apply(implementationArguments, scope);
return registry.getByID(app).map(script -> {
Rotation rotation1;
@@ -8,13 +8,11 @@
package structure;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import com.dfsek.terra.addons.terrascript.parser.Parser;
@@ -22,6 +20,7 @@ import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -1,5 +1,12 @@
package structure;
import net.jafama.FastMath;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import com.dfsek.terra.addons.terrascript.parser.Parser;
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
@@ -12,13 +19,6 @@ import com.dfsek.terra.addons.terrascript.script.builders.UnaryNumberFunctionBui
import com.dfsek.terra.addons.terrascript.script.builders.UnaryStringFunctionBuilder;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import net.jafama.FastMath;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
public class PerformanceTest {
public static void main(String... args) throws IOException {
@@ -7,13 +7,13 @@
package com.dfsek.terra.addon.terrascript.check;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import com.dfsek.terra.addons.chunkgenerator.generation.NoiseChunkGenerator3D;
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.SamplerProvider;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
@@ -44,13 +44,13 @@ public class CheckFunction implements Function<String> {
Vector2 xz = Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue());
z.apply(implementationArguments, scope).doubleValue());
RotationUtil.rotateVector(xz, arguments.getRotation());
Vector3 location = arguments.getOrigin().toVector3Mutable().add(
Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).doubleValue(),
FastMath.roundToInt(xz.getZ()))).immutable();
FastMath.roundToInt(xz.getZ()))).immutable();
return apply(location, arguments.getWorld());
}
@@ -23,7 +23,8 @@ public class TerraScriptCheckFunctionAddon implements AddonInitializer {
.register(addon, ConfigPackPreLoadEvent.class)
.priority(1)
.then(event -> {
event.getPack().getOrCreateRegistry(FunctionBuilder.class).register(addon.key("check"), new CheckFunctionBuilder(platform));
event.getPack().getOrCreateRegistry(FunctionBuilder.class).register(addon.key("check"),
new CheckFunctionBuilder(platform));
})
.failThrough();
}
@@ -1,5 +1,7 @@
package com.dfsek.terra.addons.terrascript.sampler;
import java.util.function.Supplier;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
@@ -8,8 +10,6 @@ import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.noise.NoiseSampler;
import java.util.function.Supplier;
public class SamplerFunction implements Function<Number> {
private final Returnable<Number> x, y, z;
@@ -1,5 +1,12 @@
package com.dfsek.terra.addons.terrascript.sampler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable.ReturnType;
@@ -9,13 +16,6 @@ import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.noise.NoiseSampler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
public class SamplerFunctionBuilder implements FunctionBuilder<SamplerFunction> {
private final Map<String, DimensionApplicableNoiseSampler> samplers2d;
@@ -28,6 +28,7 @@ public interface BaseAddon extends StringIdentifiable, Namespaced {
/**
* Gets the dependencies of this addon.
*
* @return Map of dependency ID to {@link VersionRange} of dependency
*/
default Map<String, VersionRange> getDependencies() {
@@ -36,6 +37,7 @@ public interface BaseAddon extends StringIdentifiable, Namespaced {
/**
* Get the version of the addon
*
* @return Version of addon
*/
Version getVersion();
@@ -14,12 +14,13 @@ import com.dfsek.terra.api.addon.BaseAddon;
/**
* Interface representing a bootstrap addon.
*
* <p>
* A bootstrap addon is the only type of addon Terra implements a loader for.
* It is a minimal base for addon loaders to be implemented on top of.
*
* <p>
* Unless you are writing your own addon loader, you will want to depend on the
* {@code manifest-addon-loader} addon, and implement its AddonInitializer.
*
* @param <T> Type of addon this bootstrap addon loads
*/
public interface BootstrapBaseAddon<T extends BaseAddon> extends BaseAddon {
@@ -17,18 +17,21 @@ import com.dfsek.terra.api.block.state.BlockState;
public interface BlockType extends Handle {
/**
* Get the default {@link BlockState} of this block
*
* @return Default block state
*/
BlockState getDefaultState();
/**
* Get whether this block is solid.
*
* @return Whether this block is solid.
*/
boolean isSolid();
/**
* Get whether this block is water.
*
* @return Whether this block is water.
*/
boolean isWater();
@@ -21,39 +21,49 @@ public interface BlockState extends Handle {
/**
* Whether this {@link BlockState} matches another.
*
* <p>
* "matches" is defined as this {@link BlockState} holding a matching {@link #getBlockType()}.
*
* @param other Other {@link BlockState}
*
* @return Whether this state matches the other
*/
boolean matches(BlockState other);
/**
* Check whether this {@link BlockState} has a {@link Property}.
*
* @param property Property to check for
*
* @return Whether this state has the property.
*/
<T extends Comparable<T>> boolean has(Property<T> property);
/**
* Get the value of a {@link Property} on this state.
*
* @param property Property to get
*
* @return Value of the property
*/
<T extends Comparable<T>> T get(Property<T> property);
/**
* Return a new {@link BlockState} with a {@link Property} set to a value.
*
* @param property Property to set
* @param value Value of property
* @param value Value of property
*
* @return New {@link BlockState} with property set.
*/
<T extends Comparable<T>> BlockState set(Property<T> property, T value);
/**
* Perform an action on this {@link BlockState} if it contains a {@link Property}
*
* @param property Property to check for
* @param action Action to perform if property is present
* @param action Action to perform if property is present
*
* @return This {@link BlockState}
*/
default <T extends Comparable<T>> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
@@ -63,8 +73,10 @@ public interface BlockState extends Handle {
/**
* Set the value of a {@link Property} on this {@link BlockState} if it is present.
*
* @param property Property to check for/set.
* @param value Value to set if property is present.
* @param value Value to set if property is present.
*
* @return Thie {@link BlockState}
*/
default <T extends Comparable<T>> BlockState setIfPresent(Property<T> property, T value) {
@@ -74,12 +86,14 @@ public interface BlockState extends Handle {
/**
* Get the {@link BlockType} this state applies to.
*
* @return Block type.
*/
BlockType getBlockType();
/**
* Get this state and its properties as a String
*
* @return String representation of this state
*/
default String getAsString() {
@@ -88,13 +102,16 @@ public interface BlockState extends Handle {
/**
* Get this state and its properties as a String
*
* @param properties Whether to include properties
*
* @return String representation of this state
*/
String getAsString(boolean properties);
/**
* Get whether this BlockState is air
*
* @return Whether this state is air
*/
boolean isAir();
@@ -7,10 +7,10 @@
package com.dfsek.terra.api.block.state.properties;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import java.util.Collection;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
/**
* Represents a property a state holds
@@ -18,12 +18,14 @@ import java.util.Collection;
public interface Property<T> extends StringIdentifiable {
/**
* Get all possible values of this property
*
* @return All values of this property
*/
Collection<T> values();
/**
* Get the type of this property.
*
* @return {@link Class} instance representing the type of this property
*/
Class<T> getType();
@@ -14,6 +14,7 @@ import com.dfsek.terra.api.block.state.properties.enums.RailShape;
import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
import com.dfsek.terra.api.block.state.properties.enums.WallHeight;
@Deprecated
public final class Properties {
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("facing", Direction.class);
@@ -7,12 +7,12 @@
package com.dfsek.terra.api.command;
import java.util.Optional;
import com.dfsek.terra.api.Handle;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.Player;
import java.util.Optional;
public interface CommandSender extends Handle {
void sendMessage(String message);
@@ -5,16 +5,6 @@ import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.context.CommandContext;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.exception.NoSuchEntryException;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.reflection.TypeKey;
import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -26,6 +16,11 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.exception.NoSuchEntryException;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
public class RegistryArgument<T, R> extends CommandArgument<T, R> {
private RegistryArgument(
@@ -63,19 +58,23 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
}
@SuppressWarnings("unchecked")
public static <T, R> Builder<T, R> builder(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType) {
public static <T, R> Builder<T, R> builder(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) {
return new Builder<>(name, registryFunction, (TypeToken<R>) TypeToken.get(registryType.getType()));
}
public static <T, R> CommandArgument<T, R> of(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType) {
public static <T, R> CommandArgument<T, R> of(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) {
return RegistryArgument.<T, R>builder(name, registryFunction, registryType).build();
}
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType) {
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType) {
return RegistryArgument.builder(name, registryFunction, registryType).asOptional().build();
}
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeKey<R> registryType, String defaultKey) {
public static <T, R> CommandArgument<T, R> optional(String name, Function<CommandContext<T>, Registry<R>> registryFunction,
TypeKey<R> registryType, String defaultKey) {
return RegistryArgument.builder(name, registryFunction, registryType).asOptionalWithDefault(defaultKey).build();
}
@@ -89,7 +88,7 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
this.registryFunction = commandContext -> registry;
this.typeToken = (TypeToken<R>) TypeToken.get(registry.getType().getType());
}
private Builder(@NonNull String name, Function<CommandContext<T>, Registry<R>> registryFunction, TypeToken<R> typeToken) {
super(typeToken, name);
this.typeToken = typeToken;
@@ -15,11 +15,9 @@ import java.util.Map;
import com.dfsek.terra.api.addon.BaseAddon;
import com.dfsek.terra.api.properties.PropertyHolder;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.registry.meta.CheckedRegistryHolder;
import com.dfsek.terra.api.registry.meta.RegistryHolder;
import com.dfsek.terra.api.registry.meta.RegistryProvider;
import com.dfsek.terra.api.tectonic.ConfigLoadingDelegate;
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
@@ -7,10 +7,7 @@
package com.dfsek.terra.api.config;
import java.util.function.Supplier;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.registry.OpenRegistry;
import com.dfsek.terra.api.util.reflection.TypeKey;
@@ -9,8 +9,8 @@ package com.dfsek.terra.api.noise;
import com.dfsek.terra.api.util.vector.Vector2;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector2Int;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
@@ -7,12 +7,11 @@
package com.dfsek.terra.api.registry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
public interface CheckedRegistry<T> extends Registry<T> {
@@ -7,12 +7,11 @@
package com.dfsek.terra.api.registry;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.registry.key.RegistryKey;
public interface OpenRegistry<T> extends Registry<T> {
@@ -8,10 +8,6 @@
package com.dfsek.terra.api.registry;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -23,6 +19,9 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import com.dfsek.terra.api.registry.key.RegistryKey;
import com.dfsek.terra.api.util.reflection.TypeKey;
public interface Registry<T> extends TypeLoader<T> {
/**
@@ -15,7 +15,7 @@ public final class RegistryKey implements StringIdentifiable, Namespaced {
"Namespace must only contain alphanumeric characters, hyphens, and underscores. \"" + namespace +
"\" is not a valid namespace.");
}
if(!ID_PATTERN.matcher(id).matches()) {
throw new IllegalArgumentException(
"ID must only contain alphanumeric characters, hyphens, and underscores. \"" + id +
@@ -1,10 +1,10 @@
package com.dfsek.terra.api.registry.meta;
import java.lang.reflect.Type;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.util.reflection.TypeKey;
import java.lang.reflect.Type;
public interface CheckedRegistryHolder extends RegistryHolder {
default <T> CheckedRegistry<T> getCheckedRegistry(Class<T> clazz) throws IllegalStateException {
@@ -9,9 +9,7 @@ package com.dfsek.terra.api.structure;
import java.util.Random;
import com.dfsek.terra.api.registry.key.Keyed;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.util.vector.Vector3Int;
import com.dfsek.terra.api.world.WritableWorld;
@@ -9,10 +9,10 @@ package com.dfsek.terra.api.structure.configured;
import org.jetbrains.annotations.ApiStatus.Experimental;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.structure.StructureSpawn;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
@@ -7,11 +7,8 @@
package com.dfsek.terra.api.structure.feature;
import java.util.ArrayList;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.IntConsumer;
import java.util.stream.IntStream;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.util.function.IntToBooleanFunction;
@@ -22,16 +19,15 @@ import com.dfsek.terra.api.util.generic.Lazy;
* A column of binary data
*/
public class BinaryColumn {
private static final BinaryColumn NULL = new BinaryColumn(0, 1, y -> false);
private final IntToBooleanFunction data;
private final int minY;
private final int maxY;
private final Lazy<boolean[]> results;
private static final BinaryColumn NULL = new BinaryColumn(0, 1, y -> false);
/**
* Constructs a new {@link BinaryColumn} with all values initiated to {@code false}
*
* @param minY Minimum Y value
* @param maxY Maximum Y value
*/
@@ -57,17 +53,19 @@ public class BinaryColumn {
this.data = y -> data[y - minY];
}
public static BinaryColumn getNull() {
return NULL;
}
public BinaryColumn(Range y, IntToBooleanFunction data) {
this(y.getMin(), y.getMax(), data);
}
public static BinaryColumn getNull() {
return NULL;
}
/**
* Get the value at a height.
*
* @param y Height of entry to get.
*
* @return Whether height has been set.
*/
public boolean get(int y) {
@@ -81,6 +79,7 @@ public class BinaryColumn {
/**
* Perform an action for all heights which have been set.
*
* @param consumer Action to perform
*/
public void forEach(IntConsumer consumer) {
@@ -94,7 +93,9 @@ public class BinaryColumn {
/**
* Return a {@link BinaryColumn} of equal height with a boolean AND operation applied to each height.
*
* @param that Other binary column, must match this column's height.
*
* @return Merged column.
*
* @throws IllegalArgumentException if column heights do not match
@@ -105,7 +106,9 @@ public class BinaryColumn {
/**
* Return a {@link BinaryColumn} of equal height with a boolean OR operation applied to each height.
*
* @param that Other binary column, must match this column's height.
*
* @return Merged column.
*
* @throws IllegalArgumentException if column heights do not match
@@ -121,7 +124,7 @@ public class BinaryColumn {
private BinaryColumn bool(BinaryColumn that, BooleanBinaryOperator operator) {
int smallMinY = Math.min(this.minY, that.minY);
int bigMaxY = Math.max(this.maxY, that.maxY);
return new BinaryColumn(smallMinY, bigMaxY, y -> operator.apply(() -> this.get(y), () -> that.get(y)));
}
@@ -7,8 +7,8 @@
package com.dfsek.terra.api.structure.feature;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.world.WritableWorld;
@@ -1,9 +1,9 @@
package com.dfsek.terra.api.util;
import com.dfsek.terra.api.util.vector.Vector3Int;
import java.util.function.Consumer;
import com.dfsek.terra.api.util.vector.Vector3Int;
public final class GeometryUtil {
private GeometryUtil() {
@@ -9,7 +9,6 @@ package com.dfsek.terra.api.util.collection;
import java.io.Serial;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -7,9 +7,6 @@
package com.dfsek.terra.api.util.collection;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -25,6 +22,8 @@ import java.util.function.Function;
import com.dfsek.terra.api.noise.NoiseSampler;
import com.dfsek.terra.api.util.MathUtil;
import com.dfsek.terra.api.util.mutable.MutableInteger;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
public class ProbabilityCollection<E> implements Collection<E> {
@@ -35,7 +35,6 @@ public class Vector2 {
}
/**
* Get the length of this Vector
*
@@ -127,34 +126,40 @@ public class Vector2 {
return new Mutable(x, z);
}
@Override
public String toString() {
return "(" + x + ", " + z + ")";
}
public static class Mutable extends Vector2 {
private Mutable(double x, double z) {
super(x, z);
}
public double getX() {
return x;
}
public double getZ() {
return z;
}
public Vector2 immutable() {
return Vector2.of(x, z);
}
public Mutable setX(double x) {
this.x = x;
return this;
}
public double getZ() {
return z;
}
public Mutable setZ(double z) {
this.z = z;
return this;
}
public Vector2 immutable() {
return Vector2.of(x, z);
}
/**
* Get the length of this Vector
*
@@ -163,7 +168,7 @@ public class Vector2 {
public double length() {
return FastMath.sqrt(lengthSquared());
}
/**
* Get the squared length of this Vector
*
@@ -172,13 +177,13 @@ public class Vector2 {
public double lengthSquared() {
return x * x + z * z;
}
public Mutable add(double x, double z) {
this.x += x;
this.z += z;
return this;
}
/**
* Multiply X and Z components by a value.
*
@@ -191,7 +196,7 @@ public class Vector2 {
z *= m;
return this;
}
/**
* Add this vector to another.
*
@@ -204,7 +209,7 @@ public class Vector2 {
z += other.getZ();
return this;
}
/**
* Subtract a vector from this vector,
*
@@ -217,7 +222,7 @@ public class Vector2 {
z -= other.getZ();
return this;
}
/**
* Normalize this vector to length 1
*
@@ -227,7 +232,7 @@ public class Vector2 {
divide(length());
return this;
}
/**
* Divide X and Z components by a value.
*
@@ -241,9 +246,4 @@ public class Vector2 {
return this;
}
}
@Override
public String toString() {
return "(" + x + ", " + z + ")";
}
}

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