Implement some BlockData stuff on Fabric, make stuff less jank

This commit is contained in:
dfsek
2020-12-14 15:38:40 -07:00
parent 875e1feafe
commit 49c445d0f7
25 changed files with 363 additions and 141 deletions

View File

@@ -1,4 +1,11 @@
package com.dfsek.terra.api.generic.world.block.data;
public interface Slab extends Bisected, Waterlogged {
public interface Slab extends Waterlogged {
Type getType();
void setType(Type type);
enum Type {
TOP, BOTTOM, DOUBLE
}
}

View File

@@ -11,14 +11,21 @@ import com.dfsek.terra.api.generic.generator.ChunkGenerator;
import com.dfsek.terra.api.generic.world.BiomeGrid;
import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.api.generic.world.block.data.Bisected;
import com.dfsek.terra.api.generic.world.block.data.Slab;
import com.dfsek.terra.api.generic.world.block.data.Stairs;
import com.dfsek.terra.api.generic.world.block.data.Waterlogged;
import com.dfsek.terra.api.generic.world.vector.Vector3;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.palette.SinglePalette;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.util.PaletteUtil;
import com.dfsek.terra.util.SlabUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Random;
public class TerraChunkGenerator implements com.dfsek.terra.api.generic.generator.TerraChunkGenerator {
@@ -26,11 +33,15 @@ public class TerraChunkGenerator implements com.dfsek.terra.api.generic.generato
private final ConfigPack configPack;
private final TerraPlugin main;
private final MaterialData water;
private final SinglePalette<BlockData> blank;
public TerraChunkGenerator(ConfigPack c, TerraPlugin main) {
this.configPack = c;
this.main = main;
water = main.getWorldHandle().createMaterialData("minecraft:water");
blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air"));
}
@Override
@@ -110,20 +121,20 @@ public class TerraChunkGenerator implements com.dfsek.terra.api.generic.generato
data = PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel, cx, cz);
chunk.setBlock(x, y, z, data);
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
SlabUtil.prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector3(x, y + 1, z), c.getSlabPalettes(),
prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector3(x, y + 1, z), c.getSlabPalettes(),
c.getStairPalettes(), c.getSlabThreshold(), sampler);
}
paletteLevel++;
} else if(y <= sea) {
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
if(justSet && c.doSlabs()) {
SlabUtil.prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
}
justSet = false;
paletteLevel = 0;
} else {
if(justSet && c.doSlabs()) {
SlabUtil.prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
}
justSet = false;
paletteLevel = 0;
@@ -137,6 +148,67 @@ public class TerraChunkGenerator implements com.dfsek.terra.api.generic.generato
}
}
private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
if(sampler.sample(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()).clone();
Stairs stairNew = (Stairs) stair;
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
}
}
BlockData slab = slabs.getOrDefault(down.getMaterial(), blank).get(0, block.getBlockX(), block.getBlockZ());
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.matches(water));
} else if(orig.matches(water)) return;
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
}
private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
if(sampler.sample(block.getBlockX(), block.getBlockY() + 0.4, block.getBlockZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()).clone();
Stairs stairNew = (Stairs) stair.clone();
stairNew.setHalf(Bisected.Half.TOP);
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
}
}
BlockData slab = slabs.getOrDefault(up.getMaterial(), blank).get(0, block.getBlockX(), block.getBlockZ()).clone();
if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.matches(water));
} else if(orig.matches(water)) return; // Only replace water if waterlogged.
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
}
private boolean placeStair(BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, double thresh, Sampler sampler, Stairs stairNew) {
if(sampler.sample(block.getBlockX() - 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
stairNew.setFacing(BlockFace.WEST);
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.55) > thresh) {
stairNew.setFacing(BlockFace.NORTH);
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.55) > thresh) {
stairNew.setFacing(BlockFace.SOUTH);
} else if(sampler.sample(block.getBlockX() + 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
stairNew.setFacing(BlockFace.EAST);
} else stairNew = null;
if(stairNew != null) {
if(orig.matches(water)) stairNew.setWaterlogged(orig.matches(water));
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
return true;
}
return false;
}
@Override
public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) {
int xOrig = (chunkX << 4);

View File

@@ -1,81 +0,0 @@
package com.dfsek.terra.util;
import com.dfsek.terra.api.gaea.world.palette.Palette;
import com.dfsek.terra.api.generic.generator.ChunkGenerator;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.api.generic.world.block.data.Stairs;
import com.dfsek.terra.api.generic.world.vector.Vector3;
import com.dfsek.terra.generation.Sampler;
import java.util.Map;
public final class SlabUtil {
public static void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
/*
if(sampler.sample(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()).clone();
Stairs stairNew = (Stairs) stair;
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
}
}
BlockData slab = slabs.getOrDefault(down.getMaterial(), PaletteUtil.BLANK_PALETTE).get(0, block.getBlockX(), block.getBlockZ());
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.matches(PaletteUtil.WATER));
} else if(orig.matches(PaletteUtil.WATER)) return;
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
*/
}
public static void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
/*
if(sampler.sample(block.getBlockX(), block.getBlockY() + 0.4, block.getBlockZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()).clone();
Stairs stairNew = (Stairs) stair.clone();
stairNew.setHalf(Bisected.Half.TOP);
if(placeStair(orig, chunk, block, thresh, sampler, stairNew)) return; // Successfully placed part.
}
}
BlockData slab = slabs.getOrDefault(up.getMaterial(), PaletteUtil.BLANK_PALETTE).get(0, block.getBlockX(), block.getBlockZ()).clone();
if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.matches(PaletteUtil.WATER));
} else if(orig.matches(PaletteUtil.WATER)) return; // Only replace water if waterlogged.
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
*/
}
private static boolean placeStair(BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, double thresh, Sampler sampler, Stairs stairNew) {
/*
if(sampler.sample(block.getBlockX() - 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
stairNew.setFacing(BlockFace.WEST);
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.55) > thresh) {
stairNew.setFacing(BlockFace.NORTH);
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.55) > thresh) {
stairNew.setFacing(BlockFace.SOUTH);
} else if(sampler.sample(block.getBlockX() + 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
stairNew.setFacing(BlockFace.EAST);
} else stairNew = null;
if(stairNew != null) {
if(orig.matches(PaletteUtil.WATER)) stairNew.setWaterlogged(true);
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
return true;
}
*/
return false;
}
}

