Unwrap BlockState in Chunk Gen

This commit is contained in:
Zoë Gidiere
2025-10-05 17:03:51 -06:00
parent 089850d633
commit a80b94ad45
2 changed files with 38 additions and 7 deletions

View File

@@ -141,9 +141,17 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) {
double noise = structureWeightSampler.sample(new UnblendedNoisePos(x + xi, y, z + zi));
if(noise > threshold) {
chunk.setBlockState(new BlockPos(x, y, z), (BlockState) delegate
.getPalette(x + xi, y, z + zi, world, biomeProvider)
.get(depth, x + xi, y, z + zi, world.getSeed()), 0);
com.dfsek.terra.api.block.state.BlockState data = delegate.getPalette(x + xi, y, z + zi, world, biomeProvider).get(depth, x + xi, y, z + zi, world.getSeed());
BlockPos blockPos = new BlockPos(x, y, z);
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
if (isExtended) {
BlockStateExtended blockStateExtended = (BlockStateExtended) data;
net.minecraft.block.BlockState blockState = (net.minecraft.block.BlockState) blockStateExtended.getState();
chunk.setBlockState(blockPos, blockState, 0);
} else {
chunk.setBlockState(blockPos, (net.minecraft.block.BlockState) data, 0);
}
depth++;
} else if(noise < airThreshold) {
chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.getDefaultState(), 0);

View File

@@ -17,9 +17,19 @@
package com.dfsek.terra.mod.mixin.implementations.terra.chunk.data;
import com.dfsek.terra.api.block.state.BlockStateExtended;
import net.minecraft.command.argument.BlockStateArgument;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.PalettesFactory;
import net.minecraft.world.chunk.UpgradeData;
import net.minecraft.world.gen.chunk.BlendingData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
@@ -31,16 +41,29 @@ import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
@Mixin(net.minecraft.world.chunk.ProtoChunk.class)
@Implements(@Interface(iface = ProtoChunk.class, prefix = "terra$"))
public abstract class ProtoChunkMixin {
public abstract class ProtoChunkMixin extends Chunk {
public ProtoChunkMixin(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, PalettesFactory palettesFactory,
long inhabitedTime, @Nullable ChunkSection[] sectionArray, @Nullable BlendingData blendingData) {
super(pos, upgradeData, heightLimitView, palettesFactory, inhabitedTime, sectionArray, blendingData);
}
@Shadow
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
@Shadow
public abstract HeightLimitView getHeightLimitView();
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
0);
public void terra$setBlock(int x, int y, int z, @NotNull BlockState data) {
BlockPos blockPos = new BlockPos(x, y, z);
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
if (isExtended) {
BlockStateExtended blockStateExtended = (BlockStateExtended) data;
net.minecraft.block.BlockState blockState = (net.minecraft.block.BlockState) blockStateExtended.getState();
this.setBlockState(blockPos, blockState, 0);
} else {
this.setBlockState(blockPos, (net.minecraft.block.BlockState) data, 0);
}
}
public @NotNull BlockState terra$getBlock(int x, int y, int z) {