Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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);

}

 

}

Try using onItemUseFirst.

  • Author

Hey, thanks for the quick response.  I just tried that and it still doesn't do anything.

Maybe it's because your returning false. Minecraft says this in the javdocs:

...

* @return Return true to prevent any further processing.
*/

 

I don't know if that has anything to do with it.

  • Author

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.

Show full code please.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

I have posted the full code for both my item class and my block class.  If there is anything else I need to show, just let me know.

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.

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

Look at how ItemReed does it, that's what string uses instead of the normal Item class. And if you didn't know, the string item when placed places tripwire.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.