Jump to content

Custom Leaves not Working


ctwagon

Recommended Posts

I am trying to make custom leaf blocks but I am having trouble. I copied the code from BlockNewLeaf and tweaked it a little. The problem I am having is that the leaves don't seem to have damage values. I can see two different blocks with my textures in the creative inventory, but instead of having the Id with a slash and the damage value, they both only show the same Id. When they are placed in the world, the two different blocks get the same texture and using the pick block key gives you just that type of block. Another problem I am having is that the blocks allow you to see through the world when placed next to another block.

 

ModLeaves.java

 

 

package com.ctwagon.testmod.blocks;

 

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

 

import com.ctwagon.testmod.Testmod;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;

import net.minecraft.block.BlockLeaves;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.world.ColorizerFoliage;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

 

public class ModLeaves extends BlockLeaves {

public static final String[][] field_150132_N = new String[][] {{"leaves_enchanted", "leaves_cursed"}, {"leaves_enchanted_opaque", "leaves_cursed_opaque"}};

    public static final String[] field_150133_O = new String[] {"enchanted", "cursed"};

   

    public ModLeaves()

    {

        super();

        this.setBlockName(Testmod.MODID + "_leaves");

        this.setTickRandomly(true);

        this.setCreativeTab(CreativeTabs.tabDecorations);

        this.setHardness(0.2F);

        this.setLightOpacity(1);

        this.setStepSound(soundTypeGrass);

    }

 

    protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_)

    {

        if ((p_150124_5_ & 3) == 1 && p_150124_1_.rand.nextInt(p_150124_6_) == 0)

        {

            this.dropBlockAsItem(p_150124_1_, p_150124_2_, p_150124_3_, p_150124_4_, new ItemStack(Items.apple, 1, 0));

        }

    }

 

    /**

    * Determines the damage on the item the block drops. Used in cloth and wood.

    */

    public int damageDropped(int p_149692_1_)

    {

        return super.damageDropped(p_149692_1_) + 4;

    }

 

    /**

    * Get the block's damage value (for use with pick block).

    */

    public int getDamageValue(World p_149643_1_, int p_149643_2_, int p_149643_3_, int p_149643_4_)

    {

        return p_149643_1_.getBlockMetadata(p_149643_2_, p_149643_3_, p_149643_4_) & 3;

    }

 

    /**

    * Gets the block's texture. Args: side, meta

    */

    @SideOnly(Side.CLIENT)

    public IIcon getIcon(int side, int meta)

    {

        return (meta & 3) == 1 ? this.field_150129_M[this.field_150127_b][1] : this.field_150129_M[this.field_150127_b][0];

    }

 

    /**

    * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)

    */

    @SideOnly(Side.CLIENT)

    public void getSubBlocks(Item item, CreativeTabs creativetabs, List list)

    {

        list.add(new ItemStack(item, 1, 0));

        list.add(new ItemStack(item, 1, 1));

    }

 

    @SideOnly(Side.CLIENT)

    public void registerBlockIcons(IIconRegister iconregister)

    {

        for (int i = 0; i < field_150132_N.length; ++i)

        {

            this.field_150129_M = new IIcon[field_150132_N.length];

 

            for (int j = 0; j < field_150132_N.length; ++j)

            {

                this.field_150129_M[j] = iconregister.registerIcon(Testmod.MODID + ":" + field_150132_N[j]);

            }

        }

    }

 

    public String[] func_150125_e()

    {

        return field_150133_O;

    }

}

 

 

Link to comment
Share on other sites

Please

 

1. Do not blindly copy and paste. It is clear you have no idea what you are doing and thus we cannot and will not help you.

2. Learn proper java because once again, if you just copy and paste it is clear you have no idea what you are doing.

3. If you cannot resist, and then I mean that you will die if you don't, copying code blindly at least try to make an effort and change those deobfuscated variablesnames.

Link to comment
Share on other sites

