Jump to content

Custom Axe/Shears help [1.11.2]


Cmonster
 Share

Recommended Posts

I'm having problems with how much damage an axe can do and the attack speed. It's all messed up and I want the values to be based off of the material.

Also, the shears' max damage can only be set in the shears class and also isn't based off of the material.

Axe class:

Spoiler

package items;
 
import java.util.List;
import java.util.Set;
import java.util.UUID;

import com.Cmonster.OreMod.Reference;
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.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.util.ResourceLocation;
import net.minecraft.item.Item.ToolMaterial;
 
public class ItemModAxe extends ItemTool {
    
    private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] {Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, Blocks.CHEST, Blocks.PUMPKIN, Blocks.LIT_PUMPKIN, Blocks.MELON_BLOCK, Blocks.LADDER, Blocks.WOODEN_BUTTON, Blocks.WOODEN_PRESSURE_PLATE});
    private static final float[] ATTACK_DAMAGES = new float[] {6.0F, 8.0F, 8.0F, 8.0F, 6.0F};
    private static final float[] ATTACK_SPEEDS = new float[] { -3.2F, -3.2F, -3.1F, -3.0F, -3.0F};
     
    public ItemModAxe(ToolMaterial material, String unlocalizedName) {
        super(material, EFFECTIVE_ON);
        this.setUnlocalizedName(unlocalizedName);
        this.setRegistryName(new ResourceLocation(Reference.MOD_ID, unlocalizedName));
    }
     
    public float getStrVsBlock(ItemStack stack, IBlockState state)
    {
        Material material = state.getMaterial();
        return material != Material.WOOD && material != Material.PLANTS && material != Material.VINE ? super.getStrVsBlock(stack, state) : this.efficiencyOnProperMaterial;
    }
 
}

Materials and tools class:

Spoiler

package init;

import com.Cmonster03.OreMod.Reference;

