mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
fabric implementations
This commit is contained in:
@@ -9,6 +9,7 @@ import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricMaterialData;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricOrientable;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricSlab;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricStairs;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged;
|
||||
@@ -49,8 +50,13 @@ public class FabricWorldHandle implements WorldHandle {
|
||||
try {
|
||||
BlockState state = parser.parse(true).getBlockState();
|
||||
if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.data.AnaloguePowerable;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
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 FabricBlockData 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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.fabric.world.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;
|
||||
@@ -10,7 +11,7 @@ import net.minecraft.block.enums.StairShape;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
public final class FabricEnumAdapter {
|
||||
public static Stairs.Shape fromFabricStairShape(StairShape shape) {
|
||||
public static Stairs.Shape adapt(StairShape shape) {
|
||||
switch(shape) {
|
||||
case OUTER_RIGHT:
|
||||
return Stairs.Shape.OUTER_RIGHT;
|
||||
@@ -27,7 +28,7 @@ public final class FabricEnumAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public static Bisected.Half fromFabricHalf(BlockHalf half) {
|
||||
public static Bisected.Half adapt(BlockHalf half) {
|
||||
switch(half) {
|
||||
case BOTTOM:
|
||||
return Bisected.Half.BOTTOM;
|
||||
@@ -38,7 +39,7 @@ public final class FabricEnumAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockFace fromFabricDirection(Direction direction) {
|
||||
public static BlockFace adapt(Direction direction) {
|
||||
switch(direction) {
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
@@ -57,7 +58,7 @@ public final class FabricEnumAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public static Slab.Type fromFabricSlabType(SlabType type) {
|
||||
public static Slab.Type adapt(SlabType type) {
|
||||
switch(type) {
|
||||
case BOTTOM:
|
||||
return Slab.Type.BOTTOM;
|
||||
@@ -69,4 +70,90 @@ public final class FabricEnumAdapter {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.Axis;
|
||||
import com.dfsek.terra.api.platform.block.data.Orientable;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FabricOrientable extends FabricBlockData implements Orientable {
|
||||
public FabricOrientable(BlockState delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Axis> getAxes() {
|
||||
return Arrays.stream(Axis.values()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Axis getAxis() {
|
||||
return FabricEnumAdapter.adapt(getHandle().get(Properties.AXIS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAxis(Axis axis) {
|
||||
delegate = delegate.with(Properties.AXIS, FabricEnumAdapter.adapt(axis));
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,11 @@ public class FabricSlab extends FabricWaterlogged implements Slab {
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return FabricEnumAdapter.fromFabricSlabType(delegate.get(Properties.SLAB_TYPE));
|
||||
return FabricEnumAdapter.adapt(delegate.get(Properties.SLAB_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(Type type) {
|
||||
delegate = delegate.with(Properties.SLAB_TYPE, TerraEnumAdapter.fromTerraSlabType(type));
|
||||
delegate = delegate.with(Properties.SLAB_TYPE, FabricEnumAdapter.adapt(type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,31 +12,31 @@ public class FabricStairs extends FabricWaterlogged implements Stairs {
|
||||
|
||||
@Override
|
||||
public Shape getShape() {
|
||||
return FabricEnumAdapter.fromFabricStairShape(getHandle().get(Properties.STAIR_SHAPE));
|
||||
return FabricEnumAdapter.adapt(getHandle().get(Properties.STAIR_SHAPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShape(Shape shape) {
|
||||
super.delegate = getHandle().with(Properties.STAIR_SHAPE, TerraEnumAdapter.fromTerraStairShape(shape));
|
||||
super.delegate = getHandle().with(Properties.STAIR_SHAPE, FabricEnumAdapter.adapt(shape));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Half getHalf() {
|
||||
return FabricEnumAdapter.fromFabricHalf(getHandle().get(Properties.BLOCK_HALF));
|
||||
return FabricEnumAdapter.adapt(getHandle().get(Properties.BLOCK_HALF));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHalf(Half half) {
|
||||
super.delegate = getHandle().with(Properties.BLOCK_HALF, TerraEnumAdapter.fromTerraHalf(half));
|
||||
super.delegate = getHandle().with(Properties.BLOCK_HALF, FabricEnumAdapter.adapt(half));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
return FabricEnumAdapter.fromFabricDirection(getHandle().get(Properties.HORIZONTAL_FACING));
|
||||
return FabricEnumAdapter.adapt(getHandle().get(Properties.HORIZONTAL_FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFacing(BlockFace facing) {
|
||||
super.delegate = getHandle().with(Properties.HORIZONTAL_FACING, TerraEnumAdapter.fromTerraBlockFace(facing));
|
||||
super.delegate = getHandle().with(Properties.HORIZONTAL_FACING, FabricEnumAdapter.adapt(facing));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
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 TerraEnumAdapter {
|
||||
public static StairShape fromTerraStairShape(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 fromTerraHalf(Bisected.Half half) {
|
||||
switch(half) {
|
||||
case TOP:
|
||||
return BlockHalf.TOP;
|
||||
case BOTTOM:
|
||||
return BlockHalf.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public static Direction fromTerraBlockFace(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 fromTerraSlabType(Slab.Type type) {
|
||||
switch(type) {
|
||||
case DOUBLE:
|
||||
return SlabType.DOUBLE;
|
||||
case TOP:
|
||||
return SlabType.TOP;
|
||||
case BOTTOM:
|
||||
return SlabType.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricWorld;
|
||||
import com.dfsek.terra.fabric.world.handles.chunk.FabricChunkWorldAccess;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
@@ -27,6 +28,7 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
|
||||
FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4);
|
||||
FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator));
|
||||
gen.getCavePopulator().populate(world1, random, chunk);
|
||||
gen.getStructurePopulator().populate(new FabricSeededWorldAccess(world, world.getSeed(), chunkGenerator), random, chunk);
|
||||
gen.getOrePopulator().populate(world1, random, chunk);
|
||||
gen.getTreePopulator().populate(world1, random, chunk);
|
||||
gen.getFloraPopulator().populate(world1, random, chunk);
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.dfsek.terra.generation.MasterChunkGenerator;
|
||||
import com.dfsek.terra.population.CavePopulator;
|
||||
import com.dfsek.terra.population.FloraPopulator;
|
||||
import com.dfsek.terra.population.OrePopulator;
|
||||
import com.dfsek.terra.population.StructurePopulator;
|
||||
import com.dfsek.terra.population.TreePopulator;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
@@ -49,6 +50,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
private final FloraPopulator floraPopulator = new FloraPopulator(TerraFabricPlugin.getInstance());
|
||||
private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance());
|
||||
private final TreePopulator treePopulator = new TreePopulator(TerraFabricPlugin.getInstance());
|
||||
private final StructurePopulator structurePopulator = new StructurePopulator(TerraFabricPlugin.getInstance());
|
||||
|
||||
public TreePopulator getTreePopulator() {
|
||||
return treePopulator;
|
||||
@@ -66,6 +68,10 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
return floraPopulator;
|
||||
}
|
||||
|
||||
public StructurePopulator getStructurePopulator() {
|
||||
return structurePopulator;
|
||||
}
|
||||
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
this.pack = configPack;
|
||||
|
||||
@@ -7,8 +7,10 @@ import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.handles.chunk.FabricChunk;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
@@ -64,12 +66,24 @@ public class FabricWorld implements World {
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
return null;
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(pos, delegate.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.generator.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof FabricWorld)) return false;
|
||||
return ((FabricWorld) obj).delegate.generator.equals(delegate.generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(Location l) {
|
||||
return null;
|
||||
return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -85,6 +85,16 @@ public class FabricSeededWorldAccess implements World {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.worldAccess.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handle getHandle() {
|
||||
return handle;
|
||||
|
||||
Reference in New Issue
Block a user