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.12.2] [Solved] How to Add Sword Harvest Functionality to a Multi Tool

Featured Replies

Posted

I was successfully able to create a tool (deathscythe) that utilized the harvesting characteristics from both an axe and a pickaxe using setHarvestLevel(IE my tool can break stone and Wood as a pickaxe/axe would), however this would not work when I attempted to add sword harvesting functionality. I suspect this is because swords all harvest at the same level (and can only harvest cobwebs as far as I am aware). Is there a way to add this functionality?

 

Here is the current version of deathscythe, if you need to see any other parts of my mod, I can provide them:

 

package com.benthom123.test.items;

import java.util.Collections;
import java.util.Set;

import com.benthom123.test.ModItems;
import com.benthom123.test.modClass;
import com.google.common.collect.ImmutableSet;
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.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.world.World;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class DeathScythe extends ItemTool {
	 
    public Item repairItem;
    public static float attack_speed = -3.7F;
    public static float base_damage = 20.0F;
 
    public DeathScythe(String registryName, ToolMaterial material, Item repairItem) {
        super(base_damage, attack_speed, material, Collections.emptySet());
        this.setHarvestLevel("pickaxe", material.getHarvestLevel());
        this.setHarvestLevel("axe", material.getHarvestLevel());
        this.repairItem = repairItem;
		setRegistryName(registryName);     
        setUnlocalizedName(modClass.MODID + "." + registryName);
        this.setCreativeTab(ModItems.extraTools);  
    }
    
    @Override
    public boolean canHarvestBlock(IBlockState state, ItemStack stack) {
        if (!(state.getMaterial() == Material.AIR) && !(state.getMaterial() == Material.BARRIER)) {
            return true;
        } else {
            return false;
        }
    }
    
 
    @Override
    public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
        return repair.getItem() == ModItems.ObsidianIngot ? true : super.getIsRepairable(toRepair, repair);
    }
 
    @Override
    public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
        // Only take one damage like a sword instead of 2
        itemStack.damageItem(1, attacker);
        return true;
    }
    
    @SideOnly(Side.CLIENT)
    public void initModel() {
       ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }
 
}

 

EDIT: Nvm I figured out how to do it myself, if anyone comes a cross this wondering how to do it: Swords have an alternate getDestroySpeed method, I just overrided the getDestroySpeed method and replaced it with the one that swords have in the ItemSword class

Edited by InterdimensionalCat

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.