document a bunch of stuff

This commit is contained in:
dfsek
2021-12-23 14:43:43 -07:00
parent f353d1686c
commit a092dfdc3b
21 changed files with 272 additions and 58 deletions

View File

@@ -16,12 +16,26 @@ import java.util.Map;
import com.dfsek.terra.api.util.StringIdentifiable;
/**
* Base interface which all Terra addons extend
*/
public interface BaseAddon extends StringIdentifiable {
/**
* Initializes the addon. To be implemented by addons, but never manually invoked.
*/
default void initialize() { }
/**
* Gets the dependencies of this addon.
* @return Map of dependency ID to {@link VersionRange} of dependency
*/
default Map<String, VersionRange> getDependencies() {
return Collections.emptyMap();
}
/**
* Get the version of the addon
* @return Version of addon
*/
Version getVersion();
}

View File

@@ -12,6 +12,16 @@ import java.nio.file.Path;
import com.dfsek.terra.api.addon.BaseAddon;
/**
* Interface representing a bootstrap addon.
*
* 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.
*
* 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 {
/**
* Load all the relevant addons in the specified path.

View File

@@ -11,10 +11,25 @@ import com.dfsek.terra.api.Handle;
import com.dfsek.terra.api.block.state.BlockState;
/**
* Represents a type of block
*/
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();
}

View File

@@ -14,33 +14,88 @@ import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.properties.Property;
/**
* Contains basic data about a {@link BlockType} in the world
*/
public interface BlockState extends Handle {
/**
* Whether this {@link BlockState} matches another.
*
* "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
* @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
* @return This {@link BlockState}
*/
default <T extends Comparable<T>> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
if(has(property)) action.accept(this);
return this;
}
/**
* 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.
* @return Thie {@link BlockState}
*/
default <T extends Comparable<T>> BlockState setIfPresent(Property<T> property, T value) {
if(has(property)) set(property, value);
return this;
}
/**
* 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() {
return getAsString(true);
}
/**
* 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();
}

View File

@@ -7,13 +7,24 @@
package com.dfsek.terra.api.block.state.properties;
import com.dfsek.terra.api.util.StringIdentifiable;
import java.util.Collection;
public interface Property<T> {
/**
* Represents a property a state holds
*/
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();
String getName();
}

View File

@@ -24,7 +24,7 @@ public interface BooleanProperty extends Property<Boolean> {
}
@Override
public String getName() {
public String getID() {
return name;
}
};

View File

@@ -30,7 +30,7 @@ public interface EnumProperty<T extends Enum<T>> extends Property<T> {
}
@Override
public String getName() {
public String getID() {
return name;
}
};

View File

@@ -32,7 +32,7 @@ public interface IntProperty extends Property<Integer> {
}
@Override
public String getName() {
public String getID() {
return name;
}
};

View File

@@ -12,5 +12,8 @@ import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.terra.api.util.StringIdentifiable;
/**
* An abstractable config template
*/
public interface AbstractableTemplate extends ConfigTemplate, StringIdentifiable {
}

View File

