Jump to content

Need Help With Death Event


Scorpyon04

Recommended Posts

Im trying to make a mod that plays a sound when a you kill a player.

this is my code

package scorpyon04.bloodeffect;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.MOD_NAME)
public class BloodEffect {

	public static void preInit(FMLPreInitializationEvent event) {

	}
	public static void Init(FMLInitializationEvent event) {
		System.out.println("Blood Effect Init");
		MinecraftForge.EVENT_BUS.register(new DeathEventHandler());
	}
	public static void postInit(FMLPostInitializationEvent event) {

	}
}

and My DeathEventHandler

package scorpyon04.bloodeffect;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.living.LivingDeathEvent;

public class DeathEventHandler {
	public void onLivingDeath(LivingDeathEvent event){
		Entity e = event.entity;
		if (e instanceof EntityPlayer) {
			EntityPlayer killedplr = (EntityPlayer) e;
			if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
				EntityPlayer plr = (EntityPlayer) event.source.getEntity();
				plr.playSound("dig.stone", 1000.0f, 1.0f);
			}
		}
	}
}

when im in game nothing happens when i kill a player

 

Link to comment
Share on other sites

public class DeathEventHandler {

       @SubscribeEvent
	public void onLivingDeath(LivingDeathEvent event){
		Entity e = event.entity;
		if (e instanceof EntityPlayer) {
			EntityPlayer killedplr = (EntityPlayer) e;
			if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
				EntityPlayer plr = (EntityPlayer) event.source.getEntity();
				plr.playSound("dig.stone", 1000.0f, 1.0f);
			}
		}
	}
}


use @subscribe event on top of the event and register This class"DeathEventHandler"
in the preInit


@EventHandler
public void preInit(FMLPreInitializationEvent event) {

MinecraftForge.EVENT_BUS.register(new DeathEventHandler());

}
I swear this site refuses to register what i write normally

Edited by Eiachh
Link to comment
Share on other sites

3 minutes ago, Scorpyon04 said:

Subscribe event is error and i cant import it btw im using 1.8.9 forge

 

Well I only used forge for 1.12 but this would be the import. Otherwise sorry no idea.

 

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Link to comment
Share on other sites

12 minutes ago, Scorpyon04 said:

Still cant hear it

@SubscribeEvent
	public void reeewdyeven(LivingDeathEvent event){
		if (event.getEntityLiving() instanceof  EntityPlayer || event.getEntityLiving() instanceof  EntityPlayerMP){
			System.out.println("asd");
		}
	}

https://cdn.discordapp.com/attachments/526458081329152002/529999484885925918/unknown.png
 

Try this if its printing then solve the sound. Ihave no clue to sounds in minecraft yet

Link to comment
Share on other sites

6 minutes ago, Scorpyon04 said:

Damn :(

 

@SubscribeEvent
	public void reeewdyeven(LivingDeathEvent event){
		if (event.getEntityLiving() instanceof  EntityPlayer || event.getEntityLiving() instanceof  EntityPlayerMP){
			System.out.println("asd");
			Minecraft mc = Minecraft.getMinecraft();
			mc.player.sendChatMessage("asdasd");

		}
	}

This event is clientsided as well tho idk what you were talking about

So now you dont have to look for the log files

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried installing forge for 1.20.6 and for some reason when i open it, it says: "Java Virtual Machine Launcher": Error: Unable to acces jarfile C:\Users\PC\OneDrive\???????????\forge-1.20.6-50.1.0-installer.jar. I dont have any idea what to do. Can anyone help?
    • Update I seem to have fixed it by removing the folders made when the server first starts (e.g. config, world) and starting it all again.  
    • Good days im working on this Costume underground dungeon the plan is creating a mineshaft tunel whit fully functional railway and rail switchs going deep down into the ground      My hypothesis its than than the rails get created before the supporting stone blocks   i was setting blocks whit  Level.setBlock(pos,blkstate,2)  in mode 2 i change it to 10 but the problem persist  in the doorblock class it uses 3 as flag   level.setBlock(p_52750_.above(), p_52751_.setValue(HALF, DoubleBlockHalf.UPPER), 3); i set 3 as flag the problem continues (i du not know what 3 means) this numbers are basically a mistery ===> i need the number mode to set a block into the world whithout doing any checks or triggering neighbors blocks  ############# The nbt class has an Enum to make more redable the code  is in "import net.minecraft.nbt.Tag;" nbtpos = entitydata.getList("blockPos", Tag.TAG_INT);// blockdata contains pos;   if theres something like this for the setBlockMode that would be nice           
    • this is a really old resurrected post  anyway    //values to nbt  ListTag nbtblockpos = new ListTag(); nbtblockpos.add(IntTag.valueOf(blockPos.getX())); nbtblockpos.add(IntTag.valueOf(blockPos.getY())); nbtblockpos.add(IntTag.valueOf(blockPos.getZ())); entitydata.put("blockPos", nbtblockpos); ListTag nbtpos = new ListTag(); nbtpos.add(DoubleTag.valueOf(Pos.x)); nbtpos.add(DoubleTag.valueOf(Pos.y)); nbtpos.add(DoubleTag.valueOf(Pos.z)); entitydata.put("pos", nbtpos);   //getting things back if(entitydata.contains("blockPos")) { nbtpos = entitydata.getList("blockPos", Tag.TAG_INT);// blockdata contains pos this.blockPos = new BlockPos( nbtpos.getInt(0), nbtpos.getInt(1), nbtpos.getInt(2) ); } this.pos = null; if(entitydata.contains("pos")) { nbtpos = entitydata.getList("pos", Tag.TAG_DOUBLE);// blockdata contains pos this.Pos = new Vec3( nbtpos.getDouble(0), nbtpos.getDouble(1), nbtpos.getDouble(2) ); }    
  • Topics

×
×
  • Create New...

Important Information

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