Jump to content

[1.9] My Custom axe is giving me an Array out of Bounds exception [SOLVED]


Recommended Posts

Posted

For some reason I'm getting an Array out of Bounds exception when compile I'm compiling my mod. I have no clue why its doing this. I'm also using forge version "1.9-12.16.0.1802-1.9" which the latest version of Java.

 

Here my custom Axe class...

 

package com.derf.ei.items;

import net.minecraft.item.ItemAxe;

public class EIItemAxe extends ItemAxe {

protected EIItemAxe(String name, ToolMaterial material) {
	super(material);
	// TODO Auto-generated constructor stub
	this.setUnlocalizedName(name);
}

}

 

Here is the stack trace.

 

Stacktrace:
at net.minecraft.item.ItemAxe.<init>(SourceFile:32)
at com.derf.ei.items.EIItemAxe.<init>(EIItemAxe.java:
at com.derf.ei.items.EIItems.create(EIItems.java:134)
at com.derf.ei.EICommonProxy.preInit(EICommonProxy.java:19)
at com.derf.ei.EIClientProxy.preInit(EIClientProxy.java:15)
at com.derf.ei.EILoader.preInit(EILoader.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:221)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:128)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:241)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:434)

Posted

It seems as if you've passed a tool material to super that super doesn't understand. You'll probably need to work around the limited array that super uses.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Well the funny thing is the only tool that is giving me the error is the Axe. The Sword, Pickaxe, Spade (aka Shovel), and Hoe are not giving me an "Array out of Bound" exception. Only the Axe...  :-\

 

Also here's the portion of code that is relevant to my problem from the EIItems class.

 

public final class EIItems {
        // ...
// Tier 1 Tools (Voidium Ingot Tools and Armor)
// Tools
public static Item voidiumSword;
public static Item voidiumPickaxe;
public static Item voidiumSpade;
public static Item voidiumAxe;
public static Item voidiumHoe;
        // ...
public static void create() {
	VOIDIUM = EnumHelper.addToolMaterial("VOIDIUM", 2, 750, 6.0F, 2.0F, 0);
                // ...
	// Tier 1 Tools VOIDIUM
	// Tools
	voidiumSword = new EIItemSword("voidium_sword", VOIDIUM);
	voidiumPickaxe = new EIItemPickaxe("voidium_pickaxe", VOIDIUM);
	voidiumSpade = new EIItemSpade("voidium_shovel", VOIDIUM);
	voidiumAxe = new EIItemAxe("voidium_axe", VOIDIUM);
	voidiumHoe = new EIItemHoe("voidium_hoe", VOIDIUM);
	// ...
}
        // ...
}

Posted

I dont think you can use ItemAxe for your custom axe anymore, since the constructor is kinda hardcoded.. I made this class for workaround

 

 

public class CustomAxe extends Item{

private final ToolMaterial material;

public CustomAxe(ToolMaterial material) {
	setCreativeTab(MiningOverhaul.miningTab);
	this.material=material;
}

@Override
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.material.getEfficiencyOnProperMaterial();
    }

}

(note that this class isnt finished , e.g. damage is not implemented yet)

Posted

i having the same issue

 

but i just leave it behind

forge 1.9 has only like a week of release and still has a lot of little isues

may the fixed in the early time

 

also custom shields dont works, dont crash or throw error of any kind but still the custom shield is not apering in the cretive inventory

Posted

i having the same issue

 

but i just leave it behind

forge 1.9 has only like a week of release and still has a lot of little isues

may the fixed in the early time

 

also custom shields dont works, dont crash or throw error of any kind but still the custom shield is not apering in the cretive inventory

 

Yeah that what I'm thing too. Due to the fact that all of the other tools are working I think its probably a bug on their end and plus forge for mc 1.9 just came too. Also thank for warning me about shields too. To me it sound like when your using using setCreativeTabs the shield class I guess ItemShield overrides the creative tabs logic or there not setting something on their end. I'm probably going to skip the axe for now and work on the rest of the port. :)

Posted

I dont think you can use ItemAxe for your custom axe anymore, since the constructor is kinda hardcoded.. I made this class for workaround

 

 

