remove most terraworld dependency

This commit is contained in:
dfsek 2021-07-22 14:13:37 -07:00
parent ea60b30321
commit 109b5e38cd
9 changed files with 9 additions and 74 deletions

View File

@ -21,7 +21,6 @@ public class FeatureGenerationStage implements TerraGenerationStage {
@Override
@SuppressWarnings("try")
public void populate(World world, Chunk chunk) {
TerraWorld terraWorld = main.getWorld(world);
try(ProfileFrame ignore = main.getProfiler().profile("feature")) {
int cx = chunk.getX() << 4;
int cz = chunk.getZ() << 4;

View File

@ -22,8 +22,6 @@ import java.io.File;
public interface TerraPlugin extends LoaderRegistrar {
WorldHandle getWorldHandle();
TerraWorld getWorld(World world);
Logger logger();
PluginConfig getTerraConfig();

View File

@ -23,6 +23,6 @@ public class GetBlockCommand implements CommandTemplate {
@Override
public void execute(CommandSender sender) {
Player player = (Player) sender;
sender.sendMessage("Block: " + main.getWorld(player.world()).getUngeneratedBlock(player.position()).getAsString());
sender.sendMessage("Block: " + player.world().getTerraGenerator().getBlock(player.world(), player.position()).getAsString());
}
}

View File

@ -23,7 +23,6 @@ import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.api.world.generator.TerraChunkGenerator;
import com.dfsek.terra.bukkit.command.BukkitCommandAdapter;
import com.dfsek.terra.bukkit.command.FixChunkCommand;
import com.dfsek.terra.bukkit.command.SaveDataCommand;
@ -35,7 +34,6 @@ import com.dfsek.terra.bukkit.listeners.PaperListener;
import com.dfsek.terra.bukkit.listeners.SpigotListener;
import com.dfsek.terra.bukkit.util.PaperUtil;
import com.dfsek.terra.bukkit.world.BukkitBiome;
import com.dfsek.terra.bukkit.world.BukkitWorld;
import com.dfsek.terra.commands.CommandUtil;
import com.dfsek.terra.commands.TerraCommandManager;
import com.dfsek.terra.config.GenericLoaders;
@ -253,17 +251,6 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
return checkedRegistry;
}
public TerraWorld getWorld(World world) {
BukkitWorld w = (BukkitWorld) world;
if(!w.isTerraWorld())
throw new IllegalArgumentException("Not a Terra world! " + w.getGenerator());
if(!worlds.containsKey(w.getName())) {
getLogger().warning("Unexpected world load detected: \"" + w.getName() + "\"");
return new TerraWorldImpl(w, ((TerraChunkGenerator) w.getGenerator().getHandle()).getConfigPack(), this);
}
return worldMap.computeIfAbsent(w, w2 -> new TerraWorldImpl(w, worlds.get(w.getName()), this));
}
@Override
public Logger logger() {
return new JavaLogger(getLogger());

View File

@ -25,9 +25,7 @@ import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.commands.CommandUtil;
import com.dfsek.terra.commands.TerraCommandManager;
@ -52,17 +50,13 @@ import com.dfsek.terra.registry.LockedRegistryImpl;
import com.dfsek.terra.registry.master.AddonRegistry;
import com.dfsek.terra.registry.master.ConfigRegistry;
import com.dfsek.terra.util.logging.DebugLogger;
import com.dfsek.terra.world.TerraWorldImpl;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.NopeDecoratorConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
@ -83,7 +77,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
private static TerraFabricPlugin instance;
private final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
private final Map<DimensionType, ServerWorld> worldMap = new HashMap<>();
private final EventManager eventManager = new EventManagerImpl(this);
private final GenericLoaders genericLoaders = new GenericLoaders(this);
private final Profiler profiler = new ProfilerImpl();
@ -119,10 +112,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
return instance;
}
public Map<DimensionType, ServerWorld> getWorldMap() {
return worldMap;
}
private ProtoBiome parseBiome(String id) throws LoadException {
Identifier identifier = Identifier.tryParse(id);
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier); // failure.
@ -138,15 +127,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
return worldHandle;
}
@Override
public TerraWorld getWorld(World world) {
return getWorld(((WorldAccess) world).getDimension());
}
public TerraWorld getWorld(DimensionType type) {
throw new IllegalArgumentException("No world exists with dimension type " + type);
}
@Override
public Logger logger() {
return logger;
@ -186,10 +166,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
config.load(this);
LangUtil.load(config.getLanguage(), this); // Load language.
boolean succeed = configRegistry.loadAll(this);
worldMap.forEach((seed, world) -> {
if(!(world instanceof World)) return;
((World) world).getConfig().getSamplerCache().clear();
});
return succeed;
}

View File

@ -65,7 +65,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
private final TerraBiomeSource biomeSource;
private final ConfigPack pack;
private DimensionType dimensionType;
private ServerWorld world;
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
super(biomeSource, new StructuresConfig(false));
@ -98,8 +98,8 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
// No-op
}
public void setDimensionType(DimensionType dimensionType) {
this.dimensionType = dimensionType;
public void setWorld(ServerWorld world) {
this.world = world;
}
@Nullable
@ -170,9 +170,8 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
@Override
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView heightmapType) {
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
int height = world.getWorld().getMaxHeight();
while(height >= world.getWorld().getMinHeight() && !heightmap.getBlockPredicate().test(((FabricBlockState) world.getUngeneratedBlock(x, height - 1, z)).getHandle())) {
int height = ((World) world).getMaxHeight();
while(height >= ((World) world).getMinHeight() && !heightmap.getBlockPredicate().test(((FabricBlockState) ((World) world).getTerraGenerator().getBlock((World) world, x, height - 1, z)).getHandle())) {
height--;
}
return height;
@ -180,10 +179,9 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
@Override
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
BlockState[] array = new BlockState[view.getHeight()];
for(int y = view.getBottomY() + view.getHeight() - 1; y >= view.getBottomY(); y--) {
array[y] = ((FabricBlockState) world.getUngeneratedBlock(x, y, z)).getHandle();
array[y] = ((FabricBlockState) ((World) world).getTerraGenerator().getBlock((World) world, x, y, z)).getHandle();
}
return new VerticalBlockSample(view.getBottomY(), array);
}

View File

@ -1,9 +1,7 @@
package com.dfsek.terra.fabric.mixin;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.world.TerraWorldImpl;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
@ -27,9 +25,8 @@ public abstract class ServerWorldMixin {
@Inject(method = "<init>", at = @At(value = "RETURN"))
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorldImpl((com.dfsek.terra.api.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
((FabricChunkGeneratorWrapper) chunkGenerator).setDimensionType(dimensionType);
TerraFabricPlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
TerraFabricPlugin.getInstance().logger().info("Registered world " + this);
}
}
}

View File

@ -1,8 +1,6 @@
package com.dfsek.terra;
import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.tectonic.loading.TypeRegistry;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.block.state.BlockState;
@ -15,9 +13,6 @@ import com.dfsek.terra.api.lang.Language;
import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.tectonic.LoaderHolder;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.config.GenericLoaders;
import com.dfsek.terra.config.PluginConfigImpl;
@ -33,12 +28,9 @@ import com.dfsek.terra.registry.master.AddonRegistry;
import com.dfsek.terra.registry.master.ConfigRegistry;
import com.dfsek.terra.util.logging.DebugLogger;
import com.dfsek.terra.util.logging.JavaLogger;
import com.dfsek.terra.world.TerraWorldImpl;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.function.Supplier;
import java.util.logging.Logger;
public class StandalonePlugin implements TerraPlugin {
@ -58,11 +50,6 @@ public class StandalonePlugin implements TerraPlugin {
return worldHandle;
}
@Override
public TerraWorld getWorld(World world) {
return new TerraWorldImpl(world, registry.get("DEFAULT"), this);
}
@Override
public com.dfsek.terra.api.Logger logger() {
return new JavaLogger(Logger.getLogger("Terra"));

View File

@ -12,8 +12,6 @@ import com.dfsek.terra.api.lang.Language;
import com.dfsek.terra.api.profiler.Profiler;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.LockedRegistry;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.config.PluginConfigImpl;
import com.dfsek.terra.config.lang.LanguageImpl;
import com.dfsek.terra.event.EventManagerImpl;
@ -68,11 +66,6 @@ public class TerraSpongePlugin implements TerraPlugin {
return spongeWorldHandle;
}
@Override
public TerraWorld getWorld(World world) {
return null;
}
@Override
public com.dfsek.terra.api.Logger logger() {
return new SpongeLogger(logger);