mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 06:40:12 +00:00
convert to new expression switches
This commit is contained in:
@@ -70,21 +70,14 @@ public final class ForgeAdapter {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
return switch(face) {
|
||||
case NORTH -> Direction.NORTH;
|
||||
case WEST -> Direction.WEST;
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
case EAST -> Direction.EAST;
|
||||
case UP -> Direction.UP;
|
||||
case DOWN -> Direction.DOWN;
|
||||
default -> throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,22 +17,14 @@ public class ForgeDirectional extends ForgeBlockData implements Directional {
|
||||
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
switch(delegate.getValue(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();
|
||||
}
|
||||
return switch(delegate.getValue(property)) {
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,148 +12,90 @@ import net.minecraft.util.Direction;
|
||||
|
||||
public final class ForgeEnumAdapter {
|
||||
public static Stairs.Shape adapt(StairsShape 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();
|
||||
}
|
||||
return switch(shape) {
|
||||
case OUTER_RIGHT -> Stairs.Shape.OUTER_RIGHT;
|
||||
case INNER_RIGHT -> Stairs.Shape.INNER_RIGHT;
|
||||
case OUTER_LEFT -> Stairs.Shape.OUTER_LEFT;
|
||||
case INNER_LEFT -> Stairs.Shape.INNER_LEFT;
|
||||
case STRAIGHT -> Stairs.Shape.STRAIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Bisected.Half adapt(Half half) {
|
||||
switch(half) {
|
||||
case BOTTOM:
|
||||
return Bisected.Half.BOTTOM;
|
||||
case TOP:
|
||||
return Bisected.Half.TOP;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case BOTTOM -> Bisected.Half.BOTTOM;
|
||||
case TOP -> Bisected.Half.TOP;
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return switch(direction) {
|
||||
case DOWN -> BlockFace.DOWN;
|
||||
case UP -> BlockFace.UP;
|
||||
case WEST -> BlockFace.WEST;
|
||||
case EAST -> BlockFace.EAST;
|
||||
case NORTH -> BlockFace.NORTH;
|
||||
case SOUTH -> BlockFace.SOUTH;
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return switch(type) {
|
||||
case BOTTOM -> Slab.Type.BOTTOM;
|
||||
case TOP -> Slab.Type.TOP;
|
||||
case DOUBLE -> Slab.Type.DOUBLE;
|
||||
};
|
||||
}
|
||||
|
||||
public static StairsShape adapt(Stairs.Shape shape) {
|
||||
switch(shape) {
|
||||
case STRAIGHT:
|
||||
return StairsShape.STRAIGHT;
|
||||
case INNER_LEFT:
|
||||
return StairsShape.INNER_LEFT;
|
||||
case OUTER_LEFT:
|
||||
return StairsShape.OUTER_LEFT;
|
||||
case INNER_RIGHT:
|
||||
return StairsShape.INNER_RIGHT;
|
||||
case OUTER_RIGHT:
|
||||
return StairsShape.OUTER_RIGHT;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(shape) {
|
||||
case STRAIGHT -> StairsShape.STRAIGHT;
|
||||
case INNER_LEFT -> StairsShape.INNER_LEFT;
|
||||
case OUTER_LEFT -> StairsShape.OUTER_LEFT;
|
||||
case INNER_RIGHT -> StairsShape.INNER_RIGHT;
|
||||
case OUTER_RIGHT -> StairsShape.OUTER_RIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Half adapt(Bisected.Half half) {
|
||||
switch(half) {
|
||||
case TOP:
|
||||
return Half.TOP;
|
||||
case BOTTOM:
|
||||
return Half.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return switch(half) {
|
||||
case TOP -> Half.TOP;
|
||||
case BOTTOM -> Half.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return switch(face) {
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
case NORTH -> Direction.NORTH;
|
||||
case EAST -> Direction.EAST;
|
||||
case WEST -> Direction.WEST;
|
||||
case UP -> Direction.UP;
|
||||
case DOWN -> Direction.DOWN;
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return switch(type) {
|
||||
case DOUBLE -> SlabType.DOUBLE;
|
||||
case TOP -> SlabType.TOP;
|
||||
case BOTTOM -> SlabType.BOTTOM;
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return switch(axis) {
|
||||
case X -> Axis.X;
|
||||
case Y -> Axis.Y;
|
||||
case Z -> Axis.Z;
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return switch(axis) {
|
||||
case Z -> Direction.Axis.Z;
|
||||
case Y -> Direction.Axis.Y;
|
||||
case X -> Direction.Axis.X;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,24 +29,12 @@ public class ForgeMultipleFacing extends ForgeBlockData implements MultipleFacin
|
||||
@Override
|
||||
public void setFace(BlockFace face, boolean facing) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.NORTH, facing);
|
||||
break;
|
||||
case SOUTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.SOUTH, facing);
|
||||
break;
|
||||
case EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.EAST, facing);
|
||||
break;
|
||||
case WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.WEST, facing);
|
||||
break;
|
||||
case UP:
|
||||
delegate = delegate.setValue(BlockStateProperties.UP, facing);
|
||||
break;
|
||||
case DOWN:
|
||||
delegate = delegate.setValue(BlockStateProperties.DOWN, facing);
|
||||
break;
|
||||
case NORTH -> delegate = delegate.setValue(BlockStateProperties.NORTH, facing);
|
||||
case SOUTH -> delegate = delegate.setValue(BlockStateProperties.SOUTH, facing);
|
||||
case EAST -> delegate = delegate.setValue(BlockStateProperties.EAST, facing);
|
||||
case WEST -> delegate = delegate.setValue(BlockStateProperties.WEST, facing);
|
||||
case UP -> delegate = delegate.setValue(BlockStateProperties.UP, facing);
|
||||
case DOWN -> delegate = delegate.setValue(BlockStateProperties.DOWN, facing);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,98 +14,47 @@ public class ForgeRotatable extends ForgeBlockData implements Rotatable {
|
||||
@Override
|
||||
public BlockFace getRotation() {
|
||||
int r = delegate.getValue(BlockStateProperties.ROTATION_16);
|
||||
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);
|
||||
}
|
||||
return switch(r) {
|
||||
case 0 -> BlockFace.SOUTH;
|
||||
case 1 -> BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 2 -> BlockFace.SOUTH_WEST;
|
||||
case 3 -> BlockFace.WEST_SOUTH_WEST;
|
||||
case 4 -> BlockFace.WEST;
|
||||
case 5 -> BlockFace.WEST_NORTH_WEST;
|
||||
case 6 -> BlockFace.NORTH_WEST;
|
||||
case 7 -> BlockFace.NORTH_NORTH_WEST;
|
||||
case 8 -> BlockFace.NORTH;
|
||||
case 9 -> BlockFace.NORTH_NORTH_EAST;
|
||||
case 10 -> BlockFace.NORTH_EAST;
|
||||
case 11 -> BlockFace.EAST_NORTH_EAST;
|
||||
case 12 -> BlockFace.EAST;
|
||||
case 13 -> BlockFace.EAST_SOUTH_EAST;
|
||||
case 14 -> BlockFace.SOUTH_EAST;
|
||||
case 15 -> 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.setValue(BlockStateProperties.ROTATION_16, 0);
|
||||
return;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 1);
|
||||
return;
|
||||
case SOUTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 2);
|
||||
return;
|
||||
case WEST_SOUTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 3);
|
||||
return;
|
||||
case WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 4);
|
||||
return;
|
||||
case WEST_NORTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 5);
|
||||
return;
|
||||
case NORTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 6);
|
||||
return;
|
||||
case NORTH_NORTH_WEST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 7);
|
||||
return;
|
||||
case NORTH:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 8);
|
||||
return;
|
||||
case NORTH_NORTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 9);
|
||||
return;
|
||||
case NORTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 10);
|
||||
return;
|
||||
case EAST_NORTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 11);
|
||||
return;
|
||||
case EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 12);
|
||||
return;
|
||||
case EAST_SOUTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 13);
|
||||
return;
|
||||
case SOUTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 14);
|
||||
return;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 15);
|
||||
return;
|
||||
case UP, DOWN -> throw new IllegalArgumentException("Illegal rotation " + face);
|
||||
case SOUTH -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 0);
|
||||
case SOUTH_SOUTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 1);
|
||||
case SOUTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 2);
|
||||
case WEST_SOUTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 3);
|
||||
case WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 4);
|
||||
case WEST_NORTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 5);
|
||||
case NORTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 6);
|
||||
case NORTH_NORTH_WEST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 7);
|
||||
case NORTH -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 8);
|
||||
case NORTH_NORTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 9);
|
||||
case NORTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 10);
|
||||
case EAST_NORTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 11);
|
||||
case EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 12);
|
||||
case EAST_SOUTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 13);
|
||||
case SOUTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 14);
|
||||
case SOUTH_SOUTH_EAST -> delegate = delegate.setValue(BlockStateProperties.ROTATION_16, 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,32 +88,15 @@ public abstract class MobSpawnerTileEntityMixin extends TileEntityMixin {
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type":
|
||||
terra$setSpawnedType(TerraForgePlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
return;
|
||||
case "delay":
|
||||
terra$setDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "min_delay":
|
||||
terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_delay":
|
||||
terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_count":
|
||||
terra$setSpawnCount(Integer.parseInt(v));
|
||||
return;
|
||||
case "spawn_range":
|
||||
terra$setSpawnRange(Integer.parseInt(v));
|
||||
return;
|
||||
case "max_nearby":
|
||||
terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
return;
|
||||
case "required_player_range":
|
||||
terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid property: " + k);
|
||||
case "type" -> terra$setSpawnedType(TerraForgePlugin.getInstance().getWorldHandle().getEntity(v));
|
||||
case "delay" -> terra$setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
case "spawn_count" -> terra$setSpawnCount(Integer.parseInt(v));
|
||||
case "spawn_range" -> terra$setSpawnRange(Integer.parseInt(v));
|
||||
case "max_nearby" -> terra$setMaxNearbyEntities(Integer.parseInt(v));
|
||||
case "required_player_range" -> terra$setRequiredPlayerRange(Integer.parseInt(v));
|
||||
default -> throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user