Jump to content

EntityListener classes


Romejanic
 Share

Recommended Posts

Hey guys!

 

I am attempting to make a mod which causes a living entity to emit a particles which looks like blood. I have already handled the particle, but which ForgeSubscribe method is right for a entity attack listener? Here is my code so far;

 

Main Mod File:

 

package romejanic.blood.common;

import net.minecraftforge.common.MinecraftForge;
import romejanic.blood.common.core.CommonProxy;
import romejanic.blood.common.core.ConfigHandler;
import romejanic.blood.common.core.EntityListener;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid="BloodParticles", name="Blood Particles", version="1.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class BloodParticles {

@SidedProxy(clientSide="romejanic.blood.client.core.ClientCore", serverSide="romejanic.blood.common.core.CommonProxy")
public static CommonProxy proxy;

@PreInit
public void preLoad(FMLPreInitializationEvent event){

	ConfigHandler.load();

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

}

@Init
public void load(FMLInitializationEvent event){

}

}

 

ConfigHandler

 

package romejanic.blood.common.core;

import java.io.File;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.Configuration;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;

public class ConfigHandler {

public static int blockID;

private static final String set = "Settings";

public static void load(){

	File location = null;
	Side s = FMLCommonHandler.instance().getEffectiveSide();
	if(s == s.CLIENT){

		location = new File(Minecraft.getMinecraftDir().toString()+"/romejanic/Blood Particles.txt");

	}
	if(s == s.SERVER){

		location = new File("./romejanic/Blood Particles.txt");

	}
	config(location);

}

private static void config(File location){

	Configuration config = new Configuration(location);

	config.load();

	config.addCustomCategoryComment(set, "Various settings which control how the mod operates");

	blockID = config.get(set, "Blood Block ID", Block.blockRedstone.blockID, "The ID of the block which the mod uses for the blood particles.").getInt();

	config.save();

}

}

 

EntityListener

package romejanic.blood.common.core;

import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.EntityEvent;

public class EntityListener {

@ForgeSubscribe
public void onEntityAttacked(EntityEvent event){

	World world = event.entity.worldObj;

	if(event.entity instanceof EntityLiving){

		world.spawnParticle("tilecrack_"+ConfigHandler.blockID+"_0", event.entity.posX, event.entity.posY, event.entity.posZ, 0, 0, 0);

	}

}

}

 

What happens at this point is that living entities ALWAYS emit the particle, and a bunch of errors spam the console.

 

Where have I gone wrong? How can this be resolved? Any help would be greatly appreciated  ;)

 

Thanks!

Romejanic

Romejanic

 

Creator of Witch Hats, Explosive Chickens and Battlefield!

Link to comment
Share on other sites

You subscribed to EntityEvent, which is the superclass of all Entity events. That means your listener will be called for every entity event that gets called (and there is a lot of them, just think of the LivingUpdateEvent, etc. etc.) You need to specify that you want to listen only to the LivingAttackEvent

Link to comment
Share on other sites

  • 2 weeks later...

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

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