user2628615
user2628615

Reputation: 23

Placing blocks with Forge Mod Loader?

How to place a block when the user right clicks with the item?

The only method I can find that would do anything is setBlockMetadataWithUpdate() but the parameters are badly explained in the javadocs.

Upvotes: 0

Views: 2613

Answers (1)

Pascal Neubert
Pascal Neubert

Reputation: 96

Have you tried taking a look into the ItemBlock class? Using the onItemUse() in combination with the placeBlockAt() function or functionality?

/**
 * Called to actually place the block, after the location is determined
 * and all permission checks have been made.
 *
 * @param stack The item stack that was used to place the block. This can be changed inside the method.
 * @param player The player who is placing the block. Can be null if the block is not being placed by a player.
 * @param side The side the player (or machine) right-clicked on.
 */
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{

   if (!world.setBlock(x, y, z, field_150939_a, metadata, 3))
   {
       return false;
   }

   if (world.getBlock(x, y, z) == field_150939_a)
   {
       field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
       field_150939_a.onPostBlockPlaced(world, x, y, z, metadata);
   }

   return true;
}

Upvotes: 1

Related Questions