Fixed #297 alternating world save folders

Forge bypasses the dimension setter in Client side, unlike Server side. This is causing inconsistent behavior in SSP. We're now delaying retrieval of the celestial object to work around it.
This commit is contained in:
Unknown 2017-12-09 15:54:28 +01:00 committed by LemADEC
parent 028b85c43a
commit 990529fb65
3 changed files with 154 additions and 252 deletions

View file

@ -0,0 +1,151 @@
package cr0s.warpdrive.world;
import cr0s.warpdrive.Commons;
import cr0s.warpdrive.data.CelestialObject;
import cr0s.warpdrive.data.CelestialObjectManager;
import cr0s.warpdrive.render.RenderBlank;
import cr0s.warpdrive.render.RenderSpaceSky;
import net.minecraft.entity.Entity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.WorldProvider;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class AbstractWorldProvider extends WorldProvider {
protected CelestialObject celestialObjectDimension = null;
protected boolean isRemote;
protected void updateCelestialObject() throws RuntimeException {
if (dimensionId == 0) {
throw new RuntimeException("Critical error: you can't use a WorldProvider before settings its dimension id!");
}
if (celestialObjectDimension == null) {
isRemote = FMLCommonHandler.instance().getEffectiveSide().isClient();
celestialObjectDimension = CelestialObjectManager.get(isRemote, dimensionId, 0, 0);
}
}
@Override
public String getSaveFolder() {
updateCelestialObject();
if (celestialObjectDimension == null) {
throw new RuntimeException(String.format("Critical error: there's no celestial object defining %s dimension id %d, unable to proceed further",
isRemote ? "client" : "server", dimensionId));
}
return celestialObjectDimension.id;
}
@Override
public String getDimensionName() {
updateCelestialObject();
if (celestialObjectDimension == null) {
if (isRemote) {
return String.format("DIM%d", dimensionId);
} else {
throw new RuntimeException(String.format("Critical error: there's no celestial object defining %s dimension id %d, unable to proceed further",
"server", dimensionId));
}
}
return celestialObjectDimension.id;
}
@Override
public boolean canCoordinateBeSpawn(int x, int z) {
int y = worldObj.getTopSolidOrLiquidBlock(x, z);
return y != 0;
}
@Override
public ChunkCoordinates getEntrancePortalLocation() {
return null;
}
/*
@Override
public ChunkCoordinates getRandomizedSpawnPoint() {
ChunkCoordinates position = new ChunkCoordinates(worldObj.getSpawnPoint());
// boolean isAdventure = worldObj.getWorldInfo().getGameType() == EnumGameType.ADVENTURE;
int spawnFuzz = 100;
int spawnFuzzHalf = spawnFuzz / 2;
{
position.posX += worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
position.posZ += worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
position.posY = 200;
}
if (worldObj.isAirBlock(position.posX, position.posY, position.posZ)) {
worldObj.setBlock(position.posX, position.posY, position.posZ, Blocks.stone, 0, 2);
worldObj.setBlock(position.posX + 1, position.posY + 1, position.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX + 1, position.posY + 2, position.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX - 1, position.posY + 1, position.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX - 1, position.posY + 2, position.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX, position.posY + 1, position.posZ + 1, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX, position.posY + 2, position.posZ + 1, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX, position.posY + 1, position.posZ - 1, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX, position.posY + 2, position.posZ - 1, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX, position.posY + 3, position.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(position.posX, position.posY, position.posZ, WarpDrive.blockAir, 15, 2);
worldObj.setBlock(position.posX, position.posY + 1, position.posZ, WarpDrive.blockAir, 15, 2);
}
return position;
}
/**/
// shared for getFogColor(), getStarBrightness()
// @SideOnly(Side.CLIENT)
protected static CelestialObject celestialObject = null;
@SideOnly(Side.CLIENT)
@Override
public Vec3 getSkyColor(Entity cameraEntity, float partialTicks) {
if (getCloudRenderer() == null) {
setCloudRenderer(RenderBlank.getInstance());
}
if (getSkyRenderer() == null) {
setSkyRenderer(RenderSpaceSky.getInstance());
}
celestialObject = cameraEntity.worldObj == null ? null : CelestialObjectManager.get(
cameraEntity.worldObj,
MathHelper.floor_double(cameraEntity.posX), MathHelper.floor_double(cameraEntity.posZ));
if (celestialObject == null) {
return Vec3.createVectorHelper(1.0D, 0.0D, 0.0D);
} else {
return Vec3.createVectorHelper(celestialObject.backgroundColor.red, celestialObject.backgroundColor.green, celestialObject.backgroundColor.blue);
}
}
@SideOnly(Side.CLIENT)
@Override
public Vec3 getFogColor(float celestialAngle, float par2) {
final float factor = Commons.clamp(0.0F, 1.0F, MathHelper.cos(celestialAngle * (float) Math.PI * 2.0F) * 2.0F + 0.5F);
float red = celestialObject == null ? 0.0F : celestialObject.colorFog.red;
float green = celestialObject == null ? 0.0F : celestialObject.colorFog.green;
float blue = celestialObject == null ? 0.0F : celestialObject.colorFog.blue;
float factorRed = celestialObject == null ? 0.0F : celestialObject.factorFog.red;
float factorGreen = celestialObject == null ? 0.0F : celestialObject.factorFog.green;
float factorBlue = celestialObject == null ? 0.0F : celestialObject.factorFog.blue;
red *= factor * factorRed + (1.0F - factorRed );
green *= factor * factorGreen + (1.0F - factorGreen);
blue *= factor * factorBlue + (1.0F - factorBlue );
return Vec3.createVectorHelper(red, green, blue);
}
@SideOnly(Side.CLIENT)
@Override
public float getStarBrightness(float partialTicks) {
if (celestialObject == null) {
return 0.0F;
}
final float starBrightnessVanilla = super.getStarBrightness(partialTicks);
return celestialObject.baseStarBrightness + celestialObject.vanillaStarBrightness * starBrightnessVanilla;
}
}

