Jump to content

onItemUse doesn't work


HeXHaX

Recommended Posts

I am working on an electricity mod where you have a copper wire item and I want it to place a copper wire block when you click.  When I run it, all I get is the little item use animation that Minecraft has.  Here is my onItemUse function from my copper wire class:

 

@Override

public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ){

boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);

BlockPos blockpos1 = flag ? pos : pos.offset(side);

 

System.out.println("Spawn that block!!!");

 

worldIn.setBlockState(blockpos1, ModBlocks.copper_wire_block.getDefaultState());

 

return false;

}

 

I am not even getting the "Spawn that block!!!" message in the console output.

 

EDIT: Full code below:

 

Copper wire item class:

 

package com.hexhax.mod.items;

 

import com.hexhax.mod.init.ModBlocks;

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.BlockPos;

import net.minecraft.util.EnumFacing;

import net.minecraft.world.World;

 

public class CopperWire extends Item{

 

@Override

public boolean onItemUseFirst(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ){

boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);

BlockPos blockpos1 = flag ? pos : pos.offset(side);

 

System.out.println("Spawn that block!!!");

 

worldIn.setBlockState(blockpos1, ModBlocks.copper_wire_block.getDefaultState());

 

return true;

}

 

@Override

public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)

    {

        return itemStackIn;

    }

}

 

Copper Wire Block Class:

 

package com.pixelnectar.infinity.blocks;

 

import com.pixelnectar.infinity.init.InfinityBlocks;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

 

public class CopperWireBlock extends Block{

 

public CopperWireBlock() {

super(Material.circuits);

}

 

}

Link to comment
Share on other sites

Unfortunately, that did not do anything either.  Is there maybe some kind of config I have to do when I register my item?  I have everything registered properly to be able to craft, view in my own creative tab, etc, but I might have missed something.

Link to comment
Share on other sites

Unfortunately, that did not do anything either.  Is there maybe some kind of config I have to do when I register my item?  I have everything registered properly to be able to craft, view in my own creative tab, etc, but I might have missed something.

You changed it to return false, correct?

Maker of the Craft++ mod.

Link to comment
Share on other sites

it is curios coz the mine works

 

@Override
public boolean onItemUse(ItemStack sierra, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{

chat.chatda(playerIn, "onItemUse pos="+pos);
System.out.println("onItemUse pos="+pos);

setInttag(sierra, "bx0", pos.getX() );
setInttag(sierra, "by0", pos.getY() );
setInttag(sierra, "bz0", pos.getZ() );
setInttag(sierra, "bf0", side.getIndex());


    return false;
}


 

and im returning false and i dont see anyting wrong whith your code

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.