public class CustomAxe extends Item{

private final ToolMaterial material;

public CustomAxe(ToolMaterial material) {
	setCreativeTab(MiningOverhaul.miningTab);
	this.material=material;
}

@Override
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.material.getEfficiencyOnProperMaterial();
    }

}

(note that this class isnt finished , e.g. damage is not implemented yet)

 

Thats cool :). Thanks for the post. Hmm, kind of strange on their part to completely cut the ItemAxe. Weird. Also thanks for the code. I'll fix it up with damage and what not and repost it. :)

 

Posted

Here's my implementation of the ItemAxe class. I tried my best to be as general as possible so it can work in any project. I hope the ItemAxe class for 1.9 gets fix pretty soon :).

 

ItemAxeCustom:

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;

/**
* This is an implementation of the ItemAxe. This class was created
* due to a bug in ItemAxe that results in an "Array out of Bound"
* exception in the constructor. 
* 
* Note: You don't need permission from me to use this code. Just use it
* if your having the same problem I'm having. 
* @author derf6060
*/
public class ItemAxeCustom extends ItemTool {
// A holder object for the tool material
private ToolMaterial material = null;
// This is a list of 
private static Set<Block> blocks = null;

/**
 * This initializes the ItemAxeCustom object.
 * @param ToolMaterial material
 */
public ItemAxeCustom(ToolMaterial material) {
	super(material, getEffectedBlocks());
	this.material = material;
}

/**
 * This create a list of vanilla blocks that the custom
 * axe can be used on.
 * @return Set<Block>
 */
private static Set<Block> getEffectedBlocks() {
	// TODO Auto-generated method stub

	if(blocks == null) {
		blocks = new HashSet<Block>();
		// Arcacia
		blocks.add(Blocks.acacia_door);
		blocks.add(Blocks.acacia_fence);
		blocks.add(Blocks.acacia_fence_gate);
		blocks.add(Blocks.acacia_stairs);
		// Birch
		blocks.add(Blocks.birch_door);
		blocks.add(Blocks.birch_fence);
		blocks.add(Blocks.birch_fence_gate);
		blocks.add(Blocks.birch_stairs);
		// Dark Oak
		blocks.add(Blocks.dark_oak_door);
		blocks.add(Blocks.dark_oak_fence);
		blocks.add(Blocks.dark_oak_fence_gate);
		blocks.add(Blocks.dark_oak_stairs);
		// Jungle
		blocks.add(Blocks.jungle_door);
		blocks.add(Blocks.jungle_fence);
		blocks.add(Blocks.jungle_fence_gate);
		blocks.add(Blocks.jungle_stairs);
		// Oak 
		blocks.add(Blocks.oak_door);
		blocks.add(Blocks.oak_fence);
		blocks.add(Blocks.oak_fence_gate);
		blocks.add(Blocks.oak_stairs);
		// Spruce
		blocks.add(Blocks.spruce_door);
		blocks.add(Blocks.spruce_fence);
		blocks.add(Blocks.spruce_fence_gate);
		blocks.add(Blocks.spruce_stairs);
		// Logs
		blocks.add(Blocks.log);
		blocks.add(Blocks.log2);
		// Leaves
		blocks.add(Blocks.leaves);
		blocks.add(Blocks.leaves2);
		// Planks
		blocks.add(Blocks.planks);
		// Crafting Table
		blocks.add(Blocks.crafting_table);
		// Pumkin
		blocks.add(Blocks.pumpkin);
		// Lit Pumkin
		blocks.add(Blocks.lit_pumpkin);
		// Vines
		blocks.add(Blocks.vine);
		// Melon
		blocks.add(Blocks.melon_block);
	}
	return blocks;
}

/**
 * This check if the block can be mined by the custom axe
 * @param ItemStack stack
 * @param IBlockState state
 * @return
 */
private boolean checkStrVsBlock(ItemStack stack, IBlockState state) {

	boolean b = false;

	// Check Block List that the axe can mine...
	Iterator<Block> it = blocks.iterator();

	while(it.hasNext()) {
		Block block = it.next();

		if(block == state.getBlock()) {
			b = true;
			break;
		}
	}


	// Check Materials
	Material material = state.getMaterial();

	// Added in harvest tool and harvest level
	return b || 
		   material == Material.wood || 
		   material == Material.plants || 
		   material == Material.vine || 
		   (((state.getBlock().getHarvestTool(state) != null && state.getBlock().getHarvestTool(state).equals("axe"))? true : false) && state.getBlock().getHarvestLevel(state) <= this.material.getHarvestLevel());
}


@Override
public float getStrVsBlock(ItemStack stack, IBlockState state) {
	// TODO Auto-generated method stub
	return (!checkStrVsBlock(stack, state))? super.getStrVsBlock(stack, state) : this.material.getEfficiencyOnProperMaterial();
}
}

 

