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

Hi all, I'd just like to preface this by saying that I'm fairly new to the modding scene.

 

That being said, I'm having a bit of trouble here. I'm trying to make a custom sword class that will give the player a resistance effect while blocking. In order to do that, I figured that I would use the isBlocking method, seeing as it is made to check if the player is blocking. However, doing this will completely freeze the game once I block, at least with the way I'm coding this. I think that this might be an infinite loop situation, but I can't for the life of me figure out why this would be the case. Any suggestions on how to fix this? All help is appreciated!

 

 

 

@Override

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {

 

if(entity instanceof EntityPlayer) {

EntityPlayer player = (EntityPlayer) entity;

 

ItemStack equipped = player.getCurrentEquippedItem();

 

if(equipped == stack) {

 

if(swingSpeed == 0) {}

else if (swingSpeed == 1) {

player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 0));

}

 

else if (swingSpeed == 2) {

player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 1));

}

 

if (blockEnhance != 0) {

while (player.isBlocking()) {

if (blockEnhance == 1) {

player.addPotionEffect(new PotionEffect(Potion.resistance.id, 1, 0));

}

else if (blockEnhance == 2) {

player.addPotionEffect(new PotionEffect(Potion.resistance.id, 1, 1));

}

        }

        }

}

}

}

 

 

 

By the way, the main thing I'm having trouble with there is everything to do with the blockEnhance variable (basically the while loop and down). Everything above that works fine.

 

Do you know what while means?

Do you know how code is run on java?

Do you know how minecraft code runs?

If any of these = no - it's bad...

Try to understand these and if you do, you will find a problem. If you don't, come back here and we will explain you things more detailed...

 

Try:

 

 

@Override
   public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
      
      if(entity instanceof EntityPlayer) {
         EntityPlayer player = (EntityPlayer) entity;
      
         ItemStack equipped = player.getCurrentEquippedItem();
      
         if(equipped == stack) {
         
            if(swingSpeed == 0) {}
            else if (swingSpeed == 1) {
               player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 0));
            }
            
            else if (swingSpeed == 2) {
               player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 1));
            }
         
            if (blockEnhance != 0) {
               if(player.isBlocking() == true) {
                  if (blockEnhance == 1) {
                     player.addPotionEffect(new PotionEffect(Potion.resistance.id, 1, 0));
                  }
                  else if (blockEnhance == 2) {
                     player.addPotionEffect(new PotionEffect(Potion.resistance.id, 1, 1));
                  }
                 }
                else
                {
                   //remove potion effect, I forget the exact code here
                }
              }
         }
      }
   }

 

if(pain == 0)

{

   gain = 0;

}

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.