Jump to content

Recommended Posts

Posted

Hey! I have a problem when crafting with a damaged item. I have it so my chisel takes damage when it's undamaged but after it's damaged I can no longer use it for crafting.

I basically want to craft with a damaged item but I can't.

 

Here's my Item code.

 

package net.be.mods.item;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.be.mods.MainModBE;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class toolJewelChisel extends Item

{

 

private ItemStack emptyItem = null;

private static int maxDamage = 64;

 

    public toolJewelChisel(int id)

    {

        super(id);

        setMaxDamage(64);

        this.setMaxStackSize(1);

        this.setCreativeTab(MainModBE.BETab);

        this.setNoRepair();

       

    }

   

    @Override

    public boolean hasContainerItem() {

    return true;

    }

    public void setEmptyItem(ItemStack ei) {

    this.emptyItem = ei;

    }

    public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack) {

    return false;

    }

    @Override

    public ItemStack getContainerItemStack(ItemStack stack) {

    int dmg = stack.getItemDamage();

    if (dmg == maxDamage) {

    return new ItemStack(stack.getItem(), 0, maxDamage);

    }

    ItemStack tr = copyStack(stack, 1);

    tr.setItemDamage(dmg + 1);

    return tr;

    }

    public static ItemStack copyStack(ItemStack stack, int n) {

    return new ItemStack(stack.itemID, n, stack.getItemDamage());

    }

 

    @SideOnly(Side.CLIENT)

    public void registerIcons(IconRegister iconRegister)

    {

        this.itemIcon = iconRegister.registerIcon(MainModBE.modid + ":" + this.getUnlocalizedName().substring(5));

    }

}

Posted

Use OreDictionary.WILDCARD_VALUE as the damage value for your ItemStack when registering the recipe

 

Thank you!

 

But now there is a new problem...

The item does not dissapear when used to 0, it has 0 uses left and I can still use it infinitly.

 

I'm kind of new but I understand most of what is going on but this has me rendered helpless...

Some help would be awesome:)

Posted

a) You should use .copy() on the ItemStack instead of your custom method, because otherwise NBT data will not be transferred (enchantments, custom names, etc. will be lost)

b) Instead of returning a 0-size ItemStack when reaching max-damage, return null.

 

I fixed the second issue, I hope. I can now craft and it takes damage but when it reaches 0, my client crashes.

I didn't really understand which ItemStack that I should use .copy() on.

 

Sorry to bother you so much but I really want to learn this :)

 

package net.be.mods.item;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.be.mods.MainModBE;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class toolJewelChisel extends Item

{

 

private ItemStack emptyItem = null;

private static int maxDamage = 64;

 

    public toolJewelChisel(int id)

    {

        super(id);

        setMaxDamage(64);

        this.setMaxStackSize(1);

        this.setCreativeTab(MainModBE.BETab);

        this.setNoRepair();

       

    }

   

    @Override

    public boolean hasContainerItem() {

    return true;

    }

    public void setEmptyItem(ItemStack ei) {

    this.emptyItem = ei;

    }

    public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack) {

    return false;

    }

    @Override

    public ItemStack getContainerItemStack(ItemStack stack) {

    int dmg = stack.getItemDamage();

    if (dmg == maxDamage) {

    return null;

    }

    ItemStack tr = copyStack(stack, 1);

    tr.setItemDamage(dmg + 1);

    return tr;

    }

    public static ItemStack copyStack(ItemStack stack, int n) {

    return new ItemStack(stack.itemID, n, stack.getItemDamage());

    }

 

    @SideOnly(Side.CLIENT)

    public void registerIcons(IconRegister iconRegister)

    {

        this.itemIcon = iconRegister.registerIcon(MainModBE.modid + ":" + this.getUnlocalizedName().substring(5));

    }

}

Posted

---- Minecraft Crash Report ----

// Would you like a cupcake?

 

Time: 2014-04-03 17:38

Description: Updating screen events

 

java.lang.NullPointerException

at net.minecraft.inventory.SlotCrafting.onPickupFromSlot(SlotCrafting.java:133)

