Fixed units sometimes exploding when payload dropped

This commit is contained in:
Anuken 2024-09-22 08:58:09 -04:00
parent 830fcb6360
commit 51b415731a

View File

@ -148,9 +148,12 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
boolean dropUnit(UnitPayload payload){
Unit u = payload.unit;
//add random offset to prevent unit stacking
Tmp.v1.rnd(Mathf.random(2f));
//can't drop ground units
//allow stacking for small units for now - otherwise, unit transfer would get annoying
if(!u.canPass(tileX(), tileY()) || Units.count(x, y, u.physicSize(), o -> o.isGrounded() && o.hitSize > 14f) > 1){
if(!u.canPass(World.toTile(x + Tmp.v1.x), World.toTile(y + Tmp.v1.y)) || Units.count(x, y, u.physicSize(), o -> o.isGrounded() && o.hitSize > 14f) > 1){
return false;
}
@ -159,8 +162,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
//clients do not drop payloads
if(Vars.net.client()) return true;
u.set(this);
u.trns(Tmp.v1.rnd(Mathf.random(2f)));
u.set(x + Tmp.v1.x, y + Tmp.v1.y);
u.rotation(rotation);
//reset the ID to a new value to make sure it's synced
u.id = EntityGroup.nextId();