mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-18 19:49:12 +00:00
Fix world client memory leaks caused by block renderers (#88)
* make threadlocals final * minor code fixes * fix custom block renderers leaking world * remove now useless threadlocal cleaning * fix memory leak from rendererOld by just deleting the field * fix ThreadLocals to work on dedicated server
This commit is contained in:
1 parent
2ae1f8ba93
commit
ec610dc876
17 files changed
+114
-203
No files matched your search
@@ -14,10 +14,10 @@ import team.chisel.ctmlib.ISubmapManager;
|
||||
|
||||
public class VariationInfoBase implements IVariationInfo {
|
||||
|
||||
private ICarvingVariation variation;
|
||||
private String unlocDesc;
|
||||
private ISubmapManager manager;
|
||||
private TextureType type;
|
||||
private final ICarvingVariation variation;
|
||||
private final String unlocDesc;
|
||||
private final ISubmapManager manager;
|
||||
private final TextureType type;
|
||||
|
||||
public VariationInfoBase(ICarvingVariation variation, String unlocDesc, ISubmapManager manager) {
|
||||
this(variation, unlocDesc, manager, TextureType.CUSTOM);
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.apache.commons.lang3.tuple.Triple;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.CTM;
|
||||
@@ -91,9 +92,9 @@ public enum TextureType {
|
||||
TextureSubmap map = data.getLeft();
|
||||
if (topConnected && botConnected)
|
||||
return map.getSubIcon(0, 1);
|
||||
if (topConnected && !botConnected)
|
||||
if (topConnected)
|
||||
return map.getSubIcon(1, 1);
|
||||
if (!topConnected && botConnected)
|
||||
if (botConnected)
|
||||
return map.getSubIcon(1, 0);
|
||||
return map.getSubIcon(0, 0);
|
||||
}
|
||||
@@ -101,11 +102,9 @@ public enum TextureType {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected RenderBlocks createRenderContext(RenderBlocks rendererOld, IBlockAccess world, Object cachedObject) {
|
||||
TextureType.initStatics();
|
||||
RenderBlocksColumn ret = theRenderBlocksColumn.get();
|
||||
Pair<TextureSubmap, IIcon> data = (Pair<TextureSubmap, IIcon>) cachedObject;
|
||||
|
||||
ret.blockAccess = world;
|
||||
ret.renderMaxX = 1.0;
|
||||
ret.renderMaxY = 1.0;
|
||||
ret.renderMaxZ = 1.0;
|
||||
@@ -207,15 +206,12 @@ public enum TextureType {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected RenderBlocks createRenderContext(RenderBlocks rendererOld, IBlockAccess world, Object cachedObject) {
|
||||
TextureType.initStatics();
|
||||
RenderBlocksCTM ret = theRenderBlocksCTM.get();
|
||||
Triple<?, TextureSubmap, TextureSubmap> data = (Triple<?, TextureSubmap, TextureSubmap>) cachedObject;
|
||||
ret.blockAccess = world;
|
||||
|
||||
ret.submap = data.getMiddle();
|
||||
ret.submapSmall = data.getRight();
|
||||
|
||||
ret.rendererOld = rendererOld;
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
@@ -332,33 +328,18 @@ public enum TextureType {
|
||||
private static final TextureType[] VALUES;
|
||||
private static final CTM ctm = CTM.getInstance();
|
||||
private static final Random rand = new Random();
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCTM> theRenderBlocksCTM;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksColumn> theRenderBlocksColumn;
|
||||
private static final ThreadLocal<RenderBlocksCTM> theRenderBlocksCTM = FMLLaunchHandler.side().isClient() ? ThreadLocal.withInitial(RenderBlocksCTM::new) : null;
|
||||
private static final ThreadLocal<RenderBlocksColumn> theRenderBlocksColumn = FMLLaunchHandler.side().isClient() ? ThreadLocal.withInitial(RenderBlocksColumn::new) : null;
|
||||
|
||||
private String[] suffixes;
|
||||
private final String[] suffixes;
|
||||
static {
|
||||
VALUES = ArrayUtils.subarray(values(), 0, values().length - 1);
|
||||
}
|
||||
|
||||
private TextureType(String... suffixes) {
|
||||
TextureType(String... suffixes) {
|
||||
this.suffixes = suffixes.length == 0 ? new String[] { "" } : suffixes;
|
||||
}
|
||||
|
||||
private static void initStatics() {
|
||||
if (theRenderBlocksCTM == null) {
|
||||
theRenderBlocksCTM = ThreadLocal.withInitial(RenderBlocksCTM::new);
|
||||
theRenderBlocksColumn = ThreadLocal.withInitial(RenderBlocksColumn::new);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clearStatics() {
|
||||
if(theRenderBlocksCTM != null) theRenderBlocksCTM.remove();
|
||||
if(theRenderBlocksColumn != null) theRenderBlocksColumn.remove();
|
||||
}
|
||||
|
||||
public ISubmapManager createManagerFor(ICarvingVariation variation, String texturePath) {
|
||||
return new SubmapManagerDefault(this, variation, texturePath);
|
||||
}
|
||||
|
||||
@@ -19,11 +19,7 @@ import team.chisel.ctmlib.Drawing;
|
||||
@ThreadSafeISBRH(perThread = false)
|
||||
public class RendererCTMPane implements ISimpleBlockRenderingHandler {
|
||||
|
||||
public static int id;
|
||||
|
||||
public RendererCTMPane() {
|
||||
id = RenderingRegistry.getNextAvailableRenderId();
|
||||
}
|
||||
public static final int id = RenderingRegistry.getNextAvailableRenderId();
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int meta, int modelID, RenderBlocks renderer) {
|
||||
@@ -33,7 +29,7 @@ public class RendererCTMPane implements ISimpleBlockRenderingHandler {
|
||||
Drawing.drawBlock(block, meta, renderer);
|
||||
}
|
||||
|
||||
class PaneRenderer {
|
||||
static class PaneRenderer {
|
||||
|
||||
double i0u0;
|
||||
double i0uh;
|
||||
|
||||
@@ -27,7 +27,8 @@ public class RendererEldritch implements ISimpleBlockRenderingHandler {
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
}
|
||||
|
||||
ThreadLocal<RenderBlocksEldritch> rendererThreadLocal = ThreadLocal.withInitial(RenderBlocksEldritch::new);
|
||||
private static final ThreadLocal<RenderBlocksEldritch> rendererThreadLocal = ThreadLocal
|
||||
.withInitial(RenderBlocksEldritch::new);
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
@@ -59,7 +60,11 @@ public class RendererEldritch implements ISimpleBlockRenderingHandler {
|
||||
renderer.renderMaxX = 1.0;
|
||||
renderer.renderMaxY = 1.0;
|
||||
renderer.renderMaxZ = 1.0;
|
||||
renderer.renderStandardBlock(block, x, y, z);
|
||||
try {
|
||||
renderer.renderStandardBlock(block, x, y, z);
|
||||
} finally {
|
||||
renderer.blockAccess = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
/*
|
||||
|
||||
@@ -28,17 +28,11 @@ public class RendererMultiLayer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
final static float bot = -0.001f;
|
||||
final static float top = 1.0f - bot;
|
||||
public static int id;
|
||||
|
||||
public RendererMultiLayer() {
|
||||
id = RenderingRegistry.getNextAvailableRenderId();
|
||||
}
|
||||
public static final int id = RenderingRegistry.getNextAvailableRenderId();
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block blck, int meta, int modelID, RenderBlocks renderer) {
|
||||
if (blck == null || !(blck instanceof BlockMultiLayerBase)) return;
|
||||
|
||||
BlockMultiLayerBase block = (BlockMultiLayerBase) blck;
|
||||
if (!(blck instanceof BlockMultiLayerBase block)) return;
|
||||
|
||||
if (block.icon != null) {
|
||||
renderer.overrideBlockTexture = block.icon;
|
||||
@@ -61,8 +55,7 @@ public class RendererMultiLayer implements ISimpleBlockRenderingHandler {
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block blck, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
if (blck == null || !(blck instanceof BlockMultiLayerBase)) return false;
|
||||
BlockMultiLayerBase block = (BlockMultiLayerBase) blck;
|
||||
if (!(blck instanceof BlockMultiLayerBase block)) return false;
|
||||
|
||||
if (MinecraftForgeClient.getRenderPass() == 0) {
|
||||
if (block.icon != null) {
|
||||
|
||||
@@ -16,11 +16,7 @@ import team.chisel.ctmlib.Drawing;
|
||||
@ThreadSafeISBRH(perThread = false)
|
||||
public class RendererStairs implements ISimpleBlockRenderingHandler {
|
||||
|
||||
public static int id;
|
||||
|
||||
public RendererStairs() {
|
||||
id = RenderingRegistry.getNextAvailableRenderId();
|
||||
}
|
||||
public static final int id = RenderingRegistry.getNextAvailableRenderId();
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int meta, int modelID, RenderBlocks renderer) {
|
||||
@@ -34,8 +30,7 @@ public class RendererStairs implements ISimpleBlockRenderingHandler {
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block blck, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
if (blck == null || !(blck instanceof BlockCarvableStairs)) return false;
|
||||
BlockCarvableStairs block = (BlockCarvableStairs) blck;
|
||||
if (!(blck instanceof BlockCarvableStairs block)) return false;
|
||||
|
||||
renderer.renderBlockStairs(block, x, y, z);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.Drawing;
|
||||
@@ -74,16 +75,10 @@ public class SubmapManagerAntiblock extends SubmapManagerBase {
|
||||
}
|
||||
};
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCTMFullbright> renderBlocksThreadLocal;
|
||||
private static final ThreadLocal<RenderBlocksCTMFullbright> renderBlocksThreadLocal = FMLLaunchHandler.side()
|
||||
.isClient() ? ThreadLocal.withInitial(RenderBlocksCTMFullbright::new) : null;
|
||||
|
||||
private static void initStatics() {
|
||||
if (renderBlocksThreadLocal == null) {
|
||||
renderBlocksThreadLocal = ThreadLocal.withInitial(RenderBlocksCTMFullbright::new);
|
||||
}
|
||||
}
|
||||
|
||||
private String color;
|
||||
private final String color;
|
||||
private TextureSubmap submap, submapSmall;
|
||||
|
||||
public SubmapManagerAntiblock(String color) {
|
||||
@@ -105,7 +100,6 @@ public class SubmapManagerAntiblock extends SubmapManagerBase {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
|
||||
initStatics();
|
||||
RenderBlocksCTMFullbright rb = renderBlocksThreadLocal.get();
|
||||
rb.setRenderBoundsFromBlock(block);
|
||||
rb.submap = submap;
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
@@ -13,18 +14,12 @@ import team.chisel.ctmlib.TextureSubmap;
|
||||
|
||||
public class SubmapManagerCarpetFloor extends SubmapManagerBase {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCTM> renderBlocksThreadLocal;
|
||||
|
||||
private static void initStatics() {
|
||||
if (renderBlocksThreadLocal == null) {
|
||||
renderBlocksThreadLocal = ThreadLocal.withInitial(RenderBlocksCTM::new);
|
||||
}
|
||||
}
|
||||
private static final ThreadLocal<RenderBlocksCTM> renderBlocksThreadLocal = FMLLaunchHandler.side()
|
||||
.isClient() ? ThreadLocal.withInitial(RenderBlocksCTM::new) : null;
|
||||
|
||||
private TextureSubmap submap;
|
||||
private TextureSubmap submapSmall;
|
||||
private String color;
|
||||
private final String color;
|
||||
|
||||
public SubmapManagerCarpetFloor(String color) {
|
||||
this.color = color;
|
||||
@@ -51,7 +46,6 @@ public class SubmapManagerCarpetFloor extends SubmapManagerBase {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
|
||||
initStatics();
|
||||
RenderBlocksCTM rb = renderBlocksThreadLocal.get();
|
||||
rb.setRenderBoundsFromBlock(block);
|
||||
rb.submap = submap;
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.cricketcraft.chisel.api.carving.CarvingUtils;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType.AbstractSubmapManager;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
@@ -78,9 +79,9 @@ public class SubmapManagerCombinedCTM extends SubmapManagerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private class Submap extends TextureSubmap {
|
||||
private static class Submap extends TextureSubmap {
|
||||
|
||||
private TextureSubmap[][] submap;
|
||||
private final TextureSubmap[][] submap;
|
||||
|
||||
public Submap(IIcon base, int wh, TextureSubmap[][] submap) {
|
||||
super(base, wh, wh);
|
||||
@@ -98,21 +99,15 @@ public class SubmapManagerCombinedCTM extends SubmapManagerBase {
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCombinedCTM> renderBlocksThreadLocal;
|
||||
|
||||
private static void initStatics() {
|
||||
if (renderBlocksThreadLocal == null) {
|
||||
renderBlocksThreadLocal = new ThreadLocal<>();
|
||||
}
|
||||
}
|
||||
private final ThreadLocal<RenderBlocksCombinedCTM> renderBlocksThreadLocal = FMLLaunchHandler.side()
|
||||
.isClient() ? ThreadLocal.withInitial(RenderBlocksCombinedCTM::new) : null;
|
||||
|
||||
private TextureSubmap submap, smallSubmap;
|
||||
private int size;
|
||||
private String texturePath;
|
||||
private int meta;
|
||||
private final int size;
|
||||
private final String texturePath;
|
||||
private final int meta;
|
||||
private IIcon defaultIcon;
|
||||
private TextureType rType;
|
||||
private final TextureType rType;
|
||||
|
||||
public SubmapManagerCombinedCTM(int meta, String texturePath, TextureType rType) {
|
||||
assert rType == TextureType.R16 || rType == TextureType.R9
|
||||
@@ -124,10 +119,7 @@ public class SubmapManagerCombinedCTM extends SubmapManagerBase {
|
||||
this.texturePath = texturePath;
|
||||
this.size = Integer.parseInt(
|
||||
rType.name()
|
||||
.substring(
|
||||
1,
|
||||
rType.name()
|
||||
.length())); // >.>
|
||||
.substring(1)); // >.>
|
||||
this.rType = rType;
|
||||
}
|
||||
|
||||
@@ -139,12 +131,7 @@ public class SubmapManagerCombinedCTM extends SubmapManagerBase {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
|
||||
initStatics();
|
||||
RenderBlocksCombinedCTM rb = renderBlocksThreadLocal.get();
|
||||
if (rb == null) {
|
||||
rb = new RenderBlocksCombinedCTM();
|
||||
renderBlocksThreadLocal.set(rb);
|
||||
}
|
||||
rb.setRenderBoundsFromBlock(block);
|
||||
return rb;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.ISubmapManager;
|
||||
@@ -15,19 +16,13 @@ import team.chisel.ctmlib.TextureSubmap;
|
||||
|
||||
public class SubmapManagerSlab implements ISubmapManager {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCTM> renderBlocksThreadLocal;
|
||||
|
||||
private static void initStatics() {
|
||||
if (renderBlocksThreadLocal == null) {
|
||||
renderBlocksThreadLocal = ThreadLocal.withInitial(RenderBlocksCTM::new);
|
||||
}
|
||||
}
|
||||
private static final ThreadLocal<RenderBlocksCTM> renderBlocksThreadLocal = FMLLaunchHandler.side()
|
||||
.isClient() ? ThreadLocal.withInitial(RenderBlocksCTM::new) : null;
|
||||
|
||||
private TextureSubmap submap;
|
||||
private TextureSubmap submapSmall;
|
||||
private IIcon sideTexture;
|
||||
private String texture;
|
||||
private final String texture;
|
||||
|
||||
public SubmapManagerSlab(String texture) {
|
||||
this.texture = texture;
|
||||
@@ -55,7 +50,6 @@ public class SubmapManagerSlab implements ISubmapManager {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
|
||||
initStatics();
|
||||
RenderBlocksCTM rb = renderBlocksThreadLocal.get();
|
||||
rb.setRenderBoundsFromBlock(block);
|
||||
rb.submap = submap;
|
||||
@@ -63,25 +57,11 @@ public class SubmapManagerSlab implements ISubmapManager {
|
||||
return rb;
|
||||
}
|
||||
|
||||
private boolean hadOverride = false;
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void preRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side) {}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void preRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
RenderBlocksCTM rbctm = (RenderBlocksCTM) renderer;
|
||||
if (side.ordinal() < 2 && !rbctm.rendererOld.hasOverrideBlockTexture()) {
|
||||
rbctm.rendererOld.setOverrideBlockTexture(sideTexture);
|
||||
hadOverride = false;
|
||||
} else {
|
||||
hadOverride = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void postRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
if (!hadOverride) {
|
||||
((RenderBlocksCTM) renderer).rendererOld.clearOverrideBlockTexture();
|
||||
}
|
||||
}
|
||||
public void postRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side) {}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
@@ -48,17 +49,11 @@ public class SubmapManagerSpecialMaterial extends SubmapManagerBase {
|
||||
}
|
||||
};
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCTMFullbright> renderBlocksThreadLocal;
|
||||
private static final ThreadLocal<RenderBlocksCTMFullbright> renderBlocksThreadLocal = FMLLaunchHandler.side()
|
||||
.isClient() ? ThreadLocal.withInitial(RenderBlocksCTMFullbright::new) : null;
|
||||
|
||||
private static void initStatics() {
|
||||
if (renderBlocksThreadLocal == null) {
|
||||
renderBlocksThreadLocal = ThreadLocal.withInitial(RenderBlocksCTMFullbright::new);
|
||||
}
|
||||
}
|
||||
|
||||
private String color;
|
||||
private MaterialType materialType;
|
||||
private final String color;
|
||||
private final MaterialType materialType;
|
||||
private TextureSubmap submap, submapSmall;
|
||||
|
||||
public SubmapManagerSpecialMaterial(String color, MaterialType materialType) {
|
||||
@@ -83,7 +78,6 @@ public class SubmapManagerSpecialMaterial extends SubmapManagerBase {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
|
||||
initStatics();
|
||||
RenderBlocksCTMFullbright renderBlocksFullbright = renderBlocksThreadLocal.get();
|
||||
renderBlocksFullbright.setRenderBoundsFromBlock(block);
|
||||
renderBlocksFullbright.submap = submap;
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import com.cricketcraft.chisel.api.carving.CarvingUtils;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.ISubmapManager;
|
||||
@@ -88,8 +89,8 @@ public class SubmapManagerVoidstone extends SubmapManagerBase {
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksVoidstone> renderBlocksThreadLocal;
|
||||
private static final ThreadLocal<RenderBlocksVoidstone> renderBlocksThreadLocal = FMLLaunchHandler.side()
|
||||
.isClient() ? ThreadLocal.withInitial(RenderBlocksVoidstone::new) : null;
|
||||
|
||||
private ISubmapManager overlay;
|
||||
private static TextureSubmap base;
|
||||
@@ -123,10 +124,6 @@ public class SubmapManagerVoidstone extends SubmapManagerBase {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
|
||||
if (renderBlocksThreadLocal == null) {
|
||||
renderBlocksThreadLocal = ThreadLocal.withInitial(RenderBlocksVoidstone::new);
|
||||
}
|
||||
|
||||
RenderBlocksVoidstone rb = renderBlocksThreadLocal.get();
|
||||
RenderBlocks ctx = overlay.createRenderContext(rendererOld, block, world);
|
||||
rb.setRenderBoundsFromBlock(block);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RenderCarvableBeacon extends TileEntityBeaconRenderer implements IS
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation("textures/entity/beacon_beam.png");
|
||||
|
||||
private int renderId;
|
||||
private final int renderId;
|
||||
|
||||
public RenderCarvableBeacon() {
|
||||
this.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
|
||||
@@ -2,6 +2,7 @@ package team.chisel.ctmlib;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
@@ -27,29 +28,38 @@ public class CTMRenderer implements ISimpleBlockRenderingHandler {
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
RenderBlocks rb = getContext(
|
||||
renderer,
|
||||
block,
|
||||
Minecraft.getMinecraft().theWorld,
|
||||
((ICTMBlock<?>) block).getManager(metadata),
|
||||
metadata);
|
||||
Drawing.drawBlock(block, metadata, rb);
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
rb.unlockBlockBounds();
|
||||
final WorldClient world = Minecraft.getMinecraft().theWorld;
|
||||
final RenderBlocks rb = getContext(renderer, block, world, ((ICTMBlock<?>) block).getManager(metadata));
|
||||
boolean clean = false;
|
||||
if (rb.blockAccess == null) {
|
||||
rb.blockAccess = world;
|
||||
clean = true;
|
||||
}
|
||||
try {
|
||||
Drawing.drawBlock(block, metadata, rb);
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
rb.unlockBlockBounds();
|
||||
} finally {
|
||||
if (clean) rb.blockAccess = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
RenderBlocks rendererOld) {
|
||||
RenderBlocks renderer) {
|
||||
final int meta = world.getBlockMetadata(x, y, z);
|
||||
final RenderBlocks rb = getContext(
|
||||
renderer,
|
||||
block,
|
||||
world,
|
||||
((ICTMBlock<?>) block).getManager(world, x, y, z, meta));
|
||||
boolean clean = false;
|
||||
if (rb.blockAccess == null) {
|
||||
rb.blockAccess = world;
|
||||
clean = true;
|
||||
}
|
||||
try {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
RenderBlocks rb = getContext(
|
||||
rendererOld,
|
||||
block,
|
||||
world,
|
||||
((ICTMBlock<?>) block).getManager(world, x, y, z, meta),
|
||||
meta);
|
||||
rb.renderAllFaces = rendererOld.renderAllFaces;
|
||||
rb.renderAllFaces = renderer.renderAllFaces;
|
||||
boolean ret = rb.renderStandardBlock(block, x, y, z);
|
||||
rb.unlockBlockBounds();
|
||||
rb.renderAllFaces = false;
|
||||
@@ -60,15 +70,15 @@ public class CTMRenderer implements ISimpleBlockRenderingHandler {
|
||||
crashreportcategory.addCrashSection("Block name", GameRegistry.findUniqueIdentifierFor(block));
|
||||
crashreportcategory.addCrashSection("Block metadata", world.getBlockMetadata(x, y, z));
|
||||
throw new ReportedException(crashreport);
|
||||
} finally {
|
||||
if (clean) rb.blockAccess = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected RenderBlocks getContext(RenderBlocks rendererOld, Block block, IBlockAccess world, ISubmapManager manager,
|
||||
int meta) {
|
||||
private RenderBlocks getContext(RenderBlocks rendererOld, Block block, IBlockAccess world, ISubmapManager manager) {
|
||||
if (!rendererOld.hasOverrideBlockTexture() && manager != null) {
|
||||
RenderBlocks rb = manager.createRenderContext(rendererOld, block, world);
|
||||
if (rb != null && rb != rendererOld) {
|
||||
rb.blockAccess = world;
|
||||
if (rendererOld.lockBlockBounds) {
|
||||
rb.overrideBlockBounds(
|
||||
rendererOld.renderMinX,
|
||||
@@ -78,10 +88,8 @@ public class CTMRenderer implements ISimpleBlockRenderingHandler {
|
||||
rendererOld.renderMaxY,
|
||||
rendererOld.renderMaxZ);
|
||||
}
|
||||
if (rb instanceof RenderBlocksCTM) {
|
||||
RenderBlocksCTM rbctm = (RenderBlocksCTM) rb;
|
||||
if (rb instanceof RenderBlocksCTM rbctm) {
|
||||
rbctm.manager = rbctm.manager == null ? manager : rbctm.manager;
|
||||
rbctm.rendererOld = rbctm.rendererOld == null ? rendererOld : rbctm.rendererOld;
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
|
||||
@@ -102,16 +102,14 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
XZ_HALF_Y(0.5, 1, 0.5);
|
||||
// @formatter:on
|
||||
|
||||
private double x, y, z;
|
||||
private final double x, y, z;
|
||||
|
||||
private Vert(double x, double y, double z) {
|
||||
Vert(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static double u, v, xDiff, yDiff, zDiff, uDiff, vDiff;
|
||||
|
||||
void render(RenderBlocksCTM inst, ForgeDirection normal, int cacheID) {
|
||||
final Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
@@ -120,12 +118,15 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
tessellator.setBrightness(inst.lightingCache[cacheID]);
|
||||
}
|
||||
|
||||
u = cacheID == 1 || cacheID == 2 ? inst.maxU : inst.minU;
|
||||
v = cacheID < 2 ? inst.maxV : inst.minV;
|
||||
double u = cacheID == 1 || cacheID == 2 ? inst.maxU : inst.minU;
|
||||
double v = cacheID < 2 ? inst.maxV : inst.minV;
|
||||
|
||||
uDiff = inst.maxU - inst.minU;
|
||||
vDiff = inst.maxV - inst.minV;
|
||||
double uDiff = inst.maxU - inst.minU;
|
||||
double vDiff = inst.maxV - inst.minV;
|
||||
|
||||
double xDiff;
|
||||
double yDiff;
|
||||
double zDiff;
|
||||
if (inst.renderMinX + inst.renderMinY + inst.renderMinZ != 0
|
||||
|| inst.renderMaxX + inst.renderMaxY + inst.renderMaxZ != 3) {
|
||||
boolean uMin = u == inst.minU;
|
||||
@@ -178,8 +179,8 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
YNEG_LB(ZERO, X_HALF, XZ_HALF, Z_HALF), YNEG_RB(X_HALF, X, Z_HALF_X, XZ_HALF), YNEG_RT(XZ_HALF, Z_HALF_X, XZ, X_HALF_Z), YNEG_LT(Z_HALF, XZ_HALF, X_HALF_Z, Z),
|
||||
YPOS_LB(YZ, X_HALF_YZ, XZ_HALF_Y, Z_HALF_Y), YPOS_RB(X_HALF_YZ, XYZ, Z_HALF_XY, XZ_HALF_Y), YPOS_RT(XZ_HALF_Y, Z_HALF_XY, XY, X_HALF_Y), YPOS_LT(Z_HALF_Y, XZ_HALF_Y, X_HALF_Y, Y);
|
||||
// @formatter:on
|
||||
private Vert xmin, xmax, ymin, ymax;
|
||||
private ForgeDirection normal;
|
||||
private final Vert xmin, xmax, ymin, ymax;
|
||||
private final ForgeDirection normal;
|
||||
|
||||
SubSide(Vert xmin, Vert ymin, Vert ymax, Vert xmax) {
|
||||
this.xmin = xmin;
|
||||
@@ -234,7 +235,6 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
protected float[] bluCache = new float[4];
|
||||
public TextureSubmap submap;
|
||||
public TextureSubmap submapSmall;
|
||||
public RenderBlocks rendererOld;
|
||||
public ISubmapManager manager;
|
||||
|
||||
protected int[][] lightmap = new int[3][3];
|
||||
@@ -257,9 +257,6 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
|
||||
tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
|
||||
tessellator.addTranslation(x, y, z);
|
||||
if (rendererOld != null && rendererOld.hasOverrideBlockTexture()) {
|
||||
setOverrideBlockTexture(rendererOld.overrideBlockTexture);
|
||||
}
|
||||
inWorld = true;
|
||||
boolean res = super.renderStandardBlock(block, x, y, z);
|
||||
inWorld = false;
|
||||
@@ -447,7 +444,7 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
if (!inWorld || submap == null) {
|
||||
super.renderFaceXNeg(block, 0, 0, 0, icon);
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 4);
|
||||
int[] tex = ctm.getSubmapIndices(blockAccess, bx, by, bz, 4);
|
||||
|
||||
fillLightmap(brightnessBottomRight, brightnessTopRight, brightnessTopLeft, brightnessBottomLeft);
|
||||
fillColormap(colorRedBottomRight, colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, redmap);
|
||||
@@ -472,7 +469,7 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
if (!inWorld || submap == null) {
|
||||
super.renderFaceXPos(block, 0, 0, 0, icon);
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 5);
|
||||
int[] tex = ctm.getSubmapIndices(blockAccess, bx, by, bz, 5);
|
||||
|
||||
fillLightmap(brightnessTopLeft, brightnessBottomLeft, brightnessBottomRight, brightnessTopRight);
|
||||
fillColormap(colorRedTopLeft, colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, redmap);
|
||||
@@ -497,7 +494,7 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
if (!inWorld || submap == null) {
|
||||
super.renderFaceZNeg(block, 0, 0, 0, icon);
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 2);
|
||||
int[] tex = ctm.getSubmapIndices(blockAccess, bx, by, bz, 2);
|
||||
|
||||
fillLightmap(brightnessBottomRight, brightnessTopRight, brightnessTopLeft, brightnessBottomLeft);
|
||||
fillColormap(colorRedBottomRight, colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, redmap);
|
||||
@@ -522,7 +519,7 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
if (!inWorld || submap == null) {
|
||||
super.renderFaceZPos(block, 0, 0, 0, icon);
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 3);
|
||||
int[] tex = ctm.getSubmapIndices(blockAccess, bx, by, bz, 3);
|
||||
|
||||
fillLightmap(brightnessBottomLeft, brightnessBottomRight, brightnessTopRight, brightnessTopLeft);
|
||||
fillColormap(colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, colorRedTopLeft, redmap);
|
||||
@@ -547,7 +544,7 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
if (!inWorld || submap == null) {
|
||||
super.renderFaceYNeg(block, 0, 0, 0, icon);
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 0);
|
||||
int[] tex = ctm.getSubmapIndices(blockAccess, bx, by, bz, 0);
|
||||
|
||||
fillLightmap(brightnessBottomLeft, brightnessBottomRight, brightnessTopRight, brightnessTopLeft);
|
||||
fillColormap(colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, colorRedTopLeft, redmap);
|
||||
@@ -572,7 +569,7 @@ public class RenderBlocksCTM extends RenderBlocks {
|
||||
if (!inWorld || submap == null) {
|
||||
super.renderFaceYPos(block, 0, 0, 0, icon);
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 1);
|
||||
int[] tex = ctm.getSubmapIndices(blockAccess, bx, by, bz, 1);
|
||||
|
||||
fillLightmap(brightnessTopRight, brightnessTopLeft, brightnessBottomLeft, brightnessBottomRight);
|
||||
fillColormap(colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, colorRedBottomRight, redmap);
|
||||
|
||||
@@ -16,8 +16,8 @@ public class RenderBlocksColumn extends RenderBlocks {
|
||||
public IIcon iconTop;
|
||||
private boolean inWorld;
|
||||
|
||||
private IIcon sides[] = new IIcon[6];
|
||||
private CTM ctm = CTM.getInstance();
|
||||
private final IIcon[] sides = new IIcon[6];
|
||||
private final CTM ctm = CTM.getInstance();
|
||||
|
||||
public RenderBlocksColumn() {
|
||||
super();
|
||||
|
||||
@@ -11,14 +11,12 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingGroup;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.chisel.api.carving.IChiselMode;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.google.common.collect.Queues;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@@ -33,11 +31,10 @@ public final class ChiselController {
|
||||
|
||||
protected static class GuiOpen implements Runnable {
|
||||
|
||||
private EntityPlayer player;
|
||||
private ItemStack stack;
|
||||
private final EntityPlayer player;
|
||||
private final ItemStack stack;
|
||||
|
||||
public GuiOpen(EntityPlayer player, ItemStack stack) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.stack = stack;
|
||||
}
|
||||
@@ -55,7 +52,7 @@ public final class ChiselController {
|
||||
|
||||
public static final ChiselController INSTANCE = new ChiselController();
|
||||
|
||||
Queue<GuiOpen> openQueue = Queues.newArrayDeque();
|
||||
final Queue<GuiOpen> openQueue = Queues.newArrayDeque();
|
||||
|
||||
private ChiselController() {}
|
||||
|
||||
@@ -163,11 +160,4 @@ public final class ChiselController {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldUnload(WorldEvent.Unload event) {
|
||||
if (event.world.isRemote) {
|
||||
TextureType.clearStatics();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user