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.

[1.11] Custom tool mining speed not working

Featured Replies

Posted

I've made custom tool based of shovel, and i have set the iron variant's efficiency to 0.1F. It works on everything, that shovel works on(but it's mining slowly, just how have i set it). But on my own block it doesn't work - shovels mine it just like dirt, but the ModShovel mines it like if i had empty hand instead of mining it slowly, what should i do?

 

ArcheologyDirt

package vms.archeology.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
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.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import vms.archeology.Reference;
import vms.archeology.blocks.item.IMetaBlockName;
import vms.archeology.handlers.EnumHandler.Nations;
import vms.archeology.handlers.EnumHandler.Types;

public class ArcheologyDirt extends Block implements IMetaBlockName{

public static final PropertyInteger DROP_ID = PropertyInteger.create("id", 0, 15);

public ArcheologyDirt(String unlocalizedName) {
	super(Material.GROUND);
	this.setUnlocalizedName(unlocalizedName);
	this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
	this.setHardness(0.5f);
	this.setHarvestLevel("shovel", 0);
	this.setResistance(2.5f);
	this.setDefaultState(this.blockState.getBaseState().withProperty(DROP_ID, 0));
	this.setSoundType(SoundType.GROUND);
}

@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
	return Item.getItemFromBlock(Blocks.DIRT);

}
@Override
protected net.minecraft.block.state.BlockStateContainer createBlockState() {
	return new BlockStateContainer(this, new IProperty[] {DROP_ID});
}

@Override
public int getMetaFromState(IBlockState state) {
	return state.getValue(DROP_ID);
}

@Override
public IBlockState getStateFromMeta(int meta) {		
		return this.getDefaultState().withProperty(DROP_ID, meta);
}

@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
	for (int i = 0; i < 16; i++) {
		list.add(new ItemStack(itemIn, 1, i));
	}
}

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
	return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
}

@Override
public int damageDropped(IBlockState state) {
	return getMetaFromState(state);
}

@Override
public String getSpecialName(ItemStack stack) {
	return null;
}

}

ModShovel

package vms.archeology.items;

import java.util.List;
import java.util.Set;

import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import vms.archeology.Reference;
import vms.archeology.init.ModBlocks;
import net.minecraft.item.Item.ToolMaterial;

public class ModShovel extends ItemTool {
     
    private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] {ModBlocks.archeology_dirt, Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND, Blocks.GRASS_PATH});
    
    public ModShovel(Item.ToolMaterial material)
    {
        super(-0.5F, -2.5F, material, EFFECTIVE_ON);
    }

    /**
     * Check whether this Item can harvest the given Block
     */
    public boolean canHarvestBlock(IBlockState blockIn)
    {
        Block block = blockIn.getBlock();
        return block == Blocks.SNOW_LAYER ? true : block == Blocks.SNOW;
    }

   

}

 

ModTools

package vms.archeology.init;

import akka.io.TcpListener.RegisterIncoming;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemSpade;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import vms.archeology.Reference;
import vms.archeology.items.ArcheologyShovel;

public class ModTools {

public static final ToolMaterial ironMaterial = EnumHelper.addToolMaterial(Reference.MODID + "iron", 2, 200, 0.1F, 2.0F, ;

public static ArcheologyShovel iron_archeology_shovel;

public static void init() {
	iron_archeology_shovel = new ArcheologyShovel(ironMaterial, "iron_archeology_shovel");
}

public static void register() {
	registerTool(iron_archeology_shovel);
}

public static void registerRenders() {
	registerRender(iron_archeology_shovel);
}

public static void registerTool(Item item) {
	GameRegistry.register(item);
}

public static void registerRender(Item item) {
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(Reference.MODID, item.getUnlocalizedName().substring(5)), "inventory"));
}

}

 

  • Author

Ok, now it works, wrong initialization order!  :D

 

I have another problem, should i create new thread for it, or can i continue in this one?

 

 

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.