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

Hello. I just added a tool to my mod, and I set the attack damage and attack speed, but when I launch the game and grab the item, it has no attributes, as if it were just a basic item. Here are the classes I used:

 

package bloopers.spearmod.items;

import java.util.Set;

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.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ItemPrimitiveSpearTool extends ItemTool
{
    private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] {Blocks.SPONGE});

    public ItemPrimitiveSpearTool(Item.ToolMaterial material)
    {
        super(1.5F, -3.0F, material, EFFECTIVE_ON);
    }
}

 

package bloopers.spearmod.items;

import net.minecraft.item.Item;

public class ItemPrimitiveSpear extends Item {

public ItemPrimitiveSpear(ToolMaterial material) {
	this.setMaxStackSize(1);
}
}

 

And then my item init class:

package bloopers.spearmod.init;

import bloopers.spearmod.items.ItemPrimitiveSpear;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class SpearItems {

/**********|DECLARE|**********/
public static ItemPrimitiveSpear primitive_spear;

public static final Item.ToolMaterial primitive = EnumHelper.addToolMaterial("primitive", 1, 300, 6.0F, 1.0F, 1);


public static void init() {
/*********************************|INIT ITEMS|***************************************/
	//primitive_spear = new ItemPrimitiveSpear(primitive);

	primitive_spear = (ItemPrimitiveSpear)(new ItemPrimitiveSpear(primitive).setUnlocalizedName("primitive_spear"));

}
/***********************************************************************************/

public static void register() {	
/*********************************|REGISTER ITEMS|***************************************/
primitive_spear.setRegistryName("primitive_spear");
GameRegistry.register(primitive_spear);	

}
/***********************************************************************************/

public static void registerRenders() {
/*********************************|RENDER ITEMS|***************************************/
registerRender(primitive_spear);

}
/***********************************************************************************/


private static void registerRender(Item item) {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0,
			new ModelResourceLocation("spear" + ":" + item.getUnlocalizedName()
			.substring(5), "inventory"));
}
}

package bloopers.spearmod.items;

import net.minecraft.item.Item;

public class ItemPrimitiveSpear extends Item // I wonder why it doesn't have any modifiers // {

public ItemPrimitiveSpear(ToolMaterial material) {
	this.setMaxStackSize(1);
}
}

 

 

 

And then my item init class:

package bloopers.spearmod.init;

import bloopers.spearmod.items.ItemPrimitiveSpear;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class SpearItems {

/**********|DECLARE|**********/
public static ItemPrimitiveSpear primitive_spear;

public static final Item.ToolMaterial primitive = EnumHelper.addToolMaterial("primitive", 1, 300, 6.0F, 1.0F, 1);


public static void init() {
/*********************************|INIT ITEMS|***************************************/
	//primitive_spear = new ItemPrimitiveSpear(primitive);

	primitive_spear = (ItemPrimitiveSpear)(new ItemPrimitiveSpear(primitive).setUnlocalizedName("primitive_spear"));

}
/***********************************************************************************/

public static void register() {	
/*********************************|REGISTER ITEMS|***************************************/
primitive_spear.setRegistryName("primitive_spear");
GameRegistry.register(primitive_spear);	

}
/***********************************************************************************/

public static void registerRenders() {
/*********************************|RENDER ITEMS|***************************************/
registerRender(primitive_spear);

}
/***********************************************************************************/


private static void registerRender(Item item) {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0,
			new ModelResourceLocation("spear" + ":" + item.getUnlocalizedName()
			.substring(5), "inventory"));
}
}

 

Do not use Minecraft.getMinecraft.getRenderItem().getItemModelMesher() just use ModelLoader.setCustomModelResourceLocation(...)

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

Why do you have this

ItemPrimitiveSpearTool

class which you never use?

Why do you have this

ToolMaterial

parameter in the

ItemPrimitiveSpear

constructor, which you never do anything with? What did you expect this to do?

Oh! I meant to have ItemPrimitiveSpear extend ItemPrimitiveSpearTool. Do I not even need the ItemPrimitiveSpearTool class?

 

I expect ToolMaterial to be able to set the durability, enchantability etc using the "primitive" tool material that I have, in the SpearItems class.

Why do you have this

ItemPrimitiveSpearTool

class which you never use?

Why do you have this

ToolMaterial

parameter in the

ItemPrimitiveSpear

constructor, which you never do anything with? What did you expect this to do?

Oh! I meant to have ItemPrimitiveSpear extend ItemPrimitiveSpearTool. Do I not even need the ItemPrimitiveSpearTool class?

 

I expect ToolMaterial to be able to set the durability, enchantability etc using the "primitive" tool material that I have, in the SpearItems class.

You do not unless it has a special effect like throwing.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

Okay. I deleted ItemPrimitiveSpearTool and put all of the stuff like EFFECTIVE_ON, and the damage and speed into one class and the item works fine now. Thank you both!

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.