Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Telling how long left click is held down
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
GravityWolf

Telling how long left click is held down

By GravityWolf, September 25, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

GravityWolf    1

GravityWolf

GravityWolf    1

  • Stone Miner
  • GravityWolf
  • Members
  • 1
  • 98 posts
Posted September 25, 2013

Hello! I'm working on a melee/ranged weapon, but I want it so you only have to use left click, as I am using dual wielding. So I'm going to try to set it up so if you hold down left click for about 1 second and let go, it shoots an entity. (Don't worry, I don't need help with that :P) So here's my code so far to stop the swing:

 

if (weaponAbility == "chakram") {
            	
            	if (player.isSwingInProgress) {
            	
            	player.isSwingInProgress = false;
            
            	}
            	
            }

 

This is in onUpdate, just by the way. So, anyone have any ideas? Thanks!

  • Quote

Share this post


Link to post
Share on other sites

Mew    36

Mew

Mew    36

  • Dragon Slayer
  • Mew
  • Members
  • 36
  • 567 posts
Posted September 25, 2013

Seems a bit... Sketchy.

 

But anyway. What I would do is make a TickHandler for client ( or is it server in this instance? :/ ) that would take a Boolean from the item that is called, something like: isThisItemLeftClickingOrNot. Then do a check in the handler to see if it is, and then add 1 onto a counter. Then, if the counter is over 20 ticks ( I believe that is one second ) wait, or keep adding, until the variable is false again. Then in the else statement, do another check to see if the counter is greater than 20 ( or however many ticks a second is ).

 

Example:

// TickHandler stuff...
// in whatever method it is
if ( player.getHeldItem ().getItem ().itemId == YourMod.YourItem.itemId ) {
    if ( YourMod.YourItem.getIsThisItemLeftClickingOrNot )
        counter++;
    else {
        if ( counter >= 20 ) {
            // RELEASE THE ENTITY! Maybe... This should be server side  Ignore the client side above 
        }
    }
}
// More TickHandler stuff..

 

So yeah.. Something along those lines. You could also make the tickhandler set a Boolean in the item and check it using the left click function to release the entity... I am not sure which is cleaner. I would assume doing it from the TickHandler would be a bit quicker.

 

Hope this helps :D

  • Quote

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Share this post


Link to post
Share on other sites

GotoLink    381

GotoLink

GotoLink    381

  • World Shaper
  • GotoLink
  • Members
  • 381
  • 2012 posts
Posted September 26, 2013

if (weaponAbility == "chakram") {

String are immutable. Use .equals(obj) instead. ;)

 

I don't have anything to add to what Mew said.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Jack Richard
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By Jack Richard · Posted 2 hours ago

      Thanks so much for your help! I removed the log4j dependency, I honesty don't remember when I put that there. Once I fixed the jar.finalizedBy line, everything worked! (One small issue where I was relocating all of "com.google" when I just should've relocated "com.google.common," too)   Thanks again!
    • Teedledee
      1.16.4 Failed to synchronize registry data with server LAN

      By Teedledee · Posted 2 hours ago

      Fixed the issue, one config didnt match, downloaded randompatches to solve badly compressed packet afterwards.
    • DaemonUmbra
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By DaemonUmbra · Posted 2 hours ago

      First of all, why are you shadowing log4j? Minecraft already provides log4j2. Second if build is running shadowjar instead of jar then you might need to tweak the line where it says jar.finalizedBy('reobfJar') to finalize shadowJar instead
    • DaemonUmbra
      "The game crashed whilst rendering overlay"

      By DaemonUmbra · Posted 2 hours ago

      What do you think you should do about this?
    • DaemonUmbra
      IntelliJ doesn't include resources folder while debugging

      By DaemonUmbra · Posted 2 hours ago

      What version of Minecraft are you using?
  • Topics

    • Jack Richard
      2
      [1.15.2] Minecraft Registry Problem When Loading from Jar

      By Jack Richard
      Started 2 hours ago

    • Teedledee
      2
      1.16.4 Failed to synchronize registry data with server LAN

      By Teedledee
      Started January 18

    • GuyWithTVHead
      1
      "The game crashed whilst rendering overlay"

      By GuyWithTVHead
      Started 2 hours ago

    • GermanBucket
      2
      IntelliJ doesn't include resources folder while debugging

      By GermanBucket
      Started 4 hours ago

    • Arthurmeade12
      8
      Error Conecting to My Minecraft Server

      By Arthurmeade12
      Started Saturday at 11:05 PM

  • Who's Online (See full list)

    • ChampionAsh5357
    • CaelTheQuail
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Telling how long left click is held down
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community