Jump to content

[1.12.2] [Solved] How to Add Sword Harvest Functionality to a Multi Tool


Recommended Posts

Posted (edited)

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

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

Announcements



×
×
  • Create New...

Important Information

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