Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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

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

if (weaponAbility == "chakram") {

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

 

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.