View File

@@ -4,7 +4,7 @@ import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;
public class BukkitBlockData implements BlockData {
private final org.bukkit.block.data.BlockData delegate;
private org.bukkit.block.data.BlockData delegate;
public BukkitBlockData(org.bukkit.block.data.BlockData delegate) {
this.delegate = delegate;
@@ -29,7 +29,9 @@ public class BukkitBlockData implements BlockData {
@Override
public BukkitBlockData clone() {
try {
return (BukkitBlockData) super.clone();
BukkitBlockData n = (BukkitBlockData) super.clone();
n.delegate = delegate.clone();
return n;
} catch(CloneNotSupportedException e) {
throw new Error(e);
}

View File

@@ -3,6 +3,7 @@ package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import com.dfsek.terra.api.generic.world.block.data.Bisected;
import com.dfsek.terra.api.generic.world.block.data.Slab;
import com.dfsek.terra.api.generic.world.block.data.Stairs;
/**
@@ -82,4 +83,17 @@ public final class BukkitEnumAdapter {
}
}
public static Slab.Type fromBukkitSlabType(org.bukkit.block.data.type.Slab.Type 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();
}
}
}

View File

@@ -8,30 +8,28 @@ import java.util.Set;
import java.util.stream.Collectors;
public class BukkitMultipleFacing extends BukkitBlockData implements MultipleFacing {
private final org.bukkit.block.data.MultipleFacing delegate;
public BukkitMultipleFacing(org.bukkit.block.data.MultipleFacing delegate) {
super(delegate);
this.delegate = delegate;
}
@Override
public Set<BlockFace> getFaces() {
return delegate.getFaces().stream().map(BukkitEnumAdapter::fromBukkitBlockFace).collect(Collectors.toSet());
return ((org.bukkit.block.data.MultipleFacing) super.getHandle()).getFaces().stream().map(BukkitEnumAdapter::fromBukkitBlockFace).collect(Collectors.toSet());
}
@Override
public void setFace(BlockFace face, boolean facing) {
delegate.setFace(TerraEnumAdapter.fromTerraBlockFace(face), facing);
((org.bukkit.block.data.MultipleFacing) super.getHandle()).setFace(TerraEnumAdapter.fromTerraBlockFace(face), facing);
}
@Override
public Set<BlockFace> getAllowedFaces() {
return delegate.getAllowedFaces().stream().map(BukkitEnumAdapter::fromBukkitBlockFace).collect(Collectors.toSet());
return ((org.bukkit.block.data.MultipleFacing) super.getHandle()).getAllowedFaces().stream().map(BukkitEnumAdapter::fromBukkitBlockFace).collect(Collectors.toSet());
}
@Override
public boolean hasFace(BlockFace f) {
return delegate.hasFace(TerraEnumAdapter.fromTerraBlockFace(f));
return ((org.bukkit.block.data.MultipleFacing) super.getHandle()).hasFace(TerraEnumAdapter.fromTerraBlockFace(f));
}
}

View File

@@ -0,0 +1,32 @@
package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.generic.world.block.data.Slab;
import com.dfsek.terra.api.generic.world.block.data.Waterlogged;
import com.dfsek.terra.bukkit.world.block.BukkitBlockData;
import org.bukkit.block.data.BlockData;
public class BukkitSlab extends BukkitBlockData implements Slab {
public BukkitSlab(BlockData delegate) {
super(delegate);
}
@Override
public boolean isWaterlogged() {
return ((Waterlogged) getHandle()).isWaterlogged();
}
@Override
public void setWaterlogged(boolean waterlogged) {
((Waterlogged) getHandle()).setWaterlogged(waterlogged);
}
@Override
public Type getType() {
return BukkitEnumAdapter.fromBukkitSlabType(((org.bukkit.block.data.type.Slab) getHandle()).getType());
}
@Override
public void setType(Type type) {
((org.bukkit.block.data.type.Slab) getHandle()).setType(TerraEnumAdapter.fromTerraSlabType(type));
}
}

View File

@@ -5,50 +5,48 @@ import com.dfsek.terra.api.generic.world.block.data.Stairs;
import com.dfsek.terra.bukkit.world.block.BukkitBlockData;
public class BukkitStairs extends BukkitBlockData implements Stairs {
private final org.bukkit.block.data.type.Stairs stairs;
public BukkitStairs(org.bukkit.block.data.type.Stairs delegate) {
super(delegate);
this.stairs = delegate;
}
@Override
public Shape getShape() {
return BukkitEnumAdapter.fromBukkitStair(stairs.getShape());
return BukkitEnumAdapter.fromBukkitStair(((org.bukkit.block.data.type.Stairs) super.getHandle()).getShape());
}
@Override
public void setShape(Shape shape) {
stairs.setShape(TerraEnumAdapter.fromTerraStair(shape));
((org.bukkit.block.data.type.Stairs) super.getHandle()).setShape(TerraEnumAdapter.fromTerraStair(shape));
}
@Override
public Half getHalf() {
return BukkitEnumAdapter.fromBukkitHalf(stairs.getHalf());
return BukkitEnumAdapter.fromBukkitHalf(((org.bukkit.block.data.type.Stairs) super.getHandle()).getHalf());
}
@Override
public void setHalf(Half half) {
stairs.setHalf(TerraEnumAdapter.fromTerraHalf(half));
((org.bukkit.block.data.type.Stairs) super.getHandle()).setHalf(TerraEnumAdapter.fromTerraHalf(half));
}
@Override
public BlockFace getFacing() {
return BukkitEnumAdapter.fromBukkitBlockFace(stairs.getFacing());
return BukkitEnumAdapter.fromBukkitBlockFace(((org.bukkit.block.data.type.Stairs) super.getHandle()).getFacing());
}
@Override
public void setFacing(BlockFace facing) {
stairs.setFacing(TerraEnumAdapter.fromTerraBlockFace(facing));
((org.bukkit.block.data.type.Stairs) super.getHandle()).setFacing(TerraEnumAdapter.fromTerraBlockFace(facing));
}
@Override
public boolean isWaterlogged() {
return stairs.isWaterlogged();
return ((org.bukkit.block.data.type.Stairs) super.getHandle()).isWaterlogged();
}
@Override
public void setWaterlogged(boolean waterlogged) {
stairs.setWaterlogged(waterlogged);
((org.bukkit.block.data.type.Stairs) super.getHandle()).setWaterlogged(waterlogged);
}
}

View File

@@ -4,19 +4,17 @@ import com.dfsek.terra.api.generic.world.block.data.Waterlogged;
import com.dfsek.terra.bukkit.world.block.BukkitBlockData;
public class BukkitWaterlogged extends BukkitBlockData implements Waterlogged {
private boolean waterlogged;
public BukkitWaterlogged(org.bukkit.block.data.Waterlogged delegate) {
super(delegate);
}
@Override
public boolean isWaterlogged() {
return waterlogged;
return ((org.bukkit.block.data.Waterlogged) super.getHandle()).isWaterlogged();
}
@Override
public void setWaterlogged(boolean waterlogged) {
this.waterlogged = waterlogged;
((org.bukkit.block.data.Waterlogged) super.getHandle()).setWaterlogged(waterlogged);
}
}

View File

@@ -3,6 +3,7 @@ package com.dfsek.terra.bukkit.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.Stairs;
/**
@@ -81,4 +82,17 @@ public final class TerraEnumAdapter {
throw new IllegalStateException();
}
}
public static Slab.Type fromTerraSlabType(com.dfsek.terra.api.generic.world.block.data.Slab.Type type) {
switch(type) {
case TOP:
return Slab.Type.TOP;
case DOUBLE:
return Slab.Type.DOUBLE;
case BOTTOM:
return Slab.Type.BOTTOM;
default:
throw new IllegalStateException();
}
}
}

View File

@@ -15,16 +15,13 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.fabric.inventory.FabricItemHandle;
import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor;
import com.dfsek.terra.fabric.world.FabricBiome;
import com.dfsek.terra.fabric.world.FabricMaterialData;
import com.dfsek.terra.fabric.world.FabricWorldHandle;
import com.dfsek.terra.fabric.world.TerraBiomeSource;
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
import com.dfsek.terra.registry.ConfigRegistry;
import com.dfsek.terra.util.MaterialSet;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Blocks;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
@@ -141,18 +138,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
@Override
public void onInitialize() {
MaterialSet set = new MaterialSet();
set.add(new FabricMaterialData(Blocks.STONE));
set.add(new FabricMaterialData(Blocks.DIRT));
System.out.println("Contains: " + set.contains(new FabricMaterialData(Blocks.AIR)));
System.out.println("Contains: " + set.contains(new FabricMaterialData(Blocks.STONE)));
System.out.println("Matches: " + new FabricMaterialData(Blocks.STONE).matches(new FabricMaterialData(Blocks.STONE)));
System.out.println("Matches: " + new FabricMaterialData(Blocks.STONE).matches(new FabricMaterialData(Blocks.DIRT)));
instance = this;
plugin.load(this);
config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");

View File

@@ -1,7 +0,0 @@
package com.dfsek.terra.fabric.world;
import com.dfsek.terra.registry.TerraRegistry;
import net.minecraft.world.biome.Biome;
public class FabricBiomeRegistry extends TerraRegistry<Biome> {
}

View File

@@ -5,9 +5,15 @@ import com.dfsek.terra.api.generic.world.WorldHandle;
import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.fabric.world.block.FabricBlockData;
import com.dfsek.terra.fabric.world.block.FabricMaterialData;
import com.dfsek.terra.fabric.world.block.data.FabricStairs;
import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.state.property.Properties;
public class FabricWorldHandle implements WorldHandle {
@Override
@@ -29,7 +35,11 @@ public class FabricWorldHandle implements WorldHandle {
public FabricBlockData createBlockData(String data) {
BlockArgumentParser parser = new BlockArgumentParser(new StringReader(data), true);
try {
return new FabricBlockData(parser.parse(true).getBlockState());
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.WATERLOGGED)) return new FabricWaterlogged(state);
return new FabricBlockData(state);
} catch(CommandSyntaxException e) {
throw new IllegalArgumentException(e);
}

View File

@@ -1,10 +1,11 @@
package com.dfsek.terra.fabric.world;
package com.dfsek.terra.fabric.world.block;
import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.fabric.world.FabricAdapters;
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;

View File

@@ -1,11 +1,11 @@
package com.dfsek.terra.fabric.world;
package com.dfsek.terra.fabric.world.block;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import net.minecraft.block.BlockState;
public class FabricBlockData implements BlockData {
private final BlockState delegate;
protected BlockState delegate;
public FabricBlockData(BlockState delegate) {
this.delegate = delegate;

View File

@@ -1,4 +1,4 @@
package com.dfsek.terra.fabric.world;
package com.dfsek.terra.fabric.world.block;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData;

View File

@@ -0,0 +1,57 @@
package com.dfsek.terra.fabric.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import com.dfsek.terra.api.generic.world.block.data.Bisected;
import com.dfsek.terra.api.generic.world.block.data.Stairs;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.StairShape;
import net.minecraft.util.math.Direction;
public final class FabricEnumAdapter {
public static Stairs.Shape fromFabricStairShape(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 fromFabricHalf(BlockHalf half) {
switch(half) {
case BOTTOM:
return Bisected.Half.BOTTOM;
case TOP:
return Bisected.Half.TOP;
default:
throw new IllegalStateException();
}
}
public static BlockFace fromFabricDirection(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();
}
}
}

View File

@@ -0,0 +1,42 @@
package com.dfsek.terra.fabric.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import com.dfsek.terra.api.generic.world.block.data.Stairs;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
public class FabricStairs extends FabricWaterlogged implements Stairs {
public FabricStairs(BlockState delegate) {
super(delegate);
}
@Override
public Shape getShape() {
return FabricEnumAdapter.fromFabricStairShape(getHandle().get(Properties.STAIR_SHAPE));
}
@Override
public void setShape(Shape shape) {
super.delegate = getHandle().with(Properties.STAIR_SHAPE, TerraEnumAdapter.fromTerraStairShape(shape));
}
@Override
public Half getHalf() {
return FabricEnumAdapter.fromFabricHalf(getHandle().get(Properties.BLOCK_HALF));
}
@Override
public void setHalf(Half half) {
super.delegate = getHandle().with(Properties.BLOCK_HALF, TerraEnumAdapter.fromTerraHalf(half));
}
@Override
public BlockFace getFacing() {
return FabricEnumAdapter.fromFabricDirection(getHandle().get(Properties.HORIZONTAL_FACING));
}
@Override
public void setFacing(BlockFace facing) {
super.delegate = getHandle().with(Properties.HORIZONTAL_FACING, TerraEnumAdapter.fromTerraBlockFace(facing));
}
}

View File

@@ -0,0 +1,22 @@
package com.dfsek.terra.fabric.world.block.data;
import com.dfsek.terra.api.generic.world.block.data.Waterlogged;
import com.dfsek.terra.fabric.world.block.FabricBlockData;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
public class FabricWaterlogged extends FabricBlockData implements Waterlogged {
public FabricWaterlogged(BlockState delegate) {
super(delegate);
}
@Override
public boolean isWaterlogged() {
return delegate.get(Properties.WATERLOGGED);
}
@Override
public void setWaterlogged(boolean waterlogged) {
super.delegate = delegate.with(Properties.WATERLOGGED, waterlogged);
}
}

View File

@@ -0,0 +1,57 @@
package com.dfsek.terra.fabric.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import com.dfsek.terra.api.generic.world.block.data.Bisected;
import com.dfsek.terra.api.generic.world.block.data.Stairs;
import net.minecraft.block.enums.BlockHalf;
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();
}
}
}

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.fabric.world.generator;
import com.dfsek.terra.api.generic.generator.ChunkGenerator;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.fabric.world.FabricBlockData;
import com.dfsek.terra.fabric.world.block.FabricBlockData;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
import org.jetbrains.annotations.NotNull;

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.fabric.world.handles.chunk;
import com.dfsek.terra.api.generic.world.Chunk;
import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.fabric.world.FabricBlock;
import com.dfsek.terra.fabric.world.block.FabricBlock;
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion;

View File

@@ -7,7 +7,7 @@ import com.dfsek.terra.api.generic.world.Chunk;
import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.fabric.world.FabricBlock;
import com.dfsek.terra.fabric.world.block.FabricBlock;
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;

View File

@@ -7,8 +7,9 @@ import com.dfsek.terra.api.generic.world.Chunk;
import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.fabric.world.FabricBlock;
import com.dfsek.terra.fabric.world.block.FabricBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.WorldAccess;
import java.io.File;
@@ -24,7 +25,7 @@ public class FabricWorldAccess implements World {
@Override
public long getSeed() {
return 1234; // TODO: actually implement this
return ((StructureWorldAccess) delegate).getSeed();
}
@Override

View File

@@ -7,7 +7,7 @@ import com.dfsek.terra.api.generic.world.Chunk;
import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.fabric.world.FabricBlock;
import com.dfsek.terra.fabric.world.block.FabricBlock;
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion;