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.

Featured Replies

Posted

I am developing a mod that adds flint and cactus tools, and my axes have weird attack speed and damage. Doing

super(material, material.getDamageVsEntity(), material.getEfficiencyOnProperMaterial());

In the constructor leaves me with values that would make the axe attack really fast and do less damage than I want it to,

super(material);

Gives me a java.lang.ExceptionInInitializerError.

 

So I have rigged up a system to fix this for the time being, but having to expand this system every time I add a new ToolMaterial will get annoying fast. Help?

 

Code:

ModAxe.java:

package com.Winseven4lyf.MoreTools.items;

import com.Winseven4lyf.MoreTools.handlers.MaterialHandler;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemAxe;

public class ModAxe extends ItemAxe
{
	public ModAxe(String name, ToolMaterial material, CreativeTabs tab)
	{
		super(material, MaterialHandler.getAxeDamage(material) - 1, MaterialHandler.getAxeAttackSpeed(material) - 4);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(tab);
	}
}

 

MaterialHandler.java:

package com.Winseven4lyf.MoreTools.handlers;

import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;

public class MaterialHandler
{
	private static float lerp(float a, float b, float t)
	{
		return (1 - t) * a + t * b;
	}
	
	private static ToolMaterial createLerpedMaterial(String name, ToolMaterial a, ToolMaterial b, float t, ItemStack repairItem)
	{
		return EnumHelper.addToolMaterial(
				name,
				a.getHarvestLevel(),
				(int) Math.floor(lerp(a.getMaxUses(), b.getMaxUses(), 0.5F)),
				lerp(a.getEfficiencyOnProperMaterial(), b.getEfficiencyOnProperMaterial(), 0.5F),
				lerp(a.getDamageVsEntity(), b.getDamageVsEntity(), 0.5F),
				(int) Math.floor(lerp(a.getEnchantability(), b.getEnchantability(), 0.5F))
		).setRepairItem(repairItem);
	}
	
	private static ToolMaterial createDuplicateMaterial(String name, ToolMaterial original, ItemStack repairItem)
	{
		return EnumHelper.addToolMaterial(
				name,
				original.getHarvestLevel(),
				original.getMaxUses(),
				original.getEfficiencyOnProperMaterial(),
				original.getDamageVsEntity(),
				original.getEnchantability()
		).setRepairItem(repairItem);
	}
	
	public static float getAxeAttackSpeed(ToolMaterial material)
	{
		float output = 0F;
		
		if (material == FLINT)
		{
			output = 0.85F;
		}
		else if (material == CACTUS)
		{
			output = 0.8F;
		}
		
		return output;
	}
	
	public static float getAxeDamage(ToolMaterial material)
	{
		float output = 0F;
		
		if (material == FLINT)
		{
			output = 9F;
		}
		else if (material == CACTUS)
		{
			output = 7F;
		}
		
		return output;
	}
	
	public static final ToolMaterial FLINT =
			createLerpedMaterial("flint", ToolMaterial.STONE, ToolMaterial.IRON, 0.5F, new ItemStack(Items.FLINT));
	public static final ToolMaterial CACTUS =
			createDuplicateMaterial("cactus", ToolMaterial.WOOD, new ItemStack(Blocks.CACTUS));
}

 

Edited by Winseven4lyf
Typo

31 minutes ago, Winseven4lyf said:

Gives me a java.lang.ExceptionInInitializerError

This is the issue to focus on, because that constructor should work fine. Can you post the full log of this error?

  • Author

The error is:

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from More Tools (moretools)
Caused by: java.lang.ExceptionInInitializerError
	at com.Winseven4lyf.MoreTools.proxy.CommonProxy.preInit(CommonProxy.java:9)
	at com.Winseven4lyf.MoreTools.proxy.ClientProxy.preInit(ClientProxy.java:9)
	at com.Winseven4lyf.MoreTools.MoreTools.preInit(MoreTools.java:21)
	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:643)
	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:246)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:224)
	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:147)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:647)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:275)
	at net.minecraft.client.Minecraft.init(Minecraft.java:478)
	at net.minecraft.client.Minecraft.run(Minecraft.java:387)
	at net.minecraft.client.main.Main.main(Main.java:118)
	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.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	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.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)

And underneath that is:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 5
	at net.minecraft.item.ItemAxe.<init>(ItemAxe.java:19)
	at com.Winseven4lyf.MoreTools.items.ModAxe.<init>(ModAxe.java:13)
	at com.Winseven4lyf.MoreTools.handlers.ItemHandler.<clinit>(ItemHandler.java:33)
	... 46 more

 

P.S: I should probably learn where the log is in a dev environment...

Ah, I was wrong in my previous post - the ItemAxe(ToolMaterial) constructor is hardcoded to only accept vanilla materials, so that constructor won't work. I don't think there's any other solution - you have to manually specify the damage and attack speed when you create an instance of ItemAxe. You can do that by storing that information elsewhere associated with your material (like you've done), or you could put literals in the constructor wherever you initalize your items, or you could give you custom axe fixed values for base damage and attack speed (rather than varying by material).

 

A more concise and expandable way of storing your damage and attack speed values would be two Map<ToolMaterial, Float>s.

Edited by Jay Avery

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.