Merge pull request #210 from PolyhedralDev/fabric/1.17-dev

1.17 implementation
This commit is contained in:
dfsek
2021-06-08 10:21:08 -07:00
committed by GitHub
37 changed files with 196 additions and 102 deletions

View File

@@ -14,8 +14,8 @@ fun Project.configureCompilation() {
apply(plugin = "idea")
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}
tasks.withType<JavaCompile> {

View File

@@ -42,7 +42,7 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
@Override
public int argNumber() {
return 1;
return 0;
}
@Override

View File

@@ -15,7 +15,7 @@ public class BufferedPulledBlock implements BufferedItem {
@Override
public void paste(Location origin) {
Block pos = origin.getBlock();
while(pos.getY() > 0) {
while(pos.getY() > origin.getWorld().getMinHeight()) {
if(!pos.isEmpty()) {
pos.setBlockData(data, false);
break;

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.api.world.carving;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.world.World;
import net.jafama.FastMath;
import java.util.Random;
@@ -85,7 +86,7 @@ public abstract class Worm {
return rad[index];
}
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer) {
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer, World world) {
int xRad = getRadius(0);
int yRad = getRadius(1);
int zRad = getRadius(2);
@@ -97,7 +98,7 @@ public abstract class Worm {
if(!(FastMath.floorDiv(origin.getBlockZ() + z, 16) == chunkZ)) continue;
for(int y = -yRad - 1; y <= yRad + 1; y++) {
Vector3 position = origin.clone().add(new Vector3(x, y, z));
if(position.getY() < 0 || position.getY() > 255) continue;
if(position.getY() < world.getMinHeight() || position.getY() > world.getMaxHeight()) continue;
double eq = ellipseEquation(x, y, z, xRad, yRad, zRad);
if(eq <= 1 &&
y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) {

View File

@@ -5,12 +5,19 @@ import com.dfsek.terra.api.world.palette.Palette;
public class PaletteHolder {
private final Palette<BlockData>[] palettes;
private final int offset;
protected PaletteHolder(Palette<BlockData>[] palettes) {
protected PaletteHolder(Palette<BlockData>[] palettes, int offset) {
this.palettes = palettes;
this.offset = offset;
}
public Palette<BlockData> getPalette(int y) {
return palettes[y];
int index = y + offset;
return index >= 0
? index < palettes.length
? palettes[index]
: palettes[palettes.length - 1]
: palettes[0];
}
}

View File

@@ -17,8 +17,12 @@ public class PaletteHolderBuilder {
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
public PaletteHolder build() {
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
int max = FastMath.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
Palette<BlockData> d = null;
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
if(e.getKey() >= y) {
@@ -27,8 +31,8 @@ public class PaletteHolderBuilder {
}
}
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
palettes[y] = d;
palettes[y - min] = d;
}
return new PaletteHolder(palettes);
return new PaletteHolder(palettes, -min);
}
}

View File

@@ -15,6 +15,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Random;
@@ -41,13 +42,13 @@ public class CarverCache {
carving.step();
TerraBiome biome = provider.getBiome(carving.getRunning().toLocation(w));
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(CarverCache.this.carver)) { // Stop if we enter a biome this carver is not present in
return new GlueList<>();
return Collections.emptyList();
}
points.add(carving.getPoint());
}
return points;
}
return new GlueList<>();
return Collections.emptyList();
}
});
}

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import net.jafama.FastMath;
import java.util.Map;
import java.util.TreeMap;
@@ -14,6 +15,7 @@ public class CarverPalette {
private final MaterialSet replace;
private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>();
private ProbabilityCollection<BlockData>[] layers;
private int offset = 0;
public CarverPalette(MaterialSet replaceable, boolean blacklist) {
this.blacklist = blacklist;
@@ -26,7 +28,12 @@ public class CarverPalette {
}
public ProbabilityCollection<BlockData> get(int y) {
return layers[y];
int index = y + offset;
return index >= 0
? index < layers.length
? layers[index]
: layers[layers.length - 1]
: layers[0];
}
public boolean canReplace(BlockType material) {
@@ -37,9 +44,11 @@ public class CarverPalette {
* Build the palette to an array.
*/
public void build() {
int size = map.lastKey() + 1;
layers = new ProbabilityCollection[size];
for(int y = 0; y < size; y++) {
int min = FastMath.min(map.keySet().stream().min(Integer::compareTo).orElse(0), 0);
int max = FastMath.max(map.keySet().stream().max(Integer::compareTo).orElse(255), 255);
layers = new ProbabilityCollection[map.lastKey() + 1 - min];
for(int y = min; y <= FastMath.max(map.lastKey(), max); y++) {
ProbabilityCollection<BlockData> d = null;
for(Map.Entry<Integer, ProbabilityCollection<BlockData>> e : map.entrySet()) {
if(e.getKey() >= y) {
@@ -47,8 +56,9 @@ public class CarverPalette {
break;
}
}
if(d == null) throw new IllegalArgumentException("Null collection at Y=" + y);
layers[y] = d;
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
layers[y - min] = d;
}
offset = -min;
}
}

View File

@@ -116,7 +116,7 @@ public class UserDefinedCarver extends Carver {
Vector3 origin = point.getOrigin();
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk.
return;
point.carve(chunkX, chunkZ, consumer);
point.carve(chunkX, chunkZ, consumer, w);
});
}
}

View File

@@ -13,9 +13,9 @@ public class OreFactory implements ConfigFactory<OreTemplate, Ore> {
BlockData m = config.getMaterial();
switch(config.getType()) {
case SPHERE:
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main);
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main, config.getMaterialOverrides());
case VANILLA:
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main);
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main, config.getMaterialOverrides());
}
return null;
}

View File

@@ -5,9 +5,13 @@ import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.world.population.items.ores.Ore;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings({"unused", "FieldMayBeFinal"})
public class OreTemplate extends AbstractableTemplate {
@Value("id")
@@ -17,6 +21,11 @@ public class OreTemplate extends AbstractableTemplate {
@Abstractable
private BlockData material;
@Value("material-overrides")
@Default
@Abstractable
private Map<BlockType, BlockData> materials = new HashMap<>();
@Value("type")
@Abstractable
@Default
@@ -76,4 +85,8 @@ public class OreTemplate extends AbstractableTemplate {
public Ore.Type getType() {
return oreType;
}
public Map<BlockType, BlockData> getMaterialOverrides() {
return materials;
}
}

View File

@@ -59,7 +59,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
}
for(int y = 0; y < size + 1; y++) {
noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin);
noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, (y << 2) + min, (z << 2) + zOrigin);
}
}
}
@@ -98,10 +98,10 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
*/
@Override
public double getNoise(double x, double y, double z) {
return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
return interpGrid[reRange(((int) x) / 4, 3)][(FastMath.max(FastMath.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
}
public double getNoise(int x, int y, int z) {
return interpGrid[x / 4][y / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
return interpGrid[x / 4][(y - min) / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
}
}

View File

@@ -90,7 +90,7 @@ public class CavePopulator implements TerraBlockPopulator, Chunkified {
Location mut = l.clone();
BlockData orig = l.getBlock().getBlockData();
do mut.subtract(0, 1, 0);
while(mut.getY() > 0 && mut.getBlock().getBlockData().matches(orig));
while(mut.getY() > world.getMinHeight() && mut.getBlock().getBlockData().matches(orig));
try {
if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) {
mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);

View File

@@ -6,10 +6,11 @@ import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.util.collections.MaterialSet;
import java.util.Map;
import java.util.Random;
public class DeformedSphereOre extends Ore {
@@ -17,8 +18,8 @@ public class DeformedSphereOre extends Ore {
private final double deformFrequency;
private final Range size;
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size, TerraPlugin main) {
super(material, replaceable, applyGravity, main);
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size, TerraPlugin main, Map<BlockType, BlockData> materials) {
super(material, replaceable, applyGravity, main, materials);
this.deform = deform;
this.deformFrequency = deformFrequency;
this.size = size;
@@ -27,7 +28,6 @@ public class DeformedSphereOre extends Ore {
@Override
public void generate(Vector3 origin, Chunk c, Random r) {
WorldHandle handle = main.getWorldHandle();
OpenSimplex2Sampler ore = new OpenSimplex2Sampler(r.nextInt());
ore.setFrequency(deformFrequency);
int rad = size.get(r);
@@ -35,12 +35,13 @@ public class DeformedSphereOre extends Ore {
for(int y = -rad; y <= rad; y++) {
for(int z = -rad; z <= rad; z++) {
Vector3 oreLoc = origin.clone().add(new Vector3(x, y, z));
if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > 255 || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < 0)
if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > c.getWorld().getMaxHeight() || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < c.getWorld().getMinHeight())
continue;
if(oreLoc.distance(origin) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) {
Block b = c.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ());
if(getReplaceable().contains(b.getType()) && b.getLocation().getY() >= 0)
b.setBlockData(getMaterial(), isApplyGravity());
BlockType type = b.getType();
if(getReplaceable().contains(type) && b.getLocation().getY() >= c.getWorld().getMinHeight())
b.setBlockData(getMaterial(type), isApplyGravity());
}
}
}

View File

@@ -3,9 +3,11 @@ package com.dfsek.terra.world.population.items.ores;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.util.collections.MaterialSet;
import java.util.Map;
import java.util.Random;
public abstract class Ore {
@@ -14,18 +16,20 @@ public abstract class Ore {
private final MaterialSet replaceable;
private final boolean applyGravity;
protected TerraPlugin main;
private final Map<BlockType, BlockData> materials;
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity, TerraPlugin main) {
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity, TerraPlugin main, Map<BlockType, BlockData> materials) {
this.material = material;
this.replaceable = replaceable;
this.applyGravity = applyGravity;
this.main = main;
this.materials = materials;
}
public abstract void generate(Vector3 origin, Chunk c, Random r);
public BlockData getMaterial() {
return material;
public BlockData getMaterial(BlockType replace) {
return materials.getOrDefault(replace, material);
}
public MaterialSet getReplaceable() {

View File

@@ -5,18 +5,20 @@ import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.util.collections.MaterialSet;
import net.jafama.FastMath;
import java.util.Map;
import java.util.Random;
public class VanillaOre extends Ore {
private final Range sizeRange;
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main) {
super(material, replaceable, applyGravity, main);
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main, Map<BlockType, BlockData> materials) {
super(material, replaceable, applyGravity, main, materials);
this.sizeRange = size;
}
@@ -67,8 +69,9 @@ public class VanillaOre extends Ore {
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue;
Block block = chunk.getBlock(x, y, z);
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block.getType())) {
block.setBlockData(getMaterial(), isApplyGravity());
BlockType type = block.getType();
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(type)) {
block.setBlockData(getMaterial(type), isApplyGravity());
}
}
}

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.jvmargs=-Xmx4096m

View File

@@ -7,7 +7,7 @@ import net.fabricmc.loom.task.RemapJarTask
plugins {
`java-library`
`maven-publish`
id("fabric-loom").version("0.6-SNAPSHOT")
id("fabric-loom").version("0.8-SNAPSHOT")
id("com.modrinth.minotaur").version("1.1.0")
}
@@ -23,9 +23,9 @@ group = "com.dfsek.terra.fabric"
dependencies {
"shadedApi"(project(":common"))
"minecraft"("com.mojang:minecraft:1.16.5")
"mappings"("net.fabricmc:yarn:1.16.5+build.5:v2")
"modImplementation"("net.fabricmc:fabric-loader:0.11.2")
"minecraft"("com.mojang:minecraft:1.17")
"mappings"("net.fabricmc:yarn:1.17+build.1:v2")
"modImplementation"("net.fabricmc:fabric-loader:0.11.3")
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
exclude(group = "com.google.guava", module = "guava")
@@ -36,6 +36,11 @@ dependencies {
}
}
tasks.named<ShadowJar>("shadowJar") {
relocate("org.json", "com.dfsek.terra.lib.json")
relocate("org.yaml", "com.dfsek.terra.lib.yaml")
}
configure<LoomGradleExtension> {
accessWidener("src/main/resources/terra.accesswidener")

View File

@@ -264,7 +264,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE);
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "populator"));
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY, new Identifier("terra", "populator"));
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
@@ -319,7 +319,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
injectTree(treeRegistry, "LARGE_OAK", ConfiguredFeatures.FANCY_OAK);
injectTree(treeRegistry, "LARGE_SPRUCE", ConfiguredFeatures.PINE);
injectTree(treeRegistry, "SMALL_JUNGLE", ConfiguredFeatures.JUNGLE_TREE);
injectTree(treeRegistry, "SWAMP_OAK", ConfiguredFeatures.SWAMP_TREE);
injectTree(treeRegistry, "SWAMP_OAK", ConfiguredFeatures.SWAMP_OAK);
injectTree(treeRegistry, "TALL_BIRCH", ConfiguredFeatures.BIRCH_TALL);
injectTree(treeRegistry, "ACACIA", ConfiguredFeatures.ACACIA);
injectTree(treeRegistry, "BIRCH", ConfiguredFeatures.BIRCH);

View File

@@ -5,10 +5,12 @@ import com.dfsek.terra.api.platform.world.generator.ChunkData;
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
import com.dfsek.terra.fabric.util.FabricAdapter;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
@@ -25,11 +27,10 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockView;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap;
import net.minecraft.world.SpawnHelper;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.chunk.Chunk;
@@ -46,6 +47,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
private final long seed;
@@ -120,11 +122,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
return super.locateStructure(world, feature, center, radius, skipExistingChunks);
}
@Override
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
delegate.generateChunkData((World) world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
}
@Override
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
if(pack.getTemplate().vanillaCaves()) super.carve(seed, access, chunk, carver);
@@ -136,6 +133,20 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
super.setStructureStarts(dynamicRegistryManager, structureAccessor, chunk, structureManager, worldSeed);
}
@Override
public CompletableFuture<Chunk> populateNoise(Executor executor, StructureAccessor accessor, Chunk chunk) {
return CompletableFuture.supplyAsync(() -> {
World world = (World) ((StructureAccessorAccessor) accessor).getWorld();
delegate.generateChunkData(world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
delegate.getPopulators().forEach(populator -> {
if(populator instanceof Chunkified) {
populator.populate(world, (com.dfsek.terra.api.platform.world.Chunk) world);
}
});
return chunk;
}, executor);
}
@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos);
@@ -143,7 +154,12 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
}
@Override
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
public int getHeightOnGround(int x, int z, Heightmap.Type heightmap, HeightLimitView world) {
return super.getHeightOnGround(x, z, heightmap, world);
}
@Override
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView heightmapType) {
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
int cx = FastMath.floorMod(x, 16);
@@ -157,11 +173,11 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
}
@Override
public BlockView getColumnSample(int x, int z) {
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE);
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE, view);
BlockState[] array = new BlockState[256];
for(int y = 255; y >= 0; y--) {
for(int y = view.getBottomY()+view.getHeight(); y >= view.getBottomY(); y--) {
if(y > height) {
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
array[y] = Blocks.AIR.getDefaultState();
@@ -173,18 +189,18 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
}
}
return new VerticalBlockSample(array);
return new VerticalBlockSample(view.getBottomY(), array);
}
@Override
public void populateEntities(ChunkRegion region) {
if(pack.getTemplate().vanillaMobs()) {
int cx = region.getCenterChunkX();
int cy = region.getCenterChunkZ();
int cx = region.getCenterPos().x;
int cy = region.getCenterPos().z;
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
ChunkRandom chunkRandom = new ChunkRandom();
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
SpawnHelper.populateEntities(region, biome, cx, cy, chunkRandom);
SpawnHelper.populateEntities(region, biome, region.getCenterPos(), chunkRandom);
}
}

