Jump to content

[1.7.2]New to mods a few questions


Recommended Posts

Hi guys this is my first time making a mod and i wanted to start simple so i have added an ore that generates and smelts into an ingot i have also added a recipe for a pick.


Now i want to make this pick do "more" when it busts the block maybe take the surrounding blocks or just the block at the players feet if there picking at head height. i know i would need to do this in a block-update of sorts so any info on this would be nice


also if you could tell me how i would go about replacing the blocks around the "updated block" with air that would also be nice


thnx in advance



Link to comment
Share on other sites

You can do this by overriding the onBlockStartBreak() method in your pick class this is called just before the block breaks. There is a bit involved in getting it to work properly but instead of trying to explain it and completely confusing you (im not good at explaining things) i have put together an example pick class that will dig a 3x3x3 area around the block you mine. Hopefully you will be able to figure out how it works and modify it to suit your needs.


You shouldnt have any trouble getting this class to work all you have to do is rename the package and add it in your main class preinit method (or wherever you add your items) using


testPick = new TestPick();


It will be in the creative tools tab and it will have the diamond pick texture.

package tolkienaddon.items.tools;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.input.Keyboard;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings.GameType;
import tolkienaddon.Tolkienaddon;
import tolkienaddon.items.ModItems;
import tolkienaddon.lib.References;
import tolkienaddon.lib.Strings;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TestPick extends ItemPickaxe {

public static Material[] materialsPick = { Material.anvil, Material.circuits, Material.coral, Material.glass, Material.ice, Material.iron, Material.rock };

public TestPick() {
	GameRegistry.registerItem(this, "testPick");

public void registerIcons(final IIconRegister iconRegister) {
	this.itemIcon = iconRegister.registerIcon("minecraft:diamond_pickaxe");

public IIcon getIconFromDamage(int par1) {
		return itemIcon;

public boolean onBlockStartBreak(final ItemStack stack, final int x, final int y, final int z, final EntityPlayer player) {
	World world = player.worldObj;
	int fortune = EnchantmentHelper.getFortuneModifier(player);
	boolean silk = EnchantmentHelper.getSilkTouchModifier(player);

	disSquare(x, y, z, player, world, silk, fortune, stack);

	return true;

public static void disSquare(int x, int y, int z, final EntityPlayer player, final World world, final boolean silk, final int fortune, ItemStack stack) {
	int sizeX = 1;
	int sizeY = 1;
	int sizeZ = 1;

	for (int x1 = x - sizeX; x1 <= x + sizeX; x1++) {
		for (int y1 = y - sizeY; y1 <= y + sizeY; y1++) {
			for (int z1 = z - sizeZ; z1 <= z + sizeZ; z1++) {
				mineBlock(x1, y1, z1, player, world, silk, fortune, stack);

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void mineBlock(int x, int y, int z, EntityPlayer player, World world, boolean silk, int fortune, ItemStack stack) {
	Block block = world.getBlock(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);
	Material mat = block.getMaterial();

	if ((block != null) && (!block.isAir(world, x, y, z)) && (block.getPlayerRelativeBlockHardness(player, world, x, y, z) != 0.0F)) {
		List<ItemStack> items = new ArrayList();

		if ((!block.canHarvestBlock(player, meta)) || (!isRightMaterial(mat, materialsPick))) {

		if ((silk) && (block.canSilkHarvest(world, player, x, y, z, meta))) {
			if (block == Blocks.lit_redstone_ore)
				items.add(new ItemStack(Item.getItemFromBlock(Blocks.redstone_ore)));
				items.add(new ItemStack(block.getItem(world, x, y, z), 1, meta));
		} else {
			items.addAll(block.getDrops(world, x, y, z, meta, fortune));
			block.dropXpOnBlockBreak(world, x, y, z, block.getExpDrop(world, meta, fortune));

		world.setBlockToAir(x, y, z);

		if (!world.isRemote) {
			for (final ItemStack item : items) {
				world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, item));

public static boolean isRightMaterial(final Material material, final Material[] materialsListing) {
	for (final Material mat : materialsListing) {
		if (material == mat) {
			return true;
	return false;


If you need me to explain anything just ask.


Oh and i will just point out that i am also very new to modding so there may be better ways to do some of this.


Edit: Also note this tool wont loose durability because i copied most of the code from one of my tool classes and my tools have infinite durability. If you cant figure out how to make the tool loose durability when you use it let me know.

I am the author of Draconic Evolution

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.

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.