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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello. I'm using IntelliJ IDEA and making a mod for Forge 1.20.1 and I'm trying to make a GUI. I found that the Minecraft-related codes are all obfuscated and when setting up the workspace, Gradle did not execute Deobfuscation tasks like createMcpToSrg. Is this normal or a bug? Can anyone help me with this?
    • Hello! I'm trying to get a list of all entries registered in the infusion upgrade registry. Code can be found in github: https://github.com/ChamoisEST/MiningMadness/tree/1.20.1 Registry in common/registries/MMRegistries.java Event that calls the registry is in MiningMadness.java List of registered entries should be called in common/capabilities/infusion/InfusionCapabilityImplementation.java:getActiveInfusions() in the for loop. Is there any way to accomplish that? Thanks in advance!  
    • So, I am trying to create and add tags to my custom damage type, but looks like I made something wrong, since it crashing with error that "cannot register" damage type. Im trying to register it, and in datagen add tags, but it everytime crashing due to not register "grimtales:entropy". Full code there - https://github.com/undertakerJ/Grim-Tales-Forge ModDamageTypes class public class ModDamageTypes { public static final DeferredRegister<DamageType> DAMAGE_TYPES = DeferredRegister.create(Registries.DAMAGE_TYPE, GrimTales.MOD_ID); public static final ResourceKey<DamageType> ENTROPY_KEY = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(GrimTales.MOD_ID, "entropy")); public static final RegistryObject<DamageType> ENTROPY = DAMAGE_TYPES.register( "entropy", () -> new DamageType("entropy_effect", DamageScaling.ALWAYS, 1f, DamageEffects.HURT)); // // public static final DamageSource ENTROPY_SOURCE = new DamageSource(Holder.direct(ENTROPY.get())); public static void register(IEventBus eventBus) { DAMAGE_TYPES.register(eventBus); } } Datagen for damageTags public class ModDamageTagsProvider extends DamageTypeTagsProvider { public ModDamageTagsProvider( PackOutput p_270719_, CompletableFuture<HolderLookup.Provider> p_270256_, @Nullable ExistingFileHelper existingFileHelper) { super(p_270719_, p_270256_, GrimTales.MOD_ID, existingFileHelper); } @Override protected void addTags(HolderLookup.Provider pProvider) { this.tag(DamageTypeTags.BYPASSES_INVULNERABILITY).add(ModDamageTypes.ENTROPY_KEY); } } Datagen class it self   @Mod.EventBusSubscriber(modid = GrimTales.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class DataGenerators { @SubscribeEvent public static void gatherData(GatherDataEvent event){ DataGenerator generator = event.getGenerator(); PackOutput packOutput = generator.getPackOutput(); ExistingFileHelper helper = event.getExistingFileHelper(); CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider(); generator.addProvider(event.includeServer(), new ModDamageTagsProvider(packOutput, lookupProvider, helper)); } } And register class in main class public GrimTales() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); ModDamageTypes.register(modEventBus); modEventBus.addListener(this::commonSetup); MinecraftForge.EVENT_BUS.register(this); modEventBus.addListener(this::addCreative); }  
    • Looking for a semi-vanilla Minecraft server? Maybe one with keep inventory and land claims? I have one for you! Let me introduce you to Safe Survival! Come on and join us at mc.safesurvival.net. It is bedrock supported too!
    • Hi. I'm trying to play RLCraft with Optifine but my game keeps crashing on startup with Exit Code 1. The modpack was working fine yesterday, not sure what changed to make it not wanna work anymore. I was hoping someone here could help me figure out what's going wrong. If I remove Optifine, nothing changes, I still get the same errors. Thanks in advance. Crash Report (I only included the errors+fatal, I’m not sure if more is needed, please let me know): https://pastebin.ai/66ivknz0f4  
  • Topics

×
×
  • Create New...

Important Information

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