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

i'm using eventhandler to create an event which will consume a certain item to grant the player immunity for a duration if their health falls bellow 15%. The actual immortality effect works ok (minor issue of not triggering on the inital damage that brings you bellow 15%) , but the particles are not working and i can't figure out how to play sounds.

Here's my code: 

 

package com.axel.main;

import java.util.Random;

import com.axel.item.MainItemClass;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class EventHandlerCommon {
	
	    @SubscribeEvent
	    
	    public void LivinghurtEvent(LivingHurtEvent event) {
	        if (event.entity instanceof EntityPlayerMP) {
	            EntityPlayerMP player = (EntityPlayerMP) event.entity;
	            InventoryPlayer inventory = player.inventory;
	            World world = player.getEntityWorld();
	            float currenthealth = player.getHealth();
    			float maxhealth = player.getMaxHealth();
    			float percenthealth = (currenthealth / maxhealth) * 100;	
    			
	            if (inventory.hasItem(MainItemClass.DivineIntervention) && 15 >= percenthealth) {
	            	
	            	 player.setHealth(maxhealth);
 		        	player.extinguish();
 		        	player.clearActivePotions();
 		        	player.addPotionEffect(new PotionEffect (12, 1200 , 1));
 		        	player.addPotionEffect(new PotionEffect (1, 600 , 2));
 		        	player.addPotionEffect(new PotionEffect (5, 60 , 4));
 		        	player.addPotionEffect(new PotionEffect (6, 5 , 1));
 		        	player.addPotionEffect(new PotionEffect (23, 60 , 4));
 		        	player.addPotionEffect(new PotionEffect (11, 60 , 255));
 		        	inventory.consumeInventoryItem(MainItemClass.DivineIntervention);
 		        	Random rand = new Random();

 		        	player.addChatMessage(new ChatComponentText("2A2A00" + "Spell Casted: Divine Intervention"));

 	
 		        	for(int countparticles = 0; countparticles <= 10; ++countparticles)
 		        	{
 			            
 			            
 		        		world.spawnParticle("reddust", player.posX + (rand.nextDouble() - 0.5D) * (double)player.width, player.posY + rand.nextDouble() * (double)player.height - (double)player.yOffset, player.posZ + (rand.nextDouble() - 0.5D) * (double)player.width, 0.0D, 0.0D, 0.0D);
 		        		world.spawnParticle("enchantmenttable", player.posX + (rand.nextDouble() - 0.5D) * (double)player.width, player.posY + rand.nextDouble() * (double)player.height - (double)player.yOffset, player.posZ + (rand.nextDouble() - 0.5D) * (double)player.width, 0.0D, 0.0D, 0.0D);
 		        		world.spawnParticle("portal", player.posX + (rand.nextDouble() - 0.5D) * (double)player.width, player.posY + rand.nextDouble() * (double)player.height - (double)player.yOffset, player.posZ + (rand.nextDouble() - 0.5D) * (double)player.width, 0.0D, 0.0D, 0.0D);

 		        	}
 		        	
 	        	{
 	        	
 	        	}
	            }
	        }
	     }
	    
	}

 

 

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.