aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/makamys/lodmod/LODMod.java51
-rw-r--r--src/main/java/makamys/lodmod/renderer/LODRenderer.java7
2 files changed, 38 insertions, 20 deletions
diff --git a/src/main/java/makamys/lodmod/LODMod.java b/src/main/java/makamys/lodmod/LODMod.java
index 1490a0a..ceed97d 100644
--- a/src/main/java/makamys/lodmod/LODMod.java
+++ b/src/main/java/makamys/lodmod/LODMod.java
@@ -4,6 +4,8 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.entity.RenderManager;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.world.World;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
@@ -99,29 +101,27 @@ public class LODMod
MinecraftForge.EVENT_BUS.register(this);
}
- @SubscribeEvent
- public void onWorldLoad(WorldEvent.Load event) {
- if(!event.world.isRemote) return;
-
- reloadConfig();
-
- if(enabled) {
- SpriteUtil.init();
- if(renderer != null) {
- LOGGER.warn("Renderer didn't get destroyed last time");
- renderer.destroy();
- }
- renderer = new LODRenderer();
+ private void onPlayerWorldChanged(World newWorld) {
+ if(getRendererWorld() == null && newWorld != null) {
+ reloadConfig();
+ if(enabled) {
+ SpriteUtil.init();
+ }
+ }
+ if(renderer != null) {
+ renderer.destroy();
+ renderer = null;
+ }
+ if(enabled && newWorld != null) {
+ renderer = new LODRenderer(newWorld);
}
}
@SubscribeEvent
+ @SideOnly(Side.CLIENT)
public void onWorldUnload(WorldEvent.Unload event) {
- if(!event.world.isRemote) return;
-
- if(renderer != null) {
- renderer.destroy();
- renderer = null;
+ if(event.world == getRendererWorld()) {
+ onPlayerWorldChanged(null);
}
}
@@ -138,6 +138,21 @@ public class LODMod
return renderer != null && renderer.hasInited;
}
+ private World getRendererWorld() {
+ return renderer != null ? renderer.world : null;
+ }
+
+ @SubscribeEvent
+ public void onClientTick(TickEvent.ClientTickEvent event) {
+ if(event.phase == TickEvent.Phase.START) {
+ EntityPlayer player = Minecraft.getMinecraft().thePlayer;
+ World world = player != null ? player.worldObj : null;
+ if(world != getRendererWorld()) {
+ onPlayerWorldChanged(world);
+ }
+ }
+ }
+
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
if(event.phase == TickEvent.Phase.START) {
diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
index fd04dcc..2d08bfb 100644
--- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java
+++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java
@@ -74,6 +74,8 @@ public class LODRenderer {
private boolean hasServerInited = false;
private Map<ChunkCoordIntPair, LODRegion> loadedRegionsMap = new HashMap<>();
+ public World world;
+
// TODO make these packets to make this work on dedicated servers
Queue<Chunk> farChunks = new ConcurrentLinkedQueue<>();
@@ -93,8 +95,9 @@ public class LODRenderer {
private boolean freezeMeshes;
public boolean disableChunkMeshes = true;
- public LODRenderer(){
+ public LODRenderer(World world){
hasInited = init();
+ this.world = world;
}
public void preRenderSortedRenderers(int renderPass, double alpha, WorldRenderer[] sortedWorldRenderers) {
@@ -497,7 +500,7 @@ public class LODRenderer {
int chunkLoadsRemaining = LODMod.chunkLoadsPerTick;
while(!serverChunkLoadQueue.isEmpty() && chunkLoadsRemaining-- > 0) {
ChunkCoordIntPair coords = serverChunkLoadQueue.remove(0);
- ChunkProviderServer chunkProviderServer = Minecraft.getMinecraft().getIntegratedServer().worldServers[0].theChunkProviderServer;
+ ChunkProviderServer chunkProviderServer = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(world.provider.dimensionId).theChunkProviderServer;
Chunk chunk = chunkProviderServer.currentChunkProvider.provideChunk(coords.chunkXPos, coords.chunkZPos);
SimpleChunkMesh.prepareFarChunkOnServer(chunk);
farChunks.add(chunk);