Jump to content

[1.7.10] [SOLVED] LivingEvent problem


Grim1ight

Recommended Posts

Hi! I have problem with LivingEvent:

When I'm trying to spawn particles near player inside worldObj.isRemote it's isnt working, when I'm using it outside it's work but then crash with TickingPlayer/TickingEntity error. Here's code:

 

public Event(EntityLivingBase par1Entity)
{
    super(par1Entity);

    double f1 = entity.posX;
    double f2 = entity.posY + 1;
    double f3 = entity.posZ;

    if (entity.worldObj.isRemote) {
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer)entity;
            spawnParticles(player, 300); //It's not working 
        }
    }
    else
    {
        if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer)entity;
        spawnParticles(player, 300); //It's working with crash after second
        }
    }
}


void spawnParticles(EntityLivingBase par1entity, int par2Value) {
spawnP(par1entity, Blocks.RedBlock, 0, 1, 2, par2Value);
}

void spawnP(EntityLivingBase par1entity, Block par2Block, int par3Meta, int par4Meta, int par5Meta, int par6Value) {
float f1 = (float)(par1entity.posX);
float f2 = (float)(par1entity.posY + 1F);
float f3 = (float)(par1entity.posZ);

for(int i = 0; i < par6Value; i++)
{
	int x = new Random().nextInt(3);
	if (x == 0 )
		Minecraft.getMinecraft().effectRenderer.addEffect(new EntityRedParticleFX(par1entity.worldObj, f1, f2, f3, 0.0D, 0.0D, 0.0D, par2Block, par3Meta));
	else if (x == 1)
		Minecraft.getMinecraft().effectRenderer.addEffect(new EntityRedParticleFX(par1entity.worldObj, f1, f2, f3, 0.0D, 0.0D, 0.0D, par2Block, par4Meta));
	else if (x == 2)
		Minecraft.getMinecraft().effectRenderer.addEffect(new EntityRedParticleFX(par1entity.worldObj, f1, f2, f3, 0.0D, 0.0D, 0.0D, par2Block, par5Meta));
}
}

 

Link to comment
Share on other sites

What are you trying to do? Are you actually trying to handle an event? You can't handle an event the way you wrote it. Just calling the method "event" doesn't make it an event. You have to use the @Subscribe annotation to indicate that the method might be an event handler and then the parameter passed must be an event (like LivingHurtEvent). I have a tutorial on event handling here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

You're also calling

super()

which makes no sense at all.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

What are you trying to do? Are you actually trying to handle an event? You can't handle an event the way you wrote it. Just calling the method "event" doesn't make it an event. You have to use the @Subscribe annotation to indicate that the method might be an event handler and then the parameter passed must be an event (like LivingHurtEvent). I have a tutorial on event handling here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

It's a part of code -_-

 

All working on clientside with mobs, with players (btw with npcs in mod CustomNPC) in serverside, but then crashing with Ticking Entity/Player error.

 

if ()

Link to comment
Share on other sites

Why are you extending LivingEvent? And WHY are you placing the code in the constructor?

You're event will only be called if you post it yourself, and you're probably not doing that.

 

If you want your event to be called by forge, you need to create an EventManager class. You need to register this class at the correct bus in your preinit, in this case:

MinecraftForge.EVENTBUS.register(new EventManager());

 

In your EventManager you need this function:

@SubscribeEvent
public void update(LivingEvent.LivingUpdateEvent event)
{
      //YOUR RENDERING CODE GOES HERE
}

 

If this short tutorial made no sense, read jabelar's tutorial:

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

Link to comment
Share on other sites

Why are you extending LivingEvent? And WHY are you placing the code in the constructor?

You're event will only be called if you post it yourself, and you're probably not doing that.

 

If you want your event to be called by forge, you need to create an EventManager class. You need to register this class at the correct bus in your preinit, in this case:

MinecraftForge.EVENTBUS.register(new EventManager());

 

In your EventManager you need this function:

@SubscribeEvent
public void update(LivingEvent.LivingUpdateEvent event)
{
      //YOUR RENDERING CODE GOES HERE
}

 

If this short tutorial made no sense, read jabelar's tutorial:

 

Srsly? It's part of code! I have this in main class:

@EventHandler
public void Load(FMLInitializationEvent Event) {
	MinecraftForge.EVENT_BUS.register(new *EventName*());
}

 

+ Smth like this:

@SubscribeEvent
public void onLivingAttackEvent(LivingAttackEvent event)
{		
        if (event.ammount > 0 && event.source != DamageSource.lava && event.source != DamageSource.inFire && event.source != DamageSource.cactus 
        		&& event.source != DamageSource.wither && event.source != DamageSource.magic) {
            TheEvent bEvent = new TheEvent(event.entityLiving);
        }
}

Link to comment
Share on other sites

Srsly? It's part of code! I have this in main class:

@EventHandler
public void Load(FMLInitializationEvent Event) {
	MinecraftForge.EVENT_BUS.register(new *EventName*());
}

 

That's not how events work. The event handler class had no hierarchical relationship to the event type they handle.

 

Check mine: https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/ArtifactServerEventHandler.java

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It is a common mistake that people think they need to create an event class, but actually you just subscribe to existing events. (Theoretically you can create a new event type but then you also have to take care of posting it to the bus, and in the case of what you're doing I don't think you need a custom event.)

 

And there are two types of subscriptions. The @EventHandler annotation is for FML lifestyle events (not what you want). The @Subscribe annotation is for in-game events, and further you need to make sure your event handling class is registered to the appropriate bus -- there are several buses so that single event buses don't get overwhelmed with other event types.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

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...

×   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.

×
×
  • Create New...

Important Information

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