implement BlockState with mixin on Fabric

This commit is contained in:
dfsek
2021-12-21 13:09:40 -07:00
parent 1a1016bdf8
commit 5dbc2c2895
25 changed files with 204 additions and 253 deletions

View File

@@ -14,31 +14,33 @@ import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.properties.Property;
public interface BlockState extends Cloneable, Handle {
public interface BlockState extends Handle {
boolean matches(BlockState other);
BlockState clone();
<T extends Comparable<T>> boolean has(Property<T> property);
<T> boolean has(Property<T> property);
<T extends Comparable<T>> T get(Property<T> property);
<T> T get(Property<T> property);
<T extends Comparable<T>> BlockState set(Property<T> property, T value);
<T> BlockState set(Property<T> property, T value);
default <T> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
default <T extends Comparable<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) {
default <T extends Comparable<T>> BlockState setIfPresent(Property<T> property, T value) {
if(has(property)) set(property, value);
return this;
}
BlockType getBlockType();
String getAsString();
default String getAsString() {
return getAsString(true);
}
String getAsString(boolean properties);
boolean isAir();
}

View File

@@ -104,8 +104,8 @@ public final class RotationUtil {
};
}
public static void rotateBlockData(BlockState data, Rotation r) {
data
public static BlockState rotateBlockData(BlockState data, Rotation r) {
return data
.ifProperty(Properties.NORTH, state -> state.set(rotateCardinal(Properties.NORTH, r), state.get(Properties.NORTH)))
.ifProperty(Properties.SOUTH, state -> state.set(rotateCardinal(Properties.SOUTH, r), state.get(Properties.SOUTH)))
.ifProperty(Properties.EAST, state -> state.set(rotateCardinal(Properties.EAST, r), state.get(Properties.EAST)))