Jump to content

Recommended Posts

Posted

Hello,

 

I am making an item that destroys every item that you pick up. I want to spawn portal particles around the player whenever he tries to pick something up. I've written this method; https://gist.github.com/anonymous/9305890

 

The method does run, but it's not spawning the particles.

It has something to do with the coordinates, because when I try to spawn particles in another event it does work. I've tried the coordinates of the entity, entityLiving and the entityPlayer, and they all failed. When I print the coords they show up just fine as doubles.

 

Does someone have a solution to this problem?

 

Thanks a lot!

 

*EDIT* I solved this problem by sending a packet to the client that spawns the particles. If you want to see my code visit this link; https://github.com/wiggertolsma/usefullstuff/tree/master/src/main/java/ace/usefullstuff

 

I've used help from the wiki and you guys, thanks!

Follow me on twitter: https://twitter.com/CoderAce_

Posted

TGG is correct, that event only fires on the server, never on the client. You will need to create a packet to send to the client (or all clients within a certain distance if you want other players to see the particles as well) in order to spawn the particles.

 

You can see an example particle packet of mine here. It's for 1.6.4, but it's simple to port over to 1.7.2. One of these days I'll get my 1.7.2 version up on git as well...

Posted

TGG is correct, that event only fires on the server, never on the client. You will need to create a packet to send to the client (or all clients within a certain distance if you want other players to see the particles as well) in order to spawn the particles.

 

You can see an example particle packet of mine here. It's for 1.6.4, but it's simple to port over to 1.7.2. One of these days I'll get my 1.7.2 version up on git as well...

Thanks! I will try your code. One weird thing is though, that this code runs perfectly fine..

@SubscribeEvent

public void onItemUse(UseHoeEvent event){

double x = event.entityPlayer.posX ;

double y = event.entityPlayer.posY;

double z = event.entityPlayer.posZ;

event.entityPlayer.addChatMessage(new ChatComponentText("Particle spawned"));

for(int i = 0; i <= 30; i++){

event.entityPlayer.worldObj.spawnParticle("portal", x,y,z, 1D, 1D,1D);

}

}

 

That's kind of odd right? Using a hoe on grass does spawn the particles.. Maybe it's send within the same packet?

Follow me on twitter: https://twitter.com/CoderAce_

Posted

Okay, so the code you provided is completely outdated.

I've managed to put the client-side together, something like this;

@Override

protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket packet)

throws Exception {

if (packet.channel().equals("UsefullStuff")) {

            ByteBuf payload = packet.payload();

            if (payload.readableBytes() == 4) {

                x = payload.readDouble();

                y = payload.readDouble();

                z = payload.readDouble();

                r = payload.readFloat();

            }

        }

 

}

 

Ill post more when its done.

Thanks ;)

Follow me on twitter: https://twitter.com/CoderAce_

Posted

That's not odd at all. The UseHoeEvent is being called on both sides. ItemPickupEvent ONLY fires on the server. Ever.

 

If you're ever curious whether an event or method of any kind is being called on both sides, place a println inside of it:

System.out.println("Is client? " + worldObj.isRemote);

Of course, getting the world object however you can, directly from the method parameters if you can or from an entity i.e. event.entity.worldObj. Run your mod and try to run that method, then check the console output. Try it with UseHoeEvent and I'll bet you whatever you want that it will print like this:

Is client? true // client, yay particles
Is client? false // server, boo, no particles
Is client? true
Is client? false

I'm not 100% sure, but the UseHoeEvent may only fire for the player actually using the hoe, in which case your particles still will not be seen by other players unless you send a packet. Whether you care enough about those particular particles is of course up to you, but it's something to be aware of.

Posted

That depends on how you set up your packets. If you set it up using a similar system of AbstractPackets, it's not that outdated at all. In fact, it's simply a matter of changing the streams to buffers and a few method names.

Is there a good way to find out how to port? Or is it randomly looking through every networking class?

Follow me on twitter: https://twitter.com/CoderAce_

Posted

Have you not set up your network code yet? Try checking the wiki. That's the tutorial / code I used to get my network going in 1.7.2.

Haha, I just went there ;) So I got everything setup, a class called PacketParticle and the PacketPipeline.

Now how do I send the packet? Because it doesn't automatically send it right? It just encodes the data in a buffer, but now how do I flush it? I did setup the handleClientSide() method.

 

Thanks

Follow me on twitter: https://twitter.com/CoderAce_

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.