Jump to content

Recommended Posts

Posted

Scenario:

I want to create a tool that is not based off of the sword, pickaxe, hoe, spade, or axe. The tool should have durability. The tool's intended use is to be used in a crafting grid as part of a recipe. The tool should not be destroyed by the recipe as long as it remains durable.

 

What I've done so far:

I haven't attempted any code in regard to the tool yet, but have view the tutorial at http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/custom-tools-swords/ and can't help but think that is too complicated for what I want to do.

 

What I'm looking for:

Is that a good resource for this type of item? Is there are a better or more to the point tutorial or wiki for the type of tool I want to create?

Posted

1) Extend

ItemTool

2) Have it override

hasContainerItem

and

getContainerItem

.  These will cause it to be left in the crafting grid and take damage (getContainerItem should return the same stack given, but with 1 point more damage).

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

You can also override getDurabilityForDisplay(ItemStack stack) for durability.

Posted

1) Extend

ItemTool

2) Have it override

hasContainerItem

and

getContainerItem

.  These will cause it to be left in the crafting grid and take damage (getContainerItem should return the same stack given, but with 1 point more damage).

 

The item is still vanishing from the grid and I am sure that I arfed something up because if I try to hit any object with the item in hand the ssp world crashes.

 

Code for the class I created:

package com.kreezxil.modname.items;

import java.util.Set;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;

public class durableCraftingTool extends ItemTool {

public durableCraftingTool(String unlocalizedName, float attackDamage, ToolMaterial material, Set effectiveBlocks) {
	super(attackDamage, material, effectiveBlocks);
	this.setUnlocalizedName(unlocalizedName);
}

public durableCraftingTool(String unlocalizedname, ToolMaterial material, Object effectiveBlocks) {
	this(unlocalizedname, 0.0f, material, (Set) effectiveBlocks);
}

@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return false;
}

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
	return new ItemStack(getContainerItem());
}
}

 

The error being thrown, not entirely sure what I need to be doing to fix:

[16:13:12] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
at net.minecraft.item.ItemTool.getStrVsBlock(ItemTool.java:50) ~[itemTool.class:?]
at net.minecraft.item.Item.getDigSpeed(Item.java:575) ~[item.class:?]
at net.minecraft.item.ItemTool.getDigSpeed(ItemTool.java:162) ~[itemTool.class:?]
at net.minecraft.entity.player.EntityPlayer.getBreakSpeed(EntityPlayer.java:949) ~[EntityPlayer.class:?]
at net.minecraftforge.common.ForgeHooks.blockStrength(ForgeHooks.java:170) ~[ForgeHooks.class:?]
at net.minecraft.block.Block.getPlayerRelativeBlockHardness(Block.java:587) ~[block.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:250) ~[PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1512) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2118) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
[16:13:12] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: ---- Minecraft Crash Report ----
// Who set us up the TNT?

