Jump to content

[SOLVED] Preventing 1st-person item change animation?


coolAlias

Recommended Posts

EDIT: Closed. Thanks Lex!

 

I've tracked this down to ItemRenderer#renderItemInFirstPerson which is the only place that actually uses the equippedProgress and prevEquippedProgress to affect how the item is rendered.

 

I've got an item that I don't want to have this 'animation' - I want it to appear in place just as it does in 3rd person, right when the player switches to it (it's actually to accommodate changing NBT [and no, I can't store it elsewhere in this case]).

 

Has anyone ever come up with a solution for this?

 

If not, how about the following solution:

 

 

It seems with all the other useful Item hooks available, there should be something like 'Item#shouldRefresh(ItemStack, ItemStack)' called from ItemRenderer#updateEquippedItem:

if (!this.itemToRender.getIsItemStackEqual(itemstack))
{
    flag = this.itemToRender.shouldRefresh(this.itemToRender, itemstack);
}

The default Item implementation would of course simply return 'true'. Would that not be useful? I know I'm not the first to encounter this limitation; the usual workaround for NBT at least is to store the data elsewhere, e.g. IEEP, but the above would, in my opinion, be a much simpler solution.

 

Can anyone think of any drawbacks to it? Is there another way already available for those cases in which it is not possible to use IEEP or other storage devices? What about if the item should simply not have any animation, regardless of NBT?

 

EDIT: Actually, it would make more sense to call the method for the second itemstack, since that would be the one that should be current, but it won't become current unless the flag is true... damn. See second solution below.

 

 

EDIT: The following solution is much better than the one in the spoiler above:

Another possible solution would be to have something like Item#getFirstEquippedProgress(ItemStack current, ItemStack previous, float equippedProgress) at this point:

if (this.equippedProgress < 0.1F)
{
  this.equippedProgress = itemstack.getItem().getFirstEquippedProgress(itemstack, this.itemToRender, this.equippedProgress);
  this.itemToRender = itemstack;
  this.equippedItemSlot = entityplayersp.inventory.currentItem;
}

I added in the current equippedProgress so the default Item implementation has an easy return value, and note that returning 1.0F will prevent any unwanted equip animation - heck, it could even just be a boolean return value, really, but the float gives more control.

 

Thanks for reading,

coolAlias

Link to comment
Share on other sites

I'm curious if this will also remove the bobbing animation that happens when you modify the NBT tags of an item stack that is in use. I had that problem awhile back, but decided the information I needed stored was better tied to the entity instead of the stack. Still, I must test this.

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

Link to comment
Share on other sites

I'm curious if this will also remove the bobbing animation that happens when you modify the NBT tags of an item stack that is in use.

That is the animation and problem he is talking about.

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

There is Item#getShareTag() which could be used to prevent the itemstack NBT from being sent to the client, which would presumably stop the animation change for that particular case, but then you couldn't use the NBT data at all for rendering.

 

So, it seems that currently there is no possible way (i.e. without ASM) to do what I am attempting.

 

In that light, does anyone have any comments on my proposed solution? Can you think of any situations it would not handle well? Is there a better way?

 

I ask because I don't want to go to the trouble of learning how to submit a proper PR to Forge (I tried once before but I had just edited the files directly, which is apparently a big no-no) and putting one together only to have it rejected for something stupid I didn't consider.

Link to comment
Share on other sites

Hi

There was a topic on this very same problem a while back (solved), I've even had to switch to IEEP because of this. I have found a close solution - reflection. Setting the equipped progress to 1.0F when setting / changing the NBT of an item. However, checking every tick if the tag is being changed and setting the value to 1.0F causes major rendering problems when trying to switch to another item (It continues to render the same item regardless of what item is actually equipped).

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

 

long ago i try something like but not soo deep like the yours

 

http://www.minecraftforge.net/forum/index.php/topic,27461.msg140547.html#msg140547

 

an i have ideas but i could not disable the thing i call "switchAnimation"

then i think the trouble is the nbttag system trigering it so if i dont use it it would'n be trouble

then research and learn how to to write data to a json file creating  a custom storing class whith the variables i need to use 

in this storing class i asign a serial number for every gun create whith mi mod to keep values from mixing betwin each other

every five minutes a server ticks class check if the vaules in the storing class has change if its so it writes the values to the json file it is not then it leave it alono for another five minutes

in teory works but then i realize the tragedy.

when you set an item in use it triggers again the swtching animation so you could not avoid the animation

 

what i do, just learn to live whith it making the code store al the nbttags from the shooting at same time to reduce the times the items switchs to only two per shoot

http://www.curse.com/mc-mods/minecraft/228033-mercenarymod

 

 

i not in your level whith  the minecraft code

 

this

