property based block data implementation

This commit is contained in:
dfsek
2021-06-26 02:17:31 -07:00
parent 43307b737c
commit bce7a181bd
45 changed files with 288 additions and 1542 deletions

View File

@@ -1,133 +0,0 @@
package com.dfsek.terra.api.block;
import org.jetbrains.annotations.NotNull;
public enum BlockFace {
NORTH(0, 0, -1),
EAST(1, 0, 0),
SOUTH(0, 0, 1),
WEST(-1, 0, 0),
UP(0, 1, 0),
DOWN(0, -1, 0),
NORTH_EAST(NORTH, EAST),
NORTH_WEST(NORTH, WEST),
SOUTH_EAST(SOUTH, EAST),
SOUTH_WEST(SOUTH, WEST),
WEST_NORTH_WEST(WEST, NORTH_WEST),
NORTH_NORTH_WEST(NORTH, NORTH_WEST),
NORTH_NORTH_EAST(NORTH, NORTH_EAST),
EAST_NORTH_EAST(EAST, NORTH_EAST),
EAST_SOUTH_EAST(EAST, SOUTH_EAST),
SOUTH_SOUTH_EAST(SOUTH, SOUTH_EAST),
SOUTH_SOUTH_WEST(SOUTH, SOUTH_WEST),
WEST_SOUTH_WEST(WEST, SOUTH_WEST),
SELF(0, 0, 0);
private final int modX;
private final int modY;
private final int modZ;
BlockFace(final int modX, final int modY, final int modZ) {
this.modX = modX;
this.modY = modY;
this.modZ = modZ;
}
BlockFace(final BlockFace face1, final BlockFace face2) {
this.modX = face1.getModX() + face2.getModX();
this.modY = face1.getModY() + face2.getModY();
this.modZ = face1.getModZ() + face2.getModZ();
}
/**
* Get the amount of X-coordinates to modify to get the represented block
*
* @return Amount of X-coordinates to modify
*/
public int getModX() {
return modX;
}
/**
* Get the amount of Y-coordinates to modify to get the represented block
*
* @return Amount of Y-coordinates to modify
*/
public int getModY() {
return modY;
}
/**
* Get the amount of Z-coordinates to modify to get the represented block
*
* @return Amount of Z-coordinates to modify
*/
public int getModZ() {
return modZ;
}
@NotNull
public BlockFace getOppositeFace() {
switch(this) {
case NORTH:
return BlockFace.SOUTH;
case SOUTH:
return BlockFace.NORTH;
case EAST:
return BlockFace.WEST;
case WEST:
return BlockFace.EAST;
case UP:
return BlockFace.DOWN;
case DOWN:
return BlockFace.UP;
case NORTH_EAST:
return BlockFace.SOUTH_WEST;
case NORTH_WEST:
return BlockFace.SOUTH_EAST;
case SOUTH_EAST:
return BlockFace.NORTH_WEST;
case SOUTH_WEST:
return BlockFace.NORTH_EAST;
case WEST_NORTH_WEST:
return BlockFace.EAST_SOUTH_EAST;
case NORTH_NORTH_WEST:
return BlockFace.SOUTH_SOUTH_EAST;
case NORTH_NORTH_EAST:
return BlockFace.SOUTH_SOUTH_WEST;
case EAST_NORTH_EAST:
return BlockFace.WEST_SOUTH_WEST;
case EAST_SOUTH_EAST:
return BlockFace.WEST_NORTH_WEST;
case SOUTH_SOUTH_EAST:
return BlockFace.NORTH_NORTH_WEST;
case SOUTH_SOUTH_WEST:
return BlockFace.NORTH_NORTH_EAST;
case WEST_SOUTH_WEST:
return BlockFace.EAST_NORTH_EAST;
case SELF:
return BlockFace.SELF;
}
return BlockFace.SELF;
}
}

View File

@@ -1,11 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
public interface AnaloguePowerable extends BlockState {
int getMaximumPower();
int getPower();
void setPower(int power);
}

View File

@@ -1,20 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
public interface Bisected extends BlockState {
Half getHalf();
void setHalf(Half half);
enum Half {
/**
* The top half of the block, normally with the higher y coordinate.
*/
TOP,
/**
* The bottom half of the block, normally with the lower y coordinate.
*/
BOTTOM
}
}

View File

@@ -1,10 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
public interface Directional extends BlockState {
BlockFace getFacing();
void setFacing(BlockFace facing);
}

View File

@@ -1,16 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
import java.util.Set;
public interface MultipleFacing extends BlockState {
Set<BlockFace> getFaces();
void setFace(BlockFace face, boolean facing);
Set<BlockFace> getAllowedFaces();
boolean hasFace(BlockFace f);
}

View File

@@ -1,14 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.state.BlockState;
import java.util.Set;
public interface Orientable extends BlockState {
Set<Axis> getAxes();
Axis getAxis();
void setAxis(Axis axis);
}

View File

@@ -1,11 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
public interface Rail extends BlockState {
RailShape getShape();
void setShape(RailShape newShape);
}

View File

@@ -1,18 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
import java.util.Set;
public interface RedstoneWire extends BlockState, AnaloguePowerable {
Set<BlockFace> getAllowedFaces();
Connection getFace(BlockFace face);
void setFace(BlockFace face, Connection connection);
enum Connection {
NONE, SIDE, UP
}
}

View File

@@ -1,10 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
public interface Rotatable extends BlockState {
BlockFace getRotation();
void setRotation(BlockFace face);
}

View File

@@ -1,11 +0,0 @@
package com.dfsek.terra.api.block.data;
public interface Slab extends Waterlogged {
Type getType();
void setType(Type type);
enum Type {
TOP, BOTTOM, DOUBLE
}
}

View File

@@ -1,30 +0,0 @@
package com.dfsek.terra.api.block.data;
public interface Stairs extends Waterlogged, Directional, Bisected {
Shape getShape();
void setShape(Shape shape);
enum Shape {
/**
* Regular stair block.
*/
STRAIGHT,
/**
* Inner corner stair block with higher left side.
*/
INNER_LEFT,
/**
* Inner corner stair block with higher right side.
*/
INNER_RIGHT,
/**
* Outer corner stair block with higher left side.
*/
OUTER_LEFT,
/**
* Outer corner stair block with higher right side.
*/
OUTER_RIGHT
}
}

View File

@@ -1,18 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
public interface Wall extends BlockState, Waterlogged {
boolean isUp();
void setHeight(BlockFace face, Height height);
Height getHeight(BlockFace face);
void setUp(boolean up);
enum Height {
LOW, NONE, TALL
}
}

View File

@@ -1,9 +0,0 @@
package com.dfsek.terra.api.block.data;
import com.dfsek.terra.api.block.state.BlockState;
public interface Waterlogged extends BlockState {
boolean isWaterlogged();
void setWaterlogged(boolean waterlogged);
}

View File

@@ -4,6 +4,8 @@ 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();
@@ -22,5 +24,15 @@ public interface BlockState extends Cloneable, Handle {
<T> T get(Property<T> property);
<T> BlockState set(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;
}
}

View File

@@ -1,17 +1,36 @@
package com.dfsek.terra.api.block.state.properties.base;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.state.properties.enums.Direction;
import com.dfsek.terra.api.block.state.properties.enums.Half;
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");
}

View File

@@ -1,5 +1,69 @@
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,SOUTH,EAST,WEST,UP,DOWN
NORTH(0, 0, 0, -1),
EAST(1, 1, 0, 0),
SOUTH(2, 0, 0, 1),
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 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:
case DOWN:
return this;
default:
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:
return UP;
case UP:
return DOWN;
case EAST:
return WEST;
case WEST:
return EAST;
case NORTH:
return SOUTH;
case SOUTH:
return NORTH;
}
throw new IllegalStateException();
}
}

