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

    • Beethoven92
      Error at load_registries event phase

      By Beethoven92 · Posted 1 minute ago

      Apparently here: BlockList.tutorial_slab = new SlabBlock(Block.Properties.from(BlockList.tutorial_slab)).setRegistryName(location("tutorial_slab")) your BlockList.tutorial_slab block is null when the block registration event is fired..i suggest you use deferred register to manage your registry entries
    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 7 minutes ago

      Ah there ya go! Thanks.
    • Beethoven92
      [1.16.4] Tile Registration

      By Beethoven92 · Posted 10 minutes ago

      public VendingTile(TileEntityType<?> tileEntityTypeIn) You don't need an argument in the constructor of your tile entity as in this case is not used since you are passing the TileEntityType to the super class: super(CommonRegistry.TILE_VENDING.get());  
    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 20 minutes ago

      Hello, I am having issues registering my tile entity. Here is my code as well as a link to the code in my github. The IDE is complaining that 'TileEntityType.Builder.create' has invalid arguments   // Tiles public static final DeferredRegister<TileEntityType<?>> TILE_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, GOCurrency.MODID); public static final RegistryObject<TileEntityType<VendingTile>> TILE_VENDING = TILE_ENTITY_TYPES.register("vending_te", () -> TileEntityType.Builder.create(VendingTile::new, BLOCK_VENDING.get()).build(null));   https://github.com/Beardlessbrady/Currency-Mod/blob/95230ca4ee2d290b3e5f3ef81810a27f73137625/src/main/java/com/beardlessbrady/gocurrency/handlers/CommonRegistry.java#L42-L43
    • ThisIsNotOriginal
      Error at load_registries event phase

      By ThisIsNotOriginal · Posted 1 hour ago

      The pastebin for the log and Registry Event is posted below this text.   https://pastebin.com/KEzJvRgG https://pastebin.com/VUrXR94k
  • Topics

    • ThisIsNotOriginal
      1
      Error at load_registries event phase

      By ThisIsNotOriginal
      Started 1 hour ago

    • BeardlessBrady
      2
      [1.16.4] Tile Registration

      By BeardlessBrady
      Started 21 minutes ago

    • PlasmaPig13
      1
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By PlasmaPig13
      Started 1 hour ago

    • EnderiumSmith
      3
      The vanilla tag system isnt suitable for ore dictionary

      By EnderiumSmith
      Started 14 hours ago

    • Ilikecheese
      0
      forge 1.16.5 wont show up

      By Ilikecheese
      Started 1 hour ago

  • Who's Online (See full list)

    • Microcellule
    • Milk_Shak3s
    • Beethoven92
    • AstroTurffx
    • Jeldrik
    • Azurelmao
    • ichttt
    • Deadlocked47
    • BeardlessBrady
    • ThisIsNotOriginal
    • ehbean
    • That_Tallone
    • squidlex
  • 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