fix: multiplayer crash
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing

This commit is contained in:
Timo Ley 2023-02-19 17:56:35 +01:00
parent a26d553b81
commit 8df255fb8b
4 changed files with 42 additions and 5 deletions

View file

@ -24,7 +24,7 @@ apply from: './gradle/scripts/mixins.gradle'
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
version = "1.7.0" version = "1.7.1"
group= "dev.tilera.modding" group= "dev.tilera.modding"
archivesBaseName = "cwg" archivesBaseName = "cwg"

View file

@ -1,6 +1,7 @@
package dev.tilera.cwg; package dev.tilera.cwg;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@ -9,7 +10,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import dev.tilera.cwg.caves.MapGenCavesSwiss; import dev.tilera.cwg.caves.MapGenCavesSwiss;
import dev.tilera.cwg.command.CommandChangeWorld; import dev.tilera.cwg.command.CommandChangeWorld;
import dev.tilera.cwg.noisegen.NoiseGeneratorOctavesFarlands; import dev.tilera.cwg.noisegen.NoiseGeneratorOctavesFarlands;
import net.minecraft.server.MinecraftServer; import dev.tilera.cwg.proxy.CommonProxy;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldType; import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
@ -27,6 +28,8 @@ public class ClassicWorldgen {
@Mod.Instance @Mod.Instance
public static ClassicWorldgen INSTANCE; public static ClassicWorldgen INSTANCE;
@SidedProxy(modId = Constants.ID, serverSide = "dev.tilera.cwg.proxy.CommonProxy", clientSide = "dev.tilera.cwg.proxy.ClientProxy")
public static CommonProxy proxy;
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
@ -70,9 +73,7 @@ public class ClassicWorldgen {
} }
public static boolean isClassicWorld() { public static boolean isClassicWorld() {
World[] worlds = MinecraftServer.getServer().worldServers; World world = proxy.getWorld();
if (worlds.length == 0) return true;
World world = worlds[0];
if (world == null) return true; if (world == null) return true;
return isClassicWorld(world); return isClassicWorld(world);
} }

View file

@ -0,0 +1,22 @@
package dev.tilera.cwg.proxy;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
public class ClientProxy extends CommonProxy {
@Override
public World getWorld() {
World world = null;
if (MinecraftServer.getServer() != null) {
World[] worlds = MinecraftServer.getServer().worldServers;
if (worlds.length == 0) return null;
world = worlds[0];
} else if (Minecraft.getMinecraft() != null) {
world = Minecraft.getMinecraft().theWorld;
}
return world;
}
}

View file

@ -0,0 +1,14 @@
package dev.tilera.cwg.proxy;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
public class CommonProxy {
public World getWorld() {
World[] worlds = MinecraftServer.getServer().worldServers;
if (worlds.length == 0) return null;
return worlds[0];
}
}