Jump to content

Recommended Posts

Posted (edited)

My item gives me a  random item whenever you right click. I tried to utilize the use() method. My issue is that I want to have the user press down the right click button for some time(5 seconds maybe??) and only once that is done should it give the item and repeat if its still held. I tried to use the getUseDuration() method but that doesn't work. I tried to take a look at how its done on some other items(like food items) but i can't figure it out. Can someone help be with this?

Edited by Skelyvelocirap
Posted
3 hours ago, Skelyvelocirap said:

Can someone help be with this?

Within Item#use, you should call PlayerEntity#startUsingItem. This will start using the item when the item is used.

You can set the maximum number of ticks that the item can be used for with the return value of Item#getUseDuration.

While the item is being used, Item#onUseTick will be called every tick, and its integer parameter is the number of ticks left in the use duration. This is probably where you want to put your logic, since you mentioned that the player should be able to keep holding the item to keep the process going.

At some point, the player will release the item, which calls Item#releaseUsing. Its integer parameter is the number of ticks that the item was used for, so you could also put some logic there.

  • Like 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted (edited)

So that's how those work! Alright, thank you! Its now working perfectly! Although one last question. Item#use() needs you to return an Action result. I never really understood those and mostly just copied what others did. My guess is that its what is responsible for the hand movement when you right click(am I correct?). If it is, how exactly would I fix it so that it only does that once Item#onUseTick's tick parameter is 0?



EDIT: Alright so, I'm now using Item#finishUsingItem as there is no need to run my logic every tick. Hopefully this will reduce the already non-existent lag.

Edited by Skelyvelocirap
different method used
Posted
30 minutes ago, Skelyvelocirap said:

My guess is that its what is responsible for the hand movement when you right click(am I correct?). If it is, how exactly would I fix it so that it only does that once Item#onUseTick's tick parameter is 0?

It is responsible for determining how the hand moves, but it also does a bit more.

Each ActionResult<T> has an ActionResultType and an object T. In the case of the ActionResult<ItemStack>, the ItemStack object of the returned ActionResult<ItemStack> is set as the held item.

Additionally, these ActionResultTypes dictate what happens after your Item's logic has been run. They are queried with the ActionResultType#shouldSwing and ActionResultType#consumesAction methods. The former is self-explanitory, while the latter dictates whether or not the click will be further processed.

For example, ActionResultType.SUCCESS both consumes the action and swings. This means that if you held an ender pearl in your offhand, and clicked with an item that returns a successful ActionResult<ItemStack>, the main item would swing, and no ender pearl would be thrown. ActionResultType.PASS doesn't swing or consume, so returning that would result in no animation of the main item, and an unblocked, thrown ender pearl. ActionResultType.CONSUME consumes the action, but doesn't swing, so that's probably what you want here. ActionResultType.FAIL behaves as PASS, but is used more in the context of Block placement, I think, and as a message to prevent a behaviour.

For your purposes, I would probably recommend returning CONSUME unless LIvingEntity#getUseItemRemainingTicks (this is the value passed into Item#onUseTick) fits your requirements (you could also use LivingEntity#getTicksUsingItem), in which case you would return SUCCESS.

It might also be helpful to return true from Item#useOnRelease, so that your item is used when released, in addition to initially.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted

Alright. So ActionResult basically just tells Minecraft whether or not to swing the hand, along with whether or not it should process the item further(so inhibiting other items from doing their thing instead). And so I would simply check(in Item#use) if LivingEntity#getUseItemRemainingTicks is greater than 0, if it is than return Consume, or else success?

For the Item#useOnRelease, i dont think i will do that as what im trying to do is wait until the 5 seconds have passed. If i return true then the user could just spam right click and get it over with.

Posted
4 minutes ago, Skelyvelocirap said:

Alright. So ActionResult basically just tells Minecraft whether or not to swing the hand, along with whether or not it should process the item further(so inhibiting other items from doing their thing instead).

Yup, that's about right.

4 minutes ago, Skelyvelocirap said:

And so I would simply check(in Item#use) if LivingEntity#getUseItemRemainingTicks is greater than 0, if it is than return Consume, or else success?

The exact details of when you should do what depend on how you want it to work and look. Ultimately, that's up to you, so you should try to set something up using these tools, experiment a bit, and figure out what produces the best result. It seems like you mostly understand what's going on here, so that ought to go fairly well.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted

Oops, i didn't submit it.

Alright!

Ok, well it seems to work exactly how i want it to currently! Although, for some reason it still swings the players arms even though im returning ActionResult#consume(stack). Am i supposed to override that somewhere else as well?

Also, this isn't 100% related but what would I need to override to add an animation to the item? I don't mean how do I make an animation(don't quite know how but i should be able to find it on google), rather how do I make it play when the item is held down. I now know that for the items it would be the Item#onUseTick. Is there a similar method for the animation?

Posted
22 minutes ago, Skelyvelocirap said:

Ok, well it seems to work exactly how i want it to currently! Although, for some reason it still swings the players arms even though im returning ActionResult#consume(stack). Am i supposed to override that somewhere else as well?

Please post your code, so that I can see what might be causing this (I won't be able to respond until tomorrow, though, since I need to sleep now).

22 minutes ago, Skelyvelocirap said:

Also, this isn't 100% related but what would I need to override to add an animation to the item? I don't mean how do I make an animation(don't quite know how but i should be able to find it on google), rather how do I make it play when the item is held down. I now know that for the items it would be the Item#onUseTick. Is there a similar method for the animation?

I've never done this before, so my knowledge is limited. Here is a link to the documentation on the topic, though, which seems fairly straightforward.

  • Like 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted

This is your problem.

The boolean parameter of ActionResult<T>#sidedSuccess is whether or not the game is running on the logical client, and so returns success on true, or consume on false. Your condition will usually be true, so a success is usually returned, which causes the item to swing. I don't think it's necessary to use sidedSuccess for this, but if you do, you should pass in World.isClientSide, or an equivalent. Regardless, the condition should be updated.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted

Oops, I forgot I switched to ActionResult#sidedSuccess. And thank you for noticing it was backwards. Although this isn't really the problem. My item is ALWAYS doing that, even if the condition is false(the if statements before it). When the player is not in the correct liquids it should return ActionResult#consume(which it does) but it still swings the players arms. I know this for sure as you might notice that its logging the item in the pan(which i forgot to remove...).

Posted

I've done some testing, and there are 3 things that cause the item to move.

The first is when you return a success, the item will swing. Updating the returns as previously discussed achieves the desired result in this context.

The second is when you return a consume, the item will bob if it is not in use. This means that if you try to use the pan while not able to do any panning, it will bob repeatedly (but not jarringly quickly). If you don't want this, you can return a pass, which has no visual effect.

The third is when you set the damage value every tick. This is what causes the glitchy-looking vibration, and it would seem you can fix it by setting the damage less frequently (once every 3 ticks eliminated all unwanted movement in my experiments).

  • Like 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted

Sweet, it works perfectly now! Im now returning pass instead of consume and updating the progress every 3 ticks. Thank you very much for your help, now my item works exactly like i want it to! Thank you again!

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

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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