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

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!

How would you do this if you only wanted it to spawn particles if the living entity was hit by a certain item?

If you really want help, give that modder a thank you.

 

Modders LOVE thank yous.

  • 2 weeks later...
  • Author

Thanks Guys!  ;) I appreciate it!

 

Thanks!

Romejanic

Romejanic

 

Creator of Witch Hats, Explosive Chickens and Battlefield!

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.