2nd Refactor started. Split to 3 type world structure

This commit is contained in:
TomTheFurry
2022-06-22 20:43:00 +08:00
parent 0f4e9792d2
commit cd2f2c4ae5
10 changed files with 51 additions and 56 deletions
@@ -22,10 +22,8 @@ package com.seibel.lod.common.wrappers;
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
import com.seibel.lod.core.objects.lod.LodDimension;
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper;
import com.seibel.lod.core.objects.DHBlockPos;
import com.seibel.lod.core.objects.DHChunkPos;
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
/**
@@ -39,7 +37,7 @@ public class WrapperFactory implements IWrapperFactory
public static final WrapperFactory INSTANCE = new WrapperFactory();
public AbstractBatchGenerationEnvionmentWrapper createBatchGenerator(LodBuilder newLodBuilder,
LodDimension newLodDimension, IWorldWrapper worldWrapper)
LodDimension newLodDimension, ILevelWrapper worldWrapper)
{
return new BatchGenerationEnvironment(worldWrapper, newLodBuilder, newLodDimension);
}
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.platform.Window;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.core.ModInfo;
import com.seibel.lod.core.enums.ELodDirection;
import com.seibel.lod.core.logging.DhLoggerBuilder;
@@ -32,12 +33,11 @@ import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IProfilerWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.lod.common.wrappers.McObjectConverter;
import com.seibel.lod.core.objects.DHBlockPos;
import com.seibel.lod.core.objects.DHChunkPos;
import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import net.minecraft.CrashReport;
import net.minecraft.client.Minecraft;
@@ -54,7 +54,6 @@ import net.minecraft.core.Direction;
#if PRE_MC_1_19
import net.minecraft.network.chat.TextComponent;
#endif
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
@@ -163,7 +162,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
@Override
public String getCurrentDimensionId()
{
return LodUtil.getDimensionIDFromWorld(WorldWrapper.getWorldWrapper(mc.level));
return LodUtil.getDimensionIDFromWorld(LevelWrapper.getWorldWrapper(mc.level));
}
//=============//
@@ -210,7 +209,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
}
@Override
public IWorldWrapper getWrappedServerWorld()
public ILevelWrapper getWrappedServerWorld()
{
if (mc.level == null)
return null;
@@ -231,15 +230,15 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
break;
}
}
return WorldWrapper.getWorldWrapper(serverWorld);
return LevelWrapper.getWorldWrapper(serverWorld);
}
public WorldWrapper getWrappedClientLevel()
public LevelWrapper getWrappedClientLevel()
{
return WorldWrapper.getWorldWrapper(mc.level);
return LevelWrapper.getWorldWrapper(mc.level);
}
public WorldWrapper getWrappedServerLevel()
public LevelWrapper getWrappedServerLevel()
{
if (mc.level == null)
@@ -261,14 +260,14 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
}
}
return WorldWrapper.getWorldWrapper(returnWorld);
return LevelWrapper.getWorldWrapper(returnWorld);
}
@Nullable
@Override
public IWorldWrapper getWrappedClientWorld()
public ILevelWrapper getWrappedClientWorld()
{
return WorldWrapper.getWorldWrapper(mc.level);
return LevelWrapper.getWorldWrapper(mc.level);
}
@Override
@@ -344,14 +343,14 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
/** Returns all worlds available to the server */
@Override
public ArrayList<IWorldWrapper> getAllServerWorlds()
public ArrayList<ILevelWrapper> getAllServerWorlds()
{
ArrayList<IWorldWrapper> worlds = new ArrayList<IWorldWrapper>();
ArrayList<ILevelWrapper> worlds = new ArrayList<ILevelWrapper>();
Iterable<ServerLevel> serverWorlds = mc.getSingleplayerServer().getAllLevels();
for (ServerLevel world : serverWorlds)
{
worlds.add(WorldWrapper.getWorldWrapper(world));
worlds.add(LevelWrapper.getWorldWrapper(world));
}
return worlds;
@@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentMap;
import com.seibel.lod.core.objects.DHChunkPos;
import com.seibel.lod.core.enums.EWorldType;
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import net.minecraft.client.multiplayer.ClientLevel;
@@ -46,14 +46,14 @@ import org.jetbrains.annotations.Nullable;
* @author ??
* @version 11-21-2021
*/
public class WorldWrapper implements IWorldWrapper
public class LevelWrapper implements ILevelWrapper
{
private static final ConcurrentMap<LevelAccessor, WorldWrapper> worldWrapperMap = new ConcurrentHashMap<>();
private static final ConcurrentMap<LevelAccessor, LevelWrapper> worldWrapperMap = new ConcurrentHashMap<>();
private final LevelAccessor world;
public final EWorldType worldType;
public WorldWrapper(LevelAccessor newWorld)
public LevelWrapper(LevelAccessor newWorld)
{
world = newWorld;
@@ -67,7 +67,7 @@ public class WorldWrapper implements IWorldWrapper
@Nullable
public static WorldWrapper getWorldWrapper(LevelAccessor world)
public static LevelWrapper getWorldWrapper(LevelAccessor world)
{
if (world == null) return null;
//first we check if the biome has already been wrapped
@@ -76,7 +76,7 @@ public class WorldWrapper implements IWorldWrapper
//if it hasn't been created yet, we create it and save it in the map
WorldWrapper worldWrapper = new WorldWrapper(world);
LevelWrapper worldWrapper = new LevelWrapper(world);
worldWrapperMap.put(world, worldWrapper);
//we return the newly created wrapper
@@ -33,7 +33,7 @@ import com.seibel.lod.core.objects.lod.LodDimension;
import com.seibel.lod.core.util.gridList.ArrayGridList;
import com.seibel.lod.core.util.LodThreadFactory;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper;
import java.time.Duration;
@@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
import com.seibel.lod.common.wrappers.DependencySetupDoneCheck;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.ChunkLoader;
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightGetterAdaptor;
import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion;
@@ -343,11 +343,11 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
}
}
public BatchGenerationEnvironment(IWorldWrapper serverlevel, LodBuilder lodBuilder, LodDimension lodDim)
public BatchGenerationEnvironment(ILevelWrapper serverlevel, LodBuilder lodBuilder, LodDimension lodDim)
{
super(serverlevel, lodBuilder, lodDim);
EVENT_LOGGER.info("================WORLD_GEN_STEP_INITING=============");
ChunkGenerator generator = ((WorldWrapper) serverlevel).getServerWorld().getChunkSource().getGenerator();
ChunkGenerator generator = ((LevelWrapper) serverlevel).getServerWorld().getChunkSource().getGenerator();
if (!(generator instanceof NoiseBasedChunkGenerator ||
generator instanceof DebugLevelSource ||
generator instanceof FlatLevelSource)) {
@@ -359,7 +359,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
EVENT_LOGGER.warn("If it does crash, set Distant Generation to OFF or Generation Mode to None.");
}
}
params = new GlobalParameters((ServerLevel) ((WorldWrapper) serverlevel).getWorld(), lodBuilder, lodDim);
params = new GlobalParameters((ServerLevel) ((LevelWrapper) serverlevel).getWorld(), lodBuilder, lodDim);
}
@SuppressWarnings("resource")
@@ -20,12 +20,12 @@
package com.seibel.lod.fabric;
import com.seibel.lod.common.wrappers.McObjectConverter;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.lod.core.api.internal.a7.ClientApi;
import com.seibel.lod.core.config.Config;
import com.mojang.blaze3d.platform.InputConstants;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents;
@@ -81,14 +81,14 @@ public class FabricClientProxy
ClientChunkEvents.CHUNK_LOAD.register((level, chunk) ->
ClientApi.INSTANCE.clientChunkLoadEvent(
new ChunkWrapper(chunk, level),
WorldWrapper.getWorldWrapper(level)
LevelWrapper.getWorldWrapper(level)
));
//#endif
// ClientChunkSaveEvent
ClientChunkEvents.CHUNK_UNLOAD.register((level, chunk)->
ClientApi.INSTANCE.clientChunkSaveEvent(
new ChunkWrapper(chunk, level),
WorldWrapper.getWorldWrapper(level)
LevelWrapper.getWorldWrapper(level)
));
// RendererStartupEvent - Done in MixinGameRenderer
@@ -113,8 +113,8 @@ public class FabricClientProxy
private boolean isValidTime() {
return !(Minecraft.getInstance().screen instanceof TitleScreen);
}
private WorldWrapper getLevelWrapper(Level level) {
return WorldWrapper.getWorldWrapper(level);
private LevelWrapper getLevelWrapper(Level level) {
return LevelWrapper.getWorldWrapper(level);
}
// public void blockChangeEvent(LevelAccessor world, BlockPos pos) {
@@ -2,10 +2,10 @@ package com.seibel.lod.fabric;
import com.seibel.lod.common.networking.Networking;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.core.api.internal.a7.ServerApi;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
@@ -35,8 +35,8 @@ public class FabricServerProxy {
//FIXME: return true immediately if this is a dedicated server
return !(Minecraft.getInstance().screen instanceof TitleScreen);
}
private WorldWrapper getLevelWrapper(Level level) {
return WorldWrapper.getWorldWrapper(level);
private LevelWrapper getLevelWrapper(Level level) {
return LevelWrapper.getWorldWrapper(level);
}
/**
* Registers Fabric Events
@@ -77,7 +77,7 @@ public class FabricServerProxy {
// ServerChunkLoadEvent
ServerChunkEvents.CHUNK_LOAD.register((server, chunk)
-> {
IWorldWrapper level = getLevelWrapper(chunk.getLevel());
ILevelWrapper level = getLevelWrapper(chunk.getLevel());
if (isValidTime()) ServerApi.INSTANCE.serverChunkLoadEvent(
new ChunkWrapper(chunk, chunk.getLevel()),
level);
@@ -20,7 +20,7 @@
package com.seibel.lod.fabric.mixins.client;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.core.api.internal.a7.ClientApi;
import net.minecraft.client.multiplayer.ClientLevel;
#if POST_MC_1_18_2
@@ -54,7 +54,7 @@ public class MixinClientLevel {
ClientLevel l = (ClientLevel) (Object) this;
LevelChunk chunk = l.getChunkSource().getChunk(x, z, false);
if (chunk!=null&& !chunk.isClientLightReady())
ClientApi.INSTANCE.clientChunkLoadEvent(new ChunkWrapper(chunk, l), WorldWrapper.getWorldWrapper(l));
ClientApi.INSTANCE.clientChunkLoadEvent(new ChunkWrapper(chunk, l), LevelWrapper.getWorldWrapper(l));
}
#endif
}
@@ -1,6 +1,6 @@
package com.seibel.lod.fabric.mixins.client;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.core.api.internal.a7.ClientApi;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
@@ -23,25 +23,25 @@ public class MixinClientPacketListener {
*/
@Inject(method = "handleLogin", at = @At("HEAD"))
void onHandleLoginStart(CallbackInfo ci) {
if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(WorldWrapper.getWorldWrapper(level));
if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(LevelWrapper.getWorldWrapper(level));
}
@Inject(method = "handleLogin", at = @At("RETURN"))
void onHandleLoginEnd(CallbackInfo ci) {
ClientApi.INSTANCE.clientLevelLoadEvent(WorldWrapper.getWorldWrapper(level));
ClientApi.INSTANCE.clientLevelLoadEvent(LevelWrapper.getWorldWrapper(level));
}
@Inject(method = "handleRespawn", at = @At("HEAD"))
void onHandleRespawnStart(CallbackInfo ci) {
ClientApi.INSTANCE.clientLevelUnloadEvent(WorldWrapper.getWorldWrapper(level));
ClientApi.INSTANCE.clientLevelUnloadEvent(LevelWrapper.getWorldWrapper(level));
}
@Inject(method = "handleRespawn", at = @At("RETURN"))
void onHandleRespawnEnd(CallbackInfo ci) {
ClientApi.INSTANCE.clientLevelLoadEvent(WorldWrapper.getWorldWrapper(level));
ClientApi.INSTANCE.clientLevelLoadEvent(LevelWrapper.getWorldWrapper(level));
}
@Inject(method = "cleanup", at = @At("HEAD"))
void onCleanupStart(CallbackInfo ci) {
if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(WorldWrapper.getWorldWrapper(level));
if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(LevelWrapper.getWorldWrapper(level));
}
}
@@ -1,9 +1,8 @@
package com.seibel.lod.fabric.mixins.server;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.core.api.internal.a7.ServerApi;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkAccess;
@@ -13,7 +12,6 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ChunkMap.class)
@@ -33,7 +31,7 @@ public class MixinChunkMap {
private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci) {
ServerApi.INSTANCE.serverChunkSaveEvent(
new ChunkWrapper(chunk, level),
WorldWrapper.getWorldWrapper(level)
LevelWrapper.getWorldWrapper(level)
);
}
@@ -19,6 +19,7 @@
package com.seibel.lod.forge;
import com.seibel.lod.common.wrappers.world.LevelWrapper;
import com.seibel.lod.core.api.internal.ClientApi;
import com.seibel.lod.core.api.internal.EventApi;
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
@@ -28,7 +29,6 @@ import org.lwjgl.glfw.GLFW;
import com.seibel.lod.common.wrappers.chunk.ChunkWrapper;
import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper;
import com.seibel.lod.common.wrappers.world.WorldWrapper;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.InputEvent;
@@ -62,7 +62,7 @@ public class ForgeClientProxy
@SubscribeEvent
public void chunkLoadEvent(ChunkEvent.Load event)
{
clientApi.clientChunkLoadEvent(new ChunkWrapper(event.getChunk(), event.getWorld()), WorldWrapper.getWorldWrapper(event.getWorld()));
clientApi.clientChunkLoadEvent(new ChunkWrapper(event.getChunk(), event.getWorld()), LevelWrapper.getWorldWrapper(event.getWorld()));
}
@SubscribeEvent
@@ -77,14 +77,14 @@ public class ForgeClientProxy
{
if (Minecraft.getInstance().screen instanceof TitleScreen) return;
if (event.getWorld() != null) {
eventApi.worldLoadEvent(WorldWrapper.getWorldWrapper(event.getWorld()));
eventApi.worldLoadEvent(LevelWrapper.getWorldWrapper(event.getWorld()));
}
}
@SubscribeEvent
public void worldUnloadEvent(WorldEvent.Unload event)
{
eventApi.worldUnloadEvent(WorldWrapper.getWorldWrapper(event.getWorld()));
eventApi.worldUnloadEvent(LevelWrapper.getWorldWrapper(event.getWorld()));
}
@SubscribeEvent