mostly working 1.17-ification

This commit is contained in:
dfsek
2021-03-17 21:17:15 -07:00
parent 2e8cd54ac2
commit d065f78c0a
18 changed files with 74 additions and 46 deletions

View File

@@ -5,12 +5,15 @@ 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 ? palettes[index] : palettes[0];
}
}

View File

@@ -17,7 +17,10 @@ public class PaletteHolderBuilder {
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
public PaletteHolder build() {
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
Palette<BlockData> d = null;
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
@@ -27,8 +30,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

@@ -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

@@ -22,11 +22,11 @@ dependencies {
"shadedImplementation"("org.yaml:snakeyaml:1.27")
"shadedImplementation"("com.googlecode.json-simple:json-simple:1.1.1")
"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:21w11a")
"mappings"("net.fabricmc:yarn:21w11a+build.3:v2")
"modImplementation"("net.fabricmc:fabric-loader:0.11.3")
"modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16")
"modImplementation"("net.fabricmc.fabric-api:fabric-api:0.32.4+1.17")
}
tasks.named<ShadowJar>("shadowJar") {

View File

@@ -406,7 +406,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

@@ -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

@@ -7,8 +7,8 @@ import com.dfsek.terra.fabric.TerraFabricPlugin;
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;
import net.minecraft.world.gen.feature.StructureFeature;

View File

@@ -67,7 +67,7 @@ public class FabricBlockState implements BlockState {
@Override
public boolean update(boolean applyPhysics) {
worldAccess.getChunk(blockEntity.getPos()).setBlockEntity(blockEntity.getPos(), blockEntity);
worldAccess.getChunk(blockEntity.getPos()).setBlockEntity(blockEntity);
return true;
}
}

View File

@@ -19,7 +19,7 @@ public class FabricMobSpawner extends FabricBlockState implements MobSpawner { /
@Override
public EntityType getSpawnedType() {
return FabricAdapter.adapt(Registry.ENTITY_TYPE.get(((MobSpawnerBlockEntity) blockEntity).getLogic().getEntityId()));
return FabricAdapter.adapt(Registry.ENTITY_TYPE.get(((MobSpawnerBlockEntity) blockEntity).getLogic().getEntityId(blockEntity.getWorld(), blockEntity.getPos())));
}
@Override

View File

@@ -17,16 +17,16 @@ public class FabricSign extends FabricBlockState implements Sign {
SignBlockEntity sign = (SignBlockEntity) blockEntity;
return new String[] {
sign.getTextOnRow(0).asString(),
sign.getTextOnRow(1).asString(),
sign.getTextOnRow(2).asString(),
sign.getTextOnRow(3).asString()
sign.getTextOnRow(0, false).asString(),
sign.getTextOnRow(1, false).asString(),
sign.getTextOnRow(2, false).asString(),
sign.getTextOnRow(3, false).asString()
};
}
@Override
public @NotNull String getLine(int index) throws IndexOutOfBoundsException {
return ((SignBlockEntity) blockEntity).getTextOnRow(index).asString();
return ((SignBlockEntity) blockEntity).getTextOnRow(index, false).asString();
}
@Override

View File

@@ -11,8 +11,7 @@ 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
@@ -23,7 +22,10 @@ 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();
StructureWorldAccess world = context.getWorld();
BlockPos pos = context.getOrigin();
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4);
FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator));
@@ -33,5 +35,6 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
gen.getTreePopulator().populate(world1, chunk);
gen.getFloraPopulator().populate(world1, chunk);
return true;
}
}

View File

