mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-12 10:46:25 +00:00
Flora and ores on Fabric
This commit is contained in:
@@ -298,7 +298,7 @@ public class Vector3 implements Cloneable {
|
||||
public Vector3 subtract(int x, int y, int z) {
|
||||
this.x -= x;
|
||||
this.y -= y;
|
||||
this.z = -z;
|
||||
this.z -= z;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class CavePopulator implements TerraBlockPopulator {
|
||||
Location mut = l.clone();
|
||||
MaterialData orig = handle.getType(l.getBlock());
|
||||
do mut.subtract(0, 1, 0);
|
||||
while(handle.getType(mut.getBlock()).equals(orig));
|
||||
while(mut.getY() > 0 && handle.getType(mut.getBlock()).equals(orig));
|
||||
try {
|
||||
if(template.getShift().get(entry.getValue()).contains(mut.getBlock().getType())) {
|
||||
handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue(), MaterialData::createBlockData), false);
|
||||
|
||||
@@ -15,14 +15,17 @@ 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.fabric.world.generator.TerraChunkGeneratorCodec;
|
||||
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;
|
||||
@@ -133,6 +136,18 @@ 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");
|
||||
|
||||
@@ -14,7 +14,7 @@ public class FabricBlock implements Block {
|
||||
private final Handle delegate;
|
||||
|
||||
public FabricBlock(BlockState state, BlockPos position, WorldAccess worldAccess) {
|
||||
this.delegate = new Handle(state, position, worldAccess);
|
||||
this.delegate = new Handle(position, worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,12 +34,13 @@ public class FabricBlock implements Block {
|
||||
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int len) {
|
||||
return new FabricBlock(delegate.state, delegate.position.add(face.getModX(), face.getModY(), face.getModZ()), delegate.worldAccess);
|
||||
BlockPos newPos = delegate.position.add(face.getModX() * len, face.getModY() * len, face.getModZ() * len);
|
||||
return new FabricBlock(delegate.worldAccess.getBlockState(newPos), newPos, delegate.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return delegate.state.isAir();
|
||||
return getBlockData().getMaterial().isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,7 +50,7 @@ public class FabricBlock implements Block {
|
||||
|
||||
@Override
|
||||
public MaterialData getType() {
|
||||
return new FabricMaterialData(delegate.state.getMaterial());
|
||||
return getBlockData().getMaterial();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +70,7 @@ public class FabricBlock implements Block {
|
||||
|
||||
@Override
|
||||
public boolean isPassable() {
|
||||
return delegate.state.isAir();
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,12 +79,10 @@ public class FabricBlock implements Block {
|
||||
}
|
||||
|
||||
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;
|
||||
public Handle(BlockPos position, WorldAccess worldAccess) {
|
||||
this.position = position;
|
||||
this.worldAccess = worldAccess;
|
||||
}
|
||||
|
||||
@@ -13,17 +13,21 @@ public class FabricBlockData implements BlockData {
|
||||
|
||||
@Override
|
||||
public MaterialData getMaterial() {
|
||||
return null;
|
||||
return new FabricMaterialData(delegate.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(MaterialData materialData) {
|
||||
return false;
|
||||
return ((FabricMaterialData) materialData).getHandle().is(delegate.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData clone() {
|
||||
return null;
|
||||
try {
|
||||
return (BlockData) super.clone();
|
||||
} catch(CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,12 +2,13 @@ package com.dfsek.terra.fabric.world;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.block.BlockData;
|
||||
import com.dfsek.terra.api.generic.world.block.MaterialData;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
||||
public class FabricMaterialData implements MaterialData {
|
||||
private final Material delegate;
|
||||
private final Block delegate;
|
||||
|
||||
public FabricMaterialData(Material delegate) {
|
||||
public FabricMaterialData(Block delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -23,12 +24,12 @@ public class FabricMaterialData implements MaterialData {
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return delegate.isSolid();
|
||||
return !delegate.is(Blocks.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return delegate.blocksMovement(); // TODO: better impl
|
||||
return delegate.is(Blocks.AIR); // TODO: better impl
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,21 +39,25 @@ public class FabricMaterialData implements MaterialData {
|
||||
|
||||
@Override
|
||||
public BlockData createBlockData() {
|
||||
return null;
|
||||
return new FabricBlockData(delegate.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getHandle() {
|
||||
public Block getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
return delegate.asItem().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return delegate.equals(obj);
|
||||
if(obj instanceof FabricMaterialData) {
|
||||
return ((FabricMaterialData) obj).matches(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FabricWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public MaterialData createMaterialData(String data) {
|
||||
return new FabricMaterialData(createBlockData(data).getHandle().getMaterial());
|
||||
return new FabricMaterialData(createBlockData(data).getHandle().getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.dfsek.terra.fabric.world.handles.world.FabricWorldChunkRegion;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.population.CavePopulator;
|
||||
import com.dfsek.terra.population.FloraPopulator;
|
||||
import com.dfsek.terra.population.OrePopulator;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -40,6 +41,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
private final CavePopulator cavePopulator = new CavePopulator(TerraFabricPlugin.getInstance());
|
||||
private final FloraPopulator floraPopulator = new FloraPopulator(TerraFabricPlugin.getInstance());
|
||||
private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance());
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed) {
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
|
||||
@@ -87,8 +89,8 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
FabricWorldChunkRegion chunkRegion = new FabricWorldChunkRegion(region, this);
|
||||
FabricChunkRegionChunk regionChunk = new FabricChunkRegionChunk(region);
|
||||
cavePopulator.populate(chunkRegion, pop, regionChunk);
|
||||
orePopulator.populate(chunkRegion, pop, regionChunk);
|
||||
floraPopulator.populate(chunkRegion, pop, regionChunk);
|
||||
// Nope
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +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.generator.FabricChunkGenerator;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.io.File;
|
||||
@@ -64,12 +66,13 @@ public class FabricSeededWorldAccess implements World {
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
return null;
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(handle.worldAccess.getBlockState(pos), pos, handle.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(Location l) {
|
||||
return null;
|
||||
return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,8 @@ 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 net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.io.File;
|
||||
@@ -62,12 +64,13 @@ public class FabricWorldAccess implements World {
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
return null;
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(delegate.getBlockState(pos), pos, delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(Location l) {
|
||||
return null;
|
||||
return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +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.generator.FabricChunkGenerator;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
|
||||
import java.io.File;
|
||||
@@ -63,12 +65,13 @@ public class FabricWorldChunkRegion implements World {
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
return null;
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(delegate.chunk.getBlockState(pos), pos, delegate.chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(Location l) {
|
||||
return null;
|
||||
return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user