remove world field from FabricChunkGeneratorWrapper

This commit is contained in:
dfsek 2021-12-22 23:41:00 -07:00
parent b4e6f2775e
commit 3d9d0d46fb
4 changed files with 44 additions and 19 deletions

View File

@ -24,6 +24,7 @@ import com.dfsek.tectonic.api.TypeRegistry;
import com.dfsek.tectonic.api.exception.LoadException;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.MinecraftVersion;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
@ -70,7 +71,7 @@ public class PlatformImpl extends AbstractPlatform {
public boolean reload() {
getTerraConfig().load(this);
boolean succeed = getRawConfigRegistry().loadAll(this);
worlds.forEach(world -> {
FabricChunkGeneratorWrapper chunkGeneratorWrapper = ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator());
chunkGeneratorWrapper.setPack(getConfigRegistry().get(chunkGeneratorWrapper.getPack().getID()).orElseThrow());

View File

@ -27,6 +27,8 @@ import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.mixin.access.StructureAccessorAccessor;
import com.dfsek.terra.fabric.util.FabricAdapter;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
@ -88,7 +90,6 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
private final TerraBiomeSource biomeSource;
private ChunkGenerator delegate;
private ConfigPack pack;
private net.minecraft.server.world.ServerWorld world;
private final Supplier<ChunkGeneratorSettings> settingsSupplier;
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack,
@ -210,22 +211,22 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
}
@Override
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView heightmapType) {
int height = getMinimumY() + getWorldHeight();
while(height >= getMinimumY() && !heightmap.getBlockPredicate().test(
(BlockState) delegate.getBlock((ServerWorld) world, x, height - 1, z))) {
height--;
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView height) {
int y = height.getTopY();
while(y >= getMinimumY() && !heightmap.getBlockPredicate().test(
(BlockState) delegate.getBlock(FabricAdapter.adapt(height, seed), x, y - 1, z))) {
y--;
}
return height;
return y;
}
@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
BlockState[] array = new BlockState[view.getHeight()];
for(int y = view.getTopY() - 1; y >= view.getBottomY(); y--) {
array[y - view.getBottomY()] = (BlockState) delegate.getBlock((ServerWorld) world, x, y, z);
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView height) {
BlockState[] array = new BlockState[height.getHeight()];
for(int y = height.getTopY() - 1; y >= height.getBottomY(); y--) {
array[y - height.getBottomY()] = (BlockState) delegate.getBlock(FabricAdapter.adapt(height, seed), x, y, z);
}
return new VerticalBlockSample(view.getBottomY(), array);
return new VerticalBlockSample(height.getBottomY(), array);
}
public ConfigPack getPack() {
@ -246,10 +247,6 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
}
public void setWorld(net.minecraft.server.world.ServerWorld world) {
this.world = world;
}
@Override
public ChunkGenerator getHandle() {
return delegate;

View File

@ -43,7 +43,7 @@ import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin {
private static final Logger logger = LoggerFactory.getLogger(ServerWorldMixin.class);
private static final Logger logger = LoggerFactory.getLogger(ServerWorld.class);
@Inject(method = "<init>", at = @At("RETURN"))
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
@ -51,7 +51,6 @@ public abstract class ServerWorldMixin {
WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator,
boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
FabricEntryPoint.getPlatform().addWorld((ServerWorld) (Object) this);
logger.info("Registered world {}", this);
}

View File

@ -17,6 +17,8 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.world.info.WorldProperties;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.WallShape;
import net.minecraft.block.enums.WireConnection;
@ -30,6 +32,8 @@ import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
import com.dfsek.terra.api.block.state.properties.enums.WallHeight;
import com.dfsek.terra.api.util.vector.Vector3;
import net.minecraft.world.HeightLimitView;
public final class FabricAdapter {
public static BlockPos adapt(Vector3 v) {
@ -51,6 +55,30 @@ public final class FabricAdapter {
};
}
public static WorldProperties adapt(HeightLimitView height, long seed) {
return new WorldProperties() {
@Override
public long getSeed() {
return seed;
}
@Override
public int getMaxHeight() {
return height.getTopY();
}
@Override
public int getMinHeight() {
return height.getBottomY();
}
@Override
public Object getHandle() {
return height;
}
};
}
public static com.dfsek.terra.api.block.state.properties.enums.Direction adapt(Direction direction) {
return switch(direction) {
case SOUTH -> com.dfsek.terra.api.block.state.properties.enums.Direction.SOUTH;