Jump to content

Recommended Posts

Posted

ok next problem, this block should be placeable on itself but is not also sometimes when it grows it auto breaks i think this is linked to the first error, it is a sugar cane esq block

package ashtonsmod.common;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.IPlantable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockIngotBush extends Block implements IPlantable
{
    protected BlockIngotBush(int par1)
    {
        super(par1, Material.plants);
        float f = 0.375F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
        this.setTickRandomly(true);
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (par1World.isAirBlock(par2, par3 + 1, par4))
        {
            int l;

            for (l = 1; par1World.getBlockId(par2, par3 - l, par4) == this.blockID; ++l)
            {
                ;
            }

            if (l < 3)
            {
                int i1 = par1World.getBlockMetadata(par2, par3, par4);

                if (i1 == 15)
                {
                    par1World.setBlock(par2, par3 + 1, par4, this.blockID);
                    par1World.setBlockMetadataWithNotify(par2, par3, par4, 0, 4);
                }
                else
                {
                    par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 + 1, 4);
                }
            }
        }
    }


    /**
     * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
     */
    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    {
        Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
        return (block != null && block.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
    }

    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor blockID
     */
    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    {
        this.checkBlockCoordValid(par1World, par2, par3, par4);
    }

    /**
     * Checks if current block pos is valid, if not, breaks the block as dropable item. Used for reed and cactus.
     */
    protected final void checkBlockCoordValid(World par1World, int par2, int par3, int par4)
    {
        if (!this.canBlockStay(par1World, par2, par3, par4))
        {
            this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
            par1World.setBlockToAir(par2, par3, par4);
        }
    }
    /**
     * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
     */
    public boolean canBlockStay(World par1World, int par2, int par3, int par4)
    {
        return this.canPlaceBlockAt(par1World, par2, par3, par4);
    }

//drops
    public int idDropped(int par1, Random par2Random, int par3)
    {
       
                    int w = par2Random.nextInt(;
                    if (w == 0)
                    {
                            return ashtonsmod.IngotBush.blockID;
                    }
                    if (w == 1)
                    {
                            return ashtonsmod.Amethyst.itemID;
                    }
                    if (w == 2)
                    {
                            return ashtonsmod.LightSteelNugget.itemID;
                    }
                    if (w == 3)
                    {
                            return Item.ingotGold.itemID;
                    }
                    if (w == 4)
                    {
                            return Item.ingotIron.itemID;
                    }
                    if (w == 5)
                    {
                            return Item.emerald.itemID;
                    }
                    if (w == 6)
                    {
                            return Block.obsidian.blockID;
                    }
                    if (w == 7)
                    {
                            return Item.coal.itemID;
                    }
                    else
                    {
                            return Item.diamond.itemID;
                    }                
    }

    public int quantityDroppedWithBonus(int par1, Random par2Random)
    {
            return quantityDropped(par2Random) + par2Random.nextInt(par1 + 1);
    }

    public int quantityDropped(Random par1Random)
    {
            return 1 + par1Random.nextInt(2); 
    }

    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 1;
    }

    @SideOnly(Side.CLIENT)

    /**
     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
     */
    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        return ashtonsmod.IngotBush.blockID;
    }

    @Override
    public EnumPlantType getPlantType(World world, int x, int y, int z)
    {
        return EnumPlantType.Beach;
    }

    @Override
    public int getPlantID(World world, int x, int y, int z)
    {
        return blockID;
    }

    @Override
    public int getPlantMetadata(World world, int x, int y, int z)
    {
        return world.getBlockMetadata(x, y, z);
        
    }
    @Override
    public void registerIcons(IconRegister par1IconRegister)
    {
        this.blockIcon = par1IconRegister.registerIcon("ashtonsmod:BlockIngotBush");
    }

Use examples, i have aspergers.

Examples make sense to me.

Posted

Place breakpoints inside the relevant methods, and see what happens when the IF statments are executed, see how the variables and then you should be able to tell why it's not placed correctly.

If you guys dont get it.. then well ya.. try harder...

Posted

whats a breakpoint?

and isnt there one specific area of code that allows sugar can to be allowed to be placed on itself?

Use examples, i have aspergers.

Examples make sense to me.

Posted

[lmgtfy=breakpoints debugging eclipse]Learn all about breakpoints, debugging and debuggers by clicking this link.[/lmgtfy]

 

Debugging is an essential skill to have as a programmer of ANY language.

print out statements and of course the use of the integrated debugger of eclipse is a MUST to learn about!

If you guys dont get it.. then well ya.. try harder...

Posted

i did and as i was i realized that it was hard and i don't know a lot of java, before you go tell me to go learn it i own a java for dummies book already and am starting ok?

Use examples, i have aspergers.

Examples make sense to me.

Posted

Good you are learning Java, and the basics of how breakpoints work can't be that hard to grasp.

it's a way to stop the program at a certain point inn the code, to see what's going on.

Just being able to stop and step by step look at what it does ain't that hard to understand I would believe?

 

The reasons why I tell you to learn this ain't to be a jerk, it's because it will be a vital skill for you to have when coding and creating programs/mods.

 

But honestly if setting a break point is hard, then I suggest you focus more on learning java than on modding first :) I would recommend watching CS106a from stanford, it's a brilliant lecture series and it's freely available here: http://see.stanford.edu/see/lecturelist.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111

 

If you have doubts wether or not it's for you then just check out the first video. also all handouts and assignments etc. are included for download on the page. Even tough this is a course from a university it's aimed towards people who have NO prior coding experience and no special education inn computers at all!

I just finished watching the later lecture series and I recommend it to anyone wanting to learn programming :)

 

 

as for your problem with the plant, I would check the method "canPlaceBlockAt" since the problem is it's breaking when it shouldnt.

If you guys dont get it.. then well ya.. try harder...

Posted

i think the problem is the block list that it is getting doesnt have my custom block in it,

 Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)]; 

this is where the blocklist is declared

public static final Block[] blocksList = new Block[4096];

 

but i dont know what the 4096 stands for? its not block id, i think i need to make a new blocklist with my own block in it but i am not sure how?

 

this is my best guess on how to fix this error :)

Use examples, i have aspergers.

Examples make sense to me.

Posted

That is the main block list which stores ALL the blocks inn the game.

If you block is a block at all, then it will be inn that list.

As long as your block extends Block then it will have a constructor asking for an ID which is used to store it inside the block list.

 

4096 is the decleared size of the Block[](Block Array)

If you guys dont get it.. then well ya.. try harder...

Posted

still havnt solved this cos i am a derp :P i tried for a bit and looked at arrays as you suggested, i just keep putting it off now it is hard :/

Use examples, i have aspergers.

Examples make sense to me.

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



×
×
  • Create New...

Important Information

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