Time: 4/21/15 4:13 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at net.minecraft.item.ItemTool.getStrVsBlock(ItemTool.java:50)
at net.minecraft.item.Item.getDigSpeed(Item.java:575)
at net.minecraft.item.ItemTool.getDigSpeed(ItemTool.java:162)
at net.minecraft.entity.player.EntityPlayer.getBreakSpeed(EntityPlayer.java:949)
at net.minecraftforge.common.ForgeHooks.blockStrength(ForgeHooks.java:170)
at net.minecraft.block.Block.getPlayerRelativeBlockHardness(Block.java:587)
at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:250)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1512)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2118)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080)
at net.minecraft.client.Minecraft.run(Minecraft.java:376)
at net.minecraft.client.main.Main.main(Main.java:117)
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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.item.ItemTool.getStrVsBlock(ItemTool.java:50)
at net.minecraft.item.Item.getDigSpeed(Item.java:575)
at net.minecraft.item.ItemTool.getDigSpeed(ItemTool.java:162)
at net.minecraft.entity.player.EntityPlayer.getBreakSpeed(EntityPlayer.java:949)
at net.minecraftforge.common.ForgeHooks.blockStrength(ForgeHooks.java:170)
at net.minecraft.block.Block.getPlayerRelativeBlockHardness(Block.java:587)
at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:250)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1512)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityPlayerSP['Player604'/83, l='MpServer', x=130.95, y=64.00, z=-221.63]]
Chunk stats: MultiplayerChunkCache: 624, 624
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: 130.00,4.00,-217.00 - World: (130,4,-217), Chunk: (at 2,0,7 in 8,-14; contains blocks 128,0,-224 to 143,255,-209), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
Level time: 13944 game time, 2610 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
Forced entities: 28 total; [EntitySheep['Sheep'/64, l='MpServer', x=193.81, y=64.00, z=-183.94], EntitySheep['Sheep'/65, l='MpServer', x=185.88, y=64.00, z=-167.88], EntityPlayerSP['Player604'/83, l='MpServer', x=130.95, y=64.00, z=-221.63], EntityBat['Bat'/33540, l='MpServer', x=63.86, y=7.13, z=-292.38], EntityChicken['Chicken'/16, l='MpServer', x=56.56, y=64.00, z=-275.41], EntityChicken['Chicken'/17, l='MpServer', x=62.50, y=64.00, z=-268.50], EntityChicken['Chicken'/19, l='MpServer', x=59.50, y=64.00, z=-268.50], EntityChicken['Chicken'/20, l='MpServer', x=58.38, y=64.00, z=-268.69], EntityBat['Bat'/55640, l='MpServer', x=174.52, y=19.92, z=-241.20], EntityBat['Bat'/32, l='MpServer', x=66.42, y=7.46, z=-291.07], EntitySquid['Squid'/36, l='MpServer', x=90.31, y=62.38, z=-170.03], EntityBat['Bat'/40, l='MpServer', x=104.75, y=28.10, z=-193.53], EntityHorse['Horse'/42, l='MpServer', x=109.28, y=64.00, z=-180.38], EntityHorse['Horse'/45, l='MpServer', x=125.31, y=64.00, z=-181.72], EntityHorse['Horse'/46, l='MpServer', x=120.09, y=64.00, z=-161.75], EntitySquid['Squid'/55406, l='MpServer', x=148.50, y=61.00, z=-264.50], EntityRabbit['Rabbit'/47, l='MpServer', x=121.88, y=64.00, z=-162.91], EntityHorse['Horse'/48, l='MpServer', x=128.81, y=64.00, z=-179.72], EntitySquid['Squid'/59953, l='MpServer', x=171.50, y=61.47, z=-211.61], EntitySquid['Squid'/59954, l='MpServer', x=171.87, y=63.00, z=-210.66], EntitySquid['Squid'/59955, l='MpServer', x=128.39, y=61.38, z=-194.50], EntitySquid['Squid'/59956, l='MpServer', x=134.47, y=60.94, z=-193.41], EntityBat['Bat'/56, l='MpServer', x=175.47, y=21.10, z=-242.75], EntityBat['Bat'/57, l='MpServer', x=174.38, y=21.10, z=-242.75], EntityZombie['Zombie'/58, l='MpServer', x=172.53, y=20.00, z=-240.91], EntityBat['Bat'/59, l='MpServer', x=174.41, y=21.10, z=-242.75], EntitySheep['Sheep'/62, l='MpServer', x=205.50, y=64.00, z=-185.50], EntitySheep['Sheep'/63, l='MpServer', x=205.50, y=64.00, z=-182.50]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:392)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2600)
at net.minecraft.client.Minecraft.run(Minecraft.java:405)
at net.minecraft.client.main.Main.main(Main.java:117)
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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 744323400 bytes (709 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.76.1375 Minecraft Forge 11.14.1.1375 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{8.0.76.1375} [Forge Mod Loader] (forgeSrc-1.8-11.14.1.1375.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{11.14.1.1375} [Minecraft Forge] (forgeSrc-1.8-11.14.1.1375.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
prismatics{0.1} [Prismatics] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Loaded coremods (and transformers): 
Launched Version: 1.8
LWJGL: 2.9.1
OpenGL: GeForce GTX 460/PCIe/SSE2 GL version 4.5.0 NVIDIA 350.12, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)

Posted

Yes, you should still extend ItemTool. getDurabilityForDisplay(ItemStack stack) just handles the durability if you want to return custom values for the damage.

Posted

	@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return false;
}

 

Dude.  False?  Really?

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

	@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return false;
}

 

Dude.  False?  Really?

 

Heh? silly me. I thought the comment in the original code meant that it was returning true to begin with so "false" seemed obvious, now I realize it is a note telling me that I should return "true" if I want a specific behavior.

/**
     * ItemStack sensitive version of hasContainerItem
     * @param stack The current item stack
     * @return True if this item has a 'container'
     */
    public boolean hasContainerItem(ItemStack stack)
    {
        /**
         * True if this Item has a container item (a.k.a. crafting result)
         */
        return hasContainerItem(); //this part has a strikethrough in it in the item.class file.
    }

Posted

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Then I've tried to control it from the recipe side of things too, the result is that it no longer crashes, but now the durability doesn't go down. That code excerpt is:

		recipe = new ShapedOreRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',ModItems.item_diamond_file.setContainerItem(ModItems.item_diamond_file),'Q',ModBlocks.block_quartz_glass);
	GameRegistry.addRecipe(recipe);

 

and the class where I think I tried everything is

package com.kreezxil.modname.items;

import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraftforge.common.util.EnumHelper;

import com.google.common.collect.Sets;

public class durableCraftingTool extends ItemTool {

  //public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", harvestLevel, maxUses, efficiency, damage, enchantability)//addToolMaterial("PRISMATICS", harvestLevel, durability, miningSpeed, damageVsEntities, enchantability);
public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", 0, 3000, 2.0f, 0.5f, 22);
    private static final Set EFFECTIVE_ON = Sets.newHashSet(new Block[] {Blocks.air});

public durableCraftingTool(String unlocalizedName, float attackDamage, ToolMaterial material, Set effectiveBlocks) {
	super(attackDamage, material, effectiveBlocks);
	this.setUnlocalizedName(unlocalizedName);
}

public durableCraftingTool(String unlocalizedname, ToolMaterial material, Set effectiveBlocks) {
	this(unlocalizedname, 0.0f, material, (Set) effectiveBlocks);
}

public durableCraftingTool(String unlocalizedname) {
	this(unlocalizedname, DIAMONDFILE, EFFECTIVE_ON);
}

@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return true;
}

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
	return new ItemStack(getContainerItem());
}

}

 

