Try to prevent render errors from non-solid painted blocks

This commit is contained in:
HenryLoenwind committed 2016-01-21 22:46:54 +01:00
1 parent ff423ae92a
commit cf8a55d3d3
2 files changed
+34 -52

No files matched your search

@@ -1,48 +0,0 @@
package crazypants.enderio.machine.painter;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
public class BlockPaintedGlowstoneRenderer implements ISimpleBlockRenderingHandler {
@Override
public int getRenderId() {
return BlockPaintedGlowstone.renderId;
}
@Override
public void renderInventoryBlock(Block arg0, int arg1, int arg2, RenderBlocks arg3) {
}
@Override
public boolean renderWorldBlock(IBlockAccess ba, int x, int y, int z, Block block, int arg5, RenderBlocks rb) {
BlockPaintedGlowstone paintedGlowstone = (BlockPaintedGlowstone) block;
TileEntity tile = ba.getTileEntity(x, y, z);
if(!(tile instanceof TileEntityPaintedBlock)) {
return false;
}
TileEntityPaintedBlock te = (TileEntityPaintedBlock) tile;
Block srcBlk = te.getSourceBlock();
if(srcBlk == null) {
srcBlk = Blocks.glowstone;
}
IBlockAccess origBa = rb.blockAccess;
rb.blockAccess = new PaintedBlockAccessWrapper(origBa);
rb.renderBlockByRenderType(srcBlk, x, y, z);
rb.blockAccess = origBa;
return true;
}
@Override
public boolean shouldRender3DInInventory(int arg0) {
return true;
}
}
@@ -6,9 +6,11 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import com.enderio.core.client.render.CubeRenderer;
import com.enderio.core.client.render.IconUtil;
import com.enderio.core.common.util.BlockCoord;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
@@ -50,11 +52,21 @@ public class PaintedBlockRenderer implements ISimpleBlockRenderingHandler {
IBlockAccess origBa = rb.blockAccess;
try {
rb.blockAccess = new PaintedBlockAccessWrapper(origBa);
if(srcBlk == block) {
rb.renderStandardBlock(srcBlk, x, y, z);
if (block.isOpaqueCube() && nonSolidPaintedBlockAround(new BlockCoord(x, y, z), origBa, rb.blockAccess)) {
if (srcBlk == block) {
rb.setRenderAllFaces(true);
rb.renderStandardBlock(srcBlk, x, y, z);
rb.setRenderAllFaces(false);
} else {
rb.renderBlockAllFaces(srcBlk, x, y, z);
}
} else {
rb.renderBlockByRenderType(srcBlk, x, y, z);
}
if (srcBlk == block) {
rb.renderStandardBlock(srcBlk, x, y, z);
} else {
rb.renderBlockByRenderType(srcBlk, x, y, z);
}
}
} catch (Exception e) {
//just in case the paint source wont render safely in this way
rb.setOverrideBlockTexture(IconUtil.errorTexture);
@@ -67,6 +79,24 @@ public class PaintedBlockRenderer implements ISimpleBlockRenderingHandler {
return true;
}
/*
* If a non-solid block is painted with a solid block, the renderer would
* think it didn't need to render faces of adjacent blocks that touch it
* because it only sees the paint.
*
* This detects this case, so the renderer can be told to just render all
* faces, even if it thinks it could save some quads.
*/
private boolean nonSolidPaintedBlockAround(BlockCoord bc, IBlockAccess reality, IBlockAccess fake) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
BlockCoord toTest = bc.getLocation(dir);
if (toTest.y >= 0 && toTest.y <= 255 && toTest.getBlock(reality).isOpaqueCube() != toTest.getBlock(fake).isOpaqueCube()) {
return true;
}
}
return false;
}
@Override
public boolean shouldRender3DInInventory(int arg0) {
return false;