View File

@@ -0,0 +1,17 @@
package com.dfsek.terra.api.block.state.properties.enums;
public enum Half {
/**
* The top half of the block, normally with the higher y coordinate.
*/
TOP,
/**
* The bottom half of the block, normally with the lower y coordinate.
*/
BOTTOM,
/**
* Some blocks, e.g. slabs, can occupy both halves.
*/
DOUBLE
}

View File

@@ -0,0 +1,5 @@
package com.dfsek.terra.api.block.state.properties.enums;
public enum RedstoneConnection {
NONE, SIDE, UP
}

View File

@@ -0,0 +1,5 @@
package com.dfsek.terra.api.block.state.properties.enums;
public enum WallHeight {
LOW, NONE, TALL
}

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.api.structures.structure.buffer.items;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.data.Waterlogged;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.structure.buffer.BufferedItem;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.World;
@@ -25,8 +25,9 @@ public class BufferedBlock implements BufferedItem {
try {
BlockState current = world.getBlockData(origin);
if(overwrite || current.isAir()) {
if(waterlog && current instanceof Waterlogged && current.getBlockType().isWater())
((Waterlogged) current).setWaterlogged(true);
if(waterlog && current.has(Properties.WATERLOGGED) && current.getBlockType().isWater()) {
current.set(Properties.WATERLOGGED, true);
}
world.setBlockData(origin, data);
}
} catch(RuntimeException e) {

View File

@@ -1,27 +1,17 @@
package com.dfsek.terra.api.util;
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Directional;
import com.dfsek.terra.api.block.data.MultipleFacing;
import com.dfsek.terra.api.block.data.Orientable;
import com.dfsek.terra.api.block.data.Rail;
import com.dfsek.terra.api.block.data.RedstoneWire;
import com.dfsek.terra.api.block.data.Rotatable;
import com.dfsek.terra.api.block.data.Wall;
import com.dfsek.terra.api.block.state.properties.base.BooleanProperty;
import com.dfsek.terra.api.block.state.properties.base.EnumProperty;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
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;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.vector.Vector2;
import com.google.common.collect.Sets;
import net.jafama.FastMath;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
public class RotationUtil {
private static final Set<BlockFace> CARDINALS = Sets.newHashSet(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
/**
* Rotate and mirror a coordinate pair.
@@ -46,112 +36,8 @@ public class RotationUtil {
orig.setZ(copy.getZ());
}
/**
* Get the BlockFace with rotation and mirrors applied to it
*
* @param f BlockFace to apply rotation to
* @param r Rotation
* @return Rotated BlockFace
*/
public static BlockFace getRotatedFace(BlockFace f, Rotation r) {
BlockFace n = f;
int rotateNum = r.getDegrees() / 90;
int rn = faceRotation(f);
if(rn >= 0) {
n = fromRotation(faceRotation(n) + 4 * rotateNum);
}
return n;
}
/**
* Get an integer representation of a BlockFace, to perform math on.
*
* @param f BlockFace to get integer for
* @return integer representation of BlockFace
*/
public static int faceRotation(BlockFace f) {
switch(f) {
case NORTH:
return 0;
case NORTH_NORTH_EAST:
return 1;
case NORTH_EAST:
return 2;
case EAST_NORTH_EAST:
return 3;
case EAST:
return 4;
case EAST_SOUTH_EAST:
return 5;
case SOUTH_EAST:
return 6;
case SOUTH_SOUTH_EAST:
return 7;
case SOUTH:
return 8;
case SOUTH_SOUTH_WEST:
return 9;
case SOUTH_WEST:
return 10;
case WEST_SOUTH_WEST:
return 11;
case WEST:
return 12;
case WEST_NORTH_WEST:
return 13;
case NORTH_WEST:
return 14;
case NORTH_NORTH_WEST:
return 15;
default:
return -1;
}
}
/**
* Convert integer to BlockFace representation
*
* @param r integer to get BlockFace for
* @return BlockFace represented by integer.
*/
public static BlockFace fromRotation(int r) {
switch(FastMath.floorMod(r, 16)) {
case 0:
return BlockFace.NORTH;
case 1:
return BlockFace.NORTH_NORTH_EAST;
case 2:
return BlockFace.NORTH_EAST;
case 3:
return BlockFace.EAST_NORTH_EAST;
case 4:
return BlockFace.EAST;
case 5:
return BlockFace.EAST_SOUTH_EAST;
case 6:
return BlockFace.SOUTH_EAST;
case 7:
return BlockFace.SOUTH_SOUTH_EAST;
case 8:
return BlockFace.SOUTH;
case 9:
return BlockFace.SOUTH_SOUTH_WEST;
case 10:
return BlockFace.SOUTH_WEST;
case 11:
return BlockFace.WEST_SOUTH_WEST;
case 12:
return BlockFace.WEST;
case 13:
return BlockFace.WEST_NORTH_WEST;
case 14:
return BlockFace.NORTH_WEST;
case 15:
return BlockFace.NORTH_NORTH_WEST;
default:
throw new IllegalArgumentException();
}
}
public static Axis getRotatedAxis(Axis orig, Rotation r) {
Axis other = orig;
@@ -250,44 +136,100 @@ public class RotationUtil {
return orig;
}
public static void rotateBlockData(BlockState data, Rotation r) {
if(data instanceof Rotatable) {
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
((Rotatable) data).setRotation(rt);
} else if(data instanceof Directional) {
BlockFace rt = getRotatedFace(((Directional) data).getFacing(), r);
((Directional) data).setFacing(rt);
} else if(data instanceof MultipleFacing) {
MultipleFacing mfData = (MultipleFacing) data;
Map<BlockFace, Boolean> faces = new EnumMap<>(BlockFace.class);
for(BlockFace f : mfData.getAllowedFaces()) {
faces.put(f, mfData.hasFace(f));
}
for(Map.Entry<BlockFace, Boolean> face : faces.entrySet()) {
mfData.setFace(getRotatedFace(face.getKey(), r), face.getValue());
}
} else if(data instanceof Rail) {
RailShape newShape = getRotatedRail(((Rail) data).getShape(), r);
((Rail) data).setShape(newShape);
} else if(data instanceof Orientable) {
Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r);
((Orientable) data).setAxis(newAxis);
} else if(data instanceof RedstoneWire) {
Map<BlockFace, RedstoneWire.Connection> connections = new EnumMap<>(BlockFace.class);
RedstoneWire rData = (RedstoneWire) data;
for(BlockFace f : rData.getAllowedFaces()) {
connections.put(f, rData.getFace(f));
}
for(Map.Entry<BlockFace, RedstoneWire.Connection> e : connections.entrySet()) {
rData.setFace(getRotatedFace(e.getKey(), r), e.getValue());
}
} else if(data instanceof Wall) {
Wall wallData = (Wall) data;
Map<BlockFace, Wall.Height> faces = new EnumMap<>(BlockFace.class);
for(BlockFace b : CARDINALS) faces.put(b, wallData.getHeight(b));
for(Map.Entry<BlockFace, Wall.Height> face : faces.entrySet()) {
wallData.setHeight(getRotatedFace(face.getKey(), r), face.getValue());
}
private static BooleanProperty rotateCardinal(BooleanProperty property, Rotation r) {
switch(r) {
case NONE:
return property;
case CW_90:
if(property == Properties.NORTH) return Properties.EAST;
if(property == Properties.EAST) return Properties.SOUTH;
if(property == Properties.SOUTH) return Properties.WEST;
if(property == Properties.WEST) return Properties.NORTH;
throw new IllegalStateException();
case CW_180:
if(property == Properties.NORTH) return Properties.SOUTH;
if(property == Properties.EAST) return Properties.WEST;
if(property == Properties.SOUTH) return Properties.NORTH;
if(property == Properties.WEST) return Properties.EAST;
throw new IllegalStateException();
case CCW_90:
if(property == Properties.NORTH) return Properties.WEST;
if(property == Properties.EAST) return Properties.NORTH;
if(property == Properties.SOUTH) return Properties.EAST;
if(property == Properties.WEST) return Properties.SOUTH;
throw new IllegalStateException();
}
throw new IllegalStateException();
}
private static EnumProperty<RedstoneConnection> rotateRedstone(EnumProperty<RedstoneConnection> property, Rotation r) {
switch(r) {
case NONE:
return property;
case CW_90:
if(property == Properties.NORTH_CONNECTION) return Properties.EAST_CONNECTION;
if(property == Properties.EAST_CONNECTION) return Properties.SOUTH_CONNECTION;
if(property == Properties.SOUTH_CONNECTION) return Properties.WEST_CONNECTION;
if(property == Properties.WEST_CONNECTION) return Properties.NORTH_CONNECTION;
throw new IllegalStateException();
case CW_180:
if(property == Properties.NORTH_CONNECTION) return Properties.SOUTH_CONNECTION;
if(property == Properties.EAST_CONNECTION) return Properties.WEST_CONNECTION;
if(property == Properties.SOUTH_CONNECTION) return Properties.NORTH_CONNECTION;
if(property == Properties.WEST_CONNECTION) return Properties.EAST_CONNECTION;
throw new IllegalStateException();
case CCW_90:
if(property == Properties.NORTH_CONNECTION) return Properties.WEST_CONNECTION;
if(property == Properties.EAST_CONNECTION) return Properties.NORTH_CONNECTION;
if(property == Properties.SOUTH_CONNECTION) return Properties.EAST_CONNECTION;
if(property == Properties.WEST_CONNECTION) return Properties.SOUTH_CONNECTION;
throw new IllegalStateException();
}
throw new IllegalStateException();
}
private static EnumProperty<WallHeight> rotateWall(EnumProperty<WallHeight> property, Rotation r) {
switch(r) {
case NONE:
return property;
case CW_90:
if(property == Properties.NORTH_HEIGHT) return Properties.EAST_HEIGHT;
if(property == Properties.EAST_HEIGHT) return Properties.SOUTH_HEIGHT;
if(property == Properties.SOUTH_HEIGHT) return Properties.WEST_HEIGHT;
if(property == Properties.WEST_HEIGHT) return Properties.NORTH_HEIGHT;
throw new IllegalStateException();
case CW_180:
if(property == Properties.NORTH_HEIGHT) return Properties.SOUTH_HEIGHT;
if(property == Properties.EAST_HEIGHT) return Properties.WEST_HEIGHT;
if(property == Properties.SOUTH_HEIGHT) return Properties.NORTH_HEIGHT;
if(property == Properties.WEST_HEIGHT) return Properties.EAST_HEIGHT;
throw new IllegalStateException();
case CCW_90:
if(property == Properties.NORTH_HEIGHT) return Properties.WEST_HEIGHT;
if(property == Properties.EAST_HEIGHT) return Properties.NORTH_HEIGHT;
if(property == Properties.SOUTH_HEIGHT) return Properties.EAST_HEIGHT;
if(property == Properties.WEST_HEIGHT) return Properties.SOUTH_HEIGHT;
throw new IllegalStateException();
}
throw new IllegalStateException();
}
public static void rotateBlockData(BlockState data, Rotation r) {
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)))
.ifProperty(Properties.WEST, state -> state.set(rotateCardinal(Properties.WEST, r), state.get(Properties.WEST)))
.ifProperty(Properties.DIRECTION, state -> state.set(Properties.DIRECTION, state.get(Properties.DIRECTION).rotate(r)))
.ifProperty(Properties.AXIS, state -> state.set(Properties.AXIS, getRotatedAxis(state.get(Properties.AXIS), r)))
.ifProperty(Properties.RAIL_SHAPE, state -> state.set(Properties.RAIL_SHAPE, getRotatedRail(state.get(Properties.RAIL_SHAPE), r)))
.ifProperty(Properties.NORTH_CONNECTION, state -> state.set(rotateRedstone(Properties.NORTH_CONNECTION, r), state.get(Properties.NORTH_CONNECTION)))
.ifProperty(Properties.SOUTH_CONNECTION, state -> state.set(rotateRedstone(Properties.SOUTH_CONNECTION, r), state.get(Properties.SOUTH_CONNECTION)))
.ifProperty(Properties.EAST_CONNECTION, state -> state.set(rotateRedstone(Properties.EAST_CONNECTION, r), state.get(Properties.EAST_CONNECTION)))
.ifProperty(Properties.WEST_CONNECTION, state -> state.set(rotateRedstone(Properties.WEST_CONNECTION, r), state.get(Properties.WEST_CONNECTION)))
.ifProperty(Properties.NORTH_HEIGHT, state -> state.set(rotateWall(Properties.NORTH_HEIGHT, r), state.get(Properties.NORTH_HEIGHT)))
.ifProperty(Properties.SOUTH_HEIGHT, state -> state.set(rotateWall(Properties.SOUTH_HEIGHT, r), state.get(Properties.SOUTH_HEIGHT)))
.ifProperty(Properties.EAST_HEIGHT, state -> state.set(rotateWall(Properties.EAST_HEIGHT, r), state.get(Properties.EAST_HEIGHT)))
.ifProperty(Properties.WEST_HEIGHT, state -> state.set(rotateWall(Properties.WEST_HEIGHT, r), state.get(Properties.WEST_HEIGHT)));
}
}

View File

@@ -1,13 +1,11 @@
package com.dfsek.terra.world.generation.generators;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.data.Bisected;
import com.dfsek.terra.api.block.data.Slab;
import com.dfsek.terra.api.block.data.Stairs;
import com.dfsek.terra.api.block.data.Waterlogged;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.block.state.properties.enums.Direction;
import com.dfsek.terra.api.block.state.properties.enums.Half;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.math.range.ConstantRange;
import com.dfsek.terra.api.profiler.ProfileFrame;
@@ -145,16 +143,16 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
Palette stairPalette = stairs.get(down.getBlockType());
if(stairPalette != null) {
BlockState stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
if(stair instanceof Stairs) {
Stairs stairNew = (Stairs) stair;
if(stair.has(Properties.DIRECTION)) {
BlockState stairNew = stair.clone();
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
}
}
}
BlockState slab = slabs.getOrDefault(down.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ());
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.getBlockType().equals(water));
} else if(orig.getBlockType().equals(water)) return;
BlockState slab = slabs.getOrDefault(down.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ())
.setIfPresent(Properties.WATERLOGGED, orig.getBlockType().equals(water));
if(orig.getBlockType().equals(water)) return;
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
}
@@ -166,37 +164,36 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
Palette stairPalette = stairs.get(up.getBlockType());
if(stairPalette != null) {
BlockState stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
if(stair instanceof Stairs) {
Stairs stairNew = (Stairs) stair.clone();
stairNew.setHalf(Bisected.Half.TOP);
stair.setIfPresent(Properties.HALF, Half.TOP);
if(stair.has(Properties.DIRECTION)) {
BlockState stairNew = stair.clone();
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
}
}
}
BlockState slab = slabs.getOrDefault(up.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ()).clone();
if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.getBlockType().equals(water));
} else if(orig.getBlockType().equals(water)) return; // Only replace water if waterlogged.
slab.setIfPresent(Properties.HALF, Half.TOP);
slab.setIfPresent(Properties.WATERLOGGED, orig.getBlockType().isWater());
if(orig.getBlockType().equals(water)) return;
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
}
private boolean placeStair(BlockState orig, ChunkData chunk, Vector3 block, double thresh, Sampler sampler, Stairs stairNew) {
private boolean placeStair(BlockState orig, ChunkData chunk, Vector3 block, double thresh, Sampler sampler, BlockState stairNew) {
if(sampler.sample(block.getBlockX() - 0.55, block.getY(), block.getZ()) > thresh) {
stairNew.setFacing(BlockFace.WEST);
stairNew.set(Properties.DIRECTION, Direction.WEST);
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() - 0.55) > thresh) {
stairNew.setFacing(BlockFace.NORTH);
stairNew.set(Properties.DIRECTION, Direction.NORTH);
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() + 0.55) > thresh) {
stairNew.setFacing(BlockFace.SOUTH);
stairNew.set(Properties.DIRECTION, Direction.SOUTH);
} else if(sampler.sample(block.getX() + 0.55, block.getY(), block.getZ()) > thresh) {
stairNew.setFacing(BlockFace.EAST);
stairNew.set(Properties.DIRECTION, Direction.EAST);
} else stairNew = null;
if(stairNew != null) {
if(orig.getBlockType().equals(water)) stairNew.setWaterlogged(orig.getBlockType().equals(water));
stairNew.setIfPresent(Properties.WATERLOGGED, orig.getBlockType().equals(water));
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
return true;
}

