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 everyone,

i have a problem with my durable item ...

in crafting it works fine but when im damaging item with itemstack.setItemDamage(itemstack.getItemDamage() + 1);

it just wont break :( i would appreciate any help

Thank you :)

 

Durable Item class

 

package fewmorethings.items;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import fewmorethings.Main;

import fewmorethings.handlers.BlocksHandler;

import fewmorethings.handlers.ItemsHandler;

import fewmorethings.help.LogHelper;

import fewmorethings.help.Reference;

 

public class ClickSmelt extends Item {

 

public ClickSmelt() {

this.setUnlocalizedName("ClickSmelt");

this.setTextureName(Reference.MODID + ":" + "ClickSmelt");

this.setCreativeTab(Main.fmtab);

this.setMaxDamage(64);

this.setMaxStackSize(1);

}

 

@Override

public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int par1, float par2, float par3, float par4) {

Block blockoneye = world.getBlock(x, y, z);

int metadata = world.getBlockMetadata(x, y, z);

 

if(player.canPlayerEdit(x, y, z, par1, itemstack)) {

//Block to Block

if(blockoneye == Blocks.sand) {

world.setBlock(x, y, z, Blocks.glass);

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

}if(blockoneye == Blocks.glass) {

world.setBlock(x, y, z, BlocksHandler.ClearGlass);

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

}if(blockoneye == Blocks.cobblestone) {

world.setBlock(x, y, z, Blocks.stone);

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

}if(blockoneye == Blocks.clay) {

world.setBlock(x, y, z, Blocks.hardened_clay);

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

//Block to Item

}if(blockoneye == Blocks.iron_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.iron_ingot));

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

}if(blockoneye == Blocks.coal_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.coal));

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

}if(blockoneye == Blocks.gold_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.gold_ingot));

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

}if(blockoneye == Blocks.lapis_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.dye,1,4));

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

}if(blockoneye == Blocks.redstone_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.redstone));

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

}if(blockoneye == Blocks.diamond_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.diamond));

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

}if(blockoneye == Blocks.emerald_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.emerald));

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

}if(blockoneye == Blocks.log || blockoneye == Blocks.log2) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.coal,1,1));

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

}if(blockoneye == Blocks.cactus) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.dye,1,2));

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

}if(blockoneye == Blocks.netherrack) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.netherbrick));

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

}if(blockoneye == Blocks.quartz_ore) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(Items.quartz));

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

}if(blockoneye == BlocksHandler.blockOres && metadata == 0) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(ItemsHandler.Ingots));

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

}if(blockoneye == BlocksHandler.blockOres && metadata == 1) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(ItemsHandler.Ingots,1,1));

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

}if(blockoneye == BlocksHandler.blockOres && metadata == 2) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(ItemsHandler.Ingots,1,2));

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

}if(blockoneye == BlocksHandler.blockOres && metadata == 3) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(ItemsHandler.Ingots,1,3));

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

}if(blockoneye == BlocksHandler.blockOres && metadata == 4) {

world.setBlockToAir(x, y, z);

player.inventory.addItemStackToInventory(new ItemStack(ItemsHandler.Ingots,1,4));

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

}

}

return false;

}

 

@Override

public boolean getShareTag() {

    return true;

}

 

    public boolean hasContainerItem(ItemStack itemStack) {

        return true;

    }

   

    @Override

    public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack) {   

      return false;

    }

   

    @Override

    public ItemStack getContainerItem(ItemStack itemStack) {

        ItemStack stack = itemStack.copy();

 

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

 

        return stack;

    }

}

 

 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

Im sorry, but thats the only way i can do it :/ Im trying to learn ...

If you could help me more i would appreciate that.

And how to do the stack size 0 to null conversion ??

Thank you

 

 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

Im gonna go look at some basic java tutorials

Thank you :)

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

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.