View file

@ -1,21 +1,9 @@
package cr0s.warpdrive.world; package cr0s.warpdrive.world;
import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.client.ClientProxy;
import cr0s.warpdrive.data.CelestialObjectManager;
import cr0s.warpdrive.data.CelestialObject;
import cr0s.warpdrive.data.StarMapRegistry; import cr0s.warpdrive.data.StarMapRegistry;
import cr0s.warpdrive.render.RenderBlank;
import cr0s.warpdrive.render.RenderSpaceSky;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.WorldChunkManagerHell; import net.minecraft.world.biome.WorldChunkManagerHell;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@ -24,31 +12,13 @@ import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
public class HyperSpaceWorldProvider extends WorldProvider { public class HyperSpaceWorldProvider extends AbstractWorldProvider {
private CelestialObject celestialObjectDimension = null;
public HyperSpaceWorldProvider() { public HyperSpaceWorldProvider() {
worldChunkMgr = new WorldChunkManagerHell(WarpDrive.spaceBiome, 0.0F); worldChunkMgr = new WorldChunkManagerHell(WarpDrive.spaceBiome, 0.0F);
hasNoSky = true; hasNoSky = true;
} }
@Override
public void setDimension(final int dimensionId) {
super.setDimension(dimensionId);
celestialObjectDimension = CelestialObjectManager.get(WarpDrive.proxy instanceof ClientProxy, dimensionId, 0, 0);
}
@Override
public String getSaveFolder() {
return dimensionId == 0 ? null : (celestialObjectDimension == null ? "WarpDriveHyperSpace" + dimensionId : celestialObjectDimension.id);
}
@Override
public String getDimensionName() {
return celestialObjectDimension == null ? "Hyperspace" + dimensionId : celestialObjectDimension.id;
}
@Override @Override
public boolean canRespawnHere() { public boolean canRespawnHere() {
return true; return true;
@ -99,74 +69,12 @@ public class HyperSpaceWorldProvider extends WorldProvider {
} }
} }
@Override
public boolean canCoordinateBeSpawn(int x, int z) {
int y = worldObj.getTopSolidOrLiquidBlock(x, z);
return y != 0;
}
// shared for getFogColor(), getStarBrightness()
// @SideOnly(Side.CLIENT)
private static CelestialObject celestialObject = null;
@SideOnly(Side.CLIENT)
@Override
public Vec3 getSkyColor(Entity cameraEntity, float partialTicks) {
if (getCloudRenderer() == null) {
setCloudRenderer(RenderBlank.getInstance());
}
if (getSkyRenderer() == null) {
setSkyRenderer(RenderSpaceSky.getInstance());
}
celestialObject = cameraEntity.worldObj == null ? null : CelestialObjectManager.get(
cameraEntity.worldObj,
MathHelper.floor_double(cameraEntity.posX), MathHelper.floor_double(cameraEntity.posZ));
if (celestialObject == null) {
return Vec3.createVectorHelper(1.0D, 0.0D, 0.0D);
} else {
return Vec3.createVectorHelper(celestialObject.backgroundColor.red, celestialObject.backgroundColor.green, celestialObject.backgroundColor.blue);
}
}
@SideOnly(Side.CLIENT)
@Override
public Vec3 getFogColor(float celestialAngle, float par2) {
final float factor = Commons.clamp(0.0F, 1.0F, MathHelper.cos(celestialAngle * (float) Math.PI * 2.0F) * 2.0F + 0.5F);
float red = celestialObject == null ? 0.0F : celestialObject.colorFog.red;
float green = celestialObject == null ? 0.0F : celestialObject.colorFog.green;
float blue = celestialObject == null ? 0.0F : celestialObject.colorFog.blue;
float factorRed = celestialObject == null ? 0.0F : celestialObject.factorFog.red;
float factorGreen = celestialObject == null ? 0.0F : celestialObject.factorFog.green;
float factorBlue = celestialObject == null ? 0.0F : celestialObject.factorFog.blue;
red *= factor * factorRed + (1.0F - factorRed );
green *= factor * factorGreen + (1.0F - factorGreen);
blue *= factor * factorBlue + (1.0F - factorBlue );
return Vec3.createVectorHelper(red, green, blue);
}
@SideOnly(Side.CLIENT)
@Override
public float getStarBrightness(float partialTicks) {
if (celestialObject == null) {
return 0.0F;
}
final float starBrightnessVanilla = super.getStarBrightness(partialTicks);
return celestialObject.baseStarBrightness + celestialObject.vanillaStarBrightness * starBrightnessVanilla;
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@Override @Override
public boolean isSkyColored() { public boolean isSkyColored() {
return true; return true;
} }
@Override
public ChunkCoordinates getEntrancePortalLocation() {
return null;
}
@Override @Override
public int getRespawnDimension(EntityPlayerMP player) { public int getRespawnDimension(EntityPlayerMP player) {
if (player == null || player.worldObj == null) { if (player == null || player.worldObj == null) {
@ -186,36 +94,6 @@ public class HyperSpaceWorldProvider extends WorldProvider {
return false; return false;
} }
@Override
public ChunkCoordinates getRandomizedSpawnPoint() {
ChunkCoordinates var5 = new ChunkCoordinates(worldObj.getSpawnPoint());
// boolean isAdventure = worldObj.getWorldInfo().getGameType() == EnumGameType.ADVENTURE;
int spawnFuzz = 100;
int spawnFuzzHalf = spawnFuzz / 2;
{
var5.posX += worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
var5.posZ += worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
var5.posY = 200;
}
if (worldObj.isAirBlock(var5.posX, var5.posY, var5.posZ)) {
worldObj.setBlock(var5.posX, var5.posY, var5.posZ, Blocks.stone, 0, 2);
worldObj.setBlock(var5.posX + 1, var5.posY + 1, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX + 1, var5.posY + 2, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX - 1, var5.posY + 1, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX - 1, var5.posY + 2, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ + 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 2, var5.posZ + 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ - 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 2, var5.posZ - 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 3, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY, var5.posZ, WarpDrive.blockAir, 15, 2);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ, WarpDrive.blockAir, 15, 2);
}
return var5;
}
@Override @Override
public boolean getWorldHasVoidParticles() { public boolean getWorldHasVoidParticles() {
return false; return false;

View file

@ -1,20 +1,9 @@
package cr0s.warpdrive.world; package cr0s.warpdrive.world;
import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.client.ClientProxy;
import cr0s.warpdrive.data.CelestialObjectManager;
import cr0s.warpdrive.data.CelestialObject;
import cr0s.warpdrive.data.StarMapRegistry; import cr0s.warpdrive.data.StarMapRegistry;
import cr0s.warpdrive.render.RenderBlank;
import cr0s.warpdrive.render.RenderSpaceSky;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.WorldChunkManagerHell; import net.minecraft.world.biome.WorldChunkManagerHell;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@ -23,31 +12,13 @@ import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
public class SpaceWorldProvider extends WorldProvider { public class SpaceWorldProvider extends AbstractWorldProvider {
private CelestialObject celestialObjectDimension = null;
public SpaceWorldProvider() { public SpaceWorldProvider() {
worldChunkMgr = new WorldChunkManagerHell(WarpDrive.spaceBiome, 0.0F); worldChunkMgr = new WorldChunkManagerHell(WarpDrive.spaceBiome, 0.0F);
hasNoSky = false; hasNoSky = false;
} }
@Override
public void setDimension(final int dimensionId) {
super.setDimension(dimensionId);
celestialObjectDimension = CelestialObjectManager.get(WarpDrive.proxy instanceof ClientProxy, dimensionId, 0, 0);
}
@Override
public String getSaveFolder() {
return celestialObjectDimension == null ? "WarpDriveSpace" + dimensionId : celestialObjectDimension.id;
}
@Override
public String getDimensionName() {
return celestialObjectDimension == null ? "Space" + dimensionId : celestialObjectDimension.id;
}
@Override @Override
public boolean canRespawnHere() { public boolean canRespawnHere() {
return true; return true;
@ -90,7 +61,7 @@ public class SpaceWorldProvider extends WorldProvider {
@Override @Override
protected void generateLightBrightnessTable() { protected void generateLightBrightnessTable() {
float f = 0.0F; // 0.1F float f = 0.0F;
for (int i = 0; i <= 15; ++i) { for (int i = 0; i <= 15; ++i) {
float f1 = 1.0F - i / 15.0F; float f1 = 1.0F - i / 15.0F;
@ -98,74 +69,12 @@ public class SpaceWorldProvider extends WorldProvider {
} }
} }
@Override
public boolean canCoordinateBeSpawn(int x, int z) {
int y = worldObj.getTopSolidOrLiquidBlock(x, z);
return y != 0;
}
// shared for getFogColor(), getStarBrightness()
// @SideOnly(Side.CLIENT)
private static CelestialObject celestialObject = null;
@SideOnly(Side.CLIENT)
@Override
public Vec3 getSkyColor(Entity cameraEntity, float partialTicks) {
if (getCloudRenderer() == null) {
setCloudRenderer(RenderBlank.getInstance());
}
if (getSkyRenderer() == null) {
setSkyRenderer(RenderSpaceSky.getInstance());
}
celestialObject = cameraEntity.worldObj == null ? null : CelestialObjectManager.get(
cameraEntity.worldObj,
MathHelper.floor_double(cameraEntity.posX), MathHelper.floor_double(cameraEntity.posZ));
if (celestialObject == null) {
return Vec3.createVectorHelper(0.0D, 0.0D, 0.0D);
} else {
return Vec3.createVectorHelper(celestialObject.backgroundColor.red, celestialObject.backgroundColor.green, celestialObject.backgroundColor.blue);
}
}
@SideOnly(Side.CLIENT)
@Override
public Vec3 getFogColor(float celestialAngle, float par2) {
final float factor = Commons.clamp(0.0F, 1.0F, MathHelper.cos(celestialAngle * (float) Math.PI * 2.0F) * 2.0F + 0.5F);
float red = celestialObject == null ? 0.0F : celestialObject.colorFog.red;
float green = celestialObject == null ? 0.0F : celestialObject.colorFog.green;
float blue = celestialObject == null ? 0.0F : celestialObject.colorFog.blue;
float factorRed = celestialObject == null ? 0.0F : celestialObject.factorFog.red;
float factorGreen = celestialObject == null ? 0.0F : celestialObject.factorFog.green;
float factorBlue = celestialObject == null ? 0.0F : celestialObject.factorFog.blue;
red *= factor * factorRed + (1.0F - factorRed );
green *= factor * factorGreen + (1.0F - factorGreen);
blue *= factor * factorBlue + (1.0F - factorBlue );
return Vec3.createVectorHelper(red, green, blue);
}
@SideOnly(Side.CLIENT)
@Override
public float getStarBrightness(float partialTicks) {
if (celestialObject == null) {
return 0.0F;
}
final float starBrightnessVanilla = super.getStarBrightness(partialTicks);
return celestialObject.baseStarBrightness + celestialObject.vanillaStarBrightness * starBrightnessVanilla;
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@Override @Override
public boolean isSkyColored() { public boolean isSkyColored() {
return false; return false;
} }
@Override
public ChunkCoordinates getEntrancePortalLocation() {
return null;
}
@Override @Override
public int getRespawnDimension(EntityPlayerMP player) { public int getRespawnDimension(EntityPlayerMP player) {
if (player == null || player.worldObj == null) { if (player == null || player.worldObj == null) {
@ -185,42 +94,6 @@ public class SpaceWorldProvider extends WorldProvider {
return false; return false;
} }
/*
@Override
public ChunkCoordinates getRandomizedSpawnPoint() {
ChunkCoordinates var5 = new ChunkCoordinates(worldObj.getSpawnPoint());
//boolean isAdventure = worldObj.getWorldInfo().getGameType() == EnumGameType.ADVENTURE;
int spawnFuzz = 1000;
int spawnFuzzHalf = spawnFuzz / 2;
{
var5.posX += worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
var5.posZ += worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
var5.posY = 200;
}
if (worldObj.isAirBlock(var5.posX, var5.posY, var5.posZ)) {
worldObj.setBlock(var5.posX, var5.posY, var5.posZ, Blocks.stone, 0, 2);
worldObj.setBlock(var5.posX + 1, var5.posY + 1, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX + 1, var5.posY + 2, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX - 1, var5.posY + 1, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX - 1, var5.posY + 2, var5.posZ, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ + 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 2, var5.posZ + 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ - 1, Blocks.glass, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 3, var5.posZ - 1, Blocks.glass, 0, 2);
// worldObj.setBlockWithNotify(var5.posX, var5.posY + 3, var5.posZ, Block.glass.blockID);
}
return var5;
}
/**/
@Override @Override
public boolean getWorldHasVoidParticles() { public boolean getWorldHasVoidParticles() {
return false; return false;