Sorry that I am still relatively new to java. I am still learning as I am making this so there is no reason to be rude. I copied and pasted because it is faster then writing the same code myself. If anyone else is kind enough to help it would be greatly appreciated.

Link to comment
Share on other sites

You need a custom ItemBlock. See https://github.com/Eternaldoom/Realms-of-Chaos/blob/master/com/eternaldoom/realmsofchaos/itemblock/ItemBlockModStoneBrick.java. You can register it with the ItemBlock using GameRegistry.registerBlock(Block, Class<? extends ItemBlock>, String).

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

Sorry that I am still relatively new to java. I am still learning as I am making this so there is no reason to be rude. I copied and pasted because it is faster then writing the same code myself. If anyone else is kind enough to help it would be greatly appreciated.

 

You seem to completely misunderstand me and think I am not helping you with my statements.

Contrary to a lot of opinions have I no problem with people trying to learn OOP through modding.

However, albeit more fun than most, it is far from the easiest way. Pasting blindly means that you have little understand of what the code does.

This is important because, the more you understand what the code does, the more you will be able to write code yourself.

If you keep paste/copying you won't really progress and for every little problem that is easy to fix you will have to run to forums, halting yourself, halting the people there and in the end get totally nowhere but a easy tutorial level problem, if you even get there.

Don't get me wrong, copy/paste is good, but only on the premise that you understand what that function does, why it is there and how it can be used.

e.g. the copy doesn't happen blind anymore.

 

Now, variable names, let me adress those. These are, without a doubt, blind copy paste. Why? Well, who would name them a number?

They are extremely unclear to anyone, yes newbies and pros alike, who looks at them. It is even more paramount for new coders to name their variables properly.

Let me give you an example:

 

   protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_)
    {
        if ((p_150124_5_ & 3) == 1 && p_150124_1_.rand.nextInt(p_150124_6_) == 0)
        {
            this.dropBlockAsItem(p_150124_1_, p_150124_2_, p_150124_3_, p_150124_4_, new ItemStack(Items.apple, 1, 0));
        }
    }

This was grabbed from your supplied code. Please tell me what the variable "p_150124_3_" is used for. I for one can immediately tell that that will most likely be a Y coordinate from a block passed through. Why? Well, minecraft has the habit of having the first few parameters be 'the worldobj, the Xvariable, the Yvariable, the Zvariable. But please tell me what 'p_150124_6_' means. I for one cannot tell and if I wanted to know I would have go look through your extended class and try to find a method that resembles yours. And that in the case this method isn't one you wrote yourself, in which case that would be totally fruitless.

You cannot expect anyone to help you with this and if they do, they're most likely wrong as well.

We cannot understand your code, you cannot understand your code and nobody benefits from using deobfuscated variable names. The only creature that could possibly do so is the cat sleeping on your lap because you will be longer on your computer struggling with the same damn problem.

 

To sum it up, there are three things a person new to coding should never ever do. Use unclear variable names, blind copy paste and learning very bad habits. You violated all three of them. It doesn't matter if you write stupid things, it doesn't matter if you program crashes, you're learning. That's good. But don't do things like that, then you won't learn and in the end you'll give up because you'll find coding too dificult. Which it isn't by the way.

 

And as a last epigraph, you call me rude, which, well I always sound rude so I'm not blaming you, but there are so many new people asking stupid beginner questions that in the end the people that can help them care very little. And if people see stuff like you posted they are even more reluctant to help.

So please do me a favor, clean up your code and do it properly.

 

Now solutions: set isOpaqueCube to false, getRenderType to 0 but render as normal block. That will get rid of the world holes.

And the itemdamage missing is most likely the case because you haven't set a unlocalizedname for each leave. Although really, this is just a guess since I don't want to bother much with your code.

And no you don't need a custom ItemBlock. You're not doing anything fancy and you don't need custom Itemclass for a leaveblock with subtypes.

 

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.