at net.minecraft.inventory.ContainerWorkbench.transferStackInSlot(ContainerWorkbench.java:143)

at net.minecraft.inventory.Container.slotClick(Container.java:282)

at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)

at net.minecraft.inventory.Container.slotClick(Container.java:291)

at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)

at net.minecraft.inventory.Container.slotClick(Container.java:291)

at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)

at net.minecraft.inventory.Container.slotClick(Container.java:291)

at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:477)

at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:820)

at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:559)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:208)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1565)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910)

at net.minecraft.client.Minecraft.run(Minecraft.java:839)

at net.minecraft.client.main.Main.main(Main.java:93)

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:131)

at net.minecraft.launchwrapper.Launch.main(Launch.java:27)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at net.minecraft.inventory.SlotCrafting.onPickupFromSlot(SlotCrafting.java:133)

at net.minecraft.inventory.ContainerWorkbench.transferStackInSlot(ContainerWorkbench.java:143)

at net.minecraft.inventory.Container.slotClick(Container.java:282)

at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)

at net.minecraft.inventory.Container.slotClick(Container.java:291)

at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)

at net.minecraft.inventory.Container.slotClick(Container.java:291)

at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)

at net.minecraft.inventory.Container.slotClick(Container.java:291)

at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:477)

at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:820)

at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:559)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:208)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)

 

-- Affected screen --

Details:

Screen name: net.minecraft.client.gui.inventory.GuiCrafting

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player351'/66, l='MpServer', x=265,96, y=5,62, z=-560,42]]

Chunk stats: MultiplayerChunkCache: 441

Level seed: 0

Level generator: ID 01 - flat, ver 0. Features enabled: false

Level generator options:

Level spawn location: World: (265,4,-558), Chunk: (at 9,0,2 in 16,-35; contains blocks 256,0,-560 to 271,255,-545), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513)

Level time: 266553 game time, 7819 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: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 50 total; [EntityPig['Pig'/8, l='MpServer', x=211,84, y=4,00, z=-636,13], EntityChicken['Chicken'/10, l='MpServer', x=231,44, y=4,00, z=-552,56], EntityPig['Pig'/11, l='MpServer', x=235,88, y=4,00, z=-501,38], EntityItemFrame['entity.ItemFrame.name'/13, l='MpServer', x=255,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/14, l='MpServer', x=255,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/15, l='MpServer', x=255,50, y=6,50, z=-559,06], EntityPig['Pig'/16, l='MpServer', x=246,91, y=4,00, z=-491,66], EntityItemFrame['entity.ItemFrame.name'/19, l='MpServer', x=257,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/18, l='MpServer', x=256,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/21, l='MpServer', x=258,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/20, l='MpServer', x=258,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/23, l='MpServer', x=256,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/22, l='MpServer', x=257,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/25, l='MpServer', x=258,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/24, l='MpServer', x=257,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/27, l='MpServer', x=256,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/26, l='MpServer', x=269,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/29, l='MpServer', x=269,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/28, l='MpServer', x=269,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/31, l='MpServer', x=268,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/30, l='MpServer', x=268,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/34, l='MpServer', x=267,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/35, l='MpServer', x=266,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/32, l='MpServer', x=267,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/33, l='MpServer', x=267,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/38, l='MpServer', x=265,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/39, l='MpServer', x=264,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/36, l='MpServer', x=266,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/37, l='MpServer', x=265,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/42, l='MpServer', x=263,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/43, l='MpServer', x=263,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/40, l='MpServer', x=264,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/41, l='MpServer', x=264,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/46, l='MpServer', x=262,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/47, l='MpServer', x=262,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/44, l='MpServer', x=263,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/45, l='MpServer', x=262,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/51, l='MpServer', x=260,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/50, l='MpServer', x=261,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/49, l='MpServer', x=261,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/48, l='MpServer', x=261,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/55, l='MpServer', x=260,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/54, l='MpServer', x=259,50, y=4,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/53, l='MpServer', x=259,50, y=5,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/52, l='MpServer', x=259,50, y=6,50, z=-559,06], EntityClientPlayerMP['Player351'/66, l='MpServer', x=265,96, y=5,62, z=-560,42], EntityPig['Pig'/58, l='MpServer', x=259,03, y=4,00, z=-506,94], EntityItemFrame['entity.ItemFrame.name'/57, l='MpServer', x=268,50, y=6,50, z=-559,06], EntityItemFrame['entity.ItemFrame.name'/56, l='MpServer', x=260,50, y=5,50, z=-559,06], EntityBat['Bat'/60, l='MpServer', x=289,75, y=5,10, z=-561,25]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:440)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2312)