View File

@@ -2,12 +2,9 @@ package com.dfsek.terra.world.population.items.flora;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Directional;
import com.dfsek.terra.api.block.data.MultipleFacing;
import com.dfsek.terra.api.block.data.Rotatable;
import com.dfsek.terra.api.block.state.properties.base.Properties;
import com.dfsek.terra.api.block.state.properties.enums.Direction;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.vector.Vector3;
@@ -19,6 +16,7 @@ import com.dfsek.terra.vector.Vector3Impl;
import net.jafama.FastMath;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
public class TerraFlora implements Flora {
@@ -100,39 +98,36 @@ public class TerraFlora implements Flora {
int size = floraPalette.getSize();
int c = ceiling ? -1 : 1;
List<BlockFace> faces = doRotation ? getFaces(location.clone().add(0, c, 0), world) : new GlueList<>();
EnumSet<Direction> faces = doRotation ? getFaces(location.clone().add(0, c, 0), world) : EnumSet.noneOf(Direction.class);
if(doRotation && faces.size() == 0) return false; // Don't plant if no faces are valid.
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
int lvl = (FastMath.abs(i));
BlockState data = floraPalette.get((ceiling ? lvl : size - lvl - 1), location.getX(), location.getY(), location.getZ()).clone();
if(doRotation) {
BlockFace oneFace = faces.get(new FastRandom(location.getBlockX() ^ location.getBlockZ()).nextInt(faces.size())); // Get random face.
if(data instanceof Directional) {
((Directional) data).setFacing(oneFace.getOppositeFace());
} else if(data instanceof MultipleFacing) {
MultipleFacing o = (MultipleFacing) data;
for(BlockFace face : o.getFaces()) o.setFace(face, false);
for(BlockFace face : faces) o.setFace(face, true);
} else if(data instanceof Rotatable) {
((Rotatable) data).setRotation(oneFace);
}
Direction oneFace = new ArrayList<>(faces).get(new FastRandom(location.getBlockX() ^ location.getBlockZ()).nextInt(faces.size())); // Get random face.
data.setIfPresent(Properties.DIRECTION, oneFace.opposite())
.setIfPresent(Properties.NORTH, faces.contains(Direction.NORTH))
.setIfPresent(Properties.SOUTH, faces.contains(Direction.SOUTH))
.setIfPresent(Properties.EAST, faces.contains(Direction.EAST))
.setIfPresent(Properties.WEST, faces.contains(Direction.WEST));
}
world.setBlockData(location.clone().add(0, i + c, 0), data, physics);
}
return true;
}
private List<BlockFace> getFaces(Vector3 b, World world) {
List<BlockFace> faces = new GlueList<>();
test(faces, BlockFace.NORTH, b, world);
test(faces, BlockFace.SOUTH, b, world);
test(faces, BlockFace.EAST, b, world);
test(faces, BlockFace.WEST, b, world);
private EnumSet<Direction> getFaces(Vector3 b, World world) {
EnumSet<Direction> faces = EnumSet.noneOf(Direction.class);
test(faces, Direction.NORTH, b, world);
test(faces, Direction.SOUTH, b, world);
test(faces, Direction.EAST, b, world);
test(faces, Direction.WEST, b, world);
return faces;
}
private void test(List<BlockFace> faces, BlockFace f, Vector3 b, World world) {
private void test(EnumSet<Direction> faces, Direction f, Vector3 b, World world) {
if(testRotation.contains(world.getBlockData(b.getBlockX() + f.getModX(), b.getBlockY() + f.getModY(), b.getBlockZ() + f.getModZ()).getBlockType()))
faces.add(f);
}

View File

@@ -1,15 +1,12 @@
package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.block.state.properties.enums.Half;
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.data.Bisected;
import com.dfsek.terra.api.block.data.RedstoneWire;
import com.dfsek.terra.api.block.data.Slab;
import com.dfsek.terra.api.block.data.Stairs;
import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
import com.dfsek.terra.api.entity.CommandSender;
import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment;
@@ -50,23 +47,6 @@ public final class BukkitAdapter {
.build();
public static Stairs.Shape adapt(org.bukkit.block.data.type.Stairs.Shape shape) {
switch(shape) {
case STRAIGHT:
return Stairs.Shape.STRAIGHT;
case INNER_LEFT:
return Stairs.Shape.INNER_LEFT;
case OUTER_LEFT:
return Stairs.Shape.OUTER_LEFT;
case INNER_RIGHT:
return Stairs.Shape.INNER_RIGHT;
case OUTER_RIGHT:
return Stairs.Shape.OUTER_RIGHT;
default:
throw new IllegalStateException();
}
}
public static BlockState adapt(org.bukkit.block.data.BlockData data) {
return BukkitBlockState.newInstance(data);
}
@@ -88,89 +68,31 @@ public final class BukkitAdapter {
}
}
public static Bisected.Half adapt(org.bukkit.block.data.Bisected.Half half) {
public static Half adapt(org.bukkit.block.data.Bisected.Half half) {
switch(half) {
case BOTTOM:
return Bisected.Half.BOTTOM;
return Half.BOTTOM;
case TOP:
return Bisected.Half.TOP;
return Half.TOP;
default:
throw new IllegalStateException();
}
}
public static BlockFace adapt(org.bukkit.block.BlockFace face) {
switch(face) {
case DOWN:
return BlockFace.DOWN;
case UP:
return BlockFace.UP;
case NORTH_WEST:
return BlockFace.NORTH_WEST;
case NORTH_EAST:
return BlockFace.NORTH_EAST;
case SOUTH_EAST:
return BlockFace.SOUTH_EAST;
case SOUTH_WEST:
return BlockFace.SOUTH_WEST;
case NORTH_NORTH_WEST:
return BlockFace.NORTH_NORTH_WEST;
case WEST_NORTH_WEST:
return BlockFace.WEST_NORTH_WEST;
case WEST_SOUTH_WEST:
return BlockFace.WEST_SOUTH_WEST;
case SOUTH_SOUTH_WEST:
return BlockFace.SOUTH_SOUTH_WEST;
case EAST_NORTH_EAST:
return BlockFace.EAST_NORTH_EAST;
case WEST:
return BlockFace.WEST;
case SOUTH:
return BlockFace.SOUTH;
case EAST:
return BlockFace.EAST;
case NORTH:
return BlockFace.NORTH;
case SELF:
return BlockFace.SELF;
case EAST_SOUTH_EAST:
return BlockFace.EAST_SOUTH_EAST;
case NORTH_NORTH_EAST:
return BlockFace.NORTH_NORTH_EAST;
case SOUTH_SOUTH_EAST:
return BlockFace.SOUTH_SOUTH_EAST;
default:
throw new IllegalStateException();
}
}
public static Slab.Type adapt(org.bukkit.block.data.type.Slab.Type type) {
switch(type) {
case BOTTOM:
return Slab.Type.BOTTOM;
case TOP:
return Slab.Type.TOP;
case DOUBLE:
return Slab.Type.DOUBLE;
default:
throw new IllegalStateException();
}
}
public static RedstoneWire.Connection adapt(org.bukkit.block.data.type.RedstoneWire.Connection connection) {
public static RedstoneConnection adapt(org.bukkit.block.data.type.RedstoneWire.Connection connection) {
switch(connection) {
case NONE:
return RedstoneWire.Connection.NONE;
return RedstoneConnection.NONE;
case UP:
return RedstoneWire.Connection.UP;
return RedstoneConnection.UP;
case SIDE:
return RedstoneWire.Connection.SIDE;
return RedstoneConnection.SIDE;
default:
throw new IllegalStateException();
}
}
public static org.bukkit.block.data.type.RedstoneWire.Connection adapt(RedstoneWire.Connection connection) {
public static org.bukkit.block.data.type.RedstoneWire.Connection adapt(RedstoneConnection connection) {
switch(connection) {
case SIDE:
return org.bukkit.block.data.type.RedstoneWire.Connection.SIDE;
@@ -183,23 +105,6 @@ public final class BukkitAdapter {
}
}
public static org.bukkit.block.data.type.Stairs.Shape adapt(Stairs.Shape shape) {
switch(shape) {
case STRAIGHT:
return org.bukkit.block.data.type.Stairs.Shape.STRAIGHT;
case INNER_LEFT:
return org.bukkit.block.data.type.Stairs.Shape.INNER_LEFT;
case OUTER_LEFT:
return org.bukkit.block.data.type.Stairs.Shape.OUTER_LEFT;
case INNER_RIGHT:
return org.bukkit.block.data.type.Stairs.Shape.INNER_RIGHT;
case OUTER_RIGHT:
return org.bukkit.block.data.type.Stairs.Shape.OUTER_RIGHT;
default:
throw new IllegalStateException();
}
}
public static RailShape adapt(org.bukkit.block.data.Rail.Shape shape) {
switch(shape) {
case SOUTH_WEST:
@@ -255,7 +160,7 @@ public final class BukkitAdapter {
}
public static org.bukkit.block.data.Bisected.Half adapt(Bisected.Half half) {
public static org.bukkit.block.data.Bisected.Half adapt(Half half) {
switch(half) {
case TOP:
return org.bukkit.block.data.Bisected.Half.TOP;
@@ -279,64 +184,6 @@ public final class BukkitAdapter {
}
}
public static org.bukkit.block.BlockFace adapt(BlockFace face) {
switch(face) {
case DOWN:
return org.bukkit.block.BlockFace.DOWN;
case UP:
return org.bukkit.block.BlockFace.UP;
case NORTH_WEST:
return org.bukkit.block.BlockFace.NORTH_WEST;
case NORTH_EAST:
return org.bukkit.block.BlockFace.NORTH_EAST;
case SOUTH_EAST:
return org.bukkit.block.BlockFace.SOUTH_EAST;
case SOUTH_WEST:
return org.bukkit.block.BlockFace.SOUTH_WEST;
case NORTH_NORTH_WEST:
return org.bukkit.block.BlockFace.NORTH_NORTH_WEST;
case WEST_NORTH_WEST:
return org.bukkit.block.BlockFace.WEST_NORTH_WEST;
case WEST_SOUTH_WEST:
return org.bukkit.block.BlockFace.WEST_SOUTH_WEST;
case SOUTH_SOUTH_WEST:
return org.bukkit.block.BlockFace.SOUTH_SOUTH_WEST;
case EAST_NORTH_EAST:
return org.bukkit.block.BlockFace.EAST_NORTH_EAST;
case WEST:
return org.bukkit.block.BlockFace.WEST;
case SOUTH:
return org.bukkit.block.BlockFace.SOUTH;
case EAST:
return org.bukkit.block.BlockFace.EAST;
case NORTH:
return org.bukkit.block.BlockFace.NORTH;
case SELF:
return org.bukkit.block.BlockFace.SELF;
case EAST_SOUTH_EAST:
return org.bukkit.block.BlockFace.EAST_SOUTH_EAST;
case NORTH_NORTH_EAST:
return org.bukkit.block.BlockFace.NORTH_NORTH_EAST;
case SOUTH_SOUTH_EAST:
return org.bukkit.block.BlockFace.SOUTH_SOUTH_EAST;
default:
throw new IllegalStateException();
}
}
public static org.bukkit.block.data.type.Slab.Type adapt(Slab.Type type) {
switch(type) {
case TOP:
return org.bukkit.block.data.type.Slab.Type.TOP;
case DOUBLE:
return org.bukkit.block.data.type.Slab.Type.DOUBLE;
case BOTTOM:
return org.bukkit.block.data.type.Slab.Type.BOTTOM;
default:
throw new IllegalStateException();
}
}
public static Vector3 adapt(Location location) {
return new Vector3Impl(location.getX(), location.getY(), location.getZ());
}

View File

@@ -1,24 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.data.AnaloguePowerable;
public class BukkitAnaloguePowerable extends BukkitBlockState implements AnaloguePowerable {
public BukkitAnaloguePowerable(org.bukkit.block.data.AnaloguePowerable delegate) {
super(delegate);
}
@Override
public int getMaximumPower() {
return ((org.bukkit.block.data.AnaloguePowerable) getHandle()).getMaximumPower();
}
@Override
public int getPower() {
return ((org.bukkit.block.data.AnaloguePowerable) getHandle()).getPower();
}
@Override
public void setPower(int power) {
((org.bukkit.block.data.AnaloguePowerable) getHandle()).setPower(power);
}
}

View File

@@ -25,24 +25,6 @@ public class BukkitBlockState implements BlockState {
}
public static BukkitBlockState newInstance(org.bukkit.block.data.BlockData bukkitData) {
if(bukkitData instanceof Rail) return new BukkitRail((Rail) bukkitData);
if(bukkitData instanceof Stairs) return new BukkitStairs((Stairs) bukkitData);
if(bukkitData instanceof Slab) return new BukkitSlab((Slab) bukkitData);
if(TerraBukkitPlugin.BUKKIT_VERSION.above(TerraBukkitPlugin.BukkitVersion.V1_16) && bukkitData instanceof Wall) { // Wall only exists on 1.16 and up.
return new BukkitWall((Wall) bukkitData);
}
if(bukkitData instanceof RedstoneWire) return new BukkitRedstoneWire((RedstoneWire) bukkitData);
if(bukkitData instanceof AnaloguePowerable) return new BukkitAnaloguePowerable((AnaloguePowerable) bukkitData);
if(bukkitData instanceof MultipleFacing) return new BukkitMultipleFacing((MultipleFacing) bukkitData);
if(bukkitData instanceof Rotatable) return new BukkitRotatable((Rotatable) bukkitData);
if(bukkitData instanceof Directional) return new BukkitDirectional((Directional) bukkitData);
if(bukkitData instanceof Orientable) return new BukkitOrientable((Orientable) bukkitData);
if(bukkitData instanceof Waterlogged) return new BukkitWaterlogged((Waterlogged) bukkitData);
return new BukkitBlockState(bukkitData);
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Directional;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitDirectional extends BukkitBlockState implements Directional {
public BukkitDirectional(org.bukkit.block.data.Directional delegate) {
super(delegate);
}
@Override
public BlockFace getFacing() {
return BukkitAdapter.adapt(((org.bukkit.block.data.Directional) getHandle()).getFacing());
}
@Override
public void setFacing(BlockFace facing) {
((org.bukkit.block.data.Directional) getHandle()).setFacing(BukkitAdapter.adapt(facing));
}
}

View File

@@ -1,35 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.MultipleFacing;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import java.util.Set;
import java.util.stream.Collectors;
public class BukkitMultipleFacing extends BukkitBlockState implements MultipleFacing {
public BukkitMultipleFacing(org.bukkit.block.data.MultipleFacing delegate) {
super(delegate);
}
@Override
public Set<BlockFace> getFaces() {
return ((org.bukkit.block.data.MultipleFacing) super.getHandle()).getFaces().stream().map(BukkitAdapter::adapt).collect(Collectors.toSet());
}
@Override
public void setFace(BlockFace face, boolean facing) {
((org.bukkit.block.data.MultipleFacing) super.getHandle()).setFace(BukkitAdapter.adapt(face), facing);
}
@Override
public Set<BlockFace> getAllowedFaces() {
return ((org.bukkit.block.data.MultipleFacing) super.getHandle()).getAllowedFaces().stream().map(BukkitAdapter::adapt).collect(Collectors.toSet());
}
@Override
public boolean hasFace(BlockFace f) {
return ((org.bukkit.block.data.MultipleFacing) super.getHandle()).hasFace(BukkitAdapter.adapt(f));
}
}

View File

@@ -1,30 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.data.Orientable;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import java.util.Set;
import java.util.stream.Collectors;
public class BukkitOrientable extends BukkitBlockState implements Orientable {
public BukkitOrientable(org.bukkit.block.data.Orientable delegate) {
super(delegate);
}
@Override
public Set<Axis> getAxes() {
return ((org.bukkit.block.data.Orientable) getHandle()).getAxes().stream().map(BukkitAdapter::adapt).collect(Collectors.toSet());
}
@Override
public Axis getAxis() {
return BukkitAdapter.adapt(((org.bukkit.block.data.Orientable) getHandle()).getAxis());
}
@Override
public void setAxis(Axis axis) {
((org.bukkit.block.data.Orientable) getHandle()).setAxis(BukkitAdapter.adapt(axis));
}
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.data.Rail;
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitRail extends BukkitBlockState implements Rail {
public BukkitRail(org.bukkit.block.data.Rail delegate) {
super(delegate);
}
@Override
public RailShape getShape() {
return BukkitAdapter.adapt(((org.bukkit.block.data.Rail) getHandle()).getShape());
}
@Override
public void setShape(RailShape newShape) {
((org.bukkit.block.data.Rail) getHandle()).setShape(BukkitAdapter.adapt(newShape));
}
}

View File

@@ -1,29 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.RedstoneWire;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import java.util.Set;
import java.util.stream.Collectors;
public class BukkitRedstoneWire extends BukkitAnaloguePowerable implements RedstoneWire {
public BukkitRedstoneWire(org.bukkit.block.data.type.RedstoneWire delegate) {
super(delegate);
}
@Override
public Set<BlockFace> getAllowedFaces() {
return ((org.bukkit.block.data.type.RedstoneWire) getHandle()).getAllowedFaces().stream().map(BukkitAdapter::adapt).collect(Collectors.toSet());
}
@Override
public Connection getFace(BlockFace face) {
return BukkitAdapter.adapt(((org.bukkit.block.data.type.RedstoneWire) getHandle()).getFace(BukkitAdapter.adapt(face)));
}
@Override
public void setFace(BlockFace face, Connection connection) {
((org.bukkit.block.data.type.RedstoneWire) getHandle()).setFace(BukkitAdapter.adapt(face), BukkitAdapter.adapt(connection));
}
}

View File

@@ -1,21 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Rotatable;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitRotatable extends BukkitBlockState implements Rotatable {
public BukkitRotatable(org.bukkit.block.data.Rotatable delegate) {
super(delegate);
}
@Override
public BlockFace getRotation() {
return BukkitAdapter.adapt(((org.bukkit.block.data.Rotatable) getHandle()).getRotation());
}
@Override
public void setRotation(BlockFace face) {
((org.bukkit.block.data.Rotatable) getHandle()).setRotation(BukkitAdapter.adapt(face));
}
}

View File

@@ -1,20 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.data.Slab;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitSlab extends BukkitWaterlogged implements Slab {
public BukkitSlab(org.bukkit.block.data.type.Slab delegate) {
super(delegate);
}
@Override
public Type getType() {
return BukkitAdapter.adapt(((org.bukkit.block.data.type.Slab) getHandle()).getType());
}
@Override
public void setType(Type type) {
((org.bukkit.block.data.type.Slab) getHandle()).setType(BukkitAdapter.adapt(type));
}
}

View File

@@ -1,52 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Stairs;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitStairs extends BukkitBlockState implements Stairs {
public BukkitStairs(org.bukkit.block.data.type.Stairs delegate) {
super(delegate);
}
@Override
public Shape getShape() {
return BukkitAdapter.adapt(((org.bukkit.block.data.type.Stairs) super.getHandle()).getShape());
}
@Override
public void setShape(Shape shape) {
((org.bukkit.block.data.type.Stairs) super.getHandle()).setShape(BukkitAdapter.adapt(shape));
}
@Override
public Half getHalf() {
return BukkitAdapter.adapt(((org.bukkit.block.data.type.Stairs) super.getHandle()).getHalf());
}
@Override
public void setHalf(Half half) {
((org.bukkit.block.data.type.Stairs) super.getHandle()).setHalf(BukkitAdapter.adapt(half));
}
@Override
public BlockFace getFacing() {
return BukkitAdapter.adapt(((org.bukkit.block.data.type.Stairs) super.getHandle()).getFacing());
}
@Override
public void setFacing(BlockFace facing) {
((org.bukkit.block.data.type.Stairs) super.getHandle()).setFacing(BukkitAdapter.adapt(facing));
}
@Override
public boolean isWaterlogged() {
return ((org.bukkit.block.data.type.Stairs) super.getHandle()).isWaterlogged();
}
@Override
public void setWaterlogged(boolean waterlogged) {
((org.bukkit.block.data.type.Stairs) super.getHandle()).setWaterlogged(waterlogged);
}
}

View File

@@ -1,57 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Wall;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitWall extends BukkitWaterlogged implements Wall {
public BukkitWall(org.bukkit.block.data.type.Wall delegate) {
super(delegate);
}
@Override
public boolean isUp() {
return ((org.bukkit.block.data.type.Wall) getHandle()).isUp();
}
@Override
public void setUp(boolean up) {
((org.bukkit.block.data.type.Wall) getHandle()).setUp(up);
}
public static org.bukkit.block.data.type.Wall.Height adapt(com.dfsek.terra.api.block.data.Wall.Height height) {
switch(height) {
case NONE:
return org.bukkit.block.data.type.Wall.Height.NONE;
case LOW:
return org.bukkit.block.data.type.Wall.Height.LOW;
case TALL:
return org.bukkit.block.data.type.Wall.Height.TALL;
default:
throw new IllegalStateException();
}
}
public static com.dfsek.terra.api.block.data.Wall.Height adapt(org.bukkit.block.data.type.Wall.Height height) {
switch(height) {
case TALL:
return com.dfsek.terra.api.block.data.Wall.Height.TALL;
case LOW:
return com.dfsek.terra.api.block.data.Wall.Height.LOW;
case NONE:
return com.dfsek.terra.api.block.data.Wall.Height.NONE;
default:
throw new IllegalStateException();
}
}
@Override
public void setHeight(BlockFace face, Height height) {
((org.bukkit.block.data.type.Wall) getHandle()).setHeight(BukkitAdapter.adapt(face), adapt(height));
}
@Override
public Height getHeight(BlockFace face) {
return adapt(((org.bukkit.block.data.type.Wall) getHandle()).getHeight(BukkitAdapter.adapt(face)));
}
}

View File

@@ -1,19 +0,0 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.block.data.Waterlogged;
public class BukkitWaterlogged extends BukkitBlockState implements Waterlogged {
public BukkitWaterlogged(org.bukkit.block.data.Waterlogged delegate) {
super(delegate);
}
@Override
public boolean isWaterlogged() {
return ((org.bukkit.block.data.Waterlogged) super.getHandle()).isWaterlogged();
}
@Override
public void setWaterlogged(boolean waterlogged) {
((org.bukkit.block.data.Waterlogged) super.getHandle()).setWaterlogged(waterlogged);
}
}

View File

@@ -1,29 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.data.AnaloguePowerable;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.block.BlockState;
/**
* None of this actually has implementation, TODO: implement this if we ever end up needing it.
*/
public class FabricAnaloguePowerable extends FabricBlockState implements AnaloguePowerable {
public FabricAnaloguePowerable(BlockState delegate) {
super(delegate);
}
@Override
public int getMaximumPower() {
return 0;
}
@Override
public int getPower() {
return 0;
}
@Override
public void setPower(int power) {
}
}

View File

@@ -1,42 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Directional;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.DirectionProperty;
public class FabricDirectional extends FabricBlockState implements Directional {
private final DirectionProperty property;
public FabricDirectional(BlockState delegate, DirectionProperty property) {
super(delegate);
this.property = property;
}
@Override
public BlockFace getFacing() {
switch(delegate.get(property)) {
case SOUTH:
return BlockFace.SOUTH;
case DOWN:
return BlockFace.DOWN;
case UP:
return BlockFace.UP;
case EAST:
return BlockFace.EAST;
case WEST:
return BlockFace.WEST;
case NORTH:
return BlockFace.NORTH;
default:
throw new IllegalStateException();
}
}
@Override
public void setFacing(BlockFace facing) {
delegate = delegate.with(property, FabricAdapter.adapt(facing));
}
}

View File

@@ -1,69 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.MultipleFacing;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
import java.util.HashSet;
import java.util.Set;
public class FabricMultipleFacing extends FabricBlockState implements MultipleFacing {
public FabricMultipleFacing(BlockState delegate) {
super(delegate);
}
@Override
public Set<BlockFace> getFaces() {
Set<BlockFace> set = new HashSet<>();
if(delegate.get(Properties.NORTH)) set.add(BlockFace.NORTH);
if(delegate.get(Properties.SOUTH)) set.add(BlockFace.SOUTH);
if(delegate.get(Properties.EAST)) set.add(BlockFace.EAST);
if(delegate.get(Properties.WEST)) set.add(BlockFace.WEST);
if(delegate.contains(Properties.UP) && delegate.get(Properties.UP)) set.add(BlockFace.UP);
if(delegate.contains(Properties.DOWN) && delegate.get(Properties.DOWN)) set.add(BlockFace.DOWN);
return set;
}
@Override
public void setFace(BlockFace face, boolean facing) {
switch(face) {
case NORTH:
delegate = delegate.with(Properties.NORTH, facing);
break;
case SOUTH:
delegate = delegate.with(Properties.SOUTH, facing);
break;
case EAST:
delegate = delegate.with(Properties.EAST, facing);
break;
case WEST:
delegate = delegate.with(Properties.WEST, facing);
break;
case UP:
delegate = delegate.with(Properties.UP, facing);
break;
case DOWN:
delegate = delegate.with(Properties.DOWN, facing);
break;
}
}
@Override
public Set<BlockFace> getAllowedFaces() {
Set<BlockFace> set = new HashSet<>();
if(delegate.contains(Properties.NORTH)) set.add(BlockFace.NORTH);
if(delegate.contains(Properties.SOUTH)) set.add(BlockFace.SOUTH);
if(delegate.contains(Properties.EAST)) set.add(BlockFace.EAST);
if(delegate.contains(Properties.WEST)) set.add(BlockFace.WEST);
if(delegate.contains(Properties.UP)) set.add(BlockFace.UP);
if(delegate.contains(Properties.DOWN)) set.add(BlockFace.DOWN);
return set;
}
@Override
public boolean hasFace(BlockFace f) {
return getFaces().contains(f);
}
}

View File

@@ -1,37 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.data.Orientable;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.math.Direction;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
public class FabricOrientable extends FabricBlockState implements Orientable {
private final EnumProperty<Direction.Axis> property;
public FabricOrientable(BlockState delegate, EnumProperty<Direction.Axis> property) {
super(delegate);
this.property = property;
}
@Override
public Set<Axis> getAxes() {
return Arrays.stream(Axis.values()).collect(Collectors.toSet());
}
@Override
public Axis getAxis() {
return FabricAdapter.adapt(getHandle().get(property));
}
@Override
public void setAxis(Axis axis) {
delegate = delegate.with(property, FabricAdapter.adapt(axis));
}
}

View File

@@ -1,111 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Rotatable;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
public class FabricRotatable extends FabricBlockState implements Rotatable {
public FabricRotatable(BlockState delegate) {
super(delegate);
}
@Override
public BlockFace getRotation() {
int r = delegate.get(Properties.ROTATION);
switch(r) {
case 0:
return BlockFace.SOUTH;
case 1:
return BlockFace.SOUTH_SOUTH_WEST;
case 2:
return BlockFace.SOUTH_WEST;
case 3:
return BlockFace.WEST_SOUTH_WEST;
case 4:
return BlockFace.WEST;
case 5:
return BlockFace.WEST_NORTH_WEST;
case 6:
return BlockFace.NORTH_WEST;
case 7:
return BlockFace.NORTH_NORTH_WEST;
case 8:
return BlockFace.NORTH;
case 9:
return BlockFace.NORTH_NORTH_EAST;
case 10:
return BlockFace.NORTH_EAST;
case 11:
return BlockFace.EAST_NORTH_EAST;
case 12:
return BlockFace.EAST;
case 13:
return BlockFace.EAST_SOUTH_EAST;
case 14:
return BlockFace.SOUTH_EAST;
case 15:
return BlockFace.SOUTH_SOUTH_EAST;
default:
throw new IllegalArgumentException("Unknown rotation " + r);
}
}
@Override
public void setRotation(BlockFace face) {
switch(face) {
case UP:
case DOWN:
throw new IllegalArgumentException("Illegal rotation " + face);
case SOUTH:
delegate = delegate.with(Properties.ROTATION, 0);
return;
case SOUTH_SOUTH_WEST:
delegate = delegate.with(Properties.ROTATION, 1);
return;
case SOUTH_WEST:
delegate = delegate.with(Properties.ROTATION, 2);
return;
case WEST_SOUTH_WEST:
delegate = delegate.with(Properties.ROTATION, 3);
return;
case WEST:
delegate = delegate.with(Properties.ROTATION, 4);
return;
case WEST_NORTH_WEST:
delegate = delegate.with(Properties.ROTATION, 5);
return;
case NORTH_WEST:
delegate = delegate.with(Properties.ROTATION, 6);
return;
case NORTH_NORTH_WEST:
delegate = delegate.with(Properties.ROTATION, 7);
return;
case NORTH:
delegate = delegate.with(Properties.ROTATION, 8);
return;
case NORTH_NORTH_EAST:
delegate = delegate.with(Properties.ROTATION, 9);
return;
case NORTH_EAST:
delegate = delegate.with(Properties.ROTATION, 10);
return;
case EAST_NORTH_EAST:
delegate = delegate.with(Properties.ROTATION, 11);
return;
case EAST:
delegate = delegate.with(Properties.ROTATION, 12);
return;
case EAST_SOUTH_EAST:
delegate = delegate.with(Properties.ROTATION, 13);
return;
case SOUTH_EAST:
delegate = delegate.with(Properties.ROTATION, 14);
return;
case SOUTH_SOUTH_EAST:
delegate = delegate.with(Properties.ROTATION, 15);
return;
}
}
}

View File

@@ -1,22 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.data.Slab;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
public class FabricSlab extends FabricWaterlogged implements Slab {
public FabricSlab(BlockState delegate) {
super(delegate);
}
@Override
public Type getType() {
return FabricAdapter.adapt(delegate.get(Properties.SLAB_TYPE));
}
@Override
public void setType(Type type) {
delegate = delegate.with(Properties.SLAB_TYPE, FabricAdapter.adapt(type));
}
}

View File

@@ -1,43 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Stairs;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
public class FabricStairs extends FabricWaterlogged implements Stairs {
public FabricStairs(BlockState delegate) {
super(delegate);
}
@Override
public Shape getShape() {
return FabricAdapter.adapt(getHandle().get(Properties.STAIR_SHAPE));
}
@Override
public void setShape(Shape shape) {
super.delegate = getHandle().with(Properties.STAIR_SHAPE, FabricAdapter.adapt(shape));
}
@Override
public Half getHalf() {
return FabricAdapter.adapt(getHandle().get(Properties.BLOCK_HALF));
}
@Override
public void setHalf(Half half) {
super.delegate = getHandle().with(Properties.BLOCK_HALF, FabricAdapter.adapt(half));
}
@Override
public BlockFace getFacing() {
return FabricAdapter.adapt(getHandle().get(Properties.HORIZONTAL_FACING));
}
@Override
public void setFacing(BlockFace facing) {
super.delegate = getHandle().with(Properties.HORIZONTAL_FACING, FabricAdapter.adapt(facing));
}
}

View File

@@ -1,22 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.block.data.Waterlogged;
import com.dfsek.terra.fabric.block.FabricBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
public class FabricWaterlogged extends FabricBlockState implements Waterlogged {
public FabricWaterlogged(BlockState delegate) {
super(delegate);
}
@Override
public boolean isWaterlogged() {
return delegate.get(Properties.WATERLOGGED);
}
@Override
public void setWaterlogged(boolean waterlogged) {
super.delegate = delegate.with(Properties.WATERLOGGED, waterlogged);
}
}

View File

@@ -1,30 +1,15 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.block.state.properties.enums.Half;
import com.dfsek.terra.api.block.state.properties.enums.Axis;
import com.dfsek.terra.api.block.BlockFace;
import com.dfsek.terra.api.block.data.Bisected;
import com.dfsek.terra.api.block.data.Slab;
import com.dfsek.terra.api.block.data.Stairs;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.fabric.block.FabricBlockState;
import com.dfsek.terra.fabric.block.data.FabricDirectional;
import com.dfsek.terra.fabric.block.data.FabricMultipleFacing;
import com.dfsek.terra.fabric.block.data.FabricOrientable;
import com.dfsek.terra.fabric.block.data.FabricRotatable;
import com.dfsek.terra.fabric.block.data.FabricSlab;
import com.dfsek.terra.fabric.block.data.FabricStairs;
import com.dfsek.terra.fabric.block.data.FabricWaterlogged;
import com.dfsek.terra.vector.Vector3Impl;
import net.minecraft.block.BlockState;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.SlabType;
import net.minecraft.block.enums.StairShape;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import java.util.Arrays;
public final class FabricAdapter {
public static BlockPos adapt(Vector3 v) {
return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ());
@@ -35,122 +20,23 @@ public final class FabricAdapter {
}
public static FabricBlockState adapt(BlockState state) {
if(state.contains(Properties.STAIR_SHAPE)) return new FabricStairs(state);
if(state.contains(Properties.SLAB_TYPE)) return new FabricSlab(state);
if(state.contains(Properties.AXIS)) return new FabricOrientable(state, Properties.AXIS);
if(state.contains(Properties.HORIZONTAL_AXIS)) return new FabricOrientable(state, Properties.HORIZONTAL_AXIS);
if(state.contains(Properties.ROTATION)) return new FabricRotatable(state);
if(state.contains(Properties.FACING)) return new FabricDirectional(state, Properties.FACING);
if(state.contains(Properties.HOPPER_FACING)) return new FabricDirectional(state, Properties.HOPPER_FACING);
if(state.contains(Properties.HORIZONTAL_FACING)) return new FabricDirectional(state, Properties.HORIZONTAL_FACING);
if(state.getProperties().containsAll(Arrays.asList(Properties.NORTH, Properties.SOUTH, Properties.EAST, Properties.WEST)))
return new FabricMultipleFacing(state);
if(state.contains(Properties.WATERLOGGED)) return new FabricWaterlogged(state);
return new FabricBlockState(state);
}
public static Direction adapt(BlockFace face) {
switch(face) {
case NORTH:
return Direction.NORTH;
case WEST:
return Direction.WEST;
case SOUTH:
return Direction.SOUTH;
case EAST:
return Direction.EAST;
case UP:
return Direction.UP;
case DOWN:
return Direction.DOWN;
default:
throw new IllegalArgumentException("Illegal direction: " + face);
}
}
public static Stairs.Shape adapt(StairShape shape) {
switch(shape) {
case OUTER_RIGHT:
return Stairs.Shape.OUTER_RIGHT;
case INNER_RIGHT:
return Stairs.Shape.INNER_RIGHT;
case OUTER_LEFT:
return Stairs.Shape.OUTER_LEFT;
case INNER_LEFT:
return Stairs.Shape.INNER_LEFT;
case STRAIGHT:
return Stairs.Shape.STRAIGHT;
default:
throw new IllegalStateException();
}
}
public static Bisected.Half adapt(BlockHalf half) {
public static Half adapt(BlockHalf half) {
switch(half) {
case BOTTOM:
return Bisected.Half.BOTTOM;
return Half.BOTTOM;
case TOP:
return Bisected.Half.TOP;
return Half.TOP;
default:
throw new IllegalStateException();
}
}
public static BlockFace adapt(Direction direction) {
switch(direction) {
case DOWN:
return BlockFace.DOWN;
case UP:
return BlockFace.UP;
case WEST:
return BlockFace.WEST;
case EAST:
return BlockFace.EAST;
case NORTH:
return BlockFace.NORTH;
case SOUTH:
return BlockFace.SOUTH;
default:
throw new IllegalStateException();
}
}
public static Slab.Type adapt(SlabType type) {
switch(type) {
case BOTTOM:
return Slab.Type.BOTTOM;
case TOP:
return Slab.Type.TOP;
case DOUBLE:
return Slab.Type.DOUBLE;
default:
throw new IllegalStateException();
}
}
public static StairShape adapt(Stairs.Shape shape) {
switch(shape) {
case STRAIGHT:
return StairShape.STRAIGHT;
case INNER_LEFT:
return StairShape.INNER_LEFT;
case OUTER_LEFT:
return StairShape.OUTER_LEFT;
case INNER_RIGHT:
return StairShape.INNER_RIGHT;
case OUTER_RIGHT:
return StairShape.OUTER_RIGHT;
default:
throw new IllegalStateException();
}
}
public static BlockHalf adapt(Bisected.Half half) {
public static BlockHalf adapt(Half half) {
switch(half) {
case TOP:
return BlockHalf.TOP;
@@ -161,18 +47,7 @@ public final class FabricAdapter {
}
}
public static SlabType adapt(Slab.Type type) {
switch(type) {
case DOUBLE:
return SlabType.DOUBLE;
case TOP:
return SlabType.TOP;
case BOTTOM:
return SlabType.BOTTOM;
default:
throw new IllegalStateException();
}
}
public static Axis adapt(Direction.Axis axis) {
switch(axis) {