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.

(Solved?) [1.13.2] Custom ItemTool explodes into missing texture particles when it hits 0 durability

Featured Replies

Posted

My item class extends ItemAxe. It has a texture and behaves the same way as normal axes. When it's destroyed due to having 0 durability, the particles that appear are the purple missing texture image. I can't figure out why this happens.

 

Here's the item class:

public class ItemImprovisedAxe extends ItemAxe {
	public ItemImprovisedAxe() {
		super(ItemTier.WOOD, 7.0f, -3.0f, new Item.Properties().addToolType(ToolType.AXE, 1).defaultMaxDamage(33).group(ItemGroup.TOOLS));
		this.setRegistryName(ModInfo.MODID, "improvised_axe");
	}
}

 

Here's src/main/resources/assets/[modid]/models/item/improvised_axe.json:

{
  "parent": "item/handheld",
  "textures": {
    "layer0": "modid:item/improvised_axe"
  }
}

 

The 16x16 texture is src/main/resources/assets/[modid]/textures.item/improvised_axe.png

Edited by treebranch

  • Author

I "fixed" this by overriding the hitEntity, onBlockDestroyed, and onItemUse methods to call my own copy/paste of ItemStack.damageItem, which passes a stack of Items.WOODEN_AXE to EntityLivingBase.renderBrokenItemStack instead of my axe's stack. It's extremely hard to look at, but it works. If anybody has a better solution please let me know still.

 

public class ItemImprovisedAxe extends ItemAxe {
	public ItemImprovisedAxe() {
		super(ItemTier.WOOD, 7.0f, -3.0f, new Item.Properties().addToolType(ToolType.AXE, 1).defaultMaxDamage(33).group(ItemGroup.TOOLS));
		this.setRegistryName(ModInfo.MODID, "improvised_axe");
	}
	
	private final ItemStack WOODEN_AXE_STACK = new ItemStack(Items.WOODEN_AXE);
	
	// from ItemStack
	private void damageItem(ItemStack stack, int amount, EntityLivingBase entityIn) {
		if (!(entityIn instanceof EntityPlayer) || !((EntityPlayer)entityIn).abilities.isCreativeMode) {
			if (/*this*/stack.isDamageable()) {
				if (/*this*/stack.attemptDamageItem(amount, entityIn.getRNG(), entityIn instanceof EntityPlayerMP ? (EntityPlayerMP)entityIn : null)) {
					//entityIn.renderBrokenItemStack(/*this*/stack);
					entityIn.renderBrokenItemStack(WOODEN_AXE_STACK);
					Item item = /*this*/stack.getItem();
					/*this*/stack.shrink(1);
					if (entityIn instanceof EntityPlayer) {
						((EntityPlayer)entityIn).addStat(StatList.ITEM_BROKEN.get(item));
					}

					/*this*/stack.setDamage(0);
				}

			}
		}
	}
	
	@Override
	public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
		//stack.damageItem(2, attacker);
		damageItem(stack, 2, attacker);
		return true;
	}
	
	@Override
	public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
		if (!worldIn.isRemote && state.getBlockHardness(worldIn, pos) != 0.0F) {
			//stack.damageItem(1, entityLiving);
			damageItem(stack, 1, entityLiving);
		}
		return true;
	}
	
	@Override
	public EnumActionResult onItemUse(ItemUseContext p_195939_1_) {
		World world = p_195939_1_.getWorld();
		BlockPos blockpos = p_195939_1_.getPos();
		IBlockState iblockstate = world.getBlockState(blockpos);
		Block block = BLOCK_STRIPPING_MAP.get(iblockstate.getBlock());
		if (block != null) {
			EntityPlayer entityplayer = p_195939_1_.getPlayer();
			world.playSound(entityplayer, blockpos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
			if (!world.isRemote) {
				world.setBlockState(blockpos, block.getDefaultState().with(BlockRotatedPillar.AXIS, iblockstate.get(BlockRotatedPillar.AXIS)), 11);
				if (entityplayer != null) {
					//p_195939_1_.getItem().damageItem(1, entityplayer);
					damageItem(p_195939_1_.getItem(), 1, entityplayer);
				}
			}
			return EnumActionResult.SUCCESS;
		} else {
			return EnumActionResult.PASS;
		}
	}
}

 

Edited by treebranch

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.