@@ -10,24 +10,45 @@ package com.dfsek.terra.api.structure.feature;
import java.util.function.IntConsumer;
/**
* A column of binary data
*/
public class BinaryColumn {
private final boolean[] data;
private final int minY;
/**
* Constructs a new {@link BinaryColumn} with all values initiated to {@code false}
* @param minY Minimum Y value
* @param maxY Maximum Y value
*/
public BinaryColumn(int minY, int maxY) {
this.minY = minY;
if(maxY <= minY) throw new IllegalArgumentException("Max y must be greater than min y");
this.data = new boolean[maxY - minY];
}
/**
* Set the value of a height to {@code true}.
* @param y Height of entry to set.
*/
public void set(int y) {
data[y - minY] = true;
}
/**
* Get the value at a height.
* @param y Height of entry to get.
* @return Whether height has been set.
*/
public boolean get(int y) {
return data[y - minY];
}
/**
* Perform an action for all heights which have been set.
* @param consumer Action to perform
*/
public void forEach(IntConsumer consumer) {
for(int y = 0; y < data.length; y++) {
if(data[y]) {
@@ -36,6 +57,13 @@ 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
*/
public BinaryColumn and(BinaryColumn that) {
if(that.minY != this.minY) throw new IllegalArgumentException("Must share same min Y");
if(that.data.length != this.data.length) throw new IllegalArgumentException("Must share same max Y");
@@ -48,6 +76,13 @@ public class BinaryColumn {
return next;
}
/**
* 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
*/
public BinaryColumn or(BinaryColumn that) {
if(that.minY != this.minY) throw new IllegalArgumentException("Must share same min Y");
if(that.data.length != this.data.length) throw new IllegalArgumentException("Must share same max Y");

View File

@@ -13,6 +13,9 @@ import java.util.ArrayList;
import java.util.List;
/**
* Thrown when all transformation attempts fail
*/
public class AttemptsFailedException extends RuntimeException {
@Serial
private static final long serialVersionUID = -1160459550006067137L;

View File

@@ -15,9 +15,9 @@ import com.dfsek.terra.api.util.MathUtil;
/**
* oh yeah
*/
public class Vector2 implements Cloneable {
private final double x;
private final double z;
public class Vector2 {
protected double x;
protected double z;
/**
* Create a vector with a given X and Z component
@@ -127,12 +127,10 @@ public class Vector2 implements Cloneable {
return new Mutable(x, z);
}
public static class Mutable {
private double x, z;
public static class Mutable extends Vector2 {
private Mutable(double x, double z) {
this.x = x;
this.z = z;
super(x, z);
}
public double getX() {

View File

@@ -2,8 +2,6 @@ package com.dfsek.terra.api.util.vector;
import com.dfsek.terra.api.util.Rotation;
import java.util.Objects;
/**
* oh yeah
@@ -11,8 +9,8 @@ import java.util.Objects;
public class Vector2Int {
private static final Vector2Int ZERO = new Vector2Int(0, 0);
private static final Vector2Int UNIT = new Vector2Int(0, 1);
private final int x;
private final int z;
protected int x;
protected int z;
protected Vector2Int(int x, int z) {
this.x = x;
@@ -56,12 +54,10 @@ public class Vector2Int {
};
}
public static class Mutable {
private int x, z;
public static class Mutable extends Vector2Int {
protected Mutable(int x, int z) {
this.x = x;
this.z = z;
super(x, z);
}
public int getZ() {

View File

@@ -14,9 +14,9 @@ import com.dfsek.terra.api.util.MathUtil;
public class Vector3 {
private final double x;
private final double y;
private final double z;
protected double x;
protected double y;
protected double z;
private Vector3(double x, double y, double z) {
this.x = x;
@@ -146,13 +146,9 @@ public class Vector3 {
return new Mutable(x, y, z);
}
public static class Mutable {
private double x, y, z;
public static class Mutable extends Vector3 {
private Mutable(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
super(x, y, z);
}
public static Mutable of(double x, double y, double z) {

View File

@@ -4,7 +4,7 @@ package com.dfsek.terra.api.util.vector;
public class Vector3Int {
private static final Vector3Int ZERO = new Vector3Int(0, 0, 0);
private static final Vector3Int UNIT = new Vector3Int(0, 1, 0);
private final int x, y, z;
protected int x, y, z;
protected Vector3Int(int x, int y, int z) {
this.x = x;
@@ -48,13 +48,9 @@ public class Vector3Int {
return Vector3.Mutable.of(x, y, z);
}
public static class Mutable {
private int x, y, z;
public static class Mutable extends Vector3Int {
protected Mutable(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
super(x, y, z);
}
public int getX() {

View File

@@ -9,6 +9,10 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
/**
* A {@link WritableWorld} implementation which delegates read/write operations to
* another {@link WritableWorld}, at an offset.
*/
public class BufferedWorld implements WritableWorld {
private final WritableWorld delegate;
private final int offsetX, offsetY, offsetZ;
@@ -76,6 +80,10 @@ public class BufferedWorld implements WritableWorld {
return delegate.spawnEntity(x + offsetX, y + offsetY, z + offsetZ, entityType);
}
/**
* Get the world this {@link BufferedWorld} delegates to.
* @return Delegate world.
*/
public WritableWorld getDelegate() {
return delegate;
}

View File

@@ -6,25 +6,37 @@ import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.Vector3Int;
/**
* A {@link World} with read access.
*/
public interface ReadableWorld extends World {
/**
* Get the {@link BlockState} at a location.
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @return {@link BlockState} at coordinates.
*/
BlockState getBlockState(int x, int y, int z);
/**
* Get the {@link BlockState} at a location.
* @param position Location to get block.
* @return {@link BlockState} at coordinates.
*/
default BlockState getBlockState(Vector3 position) {
return getBlockState(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
default BlockState getBlockState(Vector3.Mutable position) {
return getBlockState(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
/**
* Get the {@link BlockState} at a location.
* @param position Location to get block.
* @return {@link BlockState} at coordinates.
*/
default BlockState getBlockState(Vector3Int position) {
return getBlockState(position.getX(), position.getY(), position.getZ());
}
default BlockState getBlockState(Vector3Int.Mutable position) {
return getBlockState(position.getX(), position.getY(), position.getZ());
}
BlockEntity getBlockEntity(int x, int y, int z);
default BlockEntity getBlockEntity(Vector3 position) {

View File

@@ -6,10 +6,25 @@ import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.info.WorldProperties;
/**
* Represents a world.
*/
public interface World extends WorldProperties {
/**
* Get the {@link ChunkGenerator} this world uses.
* @return Chunk generator.
*/
ChunkGenerator getGenerator();
/**
* Get the {@link BiomeProvider} this world uses.
* @return Biome provider.
*/
BiomeProvider getBiomeProvider();
/**
* Get the {@link ConfigPack} this world uses.
* @return Config pack.
*/
ConfigPack getPack();
}

View File

@@ -11,23 +11,30 @@ package com.dfsek.terra.api.world.biome;
import java.util.Set;
import com.dfsek.terra.api.properties.PropertyHolder;
import com.dfsek.terra.api.util.StringIdentifiable;
/**
* Represents a custom biome
* Represents a Terra biome
*/
public interface Biome extends PropertyHolder {
public interface Biome extends PropertyHolder, StringIdentifiable {
/**
* Gets the Vanilla biome to represent the custom biome.
* Gets the platform biome this custom biome delegates to.
*
* @return TerraBiome - The Vanilla biome.
* @return The platform biome.
*/
PlatformBiome getPlatformBiome();
/**
* Get the color of this biome.
* @return ARGB color of this biome
*/
int getColor();
/**
* Get the tags this biome holds
* @return A {@link Set} of String tags this biome holds.
*/
Set<String> getTags();
String getID();
}

View File

@@ -12,16 +12,51 @@ import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.biome.Biome;
/**
* Provides locations of biomes in a world.
*/
public interface BiomeProvider {
/**
* Get the biome at a location.
*
* @param x X coordinate
* @param z Z coordinate
* @param seed World seed
*
* @return Biome at the location
*/
Biome getBiome(int x, int z, long seed);
/**
* Get the biome at a location.
*
* @param vector2 Location
* @param seed World seed
*
* @return Biome at the location
*/
default Biome getBiome(Vector2 vector2, long seed) {
return getBiome(vector2.getBlockX(), vector2.getBlockZ(), seed);
}
/**
* Get the biome at a location.
*
* @param vector3 Location
* @param seed World seed
*
* @return Biome at the location
*/
default Biome getBiome(Vector3 vector3, long seed) {
return getBiome(vector3.getBlockX(), vector3.getBlockZ(), seed);
}
/**
* Get all biomes this {@link BiomeProvider} is capable of generating in the world.
* <p>
* Must contain all biomes that could possibly generate.
*
* @return {@link Iterable} of all biomes this provider can generate.
*/
Iterable<Biome> getBiomes();
}

View File

@@ -3,6 +3,10 @@ package com.dfsek.terra.fabric.mixin.implementations.block.state;
import com.dfsek.terra.api.block.state.properties.Property;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Interface.Remap;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -10,7 +14,8 @@ import java.util.Collection;
@Mixin(net.minecraft.state.property.Property.class)
public abstract class PropertyMixin<T> implements Property<T> {
@Implements(@Interface(iface = Property.class, prefix = "terra$", remap = Remap.NONE))
public abstract class PropertyMixin<T> {
@Shadow
@Final
private Class<T> type;
@@ -22,18 +27,18 @@ public abstract class PropertyMixin<T> implements Property<T> {
@Final
private String name;
@Override
public Collection<T> values() {
@Intrinsic
public Collection<T> terra$values() {
return getValues();
}
@Override
public Class<T> getType() {
@Intrinsic
public Class<T> terra$getType() {
return type;
}
@Override
public String getName() {
@Intrinsic
public String terra$getID() {
return name;
}
}