This commit is contained in:
dfsek 2021-07-22 18:25:53 -07:00
parent ad9cc1afcb
commit 6ea11de2fd
7 changed files with 25 additions and 20 deletions

View File

@ -21,6 +21,6 @@ public class BufferedEntity implements BufferedItem {
@Override @Override
public void paste(Vector3 origin, World world) { public void paste(Vector3 origin, World world) {
Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5), type); Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5), type);
main.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getGenerator().getConfigPack(), entity)); main.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getConfig().getPack(), entity));
} }
} }

View File

@ -33,7 +33,7 @@ public class BufferedLootApplication implements BufferedItem {
} }
Container container = (Container) data; Container container = (Container) data;
LootPopulateEvent event = new LootPopulateEvent(container, table, world.getGenerator().getConfigPack(), structure); LootPopulateEvent event = new LootPopulateEvent(container, table, world.getConfig().getPack(), structure);
main.getEventManager().callEvent(event); main.getEventManager().callEvent(event);
if(event.isCancelled()) return; if(event.isCancelled()) return;

View File

@ -16,6 +16,8 @@ public interface WorldConfig {
BiomeProvider getProvider(); BiomeProvider getProvider();
ConfigPack getPack();
int elevationBlend(); int elevationBlend();
boolean disableTrees(); boolean disableTrees();

View File

@ -9,6 +9,7 @@ import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk; import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World; import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.TerraChunkGenerator;
public class DummyWorld implements World { public class DummyWorld implements World {
@Override @Override
@ -56,6 +57,11 @@ public class DummyWorld implements World {
return 0; return 0;
} }
@Override
public TerraChunkGenerator getGenerator() {
throw new UnsupportedOperationException("Cannot get generator of DummyWorld");
}
@Override @Override
public BiomeProvider getBiomeProvider() { public BiomeProvider getBiomeProvider() {
throw new UnsupportedOperationException("Cannot get biome provider of DummyWorld"); throw new UnsupportedOperationException("Cannot get biome provider of DummyWorld");

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.config.pack; package com.dfsek.terra.config.pack;
import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.WorldConfig; import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.world.World; import com.dfsek.terra.api.world.World;
@ -54,6 +55,11 @@ public class WorldConfigImpl implements WorldConfig {
return provider; return provider;
} }
@Override
public ConfigPack getPack() {
return pack;
}
@Override @Override
public int elevationBlend() { public int elevationBlend() {
return pack.getTemplate().getElevationBlend(); return pack.getTemplate().getElevationBlend();

View File

@ -51,15 +51,9 @@ public abstract class ChunkRegionMixin {
@Final @Final
private long seed; private long seed;
@Shadow
public abstract boolean setBlockState(BlockPos pos, net.minecraft.block.BlockState state, int flags, int maxUpdateDepth);
@Shadow @Shadow
public abstract TickScheduler<Fluid> getFluidTickScheduler(); public abstract TickScheduler<Fluid> getFluidTickScheduler();
@Shadow
public abstract ChunkManager getChunkManager();
public int terraWorld$getMaxHeight() { public int terraWorld$getMaxHeight() {
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight(); return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
} }
@ -69,11 +63,6 @@ public abstract class ChunkRegionMixin {
this.config = ((World) world).getConfig(); this.config = ((World) world).getConfig();
} }
@SuppressWarnings("deprecation")
public ChunkGenerator terraWorld$getGenerator() {
return (ChunkGenerator) ((ChunkRegion) (Object) this).toServerWorld().getChunkManager().getChunkGenerator();
}
public Chunk terraWorld$getChunkAt(int x, int z) { public Chunk terraWorld$getChunkAt(int x, int z) {
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z); return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
} }
@ -119,7 +108,7 @@ public abstract class ChunkRegionMixin {
return this; return this;
} }
public TerraChunkGenerator terraWorld$getTerraGenerator() { public TerraChunkGenerator terraWorld$getGenerator() {
return ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator()).getHandle(); return ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator()).getHandle();
} }

View File

@ -18,6 +18,7 @@ import com.dfsek.terra.fabric.generation.TerraBiomeSource;
import com.dfsek.terra.fabric.util.FabricUtil; import com.dfsek.terra.fabric.util.FabricUtil;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener; import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerChunkManager;
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.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
@ -28,6 +29,7 @@ import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.Spawner; import net.minecraft.world.gen.Spawner;
import net.minecraft.world.level.ServerWorldProperties; import net.minecraft.world.level.ServerWorldProperties;
import net.minecraft.world.level.storage.LevelStorage; import net.minecraft.world.level.storage.LevelStorage;
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;
@ -47,6 +49,10 @@ public abstract class ServerWorldMixin {
@Shadow @Shadow
public abstract long getSeed(); public abstract long getSeed();
@Shadow
@Final
private ServerChunkManager chunkManager;
@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/level/storage/LevelStorage$Session;Lnet/minecraft/world/level/ServerWorldProperties;Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/server/WorldGenerationProgressListener;Lnet/minecraft/world/gen/chunk/ChunkGenerator;ZJLjava/util/List;Z)V") @Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/level/storage/LevelStorage$Session;Lnet/minecraft/world/level/ServerWorldProperties;Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/server/WorldGenerationProgressListener;Lnet/minecraft/world/gen/chunk/ChunkGenerator;ZJLjava/util/List;Z)V")
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<net.minecraft.world.World> worldKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, net.minecraft.world.gen.chunk.ChunkGenerator chunkGenerator, boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, CallbackInfo ci) { public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<net.minecraft.world.World> worldKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, net.minecraft.world.gen.chunk.ChunkGenerator chunkGenerator, boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) { if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
@ -58,10 +64,6 @@ public abstract class ServerWorldMixin {
return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight(); return (((ServerWorld) (Object) this).getBottomY()) + ((ServerWorld) (Object) this).getHeight();
} }
public ChunkGenerator terra$getGenerator() {
return (ChunkGenerator) ((ServerWorld) (Object) this).getChunkManager().getChunkGenerator();
}
public Chunk terra$getChunkAt(int x, int z) { public Chunk terra$getChunkAt(int x, int z) {
return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z); return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z);
} }
@ -100,8 +102,8 @@ public abstract class ServerWorldMixin {
return this; return this;
} }
public TerraChunkGenerator terra$getTerraGenerator() { public TerraChunkGenerator terra$getGenerator() {
return ((FabricChunkGeneratorWrapper) terra$getGenerator()).getHandle(); return ((FabricChunkGeneratorWrapper) chunkManager.getChunkGenerator()).getHandle();
} }
public BiomeProvider terra$getBiomeProvider() { public BiomeProvider terra$getBiomeProvider() {