Prevent a error related to loading textures on a null clientWorld

This commit is contained in:
James Seibel
2021-09-18 09:39:53 -05:00
parent f3dd99e792
commit 5c59ba7a80
4 changed files with 41 additions and 23 deletions
@@ -29,13 +29,26 @@ import com.seibel.lod.config.LodConfig;
import com.seibel.lod.enums.DistanceGenerationMode;
import com.seibel.lod.enums.LodDetail;
import com.seibel.lod.enums.LodQualityMode;
import com.seibel.lod.util.*;
import com.seibel.lod.objects.LodDimension;
import com.seibel.lod.objects.LodRegion;
import com.seibel.lod.objects.LodWorld;
import com.seibel.lod.util.ColorUtil;
import com.seibel.lod.util.DataPointUtil;
import com.seibel.lod.util.DetailDistanceUtil;
import com.seibel.lod.util.LevelPosUtil;
import com.seibel.lod.util.LodThreadFactory;
import com.seibel.lod.util.LodUtil;
import com.seibel.lod.util.ThreadMapUtil;
import com.seibel.lod.wrappers.MinecraftWrapper;
import net.minecraft.block.*;
import net.minecraft.block.AbstractPlantBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.BushBlock;
import net.minecraft.block.GrassBlock;
import net.minecraft.block.IGrowable;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -61,10 +74,12 @@ import net.minecraftforge.client.model.data.ModelDataMap;
*
* @author Leonardo Amato
* @author James Seibel
* @version 9-7-2021
* @version 9-18-2021
*/
public class LodBuilder
{
private static MinecraftWrapper mc = MinecraftWrapper.INSTANCE;
private ExecutorService lodGenThreadPool = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName()));
public static final int CHUNK_DATA_WIDTH = LodUtil.CHUNK_WIDTH;
@@ -115,20 +130,25 @@ public class LodBuilder
{
try
{
// we need a loaded client world in order to
// get the textures for blocks
if (mc.getClientWorld() == null)
return;
DimensionType dim = world.dimensionType();
LodDimension lodDim;
int playerPosX;
int playerPosZ;
if (MinecraftWrapper.INSTANCE.getPlayer() == null)
if (mc.getPlayer() == null)
{
playerPosX = chunk.getPos().getMinBlockX();
playerPosZ = chunk.getPos().getMinBlockZ();
} else
{
playerPosX = (int) MinecraftWrapper.INSTANCE.getPlayer().getX();
playerPosZ = (int) MinecraftWrapper.INSTANCE.getPlayer().getZ();
playerPosX = (int) mc.getPlayer().getX();
playerPosZ = (int) mc.getPlayer().getZ();
}
if (lodWorld.getLodDimension(dim) == null)
{
@@ -266,7 +286,7 @@ public class LodBuilder
int xAbs;
int yAbs;
int zAbs;
boolean hasCeiling = MinecraftWrapper.INSTANCE.getWorld().dimensionType().hasCeiling();
boolean hasCeiling = mc.getClientWorld().dimensionType().hasCeiling();
BlockPos.Mutable blockPos = new BlockPos.Mutable(0, 0, 0);
int index = 0;
@@ -579,12 +599,12 @@ public class LodBuilder
{
int skyLight;
int blockLight;
if (MinecraftWrapper.INSTANCE.getPlayer() == null)
if (mc.getPlayer() == null)
return 0;
if (MinecraftWrapper.INSTANCE.getPlayer().level == null)
if (mc.getPlayer().level == null)
return 0;
IWorld world = MinecraftWrapper.INSTANCE.getPlayer().level;
IWorld world = mc.getPlayer().level;
blockLight = world.getBrightness(LightType.BLOCK, blockPos);
skyLight = world.getBrightness(LightType.SKY, blockPos);
@@ -607,23 +627,23 @@ public class LodBuilder
return colorMap.get(blockState.getBlock());
World world = MinecraftWrapper.INSTANCE.getWorld();
World world = mc.getClientWorld();
TextureAtlasSprite texture;
if(topTextureRequired)
{
List<BakedQuad> quad = ((IForgeBakedModel) MinecraftWrapper.INSTANCE.getModelManager().getBlockModelShaper().getBlockModel(blockState)).getQuads(blockState, Direction.UP, new Random(0), dataMap);
List<BakedQuad> quad = ((IForgeBakedModel) mc.getModelManager().getBlockModelShaper().getBlockModel(blockState)).getQuads(blockState, Direction.UP, new Random(0), dataMap);
if (!quad.isEmpty())
{
texture = quad.get(0).getSprite();
}
else
{
texture = MinecraftWrapper.INSTANCE.getModelManager().getBlockModelShaper().getTexture(blockState, world, blockPos);
texture = mc.getModelManager().getBlockModelShaper().getTexture(blockState, world, blockPos);
}
}
else
{
texture = MinecraftWrapper.INSTANCE.getModelManager().getBlockModelShaper().getTexture(blockState, world, blockPos);
texture = mc.getModelManager().getBlockModelShaper().getTexture(blockState, world, blockPos);
}
@@ -138,7 +138,7 @@ public class Box
this.color = color;
for (Direction direction : DIRECTIONS)
{
colorMap.get(direction)[0] = ColorUtil.applyShade(color, MinecraftWrapper.INSTANCE.getWorld().getShade(direction, true));
colorMap.get(direction)[0] = ColorUtil.applyShade(color, MinecraftWrapper.INSTANCE.getClientWorld().getShade(direction, true));
}
}
@@ -846,12 +846,12 @@ public class LodRenderer
}
// check if the lighting has changed
if (mc.getWorld().getDayTime() - prevDayTime > 1000 || mc.getOptions().gamma != prevBrightness || lightMap == null)
if (mc.getClientWorld().getDayTime() - prevDayTime > 1000 || mc.getOptions().gamma != prevBrightness || lightMap == null)
{
fullRegen = true;
lightMap = mc.getCurrentLightMap();
prevBrightness = mc.getOptions().gamma;
prevDayTime = mc.getWorld().getDayTime();
prevDayTime = mc.getClientWorld().getDayTime();
}
@@ -14,16 +14,14 @@ import net.minecraft.client.network.play.ClientPlayNetHandler;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.model.ModelManager;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.profiler.IProfiler;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.Direction;
import net.minecraft.world.DimensionType;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import org.lwjgl.system.CallbackI;
/**
* A singleton that wraps the Minecraft class
@@ -174,8 +172,8 @@ public class MinecraftWrapper
{
return mc.getModelManager();
}
public World getWorld()
public ClientWorld getClientWorld()
{
return mc.level;
}