Jump to content

[1.7.10] onPlayerStoppedUsing not running


Sythiex

Recommended Posts

I have an item with NBT data that I want to be reset to 0 when the player releases the right mouse button, but I can't figure out why onPlayerStoppedUsing() isn't being called. I'm probably overlooking something simple, here's the code:

 

public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int ticks)
    {
	System.out.println("working");
	itemStack.stackTagCompound.setInteger("castTime", 0);
    }

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
    {
	if(!world.isRemote)
	{
		ChunkCoordinates coords = player.getBedLocation(player.dimension);
		if(coords != null)
		{
			if(itemStack.stackTagCompound.getInteger("cooldown") == 0)
			{
				player.setItemInUse(itemStack, getMaxItemUseDuration(itemStack));
				if(itemStack.stackTagCompound.getInteger("castTime") >= maxCastTime)
				{
					player.setPositionAndUpdate(coords.posX + .5, coords.posY + 1, coords.posZ + .5);
					itemStack.stackTagCompound.setInteger("cooldown", maxCooldown);
					itemStack.stackTagCompound.setInteger("castTime", 0);
				}
				else
				{
					int timeCast = itemStack.stackTagCompound.getInteger("castTime") + 1;
					itemStack.stackTagCompound.setInteger("castTime", timeCast);
				}
			}
			return itemStack;
		}
		else
		{
			player.addChatMessage(new ChatComponentTranslation("msg.hearthstoneFailed.txt"));
			return itemStack;
		}
	}
	else
		return itemStack;
    }

public int getMaxItemUseDuration(ItemStack itemStack)
    {
        return 100;
    }

Link to comment
Share on other sites

Try adding @Override on onPlayerStoppedUsing method, to check if it overrides the correct method on item.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

I have an item with NBT data that I want to be reset to 0 when the player releases the right mouse button, but I can't figure out why onPlayerStoppedUsing() isn't being called. I'm probably overlooking something simple, here's the code:

 

public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int ticks)
    {
	System.out.println("working");
	itemStack.stackTagCompound.setInteger("castTime", 0);
    }

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
    {
	if(!world.isRemote)
	{
		ChunkCoordinates coords = player.getBedLocation(player.dimension);
		if(coords != null)
		{
			if(itemStack.stackTagCompound.getInteger("cooldown") == 0)
			{
				player.setItemInUse(itemStack, getMaxItemUseDuration(itemStack));
				if(itemStack.stackTagCompound.getInteger("castTime") >= maxCastTime)
				{
					player.setPositionAndUpdate(coords.posX + .5, coords.posY + 1, coords.posZ + .5);
					itemStack.stackTagCompound.setInteger("cooldown", maxCooldown);
					itemStack.stackTagCompound.setInteger("castTime", 0);
				}
				else
				{
					int timeCast = itemStack.stackTagCompound.getInteger("castTime") + 1;
					itemStack.stackTagCompound.setInteger("castTime", timeCast);
				}
			}
			return itemStack;
		}
		else
		{
			player.addChatMessage(new ChatComponentTranslation("msg.hearthstoneFailed.txt"));
			return itemStack;
		}
	}
	else
		return itemStack;
    }

public int getMaxItemUseDuration(ItemStack itemStack)
    {
        return 100;
    }

 

1.Every function you are overriding (right click, etc) must have @Override above it in order for it to be called.

2.Have you looked the code for ItemBow?

Link to comment
Share on other sites

1.Every function you are overriding (right click, etc) must have @Override above it in order for it to be called.

2.Have you looked the code for ItemBow?

 

I have tried putting @Override on just about everything, but it neither fixes the issue nor breaks my code, so I left them out. And I did read through ItemBow, but I didn't see anything I was missing.

Link to comment
Share on other sites

Of course it has no effect.. @Override is just a check. And if it doesnt give any errors, then it is fine.

+ does "working" not get printed?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

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

    • The game crashed whilst exception ticking world Error: java.lang.NullPointerException: Cannot invoke "net.minecraft.resources.ResourceLocation.equals(Object)" because "this.lootTableId" is null Error given is above. I was already playing for around 15 minutes and wasn't doing anything specific or even breaking anything when the crashed happened. This is update 1.19.2 forge: 43.2.23 Mod list: ESSENTIAL Mod (by SparkUniverse_) Traveler's Titles (Forge) (by YUNGNICKYOUNG) Resourceful Config (by ThatGravyBoat) Dynamic Lights (by atomicstrykergrumpy) TenzinLib (by CommodoreThrawn) Nature's Compass (by Chaosyr) Library Ferret - Forge (by jtl_elisa) Cold Sweat (by Mikul) Simple Voice Chat (by henkelmax) Waystones (by BlayTheNinth) Carry On (by Tschipp) [Let's Do] Meadow (by satisfy) Creeper Overhaul (by joosh_7889) AutoRegLib (by Vazkii) Moonlight Lib (by MehVahdJukaar) AppleSkin (by squeek502) Xaero's World Map (by xaero96) Rotten Creatures (by fusionstudiomc) YUNG's API (Forge) (by YUNGNICKYOUNG) Village Artifacts (by Lothrazar) Right Click, Get Crops (by TeamCoFH) Supplementaries (by MehVahdJukaar) Automatic Tool Swap (by MelanX) Better Third Person (by Socolio) Supplementaries Squared (by plantspookable) Traveler's Backpack (by Tiviacz1337) Caelus API (Forge/NeoForge) (by TheIllusiveC4) Creatures and Beasts (by joosh_7889) Architectury API (Fabric/Forge/NeoForge) (by shedaniel) Quark Oddities (by Vazkii) Origins (Forge) (by EdwinMindcraft) Villager Names (by Serilum) GeckoLib (by Gecko) Realistic Bees (by Serilum) Illuminations Forge 🔥 (by dimadencep) Serene Seasons (by TheAdubbz) Critters and Companions (by joosh_7889) [Let's Do] Bakery (by satisfy) Falling Leaves (Forge) (by Cheaterpaul) Jade 🔍 (by Snownee) Collective (by Serilum) TerraBlender (Forge) (by TheAdubbz) [Let's Do] API (by Cristelknight) Towns and Towers (by Biban_Auriu) More Villagers (by SameDifferent) Biomes O' Plenty (by Forstride) Goblin Traders (by MrCrayfish) Corpse (by henkelmax) Tree Harvester (by Serilum) Balm (Forge Edition) (by BlayTheNinth) Mouse Tweaks (by YaLTeR) Sound Physics Remastered (by henkelmax) Xaero's Minimap (by xaero96) Just Enough Items (JEI) (by mezz) Terralith (by Starmute) Quark (by Vazkii) [Let's Do] Vinery (by satisfy) [Let's Do] Candlelight (by satisfy) Repurposed Structures (Neoforge/Forge) (by telepathicgrunt) Dusty Decorations (by flint_mischiff) Immersive Armors [Fabric/Forge] (by Conczin) Serene Seasons Fix (by Or_OS) Shutup Experimental Settings! (by Corgi_Taco) Skin Layers 3D (Fabric/Forge) (by tr7zw)
    • Make sure Java is running via Nvidia GPU https://windowsreport.com/minecraft-not-using-gpu/  
    • Also make a test with other Custom Launchers like AT Launcher, MultiMC or Technic Launcher
    • Embeddium and valkyrienskies are not working together - remove one of these mods With removing Embeddium, also remove Oculus, TexTrue's Embeddium Options and Embeddium Extras Or use Rubidium instead
  • Topics

×
×
  • Create New...

Important Information

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