Posted July 22, 201510 yr 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.
July 22, 201510 yr 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... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
July 23, 201510 yr 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.