Jump to content

[SOLVED] [1.8] Crashes with Certain Methods in Custom Particle Class


Recommended Posts

Posted

I've made a custom particle class that can detect when an entity has collided with the particle (among other things) and then act accordingly. My class seemed to work perfectly, but once in a while (maybe 1/1000 times) the class would cause my game to crash. Since it was so rare and I couldn't narrow down the problem, I ignored it. But now I have one of my custom particles spawning constantly from a mob and I found that killing the mob with the command:

/kill @e[type=!Player]

can cause the same crash occasionally (maybe 1/100 times). So I made a redstone clock to spawn the mob and then have the command run every tick so I can easily replicate the crash and fix it.

 

I have found that running either of these codes in my custom particle class on the server side causes this crash:

//get list of entities that the particle has collided with
List entities = this.worldObj.getEntitiesWithinAABBExcludingEntity(action.entity /*my entity*/, new AxisAlignedBB(this.posX-0.3F, this.posY-0.3F, this.posZ-0.3F, this.posX+0.3F, this.posY+0.3F, this.posZ+0.3F)); 

Crashlog:

  Reveal hidden contents
Posted

ConcurrentModificationException happens when you are accessing not synchronized collection (here: HashMap) from wrong thread.

 

To make it clearer:

* Particles are client-side ONLY. You are not allowed to spawn them from server thread. You should always inform (e.g by packet) client that "hey, you should spawn particle now" and client should do that.

* Since Particles are client-sided, they DO NOT have access to any of server logic. They can only relay on client's data - server doesn't even know if they exist.

* You cannot use !world.isRemote (server) whenever you are dealing with particles. So yeah - since each client spawns its own particles and has a little different info (e.g on two different clients a Zombie can stand a little bit furteher than on the other). You cannot expect two clients to act same.

 

We need code, if above won't lead to solution. Also - ever tried running your mod on dedicated + client? I think you might see more problems.

 

  Quote

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

Posted

I see what you are attempting to do - Fire-breathing.

 

As mentioned - particles are client-side beings. They don't even exist on server. Imagine if server would have 100 players that all spawn hundreds of particles and server has to move tham around and send position updates about them to all players around - that would kill performance.

 

I actually have a spell that does mentioned "Fire-breathing".

You will need to extend EntityThrowable or Entity (depends on logic). When starting using your "flames" you would constantly spawn your FlameEntity on server (spawning entities happens only on server, particles on client) - you would need only one per few ticks, about 5-10 would be fine. Server would only have that FlameEntity that would actually be one which ignites stuff from server side and client would just add its own particles (Display-only for cool effect).

  Quote

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

Posted

One of the things I'm using my custom particle class is for something similar to fire-breathing. But I can also have my custom particles do other things like spawning explosions or giving effects when they collide with a player.

 

Is there any way that I can just have my custom particle class detect when a server-side event should occur (as it does now) and somehow tell the server side to do something (like run a method or a line of code)? Or would I have to use a class that extends Entitythrowable or Entity that runs server side and spawns particles client side, as you suggest?

Posted

That is totally possible, but don't even think about doing that.

 

Easy way would be to indeed - just spawn particle and make particle send packet to server telling that it hit something (you would probably use entity.entityId in this case). BUT: Easy != Good.

 

Giving clients power to dictate what server should do not only opens ways to do bad stuff to server (remember - server doesn't know about particles, if someone would want he could spawn client-particle everywhere around him and tell server to kill everything around), but also makes MP few times worse. Different client have different particles, each client can have latency/lag, small things will cause massive calculation errors.

 

Proper way of doing what you want is what I alredy told you. (server=side entity).

 

There is however mid-solution. You can actually do everything on client and then just send packet to server, but whenever server receives packet you would need to make calculations that would define if action was legal (e.g enemy hit is in range and is in proper angle (not behind your back).

This is STILL BAD solution, but better than just saying "attack that guy, because I (client) tell you".

 

Cheers!

  Quote

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

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.