View File

@@ -2,14 +2,13 @@ package com.dfsek.terra.fabric.generation;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import java.util.Random;
import net.minecraft.world.gen.feature.util.FeatureContext;
/**
* Feature wrapper for Terra populator
@@ -20,10 +19,16 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
ChunkGenerator chunkGenerator = context.getGenerator();
if(!(chunkGenerator instanceof FabricChunkGeneratorWrapper)) return true;
StructureWorldAccess world = context.getWorld();
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
gen.getHandle().getPopulators().forEach(populator -> populator.populate((World) world, (Chunk) world));
gen.getHandle().getPopulators().forEach(populator -> {
if(!(populator instanceof Chunkified)) {
populator.populate((World) world, (Chunk) world);
}
});
return true;
}
}

View File

@@ -8,8 +8,8 @@ import com.dfsek.terra.fabric.util.FabricUtil;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.RegistryLookupCodec;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryLookupCodec;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;

View File

@@ -48,7 +48,7 @@ public abstract class GeneratorOptionsMixin {
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
Registry<DimensionType> dimensionTypes = dynamicRegistryManager.get(Registry.DIMENSION_TYPE_KEY);
Registry<Biome> biomes = dynamicRegistryManager.get(Registry.BIOME_KEY);
Registry<ChunkGeneratorSettings> chunkGeneratorSettings = dynamicRegistryManager.get(Registry.NOISE_SETTINGS_WORLDGEN);
Registry<ChunkGeneratorSettings> chunkGeneratorSettings = dynamicRegistryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomes, chunkGeneratorSettings, l);
prop = prop.substring(prop.indexOf(":") + 1);
@@ -57,7 +57,7 @@ public abstract class GeneratorOptionsMixin {
if(pack == null) throw new IllegalArgumentException("No such pack " + prop);
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.method_28608(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.getRegistryWithReplacedOverworldGenerator(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
}
}
}

View File

@@ -0,0 +1,12 @@
package com.dfsek.terra.fabric.mixin;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.gen.StructureAccessor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(StructureAccessor.class)
public interface StructureAccessorAccessor {
@Accessor
WorldAccess getWorld();
}

View File

@@ -1,12 +1,14 @@
package com.dfsek.terra.fabric.mixin.access;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(MobSpawnerLogic.class)
public interface MobSpawnerLogicAccessor {
@Invoker("getEntityId")
Identifier callGetEntityId();
Identifier callGetEntityId(World world, BlockPos blockPos);
}

View File

@@ -9,6 +9,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
@@ -18,6 +19,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(BlockEntity.class)
@Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class BlockEntityMixin {
@Final
@Shadow
protected BlockPos pos;
@Shadow
@@ -56,7 +58,7 @@ public abstract class BlockEntityMixin {
}
public boolean terra$update(boolean applyPhysics) {
if(hasWorld()) world.getChunk(pos).setBlockEntity(pos, (BlockEntity) (Object) this);
if(hasWorld()) world.getChunk(pos).setBlockEntity((BlockEntity) (Object) this);
return true;
}
}

View File

@@ -5,9 +5,14 @@ import com.dfsek.terra.api.platform.block.state.SerialState;
import com.dfsek.terra.api.platform.entity.EntityType;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.mixin.access.MobSpawnerLogicAccessor;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.MobSpawnerBlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -16,12 +21,16 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(MobSpawnerBlockEntity.class)
@Implements(@Interface(iface = MobSpawner.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class MobSpawnerBlockEntityMixin {
public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
private MobSpawnerBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}
@Shadow
public abstract MobSpawnerLogic getLogic();
public EntityType terra$getSpawnedType() {
return (EntityType) Registry.ENTITY_TYPE.get(((MobSpawnerLogicAccessor) getLogic()).callGetEntityId());
return (EntityType) Registry.ENTITY_TYPE.get(((MobSpawnerLogicAccessor) getLogic()).callGetEntityId(world, pos));
}
public void terra$setSpawnedType(@NotNull EntityType creatureType) {

View File

@@ -20,18 +20,18 @@ public abstract class SignBlockEntityMixin {
@Shadow
@Final
private Text[] text;
private Text[] texts;
public @NotNull String[] terra$getLines() {
String[] lines = new String[text.length];
for(int i = 0; i < text.length; i++) {
lines[i] = text[i].asString();
String[] lines = new String[texts.length];
for(int i = 0; i < texts.length; i++) {
lines[i] = texts[i].asString();
}
return lines;
}
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
return text[index].asString();
return texts[index].asString();
}
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {

View File

@@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.fabric.block.FabricBlock;
import com.dfsek.terra.fabric.block.FabricBlockData;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ChunkRegion;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
@@ -20,18 +21,14 @@ import org.spongepowered.asm.mixin.Shadow;
public abstract class ChunkRegionMixin {
@Final
@Shadow
private int centerChunkX;
@Final
@Shadow
private int centerChunkZ;
private ChunkPos centerPos;
public int terra$getX() {
return centerChunkX;
return centerPos.x;
}
public int terra$getZ() {
return centerChunkZ;
return centerPos.z;
}
public World terra$getWorld() {
@@ -39,7 +36,7 @@ public abstract class ChunkRegionMixin {
}
public Block terra$getBlock(int x, int y, int z) {
BlockPos pos = new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4));
BlockPos pos = new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4));
return new FabricBlock(pos, (ChunkRegion) (Object) this);
}
@@ -48,7 +45,7 @@ public abstract class ChunkRegionMixin {
}
public void terra$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4)), ((FabricBlockData) blockData).getHandle(), 0);
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4)), ((FabricBlockData) blockData).getHandle(), 0);
}
// getHandle already added in world/ChunkRegionMixin.

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.fabric.mixin.implementations.inventory.item;
import com.dfsek.terra.api.platform.inventory.Item;
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -27,7 +27,7 @@ public abstract class ItemStackMixin {
public abstract boolean isDamageable();
@Shadow
public abstract void setTag(@Nullable CompoundTag tag);
public abstract void setTag(@Nullable NbtCompound tag);
public int terra$getAmount() {
return getCount();

View File

@@ -3,8 +3,8 @@ package com.dfsek.terra.fabric.mixin.implementations.inventory.meta;
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -23,7 +23,7 @@ public abstract class ItemStackMetaMixin {
public abstract boolean hasEnchantments();
@Shadow
public abstract ListTag getEnchantments();
public abstract NbtList getEnchantments();
@Shadow
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
@@ -39,7 +39,7 @@ public abstract class ItemStackMetaMixin {
Map<Enchantment, Integer> map = new HashMap<>();
getEnchantments().forEach(enchantment -> {
CompoundTag eTag = (CompoundTag) enchantment;
NbtCompound eTag = (NbtCompound) enchantment;
map.put((Enchantment) Registry.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
});
return map;

View File

@@ -34,7 +34,7 @@ public abstract class ChunkRegionMixin {
private long seed;
public int terra$getMaxHeight() {
return ((ChunkRegion) (Object) this).getDimensionHeight();
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
}
@SuppressWarnings("deprecation")
@@ -64,7 +64,7 @@ public abstract class ChunkRegionMixin {
}
public int terra$getMinHeight() {
return 0;
return ((ChunkRegion) (Object) this).getBottomY();
}
@Intrinsic

View File

@@ -13,6 +13,7 @@ import com.dfsek.terra.fabric.block.FabricBlock;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.ServerWorldAccess;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -27,7 +28,7 @@ public abstract class ServerWorldMixin {
public abstract long getSeed();
public int terra$getMaxHeight() {
return ((ServerWorld) (Object) this).getDimensionHeight();
return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight();
}
public ChunkGenerator terra$getGenerator() {
@@ -55,7 +56,7 @@ public abstract class ServerWorldMixin {
}
public int terra$getMinHeight() {
return 0;
return ((ServerWorld) (Object) this).getBottomY();
}
@Intrinsic

View File

@@ -25,7 +25,7 @@
],
"depends": {
"fabricloader": ">=0.7.4",
"minecraft": "1.16.x"
"minecraft": "1.17.x"
},
"accessWidener": "terra.accesswidener"
}

View File

@@ -1,3 +1,3 @@
accessWidener v1 named
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V
extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/String;)V

View File

@@ -2,8 +2,9 @@
"required": true,
"minVersion": "0.8",
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_8",
"compatibilityLevel": "JAVA_16",
"mixins": [
"StructureAccessorAccessor",
"CommandManagerMixin",
"GeneratorOptionsMixin",
"ServerWorldMixin",