mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
Custom carving implemented in Fabric
This commit is contained in:
@@ -50,9 +50,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final WorldHandle worldHandle = new FabricWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private File config;
|
||||
private final PluginConfig plugin;
|
||||
|
||||
{
|
||||
logger.setLevel(Level.INFO);
|
||||
plugin = new PluginConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +79,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public PluginConfig getTerraConfig() {
|
||||
return null;
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,6 +134,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
instance = this;
|
||||
plugin.load(this);
|
||||
config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");
|
||||
LangUtil.load("en_us", this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricWorldAccess;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class BlockStorage {
|
||||
private final Block block;
|
||||
private final Location location;
|
||||
|
||||
public BlockStorage(Block block, Location location) {
|
||||
this.block = block;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public WorldAccess getWorld() {
|
||||
return ((FabricWorldAccess) location.getWorld()).getHandle();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -7,4 +7,8 @@ public final class FabricAdapters {
|
||||
public static BlockPos fromVector(Vector3 v) {
|
||||
return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
}
|
||||
|
||||
public static Vector3 toVector(BlockPos pos) {
|
||||
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,71 +5,87 @@ 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.handles.world.FabricWorldAccess;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class FabricBlock implements Block {
|
||||
private final BlockStorage delegate;
|
||||
private final Handle delegate;
|
||||
|
||||
public FabricBlock(BlockStorage block) {
|
||||
this.delegate = block;
|
||||
public FabricBlock(BlockState state, BlockPos position, WorldAccess worldAccess) {
|
||||
this.delegate = new Handle(state, position, worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockData(BlockData data, boolean physics) {
|
||||
delegate.getWorld().setBlockState(FabricAdapters.fromVector(delegate.getLocation().getVector()), ((FabricBlockData) data).getHandle(), 0, 0);
|
||||
delegate.worldAccess.setBlockState(delegate.position, ((FabricBlockData) data).getHandle(), 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData() {
|
||||
return null;
|
||||
return new FabricBlockData(delegate.worldAccess.getBlockState(delegate.position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getRelative(BlockFace face) {
|
||||
return null;
|
||||
return getRelative(face, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int len) {
|
||||
return null;
|
||||
return new FabricBlock(delegate.state, delegate.position.add(face.getModX(), face.getModY(), face.getModZ()), delegate.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
return delegate.state.isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return delegate.getLocation();
|
||||
return FabricAdapters.toVector(delegate.position).toLocation(new FabricWorldAccess(delegate.worldAccess));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialData getType() {
|
||||
return null;
|
||||
return new FabricMaterialData(delegate.state.getMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return delegate.getLocation().getBlockX();
|
||||
return delegate.position.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return delegate.getLocation().getBlockZ();
|
||||
return delegate.position.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return delegate.getLocation().getBlockY();
|
||||
return delegate.position.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassable() {
|
||||
return false;
|
||||
return delegate.state.isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStorage getHandle() {
|
||||
public Handle getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public static final class Handle {
|
||||
private final BlockState state;
|
||||
private final BlockPos position;
|
||||
private final WorldAccess worldAccess;
|
||||
|
||||
public Handle(BlockState state, BlockPos position, WorldAccess worldAccess) {
|
||||
this.state = state;
|
||||
this.position = position;
|
||||
this.worldAccess = worldAccess;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,4 +45,14 @@ public class FabricMaterialData implements MaterialData {
|
||||
public Material getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return delegate.equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,17 +12,17 @@ import net.minecraft.command.argument.BlockArgumentParser;
|
||||
public class FabricWorldHandle implements WorldHandle {
|
||||
@Override
|
||||
public void setBlockData(Block block, BlockData data, boolean physics) {
|
||||
|
||||
block.setBlockData(data, physics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData(Block block) {
|
||||
return null;
|
||||
return block.getBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialData getType(Block block) {
|
||||
return null;
|
||||
return block.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.dfsek.terra.fabric.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.gaea.math.MathUtil;
|
||||
import com.dfsek.terra.api.gaea.util.FastRandom;
|
||||
import com.dfsek.terra.api.generic.Handle;
|
||||
import com.dfsek.terra.api.generic.generator.TerraBlockPopulator;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricSeededWorldAccess;
|
||||
import com.dfsek.terra.fabric.world.handles.chunk.FabricChunkRegionChunk;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldChunkRegion;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.population.CavePopulator;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -34,7 +38,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
|
||||
private final CavePopulator cavePopulator = new CavePopulator(TerraFabricPlugin.getInstance());
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed) {
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
|
||||
@@ -79,7 +83,8 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
@Override
|
||||
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
|
||||
for(TerraBlockPopulator populator : delegate.getPopulators()) {
|
||||
//populator.populate();
|
||||
FastRandom pop = new FastRandom(MathUtil.getCarverChunkSeed(region.getCenterChunkX(), region.getCenterChunkZ(), seed));
|
||||
cavePopulator.populate(new FabricWorldChunkRegion(region, this), pop, new FabricChunkRegionChunk(region));
|
||||
}
|
||||
// Nope
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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.handles.world.FabricWorldAccess;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
|
||||
public class FabricChunkRegionChunk implements Chunk {
|
||||
private final ChunkRegion chunkRegion;
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
public FabricChunkRegionChunk(ChunkRegion chunkRegion) {
|
||||
this.chunkRegion = chunkRegion;
|
||||
this.x = chunkRegion.getCenterChunkX() << 4;
|
||||
this.z = chunkRegion.getCenterChunkZ() << 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return chunkRegion.getCenterChunkX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return chunkRegion.getCenterChunkZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return new FabricWorldAccess(chunkRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + this.x, y, z + this.z);
|
||||
return new FabricBlock(chunkRegion.getBlockState(pos), pos, chunkRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkRegion getHandle() {
|
||||
return chunkRegion;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.fabric.world.handles;
|
||||
package com.dfsek.terra.fabric.world.handles.world;
|
||||
|
||||
import com.dfsek.terra.api.generic.Entity;
|
||||
import com.dfsek.terra.api.generic.Tree;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.fabric.world.handles;
|
||||
package com.dfsek.terra.fabric.world.handles.world;
|
||||
|
||||
import com.dfsek.terra.api.generic.Entity;
|
||||
import com.dfsek.terra.api.generic.Tree;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.fabric.world.handles;
|
||||
package com.dfsek.terra.fabric.world.handles.world;
|
||||
|
||||
import com.dfsek.terra.api.generic.Entity;
|
||||
import com.dfsek.terra.api.generic.Tree;
|
||||
Reference in New Issue
Block a user