From 13e08578822bebc0f22d3e60c728d5e70677bc14 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 3 May 2021 22:49:21 -0700 Subject: [PATCH] merge FabricEnumAdapter into FabricAdapter --- .../com/dfsek/terra/fabric/FabricAdapter.java | 134 +++++++++++++++ .../fabric/block/data/FabricEnumAdapter.java | 159 ------------------ .../fabric/block/data/FabricOrientable.java | 5 +- .../terra/fabric/block/data/FabricSlab.java | 5 +- .../terra/fabric/block/data/FabricStairs.java | 13 +- 5 files changed, 147 insertions(+), 169 deletions(-) delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricEnumAdapter.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAdapter.java index 3d006d637..62037173c 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/FabricAdapter.java @@ -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(); + } + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricEnumAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricEnumAdapter.java deleted file mode 100644 index 1fd1f173b..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricEnumAdapter.java +++ /dev/null @@ -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(); - } - } -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricOrientable.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricOrientable.java index 0cdc640e8..1633df9ab 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricOrientable.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricOrientable.java @@ -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)); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricSlab.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricSlab.java index 6b36a4794..390702582 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricSlab.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricSlab.java @@ -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)); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricStairs.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricStairs.java index 386314530..098cd75d6 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricStairs.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/block/data/FabricStairs.java @@ -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)); } }