at net.minecraft.client.Minecraft.run(Minecraft.java:857)

at net.minecraft.client.main.Main.main(Main.java:93)

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:131)

at net.minecraft.launchwrapper.Launch.main(Launch.java:27)

 

-- System Details --

Details:

Minecraft Version: 1.6.4

Operating System: Windows 7 (amd64) version 6.1

Java Version: 1.7.0_51, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 743305912 bytes (708 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 9648 (540288 bytes; 0 MB) allocated, 12 (672 bytes; 0 MB) used

Suspicious classes: FML and Forge are installed

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v8.11 FML v6.4.49.965 Minecraft Forge 9.11.1.965 4 mods loaded, 4 mods active

mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{6.4.49.965} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{9.11.1.965} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

beautifulexistence{Pre-alpha v0.001} [bE mods] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.6

LWJGL: 2.9.0

OpenGL: AMD Radeon HD 7570 GL version 4.2.11476 Compatibility Profile Context, ATI Technologies Inc.

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Pack: Default

Current Language: English (US)

Profiler Position: N/A (disabled)

Vec3 Pool Size: 124 (6944 bytes; 0 MB) allocated, 46 (2576 bytes; 0 MB) used

Posted

Try and only return true from hasContainerItem when the passed in ItemStack doesn't have max damage.

 

Ok. I am really confused why this didn't work.

 

    public boolean hasContainerItem(ItemStack stack) {

      if (stack.getItemDamage() < maxDamage){

          return true;

      }else{

      return false;

      }

    }

 

Is it because I'm not using the original method?

Or am I wrong there?

Posted

I just saw you are using 1.6.4. With that this method doesn't work.

With 1.6.4 you need to return an ItemStack that has more damage than the max damage from getContainerItemStack and it will be automatically destroyed.

 

Here's the code that now works for me, maybe you could check and see if there might be a problem in the future or anything, but now it works as far as I can see.

Thanks you SO much for all your help! I don't think I could've done it without your help. Fast response and good answers.

I liked that you gave me directions and not just gave me the answer. Thank you so very much! Increadibly greatful! :)

 

package net.be.mods.item;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.be.mods.MainModBE;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class toolJewelChisel extends Item

{

 

private ItemStack emptyItem = null;

private static int maxDamage = 64;

 

    public toolJewelChisel(int id)

    {

        super(id);

        setMaxDamage(64);

        this.setMaxStackSize(1);

        this.setCreativeTab(MainModBE.BETab);

        this.setNoRepair();

       

    }

   

    @Override

    public boolean hasContainerItem() {

    return true;

    }

    public void setEmptyItem(ItemStack ei) {

    this.emptyItem = ei;

    }

    public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack) {

    return false;

    }

@Override

public ItemStack getContainerItemStack(ItemStack stack)

{

stack.setItemDamage(stack.getItemDamage() + 1);

return stack;

}

    public static ItemStack copyStack(ItemStack stack, int n) {

    return new ItemStack(stack.itemID, n, stack.getItemDamage());

    }

 

    @SideOnly(Side.CLIENT)

    public void registerIcons(IconRegister iconRegister)

    {

        this.itemIcon = iconRegister.registerIcon(MainModBE.modid + ":" + this.getUnlocalizedName().substring(5));

    }

}

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
    • Instructions on how to install newer Java can be found in the FAQ
  • Topics

×
×
  • Create New...

Important Information

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