Any and All help greatly appreciated.

Posted

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Ok, would you mind posting the crash report so we can see what error crashed the game?

 

P.S. I clicked the thank you button accidentally instead of quote. lol I don't think there is a way to reverse that. :/

Posted

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Then I've tried to control it from the recipe side of things too, the result is that it no longer crashes, but now the durability doesn't go down. That code excerpt is:

		recipe = new ShapedOreRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',ModItems.item_diamond_file.setContainerItem(ModItems.item_diamond_file),'Q',ModBlocks.block_quartz_glass);
	GameRegistry.addRecipe(recipe);

 

Wait, if it's a NullPointerException I think I had that on a recipe once. I was wondering what was wrong and I ended up fixing it by putting the recipe in an Object array. Like this:

GameRegistry.addShapedRecipe(new ItemStack(result), new Object[]{
"xxx",
"xxx",
"xxx",
'x', theCraftingitem
};

 

Although I don't know what ShapedOreRecipe is.

Posted

Two things:

1. Did you override getContainerItem() to return an actual Item?

2. Why create a new ItemStack when you already have one?

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
// Assuming you want to damage it when used in crafting:
itemstack.attemptDamageItem(1, this.itemRand);
return itemstack; // then just return it
}

Posted

I must be doing all kinds of things wrong here.

 

So I tried all the things mentioned here and managed to get the tool to lose durability and produce a new object as expected but at the same time crash the game.

 

Ok, would you mind posting the crash report so we can see what error crashed the game?

 

P.S. I clicked the thank you button accidentally instead of quote. lol I don't think there is a way to reverse that. :/

 

I think that ShapedOreRecipe allows the components of the recipe to swap with other elements from other mods that would possibly match elements in the recipe. I could be wrong.

 

Here is crash report: http://pastebin.com/vmR83PLs

 

When I come back into the game, the tool will have lost one durability point but then at that point, I can no longer use it in a recipe. That recipe code follows:

GameRegistry.addRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',ModItems.item_diamond_file,'Q',ModBlocks.block_quartz_glass);

 

 

Posted

Two things:

1. Did you override getContainerItem() to return an actual Item?

2. Why create a new ItemStack when you already have one?

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
// Assuming you want to damage it when used in crafting:
itemstack.attemptDamageItem(1, this.itemRand);
return itemstack; // then just return it
}

 

1. I did override as you found

2. all I can say is IRnewb. :(

3. I tried your suggestions and that got rid of the game crashing, but I can't use the subsequent new now damaged tool, how do I allow the damaged item to continue to be used in the recipe?

Posted

Thanks to everyone in this thread, you all have gone a long way in helping to resolve the issue.

 

Resulting Code Follows ...

 

The recipe:

	GameRegistry.addRecipe(new ItemStack(ModBlocks.block_prism),"FQ",'F',new ItemStack(ModItems.item_diamond_file, 1, OreDictionary.WILDCARD_VALUE),'Q',ModBlocks.block_quartz_glass);

 

The class for the tool:

package com.kreezxil.prismatics.items;

import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraftforge.common.util.EnumHelper;

import com.google.common.collect.Sets;

public class durableCraftingTool extends ItemTool {

  //public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", harvestLevel, maxUses, efficiency, damage, enchantability)//addToolMaterial("PRISMATICS", harvestLevel, durability, miningSpeed, damageVsEntities, enchantability);
public static ToolMaterial DIAMONDFILE = EnumHelper.addToolMaterial("DIAMONDFILE", 0, 3000, 2.0f, 0.5f, 22);
    private static final Set EFFECTIVE_ON = Sets.newHashSet(new Block[] {Blocks.air});

public durableCraftingTool(String unlocalizedName, float attackDamage, ToolMaterial material, Set effectiveBlocks) {
	super(attackDamage, material, effectiveBlocks);
	this.setUnlocalizedName(unlocalizedName);
}

public durableCraftingTool(String unlocalizedname, ToolMaterial material, Set effectiveBlocks) {
	this(unlocalizedname, 0.0f, material, (Set) effectiveBlocks);
}

public durableCraftingTool(String unlocalizedname) {
	this(unlocalizedname, DIAMONDFILE, EFFECTIVE_ON);
}

@Override
public boolean hasContainerItem(ItemStack itemstack) {
	return true;
}

@Override
public ItemStack getContainerItem(ItemStack itemstack) {
	itemstack.attemptDamageItem(1, this.itemRand);
	return itemstack;
}

}

 

The code that creates the tool:

	GameRegistry.registerItem(item_diamond_file = new durableCraftingTool("item_diamond_file"),"item_diamond_file");

 

It is my sincerest hope that this thread will help others create tools that can be used in a crafting grid without losing the tool.

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.