Jump to content

[1.6.4] New grass block rendering completely in biome color.


Jodelahithit

Recommended Posts

Hello,

 

 

[glow=red,2,300]I'm fairly new to minecraft modding but i know java well enough to start with it[/glow]

 

I've been trying to make a new grass block with forge for a while now, i've tried multiple ways but everything seems to give problems.

What i've done now is just copy the BlockGrass.java from minecraft and set that as my Blockgrass.java

It seems to be working but i get this problem:

 

width=800 height=435http://i1287.photobucket.com/albums/a621/jodelahithit1/Grass_zpsf5e9d6d3.png[/img]

 

As you can see the biome colors are also rendered on the sides and bottom and the overlay is only visible when there is snow on top of the block.

 

Here's my code so far for the Blockgrass:

 

Main.java

I left all my other blocks and items out to make it less messy!

package jodelahithit.mods.rs;

import jodelahithit.mods.rs.block.Blockdirt;
import jodelahithit.mods.rs.block.Blockgrass;
import jodelahithit.mods.rs.block.Blockground;
import jodelahithit.mods.rs.block.Blockstone;
import jodelahithit.mods.rs.block.Blockwood;
import jodelahithit.mods.rs.block.Blockwool;
import jodelahithit.mods.rs.item.Logo;
import jodelahithit.mods.rs.misc.SRSCreativeTab;
import jodelahithit.mods.rs.registry.Blockground_registry;
import jodelahithit.mods.rs.registry.Blockstone_registry;
import jodelahithit.mods.rs.registry.Blockwood_registry;
import jodelahithit.mods.rs.registry.Blockwool_registry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = SRS.modid, name = "SteadycraftRS", version = "0.1")
public class SRS {

public static jodelahithit.mods.rs.block.Blockgrass Blockgrass;

@EventHandler
public void load(FMLInitializationEvent E) {

	Blockgrass = (Blockgrass) new Blockgrass(1001).setUnlocalizedName("SRS_blockgrass");

	RB(Blockgrass, "Grass");

}
public void RB(Block block, String name) {
	GameRegistry.registerBlock(block, block.getUnlocalizedName());
	LanguageRegistry.addName(block, name);
}
}

 

Blockgrass.java

package jodelahithit.mods.rs.block;

import java.util.Random;

import jodelahithit.mods.rs.SRS;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.util.Icon;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class Blockgrass extends Block {

    @SideOnly(Side.CLIENT)
    private Icon iconGrassTop;
    @SideOnly(Side.CLIENT)
    private Icon iconSnowSide;
    @SideOnly(Side.CLIENT)
    private Icon iconGrassSideOverlay;
    

    public Blockgrass(int par1)
    {
        super(par1, Material.grass);
        this.setTickRandomly(true);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }

    @SideOnly(Side.CLIENT)

    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public Icon getIcon(int par1, int par2)
    {
        return par1 == 1 ? this.iconGrassTop : (par1 == 0 ? SRS.Blockdirt.getBlockTextureFromSide(par1) : this.blockIcon);
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (!par1World.isRemote)
        {
            if (par1World.getBlockLightValue(par2, par3 + 1, par4) < 4 && par1World.getBlockLightOpacity(par2, par3 + 1, par4) > 2)
            {
                par1World.setBlock(par2, par3, par4, SRS.Blockgrass.blockID);
            }
            else if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9)
            {
                for (int l = 0; l < 4; ++l)
                {
                    int i1 = par2 + par5Random.nextInt(3) - 1;
                    int j1 = par3 + par5Random.nextInt(5) - 3;
                    int k1 = par4 + par5Random.nextInt(3) - 1;
                    int l1 = par1World.getBlockId(i1, j1 + 1, k1);

                    if (par1World.getBlockId(i1, j1, k1) == SRS.Blockdirt.blockID && par1World.getBlockLightValue(i1, j1 + 1, k1) >= 4 && par1World.getBlockLightOpacity(i1, j1 + 1, k1) <= 2)
                    {
                        par1World.setBlock(i1, j1, k1, SRS.Blockgrass.blockID);
                    }
                }
            }
        }
    }

    /**
     * Returns the ID of the items to drop on destruction.
     */
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Block.dirt.idDropped(0, par2Random, par3);
    }

    @SideOnly(Side.CLIENT)

    /**
     * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side
     */
    public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        if (par5 == 1)
        {
            return this.iconGrassTop;
        }
        else if (par5 == 0)
        {
            return this.blockIcon;
        }
        else
        {
            Material material = par1IBlockAccess.getBlockMaterial(par2, par3 + 1, par4);
            return material != Material.snow && material != Material.craftedSnow ? this.blockIcon : this.iconSnowSide;
        }
    }

    @SideOnly(Side.CLIENT)

    /**
     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
     * is the only chance you get to register icons.
     */
    public void registerIcons(IconRegister par1IconRegister)
    {

	this.blockIcon = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_side");
	this.iconGrassTop = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_top");
	this.iconGrassSideOverlay = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_side_overlay");
	this.iconSnowSide = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_side_snowed");

    }
    

    @SideOnly(Side.CLIENT)
    public int getBlockColor()
    {
        double d0 = 0.5D;
        double d1 = 1.0D;
        return ColorizerGrass.getGrassColor(d0, d1);
    }

    @SideOnly(Side.CLIENT)

    /**
     * Returns the color this block should be rendered. Used by leaves.
     */
    public int getRenderColor(int par1)
    {
        return this.getBlockColor();
    }

    @SideOnly(Side.CLIENT)

    /**
     * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
     * when first determining what to render.
     */
    public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        int l = 0;
        int i1 = 0;
        int j1 = 0;

        for (int k1 = -1; k1 <= 1; ++k1)
        {
            for (int l1 = -1; l1 <= 1; ++l1)
            {
                int i2 = par1IBlockAccess.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeGrassColor();
                l += (i2 & 16711680) >> 16;
                i1 += (i2 & 65280) >> 8;
                j1 += i2 & 255;
            }
        }

        return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
    }
    
    @SideOnly(Side.CLIENT)
    public static Icon getIconSideOverlay()
    {
        return SRS.Blockgrass.iconGrassSideOverlay;
    } 
}

 

If i forgot anything in this post please tell me.

Any help with this problem would be really appreciated!

 

 

 

Link to comment
Share on other sites

The grass block is a special render block which you can look up how it's done in RenderBlocks.java In the vanilla it is hardcoded to check to see if you change the grass block ie: the dirt block under it. You need to do a custom render for it.  It's not too hard if you are familiar with doing custom render blocks, if not you are going to have to read up on it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.