From 546431bbef8fc8a1280910e266a33186fef9632b Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 21 Jun 2022 09:59:16 -0700 Subject: [PATCH] clean up adapter --- .../FabricChunkGeneratorWrapper.java | 6 +- .../terra/entity/EntityMixin.java | 4 +- .../dfsek/terra/forge/util/FabricAdapter.java | 185 ------------------ .../dfsek/terra/forge/util/ForgeAdapter.java | 56 ++++++ 4 files changed, 61 insertions(+), 190 deletions(-) delete mode 100644 platforms/forge/src/main/java/com/dfsek/terra/forge/util/FabricAdapter.java create mode 100644 platforms/forge/src/main/java/com/dfsek/terra/forge/util/ForgeAdapter.java diff --git a/platforms/forge/src/main/java/com/dfsek/terra/forge/generation/FabricChunkGeneratorWrapper.java b/platforms/forge/src/main/java/com/dfsek/terra/forge/generation/FabricChunkGeneratorWrapper.java index e31bb40b2..f58b12deb 100644 --- a/platforms/forge/src/main/java/com/dfsek/terra/forge/generation/FabricChunkGeneratorWrapper.java +++ b/platforms/forge/src/main/java/com/dfsek/terra/forge/generation/FabricChunkGeneratorWrapper.java @@ -64,7 +64,7 @@ import com.dfsek.terra.api.world.info.WorldProperties; import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions; import com.dfsek.terra.forge.data.Codecs; import com.dfsek.terra.forge.mixin.access.StructureAccessorAccessor; -import com.dfsek.terra.forge.util.FabricAdapter; +import com.dfsek.terra.forge.util.ForgeAdapter; public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.ChunkGenerator implements GeneratorWrapper { @@ -185,7 +185,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C @Override public int getHeight(int x, int z, Type heightmap, HeightLimitView height, NoiseConfig noiseConfig) { - WorldProperties properties = FabricAdapter.adapt(height, noiseConfig.getLegacyWorldSeed()); + WorldProperties properties = ForgeAdapter.adapt(height, noiseConfig.getLegacyWorldSeed()); BiomeProvider biomeProvider = pack.getBiomeProvider(); int min = height.getBottomY(); for(int y = height.getTopY() - 1; y >= min; y--) { @@ -199,7 +199,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C @Override public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView height, NoiseConfig noiseConfig) { BlockState[] array = new BlockState[height.getHeight()]; - WorldProperties properties = FabricAdapter.adapt(height, noiseConfig.getLegacyWorldSeed()); + WorldProperties properties = ForgeAdapter.adapt(height, noiseConfig.getLegacyWorldSeed()); BiomeProvider biomeProvider = pack.getBiomeProvider(); for(int y = height.getTopY() - 1; y >= height.getBottomY(); y--) { array[y - height.getBottomY()] = (BlockState) delegate.getBlock(properties, x, y, z, biomeProvider); diff --git a/platforms/forge/src/main/java/com/dfsek/terra/forge/mixin/implementations/terra/entity/EntityMixin.java b/platforms/forge/src/main/java/com/dfsek/terra/forge/mixin/implementations/terra/entity/EntityMixin.java index 96e7be2d5..a300693b7 100644 --- a/platforms/forge/src/main/java/com/dfsek/terra/forge/mixin/implementations/terra/entity/EntityMixin.java +++ b/platforms/forge/src/main/java/com/dfsek/terra/forge/mixin/implementations/terra/entity/EntityMixin.java @@ -17,7 +17,7 @@ package com.dfsek.terra.forge.mixin.implementations.terra.entity; -import com.dfsek.terra.forge.util.FabricAdapter; +import com.dfsek.terra.forge.util.ForgeAdapter; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Implements; @@ -42,7 +42,7 @@ public abstract class EntityMixin { public abstract void teleport(double destX, double destY, double destZ); public Vector3 terra$position() { - return FabricAdapter.adapt(blockPos); + return ForgeAdapter.adapt(blockPos); } public void terra$position(Vector3 location) { diff --git a/platforms/forge/src/main/java/com/dfsek/terra/forge/util/FabricAdapter.java b/platforms/forge/src/main/java/com/dfsek/terra/forge/util/FabricAdapter.java deleted file mode 100644 index b7bc9f010..000000000 --- a/platforms/forge/src/main/java/com/dfsek/terra/forge/util/FabricAdapter.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * This file is part of Terra. - * - * Terra is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Terra is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Terra. If not, see . - */ - -package com.dfsek.terra.forge.util; - -import net.minecraft.block.enums.BlockHalf; -import net.minecraft.block.enums.WallShape; -import net.minecraft.block.enums.WireConnection; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.HeightLimitView; - -import com.dfsek.terra.api.block.state.properties.enums.Axis; -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; -import com.dfsek.terra.api.util.vector.Vector3; -import com.dfsek.terra.api.world.info.WorldProperties; - - -public final class FabricAdapter { - public static BlockPos adapt(Vector3 v) { - return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ()); - } - - public static Vector3 adapt(BlockPos pos) { - return Vector3.of(pos.getX(), pos.getY(), pos.getZ()); - } - - public static Direction adapt(com.dfsek.terra.api.block.state.properties.enums.Direction direction) { - return switch(direction) { - case SOUTH -> Direction.SOUTH; - case NORTH -> Direction.NORTH; - case WEST -> Direction.WEST; - case EAST -> Direction.EAST; - case UP -> Direction.UP; - case DOWN -> Direction.DOWN; - }; - } - - public static WorldProperties adapt(HeightLimitView height, long seed) { - return new WorldProperties() { - @Override - public long getSeed() { - return seed; - } - - @Override - public int getMaxHeight() { - return height.getTopY(); - } - - @Override - public int getMinHeight() { - return height.getBottomY(); - } - - @Override - public Object getHandle() { - return height; - } - }; - } - - public static com.dfsek.terra.api.block.state.properties.enums.Direction adapt(Direction direction) { - return switch(direction) { - case SOUTH -> com.dfsek.terra.api.block.state.properties.enums.Direction.SOUTH; - case NORTH -> com.dfsek.terra.api.block.state.properties.enums.Direction.NORTH; - case WEST -> com.dfsek.terra.api.block.state.properties.enums.Direction.WEST; - case EAST -> com.dfsek.terra.api.block.state.properties.enums.Direction.EAST; - case UP -> com.dfsek.terra.api.block.state.properties.enums.Direction.UP; - case DOWN -> com.dfsek.terra.api.block.state.properties.enums.Direction.DOWN; - }; - } - - public static WallHeight adapt(WallShape shape) { - return switch(shape) { - case LOW -> WallHeight.LOW; - case NONE -> WallHeight.NONE; - case TALL -> WallHeight.TALL; - }; - } - - public static WallShape adapt(WallHeight shape) { - return switch(shape) { - case LOW -> WallShape.LOW; - case NONE -> WallShape.NONE; - case TALL -> WallShape.TALL; - }; - } - - public static RedstoneConnection adapt(WireConnection connection) { - return switch(connection) { - case NONE -> RedstoneConnection.NONE; - case UP -> RedstoneConnection.UP; - case SIDE -> RedstoneConnection.SIDE; - }; - } - - public static WireConnection adapt(RedstoneConnection connection) { - return switch(connection) { - case NONE -> WireConnection.NONE; - case UP -> WireConnection.UP; - case SIDE -> WireConnection.SIDE; - }; - } - - - public static Half adapt(BlockHalf half) { - return switch(half) { - case BOTTOM -> Half.BOTTOM; - case TOP -> Half.TOP; - }; - } - - public static BlockHalf adapt(Half half) { - return switch(half) { - case TOP -> BlockHalf.TOP; - case BOTTOM -> BlockHalf.BOTTOM; - default -> throw new IllegalStateException(); - }; - } - - public static RailShape adapt(net.minecraft.block.enums.RailShape railShape) { - return switch(railShape) { - case EAST_WEST -> RailShape.EAST_WEST; - case NORTH_EAST -> RailShape.NORTH_EAST; - case NORTH_WEST -> RailShape.NORTH_WEST; - case SOUTH_EAST -> RailShape.SOUTH_EAST; - case SOUTH_WEST -> RailShape.SOUTH_WEST; - case NORTH_SOUTH -> RailShape.NORTH_SOUTH; - case ASCENDING_EAST -> RailShape.ASCENDING_EAST; - case ASCENDING_NORTH -> RailShape.ASCENDING_NORTH; - case ASCENDING_SOUTH -> RailShape.ASCENDING_SOUTH; - case ASCENDING_WEST -> RailShape.ASCENDING_WEST; - }; - } - - public static net.minecraft.block.enums.RailShape adapt(RailShape railShape) { - return switch(railShape) { - case EAST_WEST -> net.minecraft.block.enums.RailShape.EAST_WEST; - case NORTH_EAST -> net.minecraft.block.enums.RailShape.NORTH_EAST; - case NORTH_WEST -> net.minecraft.block.enums.RailShape.NORTH_WEST; - case SOUTH_EAST -> net.minecraft.block.enums.RailShape.SOUTH_EAST; - case SOUTH_WEST -> net.minecraft.block.enums.RailShape.SOUTH_WEST; - case NORTH_SOUTH -> net.minecraft.block.enums.RailShape.NORTH_SOUTH; - case ASCENDING_EAST -> net.minecraft.block.enums.RailShape.ASCENDING_EAST; - case ASCENDING_NORTH -> net.minecraft.block.enums.RailShape.ASCENDING_NORTH; - case ASCENDING_SOUTH -> net.minecraft.block.enums.RailShape.ASCENDING_SOUTH; - case ASCENDING_WEST -> net.minecraft.block.enums.RailShape.ASCENDING_WEST; - }; - } - - - public static Axis adapt(Direction.Axis axis) { - return switch(axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }; - } - - public static Direction.Axis adapt(Axis axis) { - return switch(axis) { - case Z -> Direction.Axis.Z; - case Y -> Direction.Axis.Y; - case X -> Direction.Axis.X; - }; - } -} diff --git a/platforms/forge/src/main/java/com/dfsek/terra/forge/util/ForgeAdapter.java b/platforms/forge/src/main/java/com/dfsek/terra/forge/util/ForgeAdapter.java new file mode 100644 index 000000000..469b80349 --- /dev/null +++ b/platforms/forge/src/main/java/com/dfsek/terra/forge/util/ForgeAdapter.java @@ -0,0 +1,56 @@ +/* + * This file is part of Terra. + * + * Terra is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Terra is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Terra. If not, see . + */ + +package com.dfsek.terra.forge.util; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.HeightLimitView; + +import com.dfsek.terra.api.util.vector.Vector3; +import com.dfsek.terra.api.world.info.WorldProperties; + + +public final class ForgeAdapter { + + public static Vector3 adapt(BlockPos pos) { + return Vector3.of(pos.getX(), pos.getY(), pos.getZ()); + } + + public static WorldProperties adapt(HeightLimitView height, long seed) { + return new WorldProperties() { + @Override + public long getSeed() { + return seed; + } + + @Override + public int getMaxHeight() { + return height.getTopY(); + } + + @Override + public int getMinHeight() { + return height.getBottomY(); + } + + @Override + public Object getHandle() { + return height; + } + }; + } +}