@@ -5,6 +5,7 @@ import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
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.world.TerraBiomeSource;
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
@@ -20,10 +21,9 @@ import net.minecraft.block.Blocks;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.world.BlockView;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.GenerationStep;
@@ -32,6 +32,9 @@ import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.StructuresConfig;
import net.minecraft.world.gen.chunk.VerticalBlockSample;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
private final long seed;
private final DefaultChunkGenerator3D delegate;
@@ -108,12 +111,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
super.generateFeatures(region, accessor);
}
@Override
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
FabricSeededWorldAccess worldAccess = new FabricSeededWorldAccess(world, seed, this);
delegate.generateChunkData(worldAccess, new FastRandom(), chunk.getPos().x, chunk.getPos().z, new FabricChunkData(chunk));
}
@Override
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
// No caves
@@ -125,17 +122,19 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
}
@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
return false;
public CompletableFuture<Chunk> populateNoise(Executor executor, StructureAccessor accessor, Chunk chunk) {
FabricSeededWorldAccess worldAccess = new FabricSeededWorldAccess(((StructureAccessorAccessor) accessor).getWorld(), seed, this);
delegate.generateChunkData(worldAccess, new FastRandom(), chunk.getPos().x, chunk.getPos().z, new FabricChunkData(chunk));
return CompletableFuture.completedFuture(chunk);
}
@Override
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView world) {
return 0;
}
@Override
public BlockView getColumnSample(int x, int z) {
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) {
int height = 64; // TODO: implementation
BlockState[] array = new BlockState[256];
for(int y = 255; y >= 0; y--) {
@@ -150,9 +149,15 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
}
}
return new VerticalBlockSample(array);
return new VerticalBlockSample(world.getBottomY(), array);
}
@Override
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
return false;
}
@Override
public TerraChunkGenerator getHandle() {
return delegate;

View File

@@ -35,7 +35,7 @@ public class FabricWorld implements World, FabricWorldHandle {
@Override
public int getMaxHeight() {
return delegate.world.getHeight();
return delegate.world.getHeight() + delegate.world.getBottomY();
}
@Override
@@ -95,7 +95,7 @@ public class FabricWorld implements World, FabricWorldHandle {
@Override
public int getMinHeight() {
return 0;
return delegate.world.getBottomY();
}
@Override

View File

@@ -34,7 +34,7 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle {
@Override
public int getMaxHeight() {
return handle.getWorldAccess().getDimensionHeight();
return handle.worldAccess.getHeight() + handle.worldAccess.getBottomY();
}
@Override
@@ -49,7 +49,7 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle {
@Override
public UUID getUID() {
return UUID.randomUUID(); // TODO: implementation
return null; // TODO: implementation
}
@Override
@@ -83,7 +83,7 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle {
@Override
public int getMinHeight() {
return 0;
return handle.worldAccess.getBottomY();
}
@Override

View File

@@ -33,7 +33,7 @@ public class FabricWorldAccess implements World, FabricWorldHandle {
@Override
public int getMaxHeight() {
return delegate.getDimensionHeight();
return delegate.getHeight() + delegate.getBottomY();
}
@Override
@@ -82,7 +82,7 @@ public class FabricWorldAccess implements World, FabricWorldHandle {
@Override
public int getMinHeight() {
return 0;
return delegate.getBottomY();
}
@Override

View File

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

View File

@@ -4,7 +4,7 @@ extendable method net/minecraft/client/world/GeneratorType <init> (Ljava/lang/St
accessible field net/minecraft/server/world/ServerWorld worldProperties Lnet/minecraft/world/level/ServerWorldProperties;
accessible method net/minecraft/world/MobSpawnerLogic getEntityId ()Lnet/minecraft/util/Identifier;
accessible method net/minecraft/world/MobSpawnerLogic getEntityId (Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/Identifier;
accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function;
@@ -17,3 +17,4 @@ accessible field net/minecraft/world/biome/BiomeEffects skyColor I
accessible field net/minecraft/world/biome/BiomeEffects foliageColor Ljava/util/Optional;
accessible field net/minecraft/world/biome/BiomeEffects grassColor Ljava/util/Optional;
accessible field net/minecraft/world/biome/BiomeEffects grassColorModifier Lnet/minecraft/world/biome/BiomeEffects$GrassColorModifier;

View File

@@ -4,6 +4,7 @@
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"StructureAccessorAccessor"
],
"client": [
"GeneratorTypeAccessor"