equippedProgress thing is an event caugth or where are you doing this ???

 

 

 

 

 

 

 

Link to comment
Share on other sites

It's not something I have done, it's something I am proposing we add to Forge so that we can avoid crazy workarounds like the one you implemented.

 

The fact that some modders go to such great lengths to prevent this stupid forced animation is, in my opinion, a strong indicator that my proposal is at least in the right direction, and I think it would solve these issues pretty elegantly with minimal code.

 

Again, if anyone can think of a better way to do it, or has suggestions of how to improve mine, I'm all ears, but something needs to be done.

 

If Lex Manos or anyone else on the Forge team happens to read this, would there be any reasons you can think of that my suggestion would be rejected as a PR?

Link to comment
Share on other sites

I myself just don't see why an animation has to play when the item is refreshed / updated. All the fields are private, and yes, reflection is hacky considering all the work-arounds that you must do to try and get it to work. I did but it was not efficient and extremely hacky. Hope that the Forge Devs work this out as it has caused a lot of trouble with my mods causing me to fall back on IEEP and packets.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

Actually, there is still an issue with it. The way it has been implemented prevents any changes in NBT from affecting the rendering of the item if you don't allow the re-equip animation to play. This would be resolved using my implementation, but I don't want to keep pestering Lex with issues (I opened one and immediately after saw his commit in the change log... doh).

 

This issue is now closed. Many thanks to Lex for implementing this!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have this raport to lounch the game The game crashed whilst rendering screen Error: java.lang.NullPointerException: Cannot invoke "net.minecraft.client.gui.components.Button.m_252907_()" because "this.serverBrowser$grabbedMultiplayerButton" is null Kod zakończenia: -1 And full message:   https://ntpd.eu/N3gq6
    • EDIT: I had to declare the library like a mod (using the @Mod annotation and adding the mods.toml + pack.mcmeta files). By doing this it works now Hi everyone  I'm trying to create an internal library for all my mods, and inside it I have a method that registers an Item public static RegistryObject<Item> registerItem(final DeferredRegister<Item> registry, final String name, final Supplier<Item> itemSupplier) { return registry.register(name, itemSupplier); } When the method is called from a mod, Forge raises this error   Exception message: java.lang.LinkageError: loader constraint violation: loader 'SECURE-BOOTSTRAP' @6bedbc4d wants to load class net.minecraftforge.registries.DeferredRegister. A different class with the same name was previously loaded by 'TRANSFORMER' @6d672bd4. (net.minecraftforge.registries.DeferredRegister is in module [email protected] of loader 'TRANSFORMER' @6d672bd4, parent loader 'bootstrap') Both the version of Forge included in the library's build.gradle and the mod's build.gradle are the same. I've never done this, so there's a good chance I'm configuring something wrong. This is the build.gradle file of the library (which is part of a multi-module project)   plugins { id 'net.minecraftforge.gradle' version '[6.0.24,6.2)' } repositories { gradlePluginPortal() maven { name = 'MinecraftForge' url = 'https://maven.minecraftforge.net/' } } java.toolchain.languageVersion = JavaLanguageVersion.of(21) minecraft { mappings channel: 'official', version: minecraft_version reobf = false copyIdeResources = true } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } } } tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' }  
    • Hello i wanna make a modded server for me and my friends and the game is crashing when i use items that pop-up and UI and we cannot place modded blocks.  Here is the video i take so it's more easy for you guys to see.   Help please! Thanks
    • The thought process for this would be checking the EnderMan class, as its not behaviour intrinsecally connected to the item but rather the enderman: The EnderMan.isLookingAtMeMethod should return false when a player is wearing your armour piece. In that method you can see a call to ForgeHooks.shouldSuppressEnderManAnger() which uses an ItemStack of the object on the players head. This uses IForgeItem's isEnderMask method that brings you to: default boolean isEnderMask(ItemStack stack, Player player, EnderMan endermanEntity) { return stack.getItem() == Blocks.CARVED_PUMPKIN.asItem(); } which means you can override it on your armour item (since all item classes extend from IForgeItem, including ArmorItem from which you will most likely want to extend from)   As for the second thing you'll most likely need to get creative: Using levitation can work if you want to make it floaty, but you most likely want to make it work as if the player is walking on air. I'd suggest something along the lines of checking the block immediately in the direction the player is facing, and if its air, place a transparent, solid block the player will walk on. As the player walks in some arbitrarry direction, keep checking to generate blocks in their path as well as deleting the ones left behind/in any direction the player isn't looking at. You will have to get *even more creative* to think how can you implement it as for only the armour user can stand on air (placing a solid block will make anyone be able to stand on it regardless of if wearing the armour or not)   So yeah. First thing pretty straightforward, second one youll have to make your own idea around it.
  • Topics

×
×
  • Create New...

Important Information

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