Skip to content

Commit

Permalink
fix discoloration while breaking blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
octarine-noise committed Sep 11, 2015
1 parent d496926 commit 284ffed
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 38 deletions.
Expand Up @@ -14,8 +14,8 @@
import mods.betterfoliage.client.render.impl.EntityFXRisingSoul;
import mods.betterfoliage.client.render.impl.RenderBlockCactus;
import mods.betterfoliage.client.render.impl.RenderBlockDirtWithAlgae;
import mods.betterfoliage.client.render.impl.RenderBlockDirtWithGrassSide;
import mods.betterfoliage.client.render.impl.RenderBlockDirtWithGrassTop;
import mods.betterfoliage.client.render.impl.RenderBlockDirtWithLogTop;
import mods.betterfoliage.client.render.impl.RenderBlockGrass;
import mods.betterfoliage.client.render.impl.RenderBlockLeaves;
import mods.betterfoliage.client.render.impl.RenderBlockLilypad;
Expand Down Expand Up @@ -76,8 +76,8 @@ public static void postInit() {
registerRenderer(new RenderBlockReed());
registerRenderer(new RenderBlockDirtWithAlgae());
registerRenderer(new RenderBlockSandWithCoral());
registerRenderer(new RenderBlockDirtWithGrassSide());
registerRenderer(new RenderBlockDirtWithGrassTop());
registerRenderer(new RenderBlockDirtWithLogTop());
registerRenderer(new RenderBlockLogs());

MinecraftForge.EVENT_BUS.register(wind);
Expand Down
Expand Up @@ -200,12 +200,23 @@ public int getRenderId() {
return 0;
}

protected void renderWorldBlockBase(int pass, IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
/** Render a block normally, and extract AO data
* @param pass extract data from rendering pass with this index
* @param world the World
* @param x x coord
* @param y y coord
* @param z z coord
* @param block the block
* @param modelId render ID of block
* @param renderer the renderer to use
* @return true if rendering block breaking overlay
*/
protected boolean renderWorldBlockBase(int pass, IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
// use original renderer for block breaking overlay
if (renderer.hasOverrideBlockTexture()) {
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlock(block, x, y, z);
return;
return true;
}

// render block
Expand All @@ -219,6 +230,7 @@ protected void renderWorldBlockBase(int pass, IBlockAccess world, int x, int y,
} else {
renderStandardBlock(block, x, y, z);
}
return false;
}

protected void renderStandardBlockAsItem(RenderBlocks renderer, Block p_147800_1_, int p_147800_2_, float p_147800_3_) {
Expand Down
Expand Up @@ -6,43 +6,39 @@
import mods.betterfoliage.client.util.RenderUtils;
import mods.betterfoliage.common.config.Config;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/** Accepts dirt blocks with wooden log on top if rounded log grass is enabled.<br/>
* Renders the dirt block with a grass top texture.
/** Accepts dirt blocks with grass on top if aggressive connected grass is enabled.<br/>
* Renders the grass block in place of dirt.
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public class RenderBlockDirtWithGrassTop extends RenderBlockAOBase implements IRenderBlockDecorator {

public static final ForgeDirection[] sides = {ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST};

public RenderBlockDirtWithGrassTop() {
skipFaces = true;
}

@Override
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return Config.logsEnabled && Config.logsConnectGrass &&
Material top2Material = blockAccess.getBlock(x, y + 2, z).getMaterial();
return Config.ctxGrassAggressiveEnabled &&
top2Material != Material.snow &&
top2Material != Material.craftedSnow &&
Config.dirt.matchesID(block) &&
Config.logs.matchesID(blockAccess.getBlock(x, y + 1, z));
Config.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
ForgeDirection offset = ForgeDirection.UNKNOWN;

// try to find grass block in neighborhood
for(ForgeDirection dir : sides) if (Config.grass.matchesID(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ))) offset = dir;

// render offset block at render location
// fake grass block @(0, +1, 0) at render location
IBlockAccess originalBA = renderer.blockAccess;
renderer.blockAccess = new OffsetBlockAccess(world, x, y, z, offset.offsetX, offset.offsetY, offset.offsetZ);
renderer.blockAccess = new OffsetBlockAccess(world, x, y, z, 0, 1, 0);

Block renderBlock = renderer.blockAccess.getBlock(x, y, z);
boolean result;
Expand Down
Expand Up @@ -6,39 +6,43 @@
import mods.betterfoliage.client.util.RenderUtils;
import mods.betterfoliage.common.config.Config;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/** Accepts dirt blocks with grass on top if aggressive connected grass is enabled.<br/>
* Renders the grass block in place of dirt.
/** Accepts dirt blocks with wooden log on top if rounded log grass is enabled.<br/>
* Renders the dirt block with a grass top texture.
* @author octarine-noise
*/
@SideOnly(Side.CLIENT)
public class RenderBlockDirtWithGrassSide extends RenderBlockAOBase implements IRenderBlockDecorator {
public class RenderBlockDirtWithLogTop extends RenderBlockAOBase implements IRenderBlockDecorator {

public RenderBlockDirtWithGrassSide() {
public static final ForgeDirection[] sides = {ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST};

public RenderBlockDirtWithLogTop() {
skipFaces = true;
}

@Override
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
Material top2Material = blockAccess.getBlock(x, y + 2, z).getMaterial();
return Config.ctxGrassAggressiveEnabled &&
top2Material != Material.snow &&
top2Material != Material.craftedSnow &&
return Config.logsEnabled && Config.logsConnectGrass &&
Config.dirt.matchesID(block) &&
Config.grass.matchesID(blockAccess.getBlock(x, y + 1, z));
Config.logs.matchesID(blockAccess.getBlock(x, y + 1, z));
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
// fake grass block @(0, +1, 0) at render location
ForgeDirection offset = ForgeDirection.UNKNOWN;

// try to find grass block in neighborhood
for(ForgeDirection dir : sides) if (Config.grass.matchesID(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ))) offset = dir;

// render offset block at render location
IBlockAccess originalBA = renderer.blockAccess;
renderer.blockAccess = new OffsetBlockAccess(world, x, y, z, 0, 1, 0);
renderer.blockAccess = new OffsetBlockAccess(world, x, y, z, offset.offsetX, offset.offsetY, offset.offsetZ);

Block renderBlock = renderer.blockAccess.getBlock(x, y, z);
boolean result;
Expand Down
Expand Up @@ -63,7 +63,7 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b
Integer avgColor = BetterFoliageClient.grassTextures.iconColors.get(grassTopIcon);
boolean useTextureColor = (avgColor != null);

renderWorldBlockBase(2, world, x, y, z, block, modelId, renderer);
if (renderWorldBlockBase(2, world, x, y, z, block, modelId, renderer)) return true;

boolean isAirTop = blockAccess.isAirBlock(x, y + 1, z);
int distance = getCameraDistance(x, y, z);
Expand Down
Expand Up @@ -36,7 +36,7 @@ public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Bl

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
blockAccess = world;
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
if (renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer)) return true;

// find generated texture to render with, assume the
// "true" texture of the block is the one on the north size
Expand Down
Expand Up @@ -39,8 +39,7 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b
}

// get AO data, bail if rendering block breaking
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
if (renderer.hasOverrideBlockTexture()) return true;
if (renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer)) return true;

// set axes
Double3 blockPos = new Double3(x, y, z);
Expand Down
Expand Up @@ -34,7 +34,7 @@ public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Bl

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
blockAccess = world;
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
if (renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer)) return true;

int iconVariation = getSemiRandomFromPos(x, y, z, 0);
IIcon renderIcon = myceliumIcons.get(iconVariation);
Expand Down
Expand Up @@ -34,7 +34,7 @@ public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Bl

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
blockAccess = world;
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
if (renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer)) return true;

int iconVariation = getSemiRandomFromPos(x, y, z, 0);
IIcon renderIcon = netherrackVineIcons.get(iconVariation);
Expand Down
Expand Up @@ -44,7 +44,7 @@ public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Bl

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
blockAccess = world;
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
if (renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer)) return true;

int iconVariation = getSemiRandomFromPos(x, y, z, 0);
int heightVariation = getSemiRandomFromPos(x, y, z, 1);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Bl

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
blockAccess = world;
renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer);
if (renderWorldBlockBase(1, world, x, y, z, block, modelId, renderer)) return true;

Double3 blockCenter = new Double3(x + 0.5, y + 0.5, z + 0.5);
double offset = pRand[getSemiRandomFromPos(x, y, z, 6)] * Config.coralVOffset;
Expand Down

0 comments on commit 284ffed

Please sign in to comment.