Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Problem with placing of my Reed-Blocks


EisCube
 Share

Recommended Posts

Hi there

I am currently working on my first mod.

My mod adds new types of Reed-Blocks.

I managed to get my reeds grow but I can place them anywhere!

I want them only to get placed on a special block with water around.

 

It would be nice if you explain the solution to me cause I'm new to java.

 

here are some examples from my code:

 

MyModMain:

	...

	public static Block myReed;
	public static Item myReedItem;


	@PreInit
	public void preInit(FMLPreInitializationEvent event) {

	}

	@Init
	public void init(FMLInitializationEvent event) {
		myReed = new BlockMyReed(500,32).setHardness(0.0F).setBlockName("Wooden Reed");
		GameRegistry.registerBlock(myReed);
		LanguageRegistry.addName(myReed, "Wood Reed");

		myReedItem = new ItemMyReed(600).setItemName("Wooden Reed");
		LanguageRegistry.addName(myReedItem, "Wood Reed");
		}

		...

 

BlockMyReed:

import java.util.Random;

import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Item;
import net.minecraft.src.Material;
import net.minecraft.src.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;

public class BlockMyReed extends Block implements IPlantable{	
protected BlockMyReed (int id,int tex){
	super(id,tex,Material.grass);
	this.setCreativeTab(CreativeTabs.tabMisc);
	float var3 = 0.375F;
        this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 1.0F, 0.5F + var3);
        this.setTickRandomly(true);
}

    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (par1World.isAirBlock(par2, par3 + 1, par4))
        {
            int var6;

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

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

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


    public int getRenderType()
    {
        return 1;
    }
    
    public boolean isOpaqueCube()
    {
        return false;
    }
    
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }
    
    public String getTextureFile(){
    	return "/eiscube/texplants.png";
    }
    
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return MyMod.myReedItem.shiftedIndex;
    }
    
    @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);
    }
}

 

ItemMyReed:

import java.util.Random;

import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;

public class ItemMyReed extends Item {

private int spawnID;

ItemMyReed(int id){
	super (id);
	this.setIconIndex(0);
	this.setCreativeTab(CreativeTabs.tabMaterials);
	this.spawnID = TheWildsMain.woodReed.blockID;
}

public String getTextureFile (){
	return "/eiscube/myitems.png";
}

    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        int var11 = par3World.getBlockId(par4, par5, par6);

        if (var11 == Block.snow.blockID)
        {
            par7 = 1;
        }
        else if (var11 != Block.vine.blockID && var11 != Block.tallGrass.blockID && var11 != Block.deadBush.blockID)
        {
            if (par7 == 0)
            {
                --par5;
            }

            if (par7 == 1)
            {
                ++par5;
            }

            if (par7 == 2)
            {
                --par6;
            }

            if (par7 == 3)
            {
                ++par6;
            }

            if (par7 == 4)
            {
                --par4;
            }

            if (par7 == 5)
            {
                ++par4;
            }
        }

        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
        else if (par1ItemStack.stackSize == 0)
        {
            return false;
        }
        else
        {
            if (par3World.canPlaceEntityOnSide(this.spawnID, par4, par5, par6, false, par7, (Entity)null))
            {
                Block var12 = Block.blocksList[this.spawnID];
                int var13 = var12.func_85104_a(par3World, par4, par5, par6, par7, par8, par9, par10, 0);

                if (par3World.setBlockAndMetadataWithNotify(par4, par5, par6, this.spawnID, var13))
                {
                    if (par3World.getBlockId(par4, par5, par6) == this.spawnID)
                    {
                        Block.blocksList[this.spawnID].onBlockPlacedBy(par3World, par4, par5, par6, par2EntityPlayer);
                        Block.blocksList[this.spawnID].func_85105_g(par3World, par4, par5, par6, var13);
                    }

                    par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), var12.stepSound.getPlaceSound(), (var12.stepSound.getVolume() + 1.0F) / 2.0F, var12.stepSound.getPitch() * 0.8F);
                    --par1ItemStack.stackSize;
                }
            }

            return true;
        }
    }
}

 

Mostly copied and pasted ;D

 

Thanks for your help

and please excuse my terrible english-writing skills

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
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.

 Share



×
×
  • Create New...

Important Information

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