From cf8a55d3d3bc7c98537cf05a8e7bef730dd3004b Mon Sep 17 00:00:00 2001 From: HenryLoenwind Date: Thu, 21 Jan 2016 22:46:54 +0100 Subject: [PATCH] Try to prevent render errors from non-solid painted blocks --- .../BlockPaintedGlowstoneRenderer.java | 48 ------------------- .../machine/painter/PaintedBlockRenderer.java | 38 +++++++++++++-- 2 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstoneRenderer.java diff --git a/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstoneRenderer.java b/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstoneRenderer.java deleted file mode 100644 index e9063e85..00000000 --- a/src/main/java/crazypants/enderio/machine/painter/BlockPaintedGlowstoneRenderer.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/crazypants/enderio/machine/painter/PaintedBlockRenderer.java b/src/main/java/crazypants/enderio/machine/painter/PaintedBlockRenderer.java index ac7b934f..fdfb1afd 100644 --- a/src/main/java/crazypants/enderio/machine/painter/PaintedBlockRenderer.java +++ b/src/main/java/crazypants/enderio/machine/painter/PaintedBlockRenderer.java @@ -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;