merge FabricEnumAdapter into FabricAdapter

This commit is contained in:
dfsek
2021-05-03 22:49:21 -07:00
parent bf93a9239c
commit 13e0857882
5 changed files with 147 additions and 169 deletions

View File

@@ -1,7 +1,11 @@
package com.dfsek.terra.fabric;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.Axis;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.block.data.Bisected;
import com.dfsek.terra.api.platform.block.data.Slab;
import com.dfsek.terra.api.platform.block.data.Stairs;
import com.dfsek.terra.api.platform.block.state.Container;
import com.dfsek.terra.api.platform.block.state.MobSpawner;
import com.dfsek.terra.api.platform.block.state.Sign;
@@ -18,6 +22,9 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.block.entity.MobSpawnerBlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
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;
@@ -87,4 +94,131 @@ public final class FabricAdapter {
}
return null;
}
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) {
switch(half) {
case BOTTOM:
return Bisected.Half.BOTTOM;
case TOP:
return Bisected.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) {
switch(half) {
case TOP:
return BlockHalf.TOP;
case BOTTOM:
return BlockHalf.BOTTOM;
default:
throw new IllegalStateException();
}
}
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) {
case X:
return Axis.X;
case Y:
return Axis.Y;
case Z:
return Axis.Z;
default:
throw new IllegalStateException();
}
}
public static Direction.Axis adapt(Axis axis) {
switch(axis) {
case Z:
return Direction.Axis.Z;
case Y:
return Direction.Axis.Y;
case X:
return Direction.Axis.X;
default:
throw new IllegalStateException();
}
}
}

View File

@@ -1,159 +0,0 @@
package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.platform.block.Axis;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.block.data.Bisected;
import com.dfsek.terra.api.platform.block.data.Slab;
import com.dfsek.terra.api.platform.block.data.Stairs;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.SlabType;
import net.minecraft.block.enums.StairShape;
import net.minecraft.util.math.Direction;
public final class FabricEnumAdapter {
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) {
switch(half) {
case BOTTOM:
return Bisected.Half.BOTTOM;
case TOP:
return Bisected.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) {
switch(half) {
case TOP:
return BlockHalf.TOP;
case BOTTOM:
return BlockHalf.BOTTOM;
default:
throw new IllegalStateException();
}
}
public static Direction adapt(BlockFace face) {
switch(face) {
case SOUTH:
return Direction.SOUTH;
case NORTH:
return Direction.NORTH;
case EAST:
return Direction.EAST;
case WEST:
return Direction.WEST;
case UP:
return Direction.UP;
case DOWN:
return Direction.DOWN;
default:
throw new IllegalArgumentException();
}
}
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) {
case X:
return Axis.X;
case Y:
return Axis.Y;
case Z:
return Axis.Z;
default:
throw new IllegalStateException();
}
}
public static Direction.Axis adapt(Axis axis) {
switch(axis) {
case Z:
return Direction.Axis.Z;
case Y:
return Direction.Axis.Y;
case X:
return Direction.Axis.X;
default:
throw new IllegalStateException();
}
}
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.fabric.block.data;
import com.dfsek.terra.api.platform.block.Axis;
import com.dfsek.terra.api.platform.block.data.Orientable;
import com.dfsek.terra.fabric.FabricAdapter;
import com.dfsek.terra.fabric.block.FabricBlockData;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.EnumProperty;
@@ -26,11 +27,11 @@ public class FabricOrientable extends FabricBlockData implements Orientable {
@Override
public Axis getAxis() {
return FabricEnumAdapter.adapt(getHandle().get(property));
return FabricAdapter.adapt(getHandle().get(property));
}
@Override
public void setAxis(Axis axis) {
delegate = delegate.with(property, FabricEnumAdapter.adapt(axis));
delegate = delegate.with(property, FabricAdapter.adapt(axis));
}
}

View File

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

View File

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