There is a small issue with this class because it makes axes really fast lol.

 

Edit:

Small little update to make sure that it mines blocks that is assigned to the "axe" class and make sure the block is at the right level to be mined.

 

Removed test code, and fixed some spelling.

Posted

I updated to forge 1804 for the 1.9 line and the ItemAxe class is still giving me "Array out of Bounds" exception when doing my port of my mod. After creating the temporary ItemAxeCustom class I probably figured out why its doing this error. In the ItemTool class, it needs both a ToolMaterial and a Set<Block> class to be passed to its constructor. This means that the ItemAxe constructor is Iterating through that Set<Block> class for some reason and going over the allocated space on it which results in this error. This is what I'm speculating.

Posted

Umm seriously you guys need to stop guessing and learn how to do your own debugging.

The issue is that ItemAxe has two arrays for damange and speed that are indexed by the tool material.

Why they have this instead of using the normal values, i don't know.

But simple solution DONT extend ItemAxe, instead extend ItemTool and set your values accordingly.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Umm seriously you guys need to stop guessing and learn how to do your own debugging.

The issue is that ItemAxe has two arrays for damange and speed that are indexed by the tool material.

Why they have this instead of using the normal values, i don't know.

But simple solution DONT extend ItemAxe, instead extend ItemTool and set your values accordingly.

From what you've stated I'll assume that it's on MCP side and mark this as solved.

Posted

But simple solution DONT extend ItemAxe, instead extend ItemTool and set your values accordingly.

 

I have a mod and I want to make sure that my custom enchantment can be applied to axes, even mod added ones.

 

How would I do that under your solution, sir?

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.

Posted

But simple solution DONT extend ItemAxe, instead extend ItemTool and set your values accordingly.

 

I have a mod and I want to make sure that my custom enchantment can be applied to axes, even mod added ones.

 

How would I do that under your solution, sir?

The best solution for this simply play the waiting game for 1.9. The problem isn't forge but MCP. I thing MCP only releases binaries so there isn't a way to fix it through forge this time. Until MCP releases a new snap shot to forge the best solution is to wait.

Posted

The issue is with Minecraft itself, not MCP.

 

MCP is only used by Forge for deobfuscation data, i.e. mapping names like

aa

to

World

. The code itself is decompiled from the Minecraft JAR, deobfuscated with the MCP data and patched by Forge.

 

ItemAxe

will only work for mods when someone submits a PR to Forge with a patch that fixes it (and the PR is accepted) or Mojang changes it in a future version of Minecraft.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

The issue is with Minecraft itself, not MCP.

 

MCP is only used by Forge for deobfuscation data, i.e. mapping names like

aa

to

World

. The code itself is decompiled from the Minecraft JAR, deobfuscated with the MCP data and patched by Forge.

 

ItemAxe

will only work for mods when someone submits a PR to Forge with a patch that fixes it (and the PR is accepted) or Mojang changes it in a future version of Minecraft.

Thanks for the post. It boosted my understanding of the relationship between Forge, MCP, and Minecraft. I would fix the ItemAxe class and post a PR to forge, however, I'm having a issue with "gradlew setupDecompWorkspace" were it locks up during the decompiling process. Right now my hands are tide at due to this issue I'm having.  :-\

Posted

We have hooks in place to allow you to be any type of tool, inculding multiple types of tools.

If you want to make sure you enchant all Axes, then ask the item what tool classes it is an if it contains "axe" enchant it:

https://github.com/MinecraftForge/MinecraftForge/blob/1.9/patches/minecraft/net/minecraft/item/Item.java.patch#L504-L541

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.