mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 17:56:03 +00:00
Reformat all code
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@@ -2,11 +2,11 @@ package com.dfsek.terra.api;
|
||||
|
||||
public interface Logger {
|
||||
void info(String message);
|
||||
|
||||
|
||||
void warning(String message);
|
||||
|
||||
|
||||
void severe(String message);
|
||||
|
||||
|
||||
default void stack(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.PluginConfig;
|
||||
@@ -12,40 +14,17 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Represents a Terra mod/plugin instance.
|
||||
*/
|
||||
public interface TerraPlugin extends LoaderRegistrar {
|
||||
WorldHandle getWorldHandle();
|
||||
|
||||
Logger logger();
|
||||
|
||||
PluginConfig getTerraConfig();
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
Language getLanguage();
|
||||
|
||||
CheckedRegistry<ConfigPack> getConfigRegistry();
|
||||
|
||||
Registry<TerraAddon> getAddons();
|
||||
|
||||
|
||||
boolean reload();
|
||||
|
||||
ItemHandle getItemHandle();
|
||||
|
||||
|
||||
String platformName();
|
||||
|
||||
Logger getDebugLogger();
|
||||
|
||||
EventManager getEventManager();
|
||||
|
||||
default String getVersion() {
|
||||
return "@VERSION@";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a task that may or may not be thread safe, depending on platform.
|
||||
* <p>
|
||||
@@ -56,6 +35,28 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
default void runPossiblyUnsafeTask(Runnable task) {
|
||||
task.run();
|
||||
}
|
||||
|
||||
|
||||
WorldHandle getWorldHandle();
|
||||
|
||||
PluginConfig getTerraConfig();
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
Language getLanguage();
|
||||
|
||||
CheckedRegistry<ConfigPack> getConfigRegistry();
|
||||
|
||||
Registry<TerraAddon> getAddons();
|
||||
|
||||
ItemHandle getItemHandle();
|
||||
|
||||
Logger getDebugLogger();
|
||||
|
||||
EventManager getEventManager();
|
||||
|
||||
default String getVersion() {
|
||||
return "@VERSION@";
|
||||
}
|
||||
|
||||
Profiler getProfiler();
|
||||
}
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package com.dfsek.terra.api.addon;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* Represents an entry point for an com.dfsek.terra.addon. Implementations must be annotated with {@link Addon}.
|
||||
*/
|
||||
public abstract class TerraAddon {
|
||||
/**
|
||||
* Invoked immediately after an com.dfsek.terra.addon is loaded.
|
||||
*/
|
||||
public abstract void initialize();
|
||||
|
||||
/**
|
||||
* Gets the version of this com.dfsek.terra.addon.
|
||||
*
|
||||
@@ -19,7 +26,7 @@ public abstract class TerraAddon {
|
||||
Version version = getClass().getAnnotation(Version.class);
|
||||
return version == null ? "0.1.0" : version.value();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the author of this com.dfsek.terra.addon.
|
||||
*
|
||||
@@ -29,7 +36,7 @@ public abstract class TerraAddon {
|
||||
Author author = getClass().getAnnotation(Author.class);
|
||||
return author == null ? "Anon Y. Mous" : author.value();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name (ID) of this com.dfsek.terra.addon.
|
||||
*
|
||||
@@ -38,12 +45,9 @@ public abstract class TerraAddon {
|
||||
public final @NotNull String getName() {
|
||||
Addon addon = getClass().getAnnotation(Addon.class);
|
||||
if(addon == null)
|
||||
throw new IllegalStateException("Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the com.dfsek.terra.addon loader.
|
||||
throw new IllegalStateException(
|
||||
"Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the com
|
||||
// .dfsek.terra.addon loader.
|
||||
return addon.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked immediately after an com.dfsek.terra.addon is loaded.
|
||||
*/
|
||||
public abstract void initialize();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies that the annotated class is an entry point for a Terra com.dfsek.terra.addon.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Optional annotation that specifies the author of an com.dfsek.terra.addon.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Optional annotation that specifies dependencies of an com.dfsek.terra.addon.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Optional annotation that specifies the version of an com.dfsek.terra.addon.
|
||||
*/
|
||||
|
||||
@@ -3,10 +3,11 @@ package com.dfsek.terra.api.block;
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
|
||||
public interface BlockType extends Handle {
|
||||
BlockState getDefaultData();
|
||||
|
||||
|
||||
boolean isSolid();
|
||||
|
||||
|
||||
boolean isWater();
|
||||
}
|
||||
|
||||
@@ -4,20 +4,21 @@ import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
|
||||
public interface BlockEntity extends Handle {
|
||||
Vector3 getPosition();
|
||||
|
||||
int getX();
|
||||
|
||||
int getY();
|
||||
|
||||
int getZ();
|
||||
|
||||
BlockState getBlockData();
|
||||
|
||||
boolean update(boolean applyPhysics);
|
||||
|
||||
|
||||
default void applyState(String state) {
|
||||
// Do nothing by default.
|
||||
}
|
||||
|
||||
Vector3 getPosition();
|
||||
|
||||
int getX();
|
||||
|
||||
int getY();
|
||||
|
||||
int getZ();
|
||||
|
||||
BlockState getBlockData();
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@ package com.dfsek.terra.api.block.entity;
|
||||
|
||||
import com.dfsek.terra.api.inventory.BlockInventoryHolder;
|
||||
|
||||
|
||||
public interface Container extends BlockEntity, BlockInventoryHolder {
|
||||
}
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
package com.dfsek.terra.api.block.entity;
|
||||
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
|
||||
|
||||
public interface MobSpawner extends BlockEntity {
|
||||
EntityType getSpawnedType();
|
||||
|
||||
|
||||
void setSpawnedType(@NotNull EntityType creatureType);
|
||||
|
||||
|
||||
int getDelay();
|
||||
|
||||
|
||||
void setDelay(int delay);
|
||||
|
||||
|
||||
int getMinSpawnDelay();
|
||||
|
||||
|
||||
void setMinSpawnDelay(int delay);
|
||||
|
||||
|
||||
int getMaxSpawnDelay();
|
||||
|
||||
|
||||
void setMaxSpawnDelay(int delay);
|
||||
|
||||
|
||||
int getSpawnCount();
|
||||
|
||||
|
||||
void setSpawnCount(int spawnCount);
|
||||
|
||||
|
||||
int getMaxNearbyEntities();
|
||||
|
||||
|
||||
void setMaxNearbyEntities(int maxNearbyEntities);
|
||||
|
||||
|
||||
int getRequiredPlayerRange();
|
||||
|
||||
|
||||
void setRequiredPlayerRange(int requiredPlayerRange);
|
||||
|
||||
|
||||
int getSpawnRange();
|
||||
|
||||
|
||||
void setSpawnRange(int spawnRange);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.dfsek.terra.api.block.entity;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SerialState {
|
||||
protected final Map<String, Property<?>> properties = new HashMap<>();
|
||||
|
||||
|
||||
public SerialState() {
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, String> parse(String props) {
|
||||
String[] sep = props.split(",");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
@@ -17,51 +18,7 @@ public class SerialState {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void checkExists(String prop) {
|
||||
if(!properties.containsKey(prop)) throw new IllegalArgumentException("No such property \"" + prop + "\"");
|
||||
}
|
||||
|
||||
private void checkType(Class<?> clazz, Object o, String id) {
|
||||
if(!clazz.isInstance(o))
|
||||
throw new IllegalArgumentException("Invalid data for property " + id + ": " + o);
|
||||
}
|
||||
|
||||
public void setProperty(String id, Object value) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(prop.getValueClass(), value, id);
|
||||
prop.setValue(value);
|
||||
}
|
||||
|
||||
public int getInteger(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(Integer.class, prop.getValue(), id);
|
||||
return (Integer) prop.getValue();
|
||||
}
|
||||
|
||||
public String getString(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(String.class, prop.getValue(), id);
|
||||
return (String) prop.getValue();
|
||||
}
|
||||
|
||||
public long getLong(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(Long.class, prop.getValue(), id);
|
||||
return (Long) prop.getValue();
|
||||
}
|
||||
|
||||
public boolean getBoolean(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(Boolean.class, prop.getValue(), id);
|
||||
return (Boolean) prop.getValue();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(String id, Class<T> clazz) {
|
||||
checkExists(id);
|
||||
@@ -69,24 +26,69 @@ public class SerialState {
|
||||
checkType(clazz, prop.getValue(), id);
|
||||
return (T) prop.getValue();
|
||||
}
|
||||
|
||||
|
||||
private void checkExists(String prop) {
|
||||
if(!properties.containsKey(prop)) throw new IllegalArgumentException("No such property \"" + prop + "\"");
|
||||
}
|
||||
|
||||
private void checkType(Class<?> clazz, Object o, String id) {
|
||||
if(!clazz.isInstance(o))
|
||||
throw new IllegalArgumentException("Invalid data for property " + id + ": " + o);
|
||||
}
|
||||
|
||||
public void setProperty(String id, Object value) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(prop.getValueClass(), value, id);
|
||||
prop.setValue(value);
|
||||
}
|
||||
|
||||
public int getInteger(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(Integer.class, prop.getValue(), id);
|
||||
return (Integer) prop.getValue();
|
||||
}
|
||||
|
||||
public String getString(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(String.class, prop.getValue(), id);
|
||||
return (String) prop.getValue();
|
||||
}
|
||||
|
||||
public long getLong(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(Long.class, prop.getValue(), id);
|
||||
return (Long) prop.getValue();
|
||||
}
|
||||
|
||||
public boolean getBoolean(String id) {
|
||||
checkExists(id);
|
||||
Property<?> prop = properties.get(id);
|
||||
checkType(Boolean.class, prop.getValue(), id);
|
||||
return (Boolean) prop.getValue();
|
||||
}
|
||||
|
||||
|
||||
protected static class Property<T> {
|
||||
private final Class<T> clazz;
|
||||
private Object value;
|
||||
|
||||
|
||||
public Property(Class<T> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
|
||||
public Class<T> getValueClass() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getValue() {
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.dfsek.terra.api.block.entity;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public interface Sign extends BlockEntity {
|
||||
@NotNull String[] getLines();
|
||||
|
||||
@NotNull String getLine(int index) throws IndexOutOfBoundsException;
|
||||
|
||||
void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException;
|
||||
|
||||
@NotNull String[] getLines();
|
||||
|
||||
@NotNull String getLine(int index) throws IndexOutOfBoundsException;
|
||||
}
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
package com.dfsek.terra.api.block.state;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface BlockState extends Cloneable, Handle {
|
||||
|
||||
BlockType getBlockType();
|
||||
|
||||
|
||||
boolean matches(BlockState other);
|
||||
|
||||
|
||||
BlockState clone();
|
||||
|
||||
String getAsString();
|
||||
|
||||
boolean isAir();
|
||||
|
||||
boolean isStructureVoid();
|
||||
|
||||
|
||||
<T> boolean has(Property<T> property);
|
||||
|
||||
|
||||
<T> T get(Property<T> property);
|
||||
|
||||
|
||||
<T> BlockState set(Property<T> property, T value);
|
||||
|
||||
default <T> BlockState setIfPresent(Property<T> property, T value) {
|
||||
if(has(property)) set(property, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
default <T> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
|
||||
if(has(property)) action.accept(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
default <T> BlockState setIfPresent(Property<T> property, T value) {
|
||||
if(has(property)) set(property, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockType getBlockType();
|
||||
|
||||
String getAsString();
|
||||
|
||||
boolean isAir();
|
||||
|
||||
boolean isStructureVoid();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.dfsek.terra.api.block.state.properties;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public interface Property<T> {
|
||||
Class<T> getType();
|
||||
|
||||
String getName();
|
||||
|
||||
Collection<T> values();
|
||||
|
||||
Class<T> getType();
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
package com.dfsek.terra.api.block.state.properties.base;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
|
||||
public interface BooleanProperty extends Property<Boolean> {
|
||||
static BooleanProperty of(String name) {
|
||||
return new BooleanProperty() {
|
||||
private static final Collection<Boolean> BOOLEANS = Arrays.asList(true, false);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Boolean> values() {
|
||||
return BOOLEANS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
default Class<Boolean> getType() {
|
||||
return Boolean.class;
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
package com.dfsek.terra.api.block.state.properties.base;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface EnumProperty<T extends Enum<T>> extends Property<T> {
|
||||
static <T extends Enum<T>> EnumProperty<T> of(String name, Class<T> clazz) {
|
||||
return new EnumProperty<T>() {
|
||||
private final Lazy<Collection<T>> constants = Lazy.lazy(() -> Arrays.asList(clazz.getEnumConstants()));
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<T> values() {
|
||||
return constants.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.api.block.state.properties.base;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
|
||||
|
||||
public interface IntProperty extends Property<Integer> {
|
||||
static IntProperty of(String name, int min, int max) {
|
||||
return new IntProperty() {
|
||||
@@ -17,19 +18,19 @@ public interface IntProperty extends Property<Integer> {
|
||||
}
|
||||
return ints;
|
||||
});
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Integer> values() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
default Class<Integer> getType() {
|
||||
return Integer.class;
|
||||
|
||||
@@ -7,30 +7,31 @@ 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;
|
||||
|
||||
|
||||
public final class Properties {
|
||||
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("facing", Direction.class);
|
||||
public static final EnumProperty<Axis> AXIS = EnumProperty.of("axis", Axis.class);
|
||||
|
||||
|
||||
public static final BooleanProperty NORTH = BooleanProperty.of("north");
|
||||
public static final BooleanProperty SOUTH = BooleanProperty.of("south");
|
||||
public static final BooleanProperty EAST = BooleanProperty.of("east");
|
||||
public static final BooleanProperty WEST = BooleanProperty.of("west");
|
||||
|
||||
|
||||
public static final EnumProperty<WallHeight> NORTH_HEIGHT = EnumProperty.of("north", WallHeight.class);
|
||||
public static final EnumProperty<WallHeight> SOUTH_HEIGHT = EnumProperty.of("south", WallHeight.class);
|
||||
public static final EnumProperty<WallHeight> EAST_HEIGHT = EnumProperty.of("east", WallHeight.class);
|
||||
public static final EnumProperty<WallHeight> WEST_HEIGHT = EnumProperty.of("west", WallHeight.class);
|
||||
|
||||
|
||||
public static final EnumProperty<RedstoneConnection> NORTH_CONNECTION = EnumProperty.of("north", RedstoneConnection.class);
|
||||
public static final EnumProperty<RedstoneConnection> SOUTH_CONNECTION = EnumProperty.of("south", RedstoneConnection.class);
|
||||
public static final EnumProperty<RedstoneConnection> EAST_CONNECTION = EnumProperty.of("east", RedstoneConnection.class);
|
||||
public static final EnumProperty<RedstoneConnection> WEST_CONNECTION = EnumProperty.of("west", RedstoneConnection.class);
|
||||
|
||||
|
||||
|
||||
|
||||
public static final EnumProperty<RailShape> RAIL_SHAPE = EnumProperty.of("shape", RailShape.class);
|
||||
public static final EnumProperty<Half> HALF = EnumProperty.of("half", Half.class);
|
||||
|
||||
|
||||
public static final IntProperty ROTATION = IntProperty.of("rotation", 0, 15);
|
||||
|
||||
|
||||
public static final BooleanProperty WATERLOGGED = BooleanProperty.of("waterlogged");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api.block.state.properties.enums;
|
||||
|
||||
public enum Axis {
|
||||
X, Y, Z
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.api.block.state.properties.enums;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
|
||||
|
||||
public enum Direction {
|
||||
NORTH(0, 0, 0, -1),
|
||||
EAST(1, 1, 0, 0),
|
||||
@@ -10,22 +11,22 @@ public enum Direction {
|
||||
WEST(3, -1, 0, 0),
|
||||
UP(-1, 0, 1, 0),
|
||||
DOWN(-1, 0, -1, 0);
|
||||
|
||||
private static final Direction[] rotations = Construct.construct(() -> new Direction[] {NORTH, SOUTH, EAST, WEST});
|
||||
|
||||
|
||||
private static final Direction[] rotations = Construct.construct(() -> new Direction[]{ NORTH, SOUTH, EAST, WEST });
|
||||
|
||||
private final int rotation;
|
||||
|
||||
|
||||
private final int modX;
|
||||
private final int modY;
|
||||
private final int modZ;
|
||||
|
||||
|
||||
Direction(int rotation, int modX, int modY, int modZ) {
|
||||
this.rotation = rotation;
|
||||
this.modX = modX;
|
||||
this.modY = modY;
|
||||
this.modZ = modZ;
|
||||
}
|
||||
|
||||
|
||||
public Direction rotate(Rotation rotation) {
|
||||
switch(this) {
|
||||
case UP:
|
||||
@@ -35,19 +36,7 @@ public enum Direction {
|
||||
return rotations[(this.rotation + rotation.getDegrees() / 90) % 4];
|
||||
}
|
||||
}
|
||||
|
||||
public int getModX() {
|
||||
return modX;
|
||||
}
|
||||
|
||||
public int getModY() {
|
||||
return modY;
|
||||
}
|
||||
|
||||
public int getModZ() {
|
||||
return modZ;
|
||||
}
|
||||
|
||||
|
||||
public Direction opposite() {
|
||||
switch(this) {
|
||||
case DOWN:
|
||||
@@ -63,7 +52,19 @@ public enum Direction {
|
||||
case SOUTH:
|
||||
return NORTH;
|
||||
}
|
||||
|
||||
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public int getModX() {
|
||||
return modX;
|
||||
}
|
||||
|
||||
public int getModY() {
|
||||
return modY;
|
||||
}
|
||||
|
||||
public int getModZ() {
|
||||
return modZ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public enum Half {
|
||||
* The bottom half of the block, normally with the lower y coordinate.
|
||||
*/
|
||||
BOTTOM,
|
||||
|
||||
|
||||
/**
|
||||
* Some blocks, e.g. slabs, can occupy both halves.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api.block.state.properties.enums;
|
||||
|
||||
public enum RedstoneConnection {
|
||||
NONE, SIDE, UP
|
||||
NONE,
|
||||
SIDE,
|
||||
UP
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api.block.state.properties.enums;
|
||||
|
||||
public enum WallHeight {
|
||||
LOW, NONE, TALL
|
||||
LOW,
|
||||
NONE,
|
||||
TALL
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package com.dfsek.terra.api.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommandManager {
|
||||
void execute(String command, CommandSender sender, List<String> args) throws CommandException;
|
||||
|
||||
|
||||
void register(String name, Class<? extends CommandTemplate> clazz) throws MalformedCommandException;
|
||||
|
||||
|
||||
List<String> tabComplete(String command, CommandSender sender, List<String> args) throws CommandException;
|
||||
|
||||
|
||||
int getMaxArgumentDepth();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.command;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public interface CommandTemplate {
|
||||
void execute(CommandSender sender);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package com.dfsek.terra.api.command.annotation;
|
||||
|
||||
import com.dfsek.terra.api.command.arg.ArgumentParser;
|
||||
import com.dfsek.terra.api.command.arg.StringArgumentParser;
|
||||
import com.dfsek.terra.api.command.tab.NothingCompleter;
|
||||
import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.dfsek.terra.api.command.arg.ArgumentParser;
|
||||
import com.dfsek.terra.api.command.arg.StringArgumentParser;
|
||||
import com.dfsek.terra.api.command.tab.NothingCompleter;
|
||||
import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
|
||||
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Argument {
|
||||
String value();
|
||||
|
||||
|
||||
boolean required() default true;
|
||||
|
||||
|
||||
Class<? extends TabCompleter> tabCompleter() default NothingCompleter.class;
|
||||
|
||||
|
||||
Class<? extends ArgumentParser<?>> argumentParser() default StringArgumentParser.class;
|
||||
|
||||
|
||||
String defaultValue() default "";
|
||||
}
|
||||
|
||||
@@ -5,14 +5,15 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Command {
|
||||
Argument[] arguments() default {};
|
||||
|
||||
Switch[] switches() default {};
|
||||
|
||||
Subcommand[] subcommands() default {};
|
||||
|
||||
Argument[] arguments() default { };
|
||||
|
||||
Switch[] switches() default { };
|
||||
|
||||
Subcommand[] subcommands() default { };
|
||||
|
||||
String usage() default "";
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package com.dfsek.terra.api.command.annotation;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
public @interface Subcommand {
|
||||
String value();
|
||||
|
||||
String[] aliases() default {};
|
||||
|
||||
|
||||
String[] aliases() default { };
|
||||
|
||||
Class<? extends CommandTemplate> clazz();
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
public @interface Switch {
|
||||
String value();
|
||||
|
||||
String[] aliases() default {};
|
||||
|
||||
String[] aliases() default { };
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ArgumentTarget {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface SwitchTarget {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Command may only be executed with debug mode enabled.
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Marks command as player-only
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Command may only be executed in a Terra world.
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.command.arg;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public interface ArgumentParser<T> {
|
||||
T parse(CommandSender sender, String arg);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.command.arg;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public class DoubleArgumentParser implements ArgumentParser<Double> {
|
||||
@Override
|
||||
public Double parse(CommandSender sender, String arg) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.command.arg;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public class IntegerArgumentParser implements ArgumentParser<Integer> {
|
||||
@Override
|
||||
public Integer parse(CommandSender sender, String arg) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.command.arg;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public class StringArgumentParser implements ArgumentParser<String> {
|
||||
@Override
|
||||
public String parse(CommandSender sender, String arg) {
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.dfsek.terra.api.command.exception;
|
||||
|
||||
public abstract class CommandException extends Exception {
|
||||
private static final long serialVersionUID = -2955328495045879822L;
|
||||
|
||||
|
||||
public CommandException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public CommandException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.dfsek.terra.api.command.exception;
|
||||
|
||||
public class ExecutionException extends CommandException {
|
||||
private static final long serialVersionUID = -6345523475880607959L;
|
||||
|
||||
|
||||
public ExecutionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public ExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.dfsek.terra.api.command.exception;
|
||||
|
||||
public class InvalidArgumentsException extends CommandException {
|
||||
private static final long serialVersionUID = 7563619667472569824L;
|
||||
|
||||
|
||||
public InvalidArgumentsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public InvalidArgumentsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ package com.dfsek.terra.api.command.exception;
|
||||
*/
|
||||
public class MalformedCommandException extends CommandException {
|
||||
private static final long serialVersionUID = -5417760860407895496L;
|
||||
|
||||
|
||||
public MalformedCommandException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public MalformedCommandException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.dfsek.terra.api.command.exception;
|
||||
|
||||
public class SwitchFormatException extends CommandException {
|
||||
private static final long serialVersionUID = -965858989317844628L;
|
||||
|
||||
|
||||
public SwitchFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public SwitchFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.dfsek.terra.api.command.tab;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public class NothingCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.dfsek.terra.api.command.tab;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TabCompleter {
|
||||
List<String> complete(CommandSender sender);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.dfsek.terra.api.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
import com.dfsek.terra.api.StringIdentifiable;
|
||||
|
||||
|
||||
public interface AbstractableTemplate extends ConfigTemplate, StringIdentifiable {
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.dfsek.terra.api.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
|
||||
public interface ConfigFactory<C extends ConfigTemplate, O> {
|
||||
O build(C config, TerraPlugin main) throws LoadException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.dfsek.terra.api.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.StringIdentifiable;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
@@ -13,52 +18,49 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.ChunkGeneratorProvider;
|
||||
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolder, StringIdentifiable {
|
||||
WorldConfig toWorldConfig(World world);
|
||||
|
||||
void registerConfigType(ConfigType<?, ?> type, String id, int priority);
|
||||
|
||||
Set<TerraAddon> addons();
|
||||
|
||||
boolean vanillaMobs();
|
||||
|
||||
boolean vanillaStructures();
|
||||
|
||||
boolean vanillaCaves();
|
||||
|
||||
boolean disableStructures();
|
||||
|
||||
boolean doBetaCarvers();
|
||||
|
||||
boolean vanillaFlora();
|
||||
|
||||
BiomeProvider getBiomeProviderBuilder();
|
||||
|
||||
|
||||
<T> CheckedRegistry<T> getOrCreateRegistry(Type clazz);
|
||||
|
||||
default <T> CheckedRegistry<T> getOrCreateRegistry(Class<T> clazz) {
|
||||
return getOrCreateRegistry((Type) clazz);
|
||||
}
|
||||
|
||||
|
||||
default <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> type) {
|
||||
return getOrCreateRegistry(type.getType());
|
||||
}
|
||||
|
||||
WorldConfig toWorldConfig(World world);
|
||||
|
||||
|
||||
List<GenerationStageProvider> getStages();
|
||||
|
||||
void registerConfigType(ConfigType<?, ?> type, String id, int priority);
|
||||
|
||||
|
||||
Loader getLoader();
|
||||
|
||||
Set<TerraAddon> addons();
|
||||
|
||||
|
||||
String getAuthor();
|
||||
|
||||
|
||||
String getVersion();
|
||||
|
||||
boolean vanillaMobs();
|
||||
|
||||
boolean vanillaStructures();
|
||||
|
||||
boolean vanillaCaves();
|
||||
|
||||
boolean disableStructures();
|
||||
|
||||
|
||||
Map<String, String> getLocatable();
|
||||
|
||||
boolean doBetaCarvers();
|
||||
|
||||
boolean vanillaFlora();
|
||||
|
||||
|
||||
RegistryFactory getRegistryFactory();
|
||||
|
||||
|
||||
ChunkGeneratorProvider getGeneratorProvider();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package com.dfsek.terra.api.config;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface ConfigType<T extends AbstractableTemplate, R> {
|
||||
T getTemplate(ConfigPack pack, TerraPlugin main);
|
||||
|
||||
ConfigFactory<T, R> getFactory();
|
||||
|
||||
TypeKey<R> getTypeKey();
|
||||
|
||||
Supplier<OpenRegistry<R>> registrySupplier(ConfigPack pack);
|
||||
|
||||
T getTemplate(ConfigPack pack, TerraPlugin main);
|
||||
|
||||
ConfigFactory<T, R> getFactory();
|
||||
|
||||
TypeKey<R> getTypeKey();
|
||||
}
|
||||
|
||||
@@ -9,20 +9,22 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public interface Loader {
|
||||
|
||||
|
||||
Loader thenNames(Consumer<List<String>> consumer) throws ConfigException;
|
||||
|
||||
|
||||
Loader thenEntries(Consumer<Set<Map.Entry<String, InputStream>>> consumer) throws ConfigException;
|
||||
|
||||
|
||||
/**
|
||||
* Get a single file from this Loader.
|
||||
*
|
||||
* @param singleFile File to get
|
||||
*
|
||||
* @return InputStream from file.
|
||||
*/
|
||||
InputStream get(String singleFile) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Open a subdirectory.
|
||||
*
|
||||
@@ -30,7 +32,7 @@ public interface Loader {
|
||||
* @param extension
|
||||
*/
|
||||
Loader open(String directory, String extension);
|
||||
|
||||
|
||||
/**
|
||||
* Close all InputStreams opened.
|
||||
*/
|
||||
|
||||
@@ -2,34 +2,35 @@ package com.dfsek.terra.api.config;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
|
||||
public interface PluginConfig {
|
||||
void load(TerraPlugin main);
|
||||
|
||||
String getLanguage();
|
||||
|
||||
boolean isDebugCommands();
|
||||
|
||||
boolean isDebugLogging();
|
||||
|
||||
boolean isDebugProfiler();
|
||||
|
||||
boolean isDebugScript();
|
||||
|
||||
long getDataSaveInterval();
|
||||
|
||||
int getBiomeSearchResolution();
|
||||
|
||||
int getCarverCacheSize();
|
||||
|
||||
int getStructureCache();
|
||||
|
||||
int getSamplerCache();
|
||||
|
||||
int getMaxRecursion();
|
||||
|
||||
int getBiomeCache();
|
||||
|
||||
int getProviderCache();
|
||||
|
||||
|
||||
boolean dumpDefaultConfig();
|
||||
|
||||
String getLanguage();
|
||||
|
||||
boolean isDebugCommands();
|
||||
|
||||
boolean isDebugLogging();
|
||||
|
||||
boolean isDebugProfiler();
|
||||
|
||||
boolean isDebugScript();
|
||||
|
||||
long getDataSaveInterval();
|
||||
|
||||
int getBiomeSearchResolution();
|
||||
|
||||
int getCarverCacheSize();
|
||||
|
||||
int getStructureCache();
|
||||
|
||||
int getSamplerCache();
|
||||
|
||||
int getMaxRecursion();
|
||||
|
||||
int getBiomeCache();
|
||||
|
||||
int getProviderCache();
|
||||
}
|
||||
|
||||
@@ -1,41 +1,42 @@
|
||||
package com.dfsek.terra.api.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.StringIdentifiable;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.SamplerCache;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface WorldConfig extends StringIdentifiable {
|
||||
<T> Registry<T> getRegistry(Class<T> clazz);
|
||||
|
||||
World getWorld();
|
||||
|
||||
SamplerCache getSamplerCache();
|
||||
|
||||
BiomeProvider getProvider();
|
||||
|
||||
ConfigPack getPack();
|
||||
|
||||
int elevationBlend();
|
||||
|
||||
|
||||
boolean disableTrees();
|
||||
|
||||
|
||||
boolean disableCarving();
|
||||
|
||||
|
||||
boolean disableOres();
|
||||
|
||||
|
||||
boolean disableFlora();
|
||||
|
||||
|
||||
boolean disableStructures();
|
||||
|
||||
|
||||
<T> Registry<T> getRegistry(Class<T> clazz);
|
||||
|
||||
World getWorld();
|
||||
|
||||
SamplerCache getSamplerCache();
|
||||
|
||||
BiomeProvider getProvider();
|
||||
|
||||
ConfigPack getPack();
|
||||
|
||||
String getAuthor();
|
||||
|
||||
|
||||
String getVersion();
|
||||
|
||||
|
||||
Map<String, String> getLocatable();
|
||||
|
||||
|
||||
boolean isDisableSaplings();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface Meta {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.entity;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
public interface CommandSender extends Handle {
|
||||
void sendMessage(String message);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.dfsek.terra.api.entity;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
public interface Entity extends Handle, CommandSender {
|
||||
|
||||
public interface Entity extends CommandSender {
|
||||
Vector3 position();
|
||||
|
||||
|
||||
void position(Vector3 position);
|
||||
|
||||
|
||||
void world(World world);
|
||||
|
||||
|
||||
World world();
|
||||
}
|
||||
|
||||
@@ -2,5 +2,6 @@ package com.dfsek.terra.api.entity;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
public interface EntityType extends Handle {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.event;
|
||||
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
|
||||
public interface EventHandler {
|
||||
void handle(Event event);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.dfsek.terra.api.event;
|
||||
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.functional.EventContext;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
/**
|
||||
* Manages event registration and triggering.
|
||||
@@ -14,8 +13,8 @@ public interface EventManager {
|
||||
* @param event Event to pass to all registered EventListeners.
|
||||
*/
|
||||
void callEvent(Event event);
|
||||
|
||||
|
||||
<T extends EventHandler> void registerHandler(Class<T> clazz, T handler);
|
||||
|
||||
|
||||
<T extends EventHandler> T getHandler(Class<T> clazz);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,18 @@ package com.dfsek.terra.api.event.events;
|
||||
|
||||
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class containing basic {@link Cancellable} implementation.
|
||||
*/
|
||||
public abstract class AbstractCancellable implements Cancellable {
|
||||
private final MutableBoolean cancelled = new MutableBoolean(false);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled.get();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled.set(cancelled);
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface Cancellable extends Event {
|
||||
* @return Whether event is cancelled.
|
||||
*/
|
||||
boolean isCancelled();
|
||||
|
||||
|
||||
/**
|
||||
* Set the cancellation status of the event.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.event.events;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
|
||||
|
||||
/**
|
||||
* An event with functionality directly linked to a {@link ConfigPack}.
|
||||
* <p>
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Fired when a pack is searched for {@link Configuration}s.
|
||||
@@ -18,25 +19,25 @@ import java.util.function.Consumer;
|
||||
public class ConfigurationDiscoveryEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigPack pack;
|
||||
private final Loader loader;
|
||||
|
||||
|
||||
private final BiConsumer<String, Configuration> consumer;
|
||||
|
||||
|
||||
public ConfigurationDiscoveryEvent(ConfigPack pack, Loader loader, BiConsumer<String, Configuration> consumer) {
|
||||
this.pack = pack;
|
||||
this.loader = loader;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
|
||||
public void register(String identifier, Configuration config) {
|
||||
consumer.accept(identifier, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
|
||||
public Loader getLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
public void register(String identifier, Configuration config) {
|
||||
consumer.accept(identifier, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@ package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfiguration;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Fired when each individual configuration is loaded.
|
||||
@@ -21,46 +23,49 @@ public class ConfigurationLoadEvent implements PackEvent, FailThroughEvent {
|
||||
private final AbstractConfiguration configuration;
|
||||
private final Consumer<ConfigTemplate> loader;
|
||||
private final ConfigType<?, ?> type;
|
||||
|
||||
|
||||
private final Object loaded;
|
||||
|
||||
public ConfigurationLoadEvent(ConfigPack pack, AbstractConfiguration configuration, Consumer<ConfigTemplate> loader, ConfigType<?, ?> type, Object loaded) {
|
||||
|
||||
public ConfigurationLoadEvent(ConfigPack pack, AbstractConfiguration configuration, Consumer<ConfigTemplate> loader,
|
||||
ConfigType<?, ?> type, Object loaded) {
|
||||
this.pack = pack;
|
||||
this.configuration = configuration;
|
||||
this.loader = loader;
|
||||
this.type = type;
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public AbstractConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
||||
public <T extends ConfigTemplate> T load(T template) {
|
||||
loader.accept(template);
|
||||
return template;
|
||||
}
|
||||
|
||||
public ConfigType<?, ?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public boolean is(Class<?> clazz) {
|
||||
return clazz.isAssignableFrom(type.getTypeKey().getRawType());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public AbstractConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public ConfigType<?, ?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getLoadedObject(Class<T> clazz) {
|
||||
if(!clazz.isAssignableFrom(type.getTypeKey().getRawType()))
|
||||
throw new ClassCastException("Cannot assign object from loader of type " + ReflectionUtil.typeToString(type.getTypeKey().getType()) + " to class " + clazz.getCanonicalName());
|
||||
throw new ClassCastException(
|
||||
"Cannot assign object from loader of type " + ReflectionUtil.typeToString(type.getTypeKey().getType()) + " to class " +
|
||||
clazz.getCanonicalName());
|
||||
return (T) loaded;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getLoadedObject() {
|
||||
return (T) loaded;
|
||||
|
||||
@@ -2,27 +2,24 @@ package com.dfsek.terra.api.event.events.config.pack;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
|
||||
/**
|
||||
* An event related to the loading process of config packs.
|
||||
*/
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigPack pack;
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
|
||||
|
||||
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||
this.pack = pack;
|
||||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||
*
|
||||
@@ -31,7 +28,12 @@ public abstract class ConfigPackLoadEvent implements PackEvent, FailThroughEvent
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||
void accept(T value) throws ConfigException;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.api.event.events.config.pack;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
|
||||
|
||||
/**
|
||||
* Called when a config pack has finished loading.
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.api.event.events.config.pack;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
|
||||
|
||||
/**
|
||||
* Called before a config pack's registries are filled.
|
||||
*/
|
||||
|
||||
@@ -7,31 +7,34 @@ import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
|
||||
|
||||
public abstract class ConfigTypeLoadEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigType<?, ?> type;
|
||||
private final CheckedRegistry<?> registry;
|
||||
|
||||
|
||||
private final ConfigPack pack;
|
||||
|
||||
|
||||
public ConfigTypeLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||
this.type = type;
|
||||
this.registry = registry;
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
|
||||
public boolean is(Class<?> clazz) {
|
||||
return clazz.isAssignableFrom(type.getTypeKey().getRawType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public boolean is(Class<?> clazz) {
|
||||
return clazz.isAssignableFrom(type.getTypeKey().getRawType());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> CheckedRegistry<T> getRegistry(Class<T> clazz) {
|
||||
if(!clazz.isAssignableFrom(type.getTypeKey().getRawType()))
|
||||
throw new ClassCastException("Cannot assign object from loader of type " + ReflectionUtil.typeToString(type.getTypeKey().getType()) + " to class " + clazz.getCanonicalName());
|
||||
throw new ClassCastException(
|
||||
"Cannot assign object from loader of type " + ReflectionUtil.typeToString(type.getTypeKey().getType()) + " to class " +
|
||||
clazz.getCanonicalName());
|
||||
return (CheckedRegistry<T>) registry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
|
||||
|
||||
public class ConfigTypePostLoadEvent extends ConfigTypeLoadEvent {
|
||||
public ConfigTypePostLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||
super(type, registry, pack);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
|
||||
|
||||
public class ConfigTypePreLoadEvent extends ConfigTypeLoadEvent {
|
||||
public ConfigTypePreLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
|
||||
super(type, registry, pack);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.event.events.platform;
|
||||
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
|
||||
/**
|
||||
* Called when the platform is initialized.
|
||||
*/
|
||||
|
||||
@@ -4,23 +4,24 @@ import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Called when an entity is spawned.
|
||||
*/
|
||||
public class EntitySpawnEvent implements PackEvent {
|
||||
private final ConfigPack pack;
|
||||
private final Entity entity;
|
||||
|
||||
|
||||
public EntitySpawnEvent(ConfigPack pack, Entity entity) {
|
||||
this.pack = pack;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the entity that triggered the event.
|
||||
*
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
package com.dfsek.terra.api.event.events.world.generation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.AbstractCancellable;
|
||||
import com.dfsek.terra.api.event.events.Cancellable;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* Called when loot is populated.
|
||||
*/
|
||||
public class LootPopulateEvent extends AbstractCancellable implements PackEvent, Cancellable {
|
||||
public class LootPopulateEvent extends AbstractCancellable implements PackEvent {
|
||||
private final Container container;
|
||||
private final ConfigPack pack;
|
||||
private final Structure structure;
|
||||
private LootTable table;
|
||||
|
||||
|
||||
public LootPopulateEvent(Container container, LootTable table, ConfigPack pack, Structure structure) {
|
||||
this.container = container;
|
||||
this.table = table;
|
||||
this.pack = pack;
|
||||
this.structure = structure;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
|
||||
public Vector3 getPosition() {
|
||||
return container.getPosition();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the {@link Container} representing the inventory.
|
||||
*
|
||||
@@ -43,7 +44,7 @@ public class LootPopulateEvent extends AbstractCancellable implements PackEvent,
|
||||
public Container getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the loot table to be populated.
|
||||
*
|
||||
@@ -52,7 +53,7 @@ public class LootPopulateEvent extends AbstractCancellable implements PackEvent,
|
||||
public LootTable getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the loot table to be populated.
|
||||
*
|
||||
@@ -61,7 +62,7 @@ public class LootPopulateEvent extends AbstractCancellable implements PackEvent,
|
||||
public void setTable(@NotNull LootTable table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the script used to generate the structure.
|
||||
*
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.dfsek.terra.api.event.functional;
|
||||
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
|
||||
public interface EventContext<T extends Event> {
|
||||
EventContext<T> then(Consumer<T> action);
|
||||
|
||||
|
||||
EventContext<T> priority(int priority);
|
||||
|
||||
|
||||
EventContext<T> failThrough();
|
||||
|
||||
|
||||
EventContext<T> global();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import com.dfsek.terra.api.event.EventHandler;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
public interface FunctionalEventHandler extends EventHandler {
|
||||
<T extends Event> EventContext<T> register(TerraAddon addon, Class<T> clazz);
|
||||
|
||||
|
||||
<T extends Event> EventContext<T> register(TerraAddon addon, TypeKey<T> clazz);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.dfsek.terra.api.handle;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ItemHandle {
|
||||
|
||||
|
||||
Item createItem(String data);
|
||||
|
||||
|
||||
Enchantment getEnchantment(String id);
|
||||
|
||||
|
||||
Set<Enchantment> getEnchantments();
|
||||
}
|
||||
|
||||
@@ -7,22 +7,24 @@ import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
|
||||
/**
|
||||
* Interface to be implemented for world manipulation.
|
||||
*/
|
||||
public interface WorldHandle {
|
||||
BlockState createBlockData(String data);
|
||||
|
||||
|
||||
BlockState air();
|
||||
|
||||
EntityType getEntity(String id);
|
||||
|
||||
|
||||
BlockEntity createBlockEntity(Vector3 location, BlockState block, String snbt);
|
||||
|
||||
|
||||
EntityType getEntity(String id);
|
||||
|
||||
/**
|
||||
* Get the locations selected by a player. (Usually via WorldEdit)
|
||||
*
|
||||
* @param player Player to get locations for
|
||||
*
|
||||
* @return Pair of locations.
|
||||
*/
|
||||
default Pair<Vector3, Vector3> getSelectedLocation(Player player) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.api.injection;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.injection.exception.InjectionException;
|
||||
|
||||
|
||||
/**
|
||||
* Dynamic dependency injector.
|
||||
* <p>
|
||||
@@ -17,7 +18,7 @@ public interface Injector<T> {
|
||||
* @param target Target class type.
|
||||
*/
|
||||
void addExplicitTarget(Class<? extends T> target);
|
||||
|
||||
|
||||
/**
|
||||
* Inject the stored object into an object.
|
||||
* <p>
|
||||
@@ -27,6 +28,7 @@ public interface Injector<T> {
|
||||
* ({@link #addExplicitTarget(Class)}.
|
||||
*
|
||||
* @param object Object to inject into
|
||||
*
|
||||
* @throws InjectionException If:
|
||||
* <ul>
|
||||
* <li>Matching field annotated with {@link Inject} is final</li>
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies that a field is a target for dependency injection.
|
||||
*/
|
||||
|
||||
@@ -2,16 +2,17 @@ package com.dfsek.terra.api.injection.exception;
|
||||
|
||||
import com.dfsek.terra.api.injection.Injector;
|
||||
|
||||
|
||||
/**
|
||||
* Thrown when dynamic dependency injection cannot be completed by an {@link Injector}.
|
||||
*/
|
||||
public class InjectionException extends Exception {
|
||||
private static final long serialVersionUID = -6929631447064215387L;
|
||||
|
||||
|
||||
public InjectionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public InjectionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.inventory;
|
||||
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
|
||||
public interface BlockInventoryHolder extends InventoryHolder {
|
||||
Vector3 getPosition();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.dfsek.terra.api.inventory;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
public interface Inventory extends Handle {
|
||||
int getSize();
|
||||
|
||||
ItemStack getItem(int slot);
|
||||
|
||||
void setItem(int slot, ItemStack newStack);
|
||||
|
||||
int getSize();
|
||||
|
||||
ItemStack getItem(int slot);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.inventory;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
public interface InventoryHolder extends Handle {
|
||||
Inventory getInventory();
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ package com.dfsek.terra.api.inventory;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
/**
|
||||
* An inventory item.
|
||||
*/
|
||||
public interface Item extends Handle {
|
||||
ItemStack newItemStack(int amount);
|
||||
|
||||
|
||||
double getMaxDurability();
|
||||
}
|
||||
|
||||
@@ -4,17 +4,18 @@ import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.inventory.item.Damageable;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
|
||||
public interface ItemStack extends Handle {
|
||||
int getAmount();
|
||||
|
||||
|
||||
void setAmount(int i);
|
||||
|
||||
|
||||
Item getType();
|
||||
|
||||
|
||||
ItemMeta getItemMeta();
|
||||
|
||||
|
||||
void setItemMeta(ItemMeta meta);
|
||||
|
||||
|
||||
default boolean isDamageable() {
|
||||
return getItemMeta() instanceof Damageable;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.dfsek.terra.api.inventory.item;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
public interface Damageable extends Handle {
|
||||
int getDamage();
|
||||
|
||||
|
||||
void setDamage(int damage);
|
||||
|
||||
|
||||
boolean hasDamage();
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.dfsek.terra.api.inventory.item;
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
|
||||
public interface Enchantment extends Handle {
|
||||
boolean canEnchantItem(ItemStack itemStack);
|
||||
|
||||
String getID();
|
||||
|
||||
|
||||
boolean conflictsWith(Enchantment other);
|
||||
|
||||
|
||||
String getID();
|
||||
|
||||
int getMaxLevel();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.dfsek.terra.api.inventory.item;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ItemMeta extends Handle {
|
||||
Map<Enchantment, Integer> getEnchantments();
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
|
||||
public interface ItemMeta extends Handle {
|
||||
void addEnchantment(Enchantment enchantment, int level);
|
||||
|
||||
Map<Enchantment, Integer> getEnchantments();
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.dfsek.terra.api.lang;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public interface Language {
|
||||
void log(String messageID, Level level, Logger logger, String... args);
|
||||
|
||||
void send(String messageID, CommandSender sender, String... args);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Message getMessage(String id);
|
||||
|
||||
void log(String messageID, Level level, Logger logger, String... args);
|
||||
|
||||
void send(String messageID, CommandSender sender, String... args);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.dfsek.terra.api.lang;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
|
||||
|
||||
public interface Message {
|
||||
void log(Logger logger, Level level, String... args);
|
||||
|
||||
|
||||
void send(CommandSender sender, String... args);
|
||||
|
||||
|
||||
boolean isEmpty();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.dfsek.terra.api.noise;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
|
||||
public interface NoiseSampler {
|
||||
static NoiseSampler zero() {
|
||||
return new NoiseSampler() {
|
||||
@@ -11,23 +12,23 @@ public interface NoiseSampler {
|
||||
public double getNoiseSeeded(long seed, double x, double y) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getNoiseSeeded(long seed, double x, double y, double z) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
default double getNoiseSeeded(Vector3 vector3, long seed) {
|
||||
return getNoiseSeeded(seed, vector3.getX(), vector3.getY(), vector3.getZ());
|
||||
}
|
||||
|
||||
|
||||
default double getNoiseSeeded(Vector2 vector2, long seed) {
|
||||
return getNoiseSeeded(seed, vector2.getX(), vector2.getZ());
|
||||
}
|
||||
|
||||
|
||||
double getNoiseSeeded(long seed, double x, double y);
|
||||
|
||||
|
||||
double getNoiseSeeded(long seed, double x, double y, double z);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.dfsek.terra.api.profiler;
|
||||
|
||||
public class ProfileFrame implements AutoCloseable {
|
||||
private final Runnable action;
|
||||
|
||||
|
||||
public ProfileFrame(Runnable action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
action.run();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.profiler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface Profiler {
|
||||
/**
|
||||
* Push a frame to this profiler.
|
||||
@@ -9,7 +10,7 @@ public interface Profiler {
|
||||
* @param frame ID of frame.
|
||||
*/
|
||||
void push(String frame);
|
||||
|
||||
|
||||
/**
|
||||
* Pop a frame from this profiler.
|
||||
*
|
||||
@@ -17,40 +18,41 @@ public interface Profiler {
|
||||
* at the top of the profiler stack.
|
||||
*/
|
||||
void pop(String frame);
|
||||
|
||||
|
||||
/**
|
||||
* Start profiling.
|
||||
*/
|
||||
void start();
|
||||
|
||||
|
||||
/**
|
||||
* Stop profiling.
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Get the profiler data.
|
||||
*
|
||||
* @return Profiler data.
|
||||
*/
|
||||
Map<String, Timings> getTimings();
|
||||
|
||||
|
||||
/**
|
||||
* Return a {@link AutoCloseable} implementation that
|
||||
* may be used in a try-with-resources statement for
|
||||
* more intuitive profiling, with auto-push/pop.
|
||||
*
|
||||
* @param frame ID of frame.
|
||||
*
|
||||
* @return {@link AutoCloseable} implementation for use
|
||||
* in try-with-resources.
|
||||
* in try-with-resources.
|
||||
*/
|
||||
default ProfileFrame profile(String frame) {
|
||||
push(frame);
|
||||
return new ProfileFrame(() -> pop(frame));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the profiler data.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Get the profiler data.
|
||||
*
|
||||
* @return Profiler data.
|
||||
*/
|
||||
Map<String, Timings> getTimings();
|
||||
}
|
||||
|
||||
@@ -8,51 +8,49 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class Timings {
|
||||
private final Map<String, Timings> subItems = new HashMap<>();
|
||||
|
||||
|
||||
private final List<Long> timings = new ArrayList<>();
|
||||
|
||||
|
||||
public void addTime(long time) {
|
||||
timings.add(time);
|
||||
}
|
||||
|
||||
public List<Long> getTimings() {
|
||||
return timings;
|
||||
}
|
||||
|
||||
|
||||
public double average() {
|
||||
return (double) timings.stream().reduce(0L, Long::sum) / timings.size();
|
||||
}
|
||||
|
||||
|
||||
public long max() {
|
||||
return timings.stream().mapToLong(Long::longValue).max().orElse(0L);
|
||||
}
|
||||
|
||||
|
||||
public long min() {
|
||||
return timings.stream().mapToLong(Long::longValue).min().orElse(0L);
|
||||
}
|
||||
|
||||
|
||||
public double sum() {
|
||||
return timings.stream().mapToDouble(Long::doubleValue).sum();
|
||||
}
|
||||
|
||||
public Timings getSubItem(String id) {
|
||||
return subItems.computeIfAbsent(id, s -> new Timings());
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(1, this, Collections.emptySet());
|
||||
}
|
||||
|
||||
|
||||
private String toString(int indent, Timings parent, Set<Integer> branches) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
builder.append((double) min() / 1000000).append("ms min / ").append(average() / 1000000).append("ms avg / ")
|
||||
.append((double) max() / 1000000).append("ms max (").append(timings.size()).append(" samples, ")
|
||||
.append((sum() / parent.sum()) * 100).append("% of parent)");
|
||||
|
||||
.append((double) max() / 1000000).append("ms max (").append(timings.size()).append(" samples, ")
|
||||
.append((sum() / parent.sum()) * 100).append("% of parent)");
|
||||
|
||||
List<String> frames = new ArrayList<>();
|
||||
Set<Integer> newBranches = new HashSet<>(branches);
|
||||
newBranches.add(indent);
|
||||
subItems.forEach((id, timings) -> frames.add(id + ": " + timings.toString(indent + 1, this, newBranches)));
|
||||
|
||||
|
||||
for(int i = 0; i < frames.size(); i++) {
|
||||
builder.append('\n');
|
||||
for(int j = 0; j < indent; j++) {
|
||||
@@ -65,9 +63,12 @@ public class Timings {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(1, this, Collections.emptySet());
|
||||
|
||||
public List<Long> getTimings() {
|
||||
return timings;
|
||||
}
|
||||
|
||||
public Timings getSubItem(String id) {
|
||||
return subItems.computeIfAbsent(id, s -> new Timings());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,20 @@ package com.dfsek.terra.api.properties;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Context {
|
||||
private final Map<Class<? extends Properties>, Properties> map = new HashMap<>();
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Properties> T get(Class<T> clazz) {
|
||||
return (T) map.computeIfAbsent(clazz, k -> {
|
||||
throw new IllegalArgumentException("No properties registered for class " + clazz.getCanonicalName());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Context put(Properties properties) {
|
||||
if(map.containsKey(properties.getClass())) throw new IllegalArgumentException("Property for class " + properties.getClass().getCanonicalName() + " already registered.");
|
||||
if(map.containsKey(properties.getClass())) throw new IllegalArgumentException(
|
||||
"Property for class " + properties.getClass().getCanonicalName() + " already registered.");
|
||||
map.put(properties.getClass(), properties);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.api.properties.annotations;
|
||||
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies that this property holder shares properties
|
||||
* with the {@link #value()} holder.
|
||||
|
||||
@@ -2,16 +2,18 @@ package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
|
||||
|
||||
public interface CheckedRegistry<T> extends Registry<T> {
|
||||
/**
|
||||
* Add a value to this registry, checking whether it is present first.
|
||||
*
|
||||
* @param identifier Identifier to assign value.
|
||||
* @param value Value to register.
|
||||
*
|
||||
* @throws DuplicateEntryException If an entry with the same identifier is already present.
|
||||
*/
|
||||
void register(String identifier, T value) throws DuplicateEntryException;
|
||||
|
||||
|
||||
/**
|
||||
* Add a value to the registry, without checking presence beforehand.
|
||||
* <p>
|
||||
@@ -19,6 +21,7 @@ public interface CheckedRegistry<T> extends Registry<T> {
|
||||
*
|
||||
* @param identifier Identifier to assign value.
|
||||
* @param value Value to register.
|
||||
*
|
||||
* @deprecated Use of {@link #register(String, Object)} is encouraged.
|
||||
*/
|
||||
@Deprecated
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
|
||||
|
||||
public interface OpenRegistry<T> extends Registry<T> {
|
||||
/**
|
||||
* Add a value to this registry.
|
||||
@@ -10,16 +11,17 @@ public interface OpenRegistry<T> extends Registry<T> {
|
||||
* @param value Value to register.
|
||||
*/
|
||||
boolean register(String identifier, T value);
|
||||
|
||||
|
||||
/**
|
||||
* Add a value to this registry, checking whether it is present first.
|
||||
*
|
||||
* @param identifier Identifier to assign value.
|
||||
* @param value Value to register.
|
||||
*
|
||||
* @throws DuplicateEntryException If an entry with the same identifier is already present.
|
||||
*/
|
||||
void registerChecked(String identifier, T value) throws DuplicateEntryException;
|
||||
|
||||
|
||||
/**
|
||||
* Clears all entries from the registry.
|
||||
*/
|
||||
|
||||
@@ -7,44 +7,47 @@ import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public interface Registry<T> extends TypeLoader<T> {
|
||||
/**
|
||||
* Get a value from the registry.
|
||||
*
|
||||
* @param identifier Identifier of value.
|
||||
*
|
||||
* @return Value matching the identifier, {@code null} if no value is present.
|
||||
*/
|
||||
T get(String identifier);
|
||||
|
||||
|
||||
/**
|
||||
* Check if the registry contains a value.
|
||||
*
|
||||
* @param identifier Identifier of value.
|
||||
*
|
||||
* @return Whether the registry contains the value.
|
||||
*/
|
||||
boolean contains(String identifier);
|
||||
|
||||
|
||||
/**
|
||||
* Perform the given action for every value in the registry.
|
||||
*
|
||||
* @param consumer Action to perform on value.
|
||||
*/
|
||||
void forEach(Consumer<T> consumer);
|
||||
|
||||
|
||||
/**
|
||||
* Perform an action for every key-value pair in the registry.
|
||||
*
|
||||
* @param consumer Action to perform on pair.
|
||||
*/
|
||||
void forEach(BiConsumer<String, T> consumer);
|
||||
|
||||
|
||||
/**
|
||||
* Get the entries of this registry as a {@link Set}.
|
||||
*
|
||||
* @return Set containing all entries.
|
||||
*/
|
||||
Collection<T> entries();
|
||||
|
||||
|
||||
/**
|
||||
* Get all the keys in this registry.
|
||||
*
|
||||
|
||||
@@ -5,11 +5,11 @@ package com.dfsek.terra.api.registry.exception;
|
||||
*/
|
||||
public class DuplicateEntryException extends RuntimeException {
|
||||
private static final long serialVersionUID = -7199021672428288780L;
|
||||
|
||||
|
||||
public DuplicateEntryException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public DuplicateEntryException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user