Jump to content

[1.7.10] Can't mine blocks while setting stack NBT


HappyKiller1O1

Recommended Posts

This is so weird, I am using NBT as a timer and basically while I set it for the hammer I can't mine blocks. It keeps canceling. Here is how I use it:

public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean flag) { //3600 = 3 minutes
	fixNBT(stack);

	if(!world.isRemote) {
		if(stack.stackTagCompound.getBoolean("AutoRepair")) {
			if(stack.isItemDamaged()) {
				int autoRepairDelay = stack.stackTagCompound.getInteger("RepairBase");

				if(autoRepairDelay < stack.stackTagCompound.getInteger("RepairDelay")) {
					autoRepairDelay++;
					stack.stackTagCompound.setInteger("RepairBase", autoRepairDelay);
				}

				LogHelper.logInfo("Delay: " + autoRepairDelay); //TODO WORK ON AUTO REPAIR

				if(autoRepairDelay == stack.stackTagCompound.getInteger("RepairDelay")) {
					stack.damageItem(-1, (EntityPlayer)entity);

					stack.stackTagCompound.setInteger("RepairBase", 0);
				}
			}
		}
	}
}

 

All I can say is it cancels while it sets NBT. Pretty weird so any help is appreciated.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

When Minecraft detects even a slight change in the ItemStack the player is holding, like changing hotbar slot, or changing the ItemStack's NBT, it resets the break timer, and does that animation. I believe Tinkers' Construct fixes this by not changing the NBT when the tool is used.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

So I have this to check if the item is in use:

if(player.getItemInUse() != stack) {
						LogHelper.logInfo(player.getItemInUse());

						int autoRepairDelay = stack.stackTagCompound.getInteger("RepairBase");

						if(autoRepairDelay < stack.stackTagCompound.getInteger("RepairDelay")) {
							autoRepairDelay++;
							stack.stackTagCompound.setInteger("RepairBase", autoRepairDelay);
						}

						LogHelper.logInfo("Delay: " + autoRepairDelay); //TODO WORK ON AUTO REPAIR

						if(autoRepairDelay == stack.stackTagCompound.getInteger("RepairDelay")) {
							stack.damageItem(-1, player);

							stack.stackTagCompound.setInteger("RepairBase", 0);
						}
					}

 

But, the Item in use is CONSTANTLY null. How does Minecraft determine if the Item is in use?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

So, I found this example of reflection here:

http://examples.javacodegeeks.com/core-java/reflection/java-reflection-example/

 

My two questions are, do I have to do EVERYTHING shown in order to retrieve the field and set it accessible? Or, can I just set the class and make it accessible? And, do I have to make a separate reflection class or, can I put the reflection in my Item class?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

If you think you read enough, look at this:

 

List<IResourcePack> defaultResourcePacks = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "defaultResourcePacks", "field_110449_ao");

 

Example of usage reflection in MC.

And yeah - use ObfRefHelper to make it work after compiling, you need to find correct obfuscated field for one you want to access.

 

Next post will probably tell you where to look for them, as I don't remember now. :D

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Better idea:

Rather than counting a timer in your NBT, save a worldTime plus your delay, and wait for the world's time to exceed the time you saved in the NBT.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If you think you read enough, look at this:

 

List<IResourcePack> defaultResourcePacks = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "defaultResourcePacks", "field_110449_ao");

 

Example of usage reflection in MC.

And yeah - use ObfRefHelper to make it work after compiling, you need to find correct obfuscated field for one you want to access.

 

Next post will probably tell you where to look for them, as I don't remember now. :D

 

That seemed to work. :P

 

@Draco18s I would do that but, considering it takes twenty minutes for a full day and night cycle more or less. Wouldn't it only run every twenty minutes?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Well, I used what Ernio said and it works. :P World time would probably be more efficient but, I think the way I have it now is fine too. :P Thanks for all the help guys! Couldn't of done it without you. :D

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Well, I used what Ernio said and it works. :P World time would probably be more efficient but, I think the way I have it now is fine too. :P Thanks for all the help guys! Couldn't of done it without you. :D

 

Note:

Reflection is slow.  And I don't mean in a "don't do it much" kind of way, I mean in a "don't do it in the onUpdate of any object" way.

 

While I don't think the following description is technically accurate, but it might explain the problem conceptually:

 

Try...catch spawns a thread and waits for it to either crash (catching the exception) or finish executing.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

While I don't think the following description is technically accurate, but it might explain the problem conceptually:

 

Try...catch spawns a thread and waits for it to either crash (catching the exception) or finish executing.

Not sure what you are saying here. But if it means that try-catch is slow, that's not true either.

Try-catch is basically free. Unless an exception actually happens, which is then quite slow, but that's ok, since it's an exception, meaning it's exceptional that it happens.

 

False.

I had code wrapped in try...catch (a method.invoke call) in a block-update function (ASM injection).

It ran so hilariously slow as to take 10 seconds for water to flow 1 block But /forge tps still reported 20 ticks a second.

Removing the try...catch fixed it.

The only reason i could remove the try...catch was because the calling method was ASMed and the compiler couldn't complain about the unhandled exception involved.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Kind of without Internet at the moment, but I'll try and remember when I get home again.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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