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 made a sword item that summons in mobs while taking 1 durability. problem is when it reaches zero it doesn't break, and keeps reducing the durability. when I use the .setdamage as soon as I click the item it reduces the durability to zero and still works until I try to hit a mob, then I breaks. how should I fix this.

 

heres my code

package com.OlympiansMod.Item;

import com.OlympiansMod.entity.EntityUndead;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class DioceltiansSepter extends ItemSword{

public DioceltiansSepter(ToolMaterial p_i45356_1_) {
	super(p_i45356_1_);
	// TODO Auto-generated constructor stub
}

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){
	if(!player.capabilities.isCreativeMode){

	itemstack.setItemDamage(itemstack.getItemDamage() + 1);
	player.attackEntityFrom(DamageSource.causeIndirectMagicDamage(player, player), 10);



	}	
	if(!world.isRemote){


	//for (int i = 0 ; i < 5 ; i++){
	EntityUndead undead = new EntityUndead(world);
	undead.setPosition(player.posX + 1, player.posY, player.posZ);
	world.spawnEntityInWorld(undead);

	EntityUndead undead2 = new EntityUndead(world);
	undead2.setPosition(player.posX, player.posY, player.posZ + 1);
	world.spawnEntityInWorld(undead2);

	EntityUndead undead3 = new EntityUndead(world);
	undead3.setPosition(player.posX, player.posY, player.posZ - 2);
	world.spawnEntityInWorld(undead3);

	EntityUndead undead4 = new EntityUndead(world);
	undead4.setPosition(player.posX - 2, player.posY, player.posZ);
	world.spawnEntityInWorld(undead4);

	EntityUndead undead5 = new EntityUndead(world);
	undead5.setPosition(player.posX + 1.5, player.posY, player.posZ);
	world.spawnEntityInWorld(undead5);



}



//}
	return itemstack;
}
}


Im serious don't look at it!!

You probably need to check yourself if the durability is below 0. Then break the item.

how do you get when the item breaks?

 

When? Check to see if the durability is 0.

 

How? I have no idea, check an item tool class, might have something in there.

What do you mean? Like I said... Do it yourself.

 

Pseudo code:

 

if(itemstack.getDurability() <= 0){

    return null;

    //play breaking animation

}else{

    return itemstack;

}

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.