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
@@ -14,8 +14,8 @@ fun Project.configureCompilation() {
apply(plugin = "idea") apply(plugin = "idea")
configure<JavaPluginConvention> { configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_16
} }
tasks.withType<JavaCompile> { tasks.withType<JavaCompile> {
@@ -42,7 +42,7 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
@Override @Override
public int argNumber() { public int argNumber() {
return 1; return 0;
} }
@Override @Override
@@ -15,7 +15,7 @@ public class BufferedPulledBlock implements BufferedItem {
@Override @Override
public void paste(Location origin) { public void paste(Location origin) {
Block pos = origin.getBlock(); Block pos = origin.getBlock();
while(pos.getY() > 0) { while(pos.getY() > origin.getWorld().getMinHeight()) {
if(!pos.isEmpty()) { if(!pos.isEmpty()) {
pos.setBlockData(data, false); pos.setBlockData(data, false);
break; break;
@@ -1,6 +1,7 @@
package com.dfsek.terra.api.world.carving; package com.dfsek.terra.api.world.carving;
import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.world.World;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.Random; import java.util.Random;
@@ -85,7 +86,7 @@ public abstract class Worm {
return rad[index]; 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 xRad = getRadius(0);
int yRad = getRadius(1); int yRad = getRadius(1);
int zRad = getRadius(2); int zRad = getRadius(2);
@@ -97,7 +98,7 @@ public abstract class Worm {
if(!(FastMath.floorDiv(origin.getBlockZ() + z, 16) == chunkZ)) continue; if(!(FastMath.floorDiv(origin.getBlockZ() + z, 16) == chunkZ)) continue;
for(int y = -yRad - 1; y <= yRad + 1; y++) { for(int y = -yRad - 1; y <= yRad + 1; y++) {
Vector3 position = origin.clone().add(new Vector3(x, y, z)); 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); double eq = ellipseEquation(x, y, z, xRad, yRad, zRad);
if(eq <= 1 && if(eq <= 1 &&
y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) { y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) {
@@ -5,12 +5,19 @@ import com.dfsek.terra.api.world.palette.Palette;
public class PaletteHolder { public class PaletteHolder {
private final Palette<BlockData>[] palettes; 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.palettes = palettes;
this.offset = offset;
} }
public Palette<BlockData> getPalette(int y) { 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];
} }
} }
@@ -17,8 +17,12 @@ public class PaletteHolderBuilder {
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"}) @SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
public PaletteHolder build() { 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; Palette<BlockData> d = null;
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) { for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
if(e.getKey() >= y) { if(e.getKey() >= y) {
@@ -27,8 +31,8 @@ public class PaletteHolderBuilder {
} }
} }
if(d == null) throw new IllegalArgumentException("No palette for Y=" + y); 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);
} }
} }
@@ -15,6 +15,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -41,13 +42,13 @@ public class CarverCache {
carving.step(); carving.step();
TerraBiome biome = provider.getBiome(carving.getRunning().toLocation(w)); 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 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()); points.add(carving.getPoint());
} }
return points; return points;
} }
return new GlueList<>(); return Collections.emptyList();
} }
}); });
} }
@@ -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.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import net.jafama.FastMath;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@@ -14,6 +15,7 @@ public class CarverPalette {
private final MaterialSet replace; private final MaterialSet replace;
private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>(); private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>();
private ProbabilityCollection<BlockData>[] layers; private ProbabilityCollection<BlockData>[] layers;
private int offset = 0;
public CarverPalette(MaterialSet replaceable, boolean blacklist) { public CarverPalette(MaterialSet replaceable, boolean blacklist) {
this.blacklist = blacklist; this.blacklist = blacklist;
@@ -26,7 +28,12 @@ public class CarverPalette {
} }
public ProbabilityCollection<BlockData> get(int y) { 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) { public boolean canReplace(BlockType material) {
@@ -37,9 +44,11 @@ public class CarverPalette {
* Build the palette to an array. * Build the palette to an array.
*/ */
public void build() { public void build() {
int size = map.lastKey() + 1; int min = FastMath.min(map.keySet().stream().min(Integer::compareTo).orElse(0), 0);
layers = new ProbabilityCollection[size]; int max = FastMath.max(map.keySet().stream().max(Integer::compareTo).orElse(255), 255);
for(int y = 0; y < size; y++) {
layers = new ProbabilityCollection[map.lastKey() + 1 - min];
for(int y = min; y <= FastMath.max(map.lastKey(), max); y++) {
ProbabilityCollection<BlockData> d = null; ProbabilityCollection<BlockData> d = null;
for(Map.Entry<Integer, ProbabilityCollection<BlockData>> e : map.entrySet()) { for(Map.Entry<Integer, ProbabilityCollection<BlockData>> e : map.entrySet()) {
if(e.getKey() >= y) { if(e.getKey() >= y) {
@@ -47,8 +56,9 @@ public class CarverPalette {
break; break;
} }
} }
if(d == null) throw new IllegalArgumentException("Null collection at Y=" + y); if(d == null) throw new IllegalArgumentException("No palette for Y=" + y);
layers[y] = d; layers[y - min] = d;
} }
offset = -min;
} }
} }
@@ -116,7 +116,7 @@ public class UserDefinedCarver extends Carver {
Vector3 origin = point.getOrigin(); Vector3 origin = point.getOrigin();
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk. if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk.
return; return;
point.carve(chunkX, chunkZ, consumer); point.carve(chunkX, chunkZ, consumer, w);
}); });
} }
} }
@@ -13,9 +13,9 @@ public class OreFactory implements ConfigFactory<OreTemplate, Ore> {
BlockData m = config.getMaterial(); BlockData m = config.getMaterial();
switch(config.getType()) { switch(config.getType()) {
case SPHERE: 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: 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; return null;
} }
@@ -5,9 +5,13 @@ import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.annotations.Value;
import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.platform.block.BlockData; 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.MaterialSet;
import com.dfsek.terra.world.population.items.ores.Ore; import com.dfsek.terra.world.population.items.ores.Ore;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings({"unused", "FieldMayBeFinal"}) @SuppressWarnings({"unused", "FieldMayBeFinal"})
public class OreTemplate extends AbstractableTemplate { public class OreTemplate extends AbstractableTemplate {
@Value("id") @Value("id")
@@ -17,6 +21,11 @@ public class OreTemplate extends AbstractableTemplate {
@Abstractable @Abstractable
private BlockData material; private BlockData material;
@Value("material-overrides")
@Default
@Abstractable
private Map<BlockType, BlockData> materials = new HashMap<>();
@Value("type") @Value("type")
@Abstractable @Abstractable
@Default @Default
@@ -76,4 +85,8 @@ public class OreTemplate extends AbstractableTemplate {
public Ore.Type getType() { public Ore.Type getType() {
return oreType; return oreType;
} }
public Map<BlockType, BlockData> getMaterialOverrides() {
return materials;
}
} }
@@ -59,7 +59,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
} }
for(int y = 0; y < size + 1; y++) { 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 @Override
public double getNoise(double x, double y, double z) { 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) { 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);
} }
} }
@@ -90,7 +90,7 @@ public class CavePopulator implements TerraBlockPopulator, Chunkified {
Location mut = l.clone(); Location mut = l.clone();
BlockData orig = l.getBlock().getBlockData(); BlockData orig = l.getBlock().getBlockData();
do mut.subtract(0, 1, 0); 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 { try {
if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) { if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) {
mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false); mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
@@ -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.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData; 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.platform.world.Chunk;
import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.MaterialSet;
import java.util.Map;
import java.util.Random; import java.util.Random;
public class DeformedSphereOre extends Ore { public class DeformedSphereOre extends Ore {
@@ -17,8 +18,8 @@ public class DeformedSphereOre extends Ore {
private final double deformFrequency; private final double deformFrequency;
private final Range size; private final Range size;
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size, TerraPlugin 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); super(material, replaceable, applyGravity, main, materials);
this.deform = deform; this.deform = deform;
this.deformFrequency = deformFrequency; this.deformFrequency = deformFrequency;
this.size = size; this.size = size;
@@ -27,7 +28,6 @@ public class DeformedSphereOre extends Ore {
@Override @Override
public void generate(Vector3 origin, Chunk c, Random r) { public void generate(Vector3 origin, Chunk c, Random r) {
WorldHandle handle = main.getWorldHandle();
OpenSimplex2Sampler ore = new OpenSimplex2Sampler(r.nextInt()); OpenSimplex2Sampler ore = new OpenSimplex2Sampler(r.nextInt());
ore.setFrequency(deformFrequency); ore.setFrequency(deformFrequency);
int rad = size.get(r); int rad = size.get(r);
@@ -35,12 +35,13 @@ public class DeformedSphereOre extends Ore {
for(int y = -rad; y <= rad; y++) { for(int y = -rad; y <= rad; y++) {
for(int z = -rad; z <= rad; z++) { for(int z = -rad; z <= rad; z++) {
Vector3 oreLoc = origin.clone().add(new Vector3(x, y, 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; continue;
if(oreLoc.distance(origin) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) { if(oreLoc.distance(origin) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) {
Block b = c.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ()); Block b = c.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ());
if(getReplaceable().contains(b.getType()) && b.getLocation().getY() >= 0) BlockType type = b.getType();
b.setBlockData(getMaterial(), isApplyGravity()); if(getReplaceable().contains(type) && b.getLocation().getY() >= c.getWorld().getMinHeight())
b.setBlockData(getMaterial(type), isApplyGravity());
} }
} }
} }
@@ -3,9 +3,11 @@ package com.dfsek.terra.world.population.items.ores;
import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData; 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.platform.world.Chunk;
import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.MaterialSet;
import java.util.Map;
import java.util.Random; import java.util.Random;
public abstract class Ore { public abstract class Ore {
@@ -14,18 +16,20 @@ public abstract class Ore {
private final MaterialSet replaceable; private final MaterialSet replaceable;
private final boolean applyGravity; private final boolean applyGravity;
protected TerraPlugin main; 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.material = material;
this.replaceable = replaceable; this.replaceable = replaceable;
this.applyGravity = applyGravity; this.applyGravity = applyGravity;
this.main = main; this.main = main;
this.materials = materials;
} }
public abstract void generate(Vector3 origin, Chunk c, Random r); public abstract void generate(Vector3 origin, Chunk c, Random r);
public BlockData getMaterial() { public BlockData getMaterial(BlockType replace) {
return material; return materials.getOrDefault(replace, material);
} }
public MaterialSet getReplaceable() { public MaterialSet getReplaceable() {
@@ -5,18 +5,20 @@ import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData; 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.platform.world.Chunk;
import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.MaterialSet;
import net.jafama.FastMath; import net.jafama.FastMath;
import java.util.Map;
import java.util.Random; import java.util.Random;
public class VanillaOre extends Ore { public class VanillaOre extends Ore {
private final Range sizeRange; private final Range sizeRange;
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main) { public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main, Map<BlockType, BlockData> materials) {
super(material, replaceable, applyGravity, main); super(material, replaceable, applyGravity, main, materials);
this.sizeRange = size; this.sizeRange = size;
} }
@@ -67,8 +69,9 @@ public class VanillaOre extends Ore {
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D); 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; if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue;
Block block = chunk.getBlock(x, y, z); Block block = chunk.getBlock(x, y, z);
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block.getType())) { BlockType type = block.getType();
block.setBlockData(getMaterial(), isApplyGravity()); if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(type)) {
block.setBlockData(getMaterial(type), isApplyGravity());
} }
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
org.gradle.jvmargs=-Xmx4096m org.gradle.jvmargs=-Xmx4096m
+9 -4
View File
@@ -7,7 +7,7 @@ import net.fabricmc.loom.task.RemapJarTask
plugins { plugins {
`java-library` `java-library`
`maven-publish` `maven-publish`
id("fabric-loom").version("0.6-SNAPSHOT") id("fabric-loom").version("0.8-SNAPSHOT")
id("com.modrinth.minotaur").version("1.1.0") id("com.modrinth.minotaur").version("1.1.0")
} }
@@ -23,9 +23,9 @@ group = "com.dfsek.terra.fabric"
dependencies { dependencies {
"shadedApi"(project(":common")) "shadedApi"(project(":common"))
"minecraft"("com.mojang:minecraft:1.16.5") "minecraft"("com.mojang:minecraft:1.17")
"mappings"("net.fabricmc:yarn:1.16.5+build.5:v2") "mappings"("net.fabricmc:yarn:1.17+build.1:v2")
"modImplementation"("net.fabricmc:fabric-loader:0.11.2") "modImplementation"("net.fabricmc:fabric-loader:0.11.3")
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") { "modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
exclude(group = "com.google.guava", module = "guava") 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> { configure<LoomGradleExtension> {
accessWidener("src/main/resources/terra.accesswidener") accessWidener("src/main/resources/terra.accesswidener")
@@ -264,7 +264,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE); 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(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC); 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_OAK", ConfiguredFeatures.FANCY_OAK);
injectTree(treeRegistry, "LARGE_SPRUCE", ConfiguredFeatures.PINE); injectTree(treeRegistry, "LARGE_SPRUCE", ConfiguredFeatures.PINE);
injectTree(treeRegistry, "SMALL_JUNGLE", ConfiguredFeatures.JUNGLE_TREE); 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, "TALL_BIRCH", ConfiguredFeatures.BIRCH_TALL);
injectTree(treeRegistry, "ACACIA", ConfiguredFeatures.ACACIA); injectTree(treeRegistry, "ACACIA", ConfiguredFeatures.ACACIA);
injectTree(treeRegistry, "BIRCH", ConfiguredFeatures.BIRCH); injectTree(treeRegistry, "BIRCH", ConfiguredFeatures.BIRCH);
@@ -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.platform.world.generator.GeneratorWrapper;
import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.biome.UserDefinedBiome; 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.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.locate.AsyncStructureFinder; import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
import com.dfsek.terra.fabric.util.FabricAdapter; import com.dfsek.terra.fabric.util.FabricAdapter;
import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; 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.math.ChunkPos;
import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockView;
import net.minecraft.world.ChunkRegion; import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.SpawnHelper; import net.minecraft.world.SpawnHelper;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeAccess; import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@@ -46,6 +47,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper { public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
private final long seed; private final long seed;
@@ -120,11 +122,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
return super.locateStructure(world, feature, center, radius, skipExistingChunks); 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 @Override
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) { public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
if(pack.getTemplate().vanillaCaves()) super.carve(seed, access, chunk, 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); 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 @Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) { public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos); if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos);
@@ -143,7 +154,12 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
} }
@Override @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); TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16)); Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
int cx = FastMath.floorMod(x, 16); int cx = FastMath.floorMod(x, 16);
@@ -157,11 +173,11 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
} }
@Override @Override
public BlockView getColumnSample(int x, int z) { public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType); 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]; 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 > height) {
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) { if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
array[y] = Blocks.AIR.getDefaultState(); 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 @Override
public void populateEntities(ChunkRegion region) { public void populateEntities(ChunkRegion region) {
if(pack.getTemplate().vanillaMobs()) { if(pack.getTemplate().vanillaMobs()) {
int cx = region.getCenterChunkX(); int cx = region.getCenterPos().x;
int cy = region.getCenterChunkZ(); int cy = region.getCenterPos().z;
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos()); Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
ChunkRandom chunkRandom = new ChunkRandom(); ChunkRandom chunkRandom = new ChunkRandom();
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4); chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
SpawnHelper.populateEntities(region, biome, cx, cy, chunkRandom); SpawnHelper.populateEntities(region, biome, region.getCenterPos(), chunkRandom);
} }
} }
@@ -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.Chunk;
import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.world.generation.Chunkified;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess; import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig; import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.util.FeatureContext;
import java.util.Random;
/** /**
* Feature wrapper for Terra populator * Feature wrapper for Terra populator
@@ -20,10 +19,16 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
} }
@Override @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; if(!(chunkGenerator instanceof FabricChunkGeneratorWrapper)) return true;
StructureWorldAccess world = context.getWorld();
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator; 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; return true;
} }
} }
@@ -8,8 +8,8 @@ import com.dfsek.terra.fabric.util.FabricUtil;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.RegistryLookupCodec;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryLookupCodec;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.biome.source.BiomeSource;
@@ -48,7 +48,7 @@ public abstract class GeneratorOptionsMixin {
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures); boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
Registry<DimensionType> dimensionTypes = dynamicRegistryManager.get(Registry.DIMENSION_TYPE_KEY); Registry<DimensionType> dimensionTypes = dynamicRegistryManager.get(Registry.DIMENSION_TYPE_KEY);
Registry<Biome> biomes = dynamicRegistryManager.get(Registry.BIOME_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); SimpleRegistry<DimensionOptions> dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomes, chunkGeneratorSettings, l);
prop = prop.substring(prop.indexOf(":") + 1); prop = prop.substring(prop.indexOf(":") + 1);
@@ -57,7 +57,7 @@ public abstract class GeneratorOptionsMixin {
if(pack == null) throw new IllegalArgumentException("No such pack " + prop); 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))));
} }
} }
} }
@@ -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();
}
@@ -1,12 +1,14 @@
package com.dfsek.terra.fabric.mixin.access; package com.dfsek.terra.fabric.mixin.access;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.MobSpawnerLogic; import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(MobSpawnerLogic.class) @Mixin(MobSpawnerLogic.class)
public interface MobSpawnerLogicAccessor { public interface MobSpawnerLogicAccessor {
@Invoker("getEntityId") @Invoker("getEntityId")
Identifier callGetEntityId(); Identifier callGetEntityId(World world, BlockPos blockPos);
} }
@@ -9,6 +9,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.Intrinsic;
@@ -18,6 +19,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(BlockEntity.class) @Mixin(BlockEntity.class)
@Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE)) @Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class BlockEntityMixin { public abstract class BlockEntityMixin {
@Final
@Shadow @Shadow
protected BlockPos pos; protected BlockPos pos;
@Shadow @Shadow
@@ -56,7 +58,7 @@ public abstract class BlockEntityMixin {
} }
public boolean terra$update(boolean applyPhysics) { 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; return true;
} }
} }
@@ -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.api.platform.entity.EntityType;
import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.mixin.access.MobSpawnerLogicAccessor; 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.block.entity.MobSpawnerBlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.MobSpawnerLogic; import net.minecraft.world.MobSpawnerLogic;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
@@ -16,12 +21,16 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(MobSpawnerBlockEntity.class) @Mixin(MobSpawnerBlockEntity.class)
@Implements(@Interface(iface = MobSpawner.class, prefix = "terra$", remap = Interface.Remap.NONE)) @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 @Shadow
public abstract MobSpawnerLogic getLogic(); public abstract MobSpawnerLogic getLogic();
public EntityType terra$getSpawnedType() { 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) { public void terra$setSpawnedType(@NotNull EntityType creatureType) {
@@ -20,18 +20,18 @@ public abstract class SignBlockEntityMixin {
@Shadow @Shadow
@Final @Final
private Text[] text; private Text[] texts;
public @NotNull String[] terra$getLines() { public @NotNull String[] terra$getLines() {
String[] lines = new String[text.length]; String[] lines = new String[texts.length];
for(int i = 0; i < text.length; i++) { for(int i = 0; i < texts.length; i++) {
lines[i] = text[i].asString(); lines[i] = texts[i].asString();
} }
return lines; return lines;
} }
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException { 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 { public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
@@ -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.FabricBlock;
import com.dfsek.terra.fabric.block.FabricBlockData; import com.dfsek.terra.fabric.block.FabricBlockData;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ChunkRegion; import net.minecraft.world.ChunkRegion;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@@ -20,18 +21,14 @@ import org.spongepowered.asm.mixin.Shadow;
public abstract class ChunkRegionMixin { public abstract class ChunkRegionMixin {
@Final @Final
@Shadow @Shadow
private int centerChunkX; private ChunkPos centerPos;
@Final
@Shadow
private int centerChunkZ;
public int terra$getX() { public int terra$getX() {
return centerChunkX; return centerPos.x;
} }
public int terra$getZ() { public int terra$getZ() {
return centerChunkZ; return centerPos.z;
} }
public World terra$getWorld() { public World terra$getWorld() {
@@ -39,7 +36,7 @@ public abstract class ChunkRegionMixin {
} }
public Block terra$getBlock(int x, int y, int z) { 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); 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) { 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. // getHandle already added in world/ChunkRegionMixin.
@@ -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;
import com.dfsek.terra.api.platform.inventory.item.ItemMeta; import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
@@ -27,7 +27,7 @@ public abstract class ItemStackMixin {
public abstract boolean isDamageable(); public abstract boolean isDamageable();
@Shadow @Shadow
public abstract void setTag(@Nullable CompoundTag tag); public abstract void setTag(@Nullable NbtCompound tag);
public int terra$getAmount() { public int terra$getAmount() {
return getCount(); return getCount();
@@ -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.Enchantment;
import com.dfsek.terra.api.platform.inventory.item.ItemMeta; import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtList;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
@@ -23,7 +23,7 @@ public abstract class ItemStackMetaMixin {
public abstract boolean hasEnchantments(); public abstract boolean hasEnchantments();
@Shadow @Shadow
public abstract ListTag getEnchantments(); public abstract NbtList getEnchantments();
@Shadow @Shadow
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level); 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<>(); Map<Enchantment, Integer> map = new HashMap<>();
getEnchantments().forEach(enchantment -> { getEnchantments().forEach(enchantment -> {
CompoundTag eTag = (CompoundTag) enchantment; NbtCompound eTag = (NbtCompound) enchantment;
map.put((Enchantment) Registry.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl")); map.put((Enchantment) Registry.ENCHANTMENT.get(eTag.getInt("id")), eTag.getInt("lvl"));
}); });
return map; return map;
@@ -34,7 +34,7 @@ public abstract class ChunkRegionMixin {
private long seed; private long seed;
public int terra$getMaxHeight() { public int terra$getMaxHeight() {
return ((ChunkRegion) (Object) this).getDimensionHeight(); return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -64,7 +64,7 @@ public abstract class ChunkRegionMixin {
} }
public int terra$getMinHeight() { public int terra$getMinHeight() {
return 0; return ((ChunkRegion) (Object) this).getBottomY();
} }
@Intrinsic @Intrinsic
@@ -13,6 +13,7 @@ import com.dfsek.terra.fabric.block.FabricBlock;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper; import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.ServerWorldAccess;
import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface;
@@ -27,7 +28,7 @@ public abstract class ServerWorldMixin {
public abstract long getSeed(); public abstract long getSeed();
public int terra$getMaxHeight() { public int terra$getMaxHeight() {
return ((ServerWorld) (Object) this).getDimensionHeight(); return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight();
} }
public ChunkGenerator terra$getGenerator() { public ChunkGenerator terra$getGenerator() {
@@ -55,7 +56,7 @@ public abstract class ServerWorldMixin {
} }
public int terra$getMinHeight() { public int terra$getMinHeight() {
return 0; return ((ServerWorld) (Object) this).getBottomY();
} }
@Intrinsic @Intrinsic
@@ -25,7 +25,7 @@
], ],
"depends": { "depends": {
"fabricloader": ">=0.7.4", "fabricloader": ">=0.7.4",
"minecraft": "1.16.x" "minecraft": "1.17.x"
}, },
"accessWidener": "terra.accesswidener" "accessWidener": "terra.accesswidener"
} }
@@ -1,3 +1,3 @@
accessWidener v1 named 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
@@ -2,8 +2,9 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.dfsek.terra.fabric.mixin", "package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_16",
"mixins": [ "mixins": [
"StructureAccessorAccessor",
"CommandManagerMixin", "CommandManagerMixin",
"GeneratorOptionsMixin", "GeneratorOptionsMixin",
"ServerWorldMixin", "ServerWorldMixin",