mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 22:30:00 +00:00
more properties
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
package com.dfsek.terra.api.block;
|
||||
|
||||
public enum Axis {
|
||||
X, Y, Z
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.api.block;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.block.data.properties.Property;
|
||||
|
||||
public interface BlockState extends Cloneable, Handle {
|
||||
|
||||
@@ -15,4 +16,10 @@ public interface BlockState extends Cloneable, Handle {
|
||||
boolean isAir();
|
||||
|
||||
boolean isStructureVoid();
|
||||
|
||||
<T> boolean has(Property<T> property);
|
||||
|
||||
<T> T get(Property<T> property);
|
||||
|
||||
<T> BlockState set(Property<T> property);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.api.block.data;
|
||||
|
||||
import com.dfsek.terra.api.block.Axis;
|
||||
import com.dfsek.terra.api.block.data.properties.enums.Axis;
|
||||
import com.dfsek.terra.api.block.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
package com.dfsek.terra.api.block.data;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockState;
|
||||
import com.dfsek.terra.api.block.data.properties.enums.RailShape;
|
||||
|
||||
public interface Rail extends BlockState {
|
||||
Shape getShape();
|
||||
RailShape getShape();
|
||||
|
||||
void setShape(Shape newShape);
|
||||
void setShape(RailShape newShape);
|
||||
|
||||
enum Shape {
|
||||
ASCENDING_EAST,
|
||||
ASCENDING_NORTH,
|
||||
ASCENDING_SOUTH,
|
||||
ASCENDING_WEST,
|
||||
EAST_WEST,
|
||||
NORTH_EAST,
|
||||
NORTH_SOUTH,
|
||||
NORTH_WEST,
|
||||
SOUTH_EAST,
|
||||
SOUTH_WEST
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,28 @@ package com.dfsek.terra.api.block.data.properties.base;
|
||||
|
||||
import com.dfsek.terra.api.block.data.properties.Property;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface BooleanProperty extends Property<Boolean> {
|
||||
@Override
|
||||
default Class<Boolean> getType() {
|
||||
return Boolean.class;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
package com.dfsek.terra.api.block.data.properties.base;
|
||||
|
||||
import com.dfsek.terra.api.block.data.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.of(() -> 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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,37 @@
|
||||
package com.dfsek.terra.api.block.data.properties.base;
|
||||
|
||||
import com.dfsek.terra.api.block.data.properties.Property;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface IntProperty extends Property<Integer> {
|
||||
@Override
|
||||
default Class<Integer> getType() {
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
static IntProperty of(String name, int min, int max) {
|
||||
return new IntProperty() {
|
||||
private final Collection<Integer> collection = Construct.construct(() -> {
|
||||
List<Integer> ints = new ArrayList<>();
|
||||
for(int i = min; i <= max; i++) {
|
||||
ints.add(i);
|
||||
}
|
||||
return ints;
|
||||
});
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Integer> values() {
|
||||
return collection;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.api.block.data.properties.base;
|
||||
|
||||
import com.dfsek.terra.api.block.data.properties.enums.Direction;
|
||||
import com.dfsek.terra.api.block.data.properties.enums.RailShape;
|
||||
|
||||
public final class Properties {
|
||||
public static final EnumProperty<Direction> DIRECTION = EnumProperty.of("facing", Direction.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<RailShape> RAIL_SHAPE = EnumProperty.of("shape", RailShape.class);
|
||||
|
||||
public static final IntProperty ROTATION = IntProperty.of("rotation", 0, 15);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.dfsek.terra.api.block.data.properties.enums;
|
||||
|
||||
public enum Axis {
|
||||
X, Y, Z
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.dfsek.terra.api.block.data.properties.enums;
|
||||
|
||||
public enum Direction {
|
||||
NORTH,SOUTH,EAST,WEST,UP,DOWN
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.dfsek.terra.api.block.data.properties.enums;
|
||||
|
||||
public enum RailShape {
|
||||
ASCENDING_EAST,
|
||||
ASCENDING_NORTH,
|
||||
ASCENDING_SOUTH,
|
||||
ASCENDING_WEST,
|
||||
EAST_WEST,
|
||||
NORTH_EAST,
|
||||
NORTH_SOUTH,
|
||||
NORTH_WEST,
|
||||
SOUTH_EAST,
|
||||
SOUTH_WEST
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class Construct {
|
||||
public static <T> T construct(Supplier<T> in) {
|
||||
return in.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class Lazy<T> {
|
||||
private final Supplier<T> valueSupplier;
|
||||
private T value = null;
|
||||
private boolean got = false;
|
||||
|
||||
private Lazy(Supplier<T> valueSupplier) {
|
||||
this.valueSupplier = valueSupplier;
|
||||
}
|
||||
|
||||
public T value() {
|
||||
if(!got && value == null) {
|
||||
got = true;
|
||||
value = valueSupplier.get();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static <T> Lazy<T> of(Supplier<T> valueSupplier) {
|
||||
return new Lazy<>(valueSupplier);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user