import items.ItemModAxe;
import items.ItemModHoe;
import items.ItemModMultiTool;
import items.ItemModPickaxe;
import items.ItemModShears;
import items.ItemModShovel;
import items.ItemModSword;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModTools {
    
    public static final ToolMaterial lithium_material = EnumHelper.addToolMaterial(Reference.MOD_ID + ":lithium", 1, 150, 7.0F, 1.0F, 25);
    public static final ToolMaterial opal_material = EnumHelper.addToolMaterial(Reference.MOD_ID + ":opal", 3, 700, 6.0F, 2.0F, 10);
    public static final ToolMaterial johnium_material = EnumHelper.addToolMaterial(Reference.MOD_ID + ":johnium", 4, 2000, 10.0F, 4.0F, 8);
    public static final ToolMaterial nokia_material = EnumHelper.addToolMaterial(Reference.MOD_ID + ":nokia", 5, 3000, 7.0F, 6.0F, 17);
    
    public static ItemPickaxe lithium_pickaxe;
    public static ItemModAxe lithium_axe;
    public static ItemHoe lithium_hoe;
    public static ItemSpade lithium_shovel;
    public static ItemSword lithium_sword;
    public static ItemPickaxe opal_pickaxe;
    public static ItemModAxe opal_axe;
    public static ItemHoe opal_hoe;
    public static ItemSpade opal_shovel;
    public static ItemSword opal_sword;
    public static ItemPickaxe johnium_pickaxe;
    public static ItemModAxe johnium_axe;
    public static ItemHoe johnium_hoe;
    public static ItemSpade johnium_shovel;
    public static ItemSword johnium_sword;
    public static ItemPickaxe nokia_pickaxe;
    public static ItemModAxe nokia_axe;
    public static ItemHoe nokia_hoe;
    public static ItemSpade nokia_shovel;
    public static ItemSword nokia_sword;
    public static ItemShears nokia_shears;
    public static ItemModMultiTool nokia_multitool;
    
    public static void init() {
        lithium_pickaxe = new ItemModPickaxe(lithium_material, "lithium_pickaxe");
        lithium_axe = new ItemModAxe(lithium_material, "lithium_axe");
        lithium_hoe = new ItemModHoe(lithium_material, "lithium_hoe");
        lithium_shovel = new ItemModShovel(lithium_material, "lithium_shovel");
        lithium_sword = new ItemModSword(lithium_material, "lithium_sword");
        opal_pickaxe = new ItemModPickaxe(opal_material, "opal_pickaxe");
        opal_axe = new ItemModAxe(opal_material, "opal_axe");
        opal_hoe = new ItemModHoe(opal_material, "opal_hoe");
        opal_shovel = new ItemModShovel(opal_material, "opal_shovel");
        opal_sword = new ItemModSword(opal_material, "opal_sword");
        johnium_pickaxe = new ItemModPickaxe(johnium_material, "johnium_pickaxe");
        johnium_axe = new ItemModAxe(johnium_material, "johnium_axe");
        johnium_hoe = new ItemModHoe(johnium_material, "johnium_hoe");
        johnium_shovel = new ItemModShovel(johnium_material, "johnium_shovel");
        johnium_sword = new ItemModSword(johnium_material, "johnium_sword");
        nokia_pickaxe = new ItemModPickaxe(nokia_material, "nokia_pickaxe");
        nokia_axe = new ItemModAxe(nokia_material, "nokia_axe");
        nokia_hoe = new ItemModHoe(nokia_material, "nokia_hoe");
        nokia_shovel = new ItemModShovel(nokia_material, "nokia_shovel");
        nokia_sword = new ItemModSword(nokia_material, "nokia_sword");
        nokia_shears = new ItemModShears(nokia_material, "nokia_shears");
        nokia_multitool = new ItemModMultiTool(nokia_material, "nokia_multitool");
        
    }
    
    public static void register() {
        GameRegistry.register(lithium_pickaxe);
        GameRegistry.register(lithium_axe);
        GameRegistry.register(lithium_hoe);
        GameRegistry.register(lithium_shovel);
        GameRegistry.register(lithium_sword);
        GameRegistry.register(opal_pickaxe);
        GameRegistry.register(opal_axe);
        GameRegistry.register(opal_hoe);
        GameRegistry.register(opal_shovel);
        GameRegistry.register(opal_sword);
        GameRegistry.register(johnium_pickaxe);
        GameRegistry.register(johnium_axe);
        GameRegistry.register(johnium_hoe);
        GameRegistry.register(johnium_shovel);
        GameRegistry.register(johnium_sword);
        GameRegistry.register(nokia_pickaxe);
        GameRegistry.register(nokia_axe);
        GameRegistry.register(nokia_hoe);
        GameRegistry.register(nokia_shovel);
        GameRegistry.register(nokia_sword);
        GameRegistry.register(nokia_shears);
        GameRegistry.register(nokia_multitool);
    }
    
    public static void registerRenders(){
        registerRender (lithium_pickaxe);
        registerRender (lithium_axe);
        registerRender (lithium_hoe);
        registerRender (lithium_shovel);
        registerRender (lithium_sword);
        registerRender (opal_pickaxe);
        registerRender (opal_axe);
        registerRender (opal_hoe);
        registerRender (opal_shovel);
        registerRender (opal_sword);
        registerRender (johnium_pickaxe);
        registerRender (johnium_axe);
        registerRender (johnium_hoe);
        registerRender (johnium_shovel);
        registerRender (johnium_sword);
        registerRender (nokia_pickaxe);
        registerRender (nokia_axe);
        registerRender (nokia_hoe);
        registerRender (nokia_shovel);
        registerRender (nokia_sword);
        registerRender (nokia_shears);
        registerRender (nokia_multitool);
    }
    
    private static void registerRender(Item item) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
    }
}

All of the axes have the same attack damage and speed, and I want to base it off material.

Link to comment
Share on other sites

1. There is no reason to have the EFFECTIVE_ON array, setHarvestLevel() is sufficient. 

2. You need to use a different constructor, the one that takes 2 floats, because vanilla wants the damage and speed values from the material passed to that constructor, but your material doesn't exist in its enum array, so it crashes.

3. Don't set the unlocalized name like that, you should use setUnlocalizedName(getRegistryName()) after you give the item a registry name, this allows your lang file to not conflict with other mods

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

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

 Share



×
×
  • Create New...

Important Information

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