Jump to content

[1.8] Bullet Particles


Darkflame

Recommended Posts

Hi!

 

I was working on a bullet entity, and right now it's invisible, and I'd like to add particles that spawn every tick at it's coordinates while it's flying. I looked at the world.spawnParticle(etc etc etc etc);, and then I poked around the arrow class a bit and found this bit of code, but I don't know how to set the particles to always spawn:

 

public void setIsCritical(boolean p_70243_1_)
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);

        p_70243_1_ = true;
        
        if (p_70243_1_)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1)));
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2)));
        }
        
        p_70243_1_ = true;
    }

public boolean getIsCritical()
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);
        return (b0 & 1) != 0;
    }

 

So, how would I change it to make it so it would always spawn crit particles behind the entity while it flies?

I. Am. A. Noob.

Noobs. :P

Link to comment
Share on other sites

It just needs to get ran somehow. This can be achieved by hooking into events. Inside the 'onLivingUpdate' event, you can add your code specifically.

 

For my project I actually took code from one of the vanilla mobs and began tweaking it to what I need. If you want to go this route, you could create your own 'renderParticle' method, pass in an EntityLiving or something else with coordinates, and an EnumParticleTypes. For a full list of those, find the EnumParticleTypes file. Not sure how fireworks work yet, so I can't help you with those particles.

By doing this, you can skip rewriting a bunch of particle code, but if you only need one thing to have particles, you're better off just copying and modifying code from vanilla mobs.

Link to comment
Share on other sites

It just needs to get ran somehow. This can be achieved by hooking into events. Inside the 'onLivingUpdate' event, you can add your code specifically.

 

For my project I actually took code from one of the vanilla mobs and began tweaking it to what I need. If you want to go this route, you could create your own 'renderParticle' method, pass in an EntityLiving or something else with coordinates, and an EnumParticleTypes. For a full list of those, find the EnumParticleTypes file. Not sure how fireworks work yet, so I can't help you with those particles.

By doing this, you can skip rewriting a bunch of particle code, but if you only need one thing to have particles, you're better off just copying and modifying code from vanilla mobs.

 

I looked at that, but when I try to do that it makes me change it to onUpdate().  :-\ But I after poking around the arrow class I think that's better.

I. Am. A. Noob.

Noobs. :P

Link to comment
Share on other sites

I looked at that, but when I try to do that it makes me change it to onUpdate().  :-\ But I after poking around the arrow class I think that's better.

 

Did you have the @SubscribeEvent and all? It should look like:

@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
	// Code
}

 

You'll also need to register the event; have you done that? You should have somewhere (either postInit or a manager called in postInit):

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

 

Lastly make sure you're actually running the register event code, in your postInit method. For organization you might want to make a class that has one method that runs all the register event code, and you call this one method in postInit, instead of a bunch of methods. Up to you though.

Link to comment
Share on other sites

Nope.

 

1. Throwables are not LIVING entities. LivingUpdateEvent will not be called on them.

2. You DON'T use events when working with your own code. There is probably only one case when you can make exception ("flattening" code to apply on all entities, not just yours).

3.

Inside the 'onLivingUpdate' event

This is not an event. This is eventually a method inside EntityLiving.

 

Finally:

To spawn particles let's say around given bullet you will need to extend EntityThrowable and override:

public void onUpdate()

Don't forget to call super.

 

Spawnin particles SHOULD happen on CLIENT side only!

If your particles are occuring always - you don't need any kind of packets.

If you want server to decide about them - you need either DataWatcher applied on Throwable, or dynamic packets.

Other way is to use #writeSpawnData to send additional data about entity to client (sent only on spawning/loading entity).

 

1.7.10 is no longer supported by forge, you are on your own.

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.

Announcements



×
×
  • Create New...

Important Information

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