mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 19:39:04 +07:00
UnitCreateEvent / UnitDeployEvent split
This commit is contained in:
parent
c420ad1a16
commit
f231849a42
@ -351,10 +351,22 @@ public class EventType{
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when a unit is created in a reconstructor or factory. */
|
||||
public static class UnitCreateEvent{
|
||||
public final Unit unit;
|
||||
public final Building spawner;
|
||||
|
||||
public UnitCreateEvent(Unit unit){
|
||||
public UnitCreateEvent(Unit unit, Building spawner){
|
||||
this.unit = unit;
|
||||
this.spawner = spawner;
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when a unit is dumped from any payload block. */
|
||||
public static class UnitUnloadEvent{
|
||||
public final Unit unit;
|
||||
|
||||
public UnitUnloadEvent(Unit unit){
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
@ -9,6 +10,7 @@ import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.entities.EntityCollisions.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
@ -67,6 +69,7 @@ public class UnitPayload implements Payload{
|
||||
//prevents stacking
|
||||
unit.vel.add(Mathf.range(0.5f), Mathf.range(0.5f));
|
||||
unit.add();
|
||||
Events.fire(new UnitUnloadEvent(unit));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class Reconstructor extends UnitBlock{
|
||||
Effect.shake(2f, 3f, this);
|
||||
Fx.producesmoke.at(this);
|
||||
consume();
|
||||
Events.fire(new UnitCreateEvent(payload.unit));
|
||||
Events.fire(new UnitCreateEvent(payload.unit, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,21 +36,6 @@ public class UnitBlock extends PayloadAcceptor{
|
||||
|
||||
public void spawned(){
|
||||
progress = 0f;
|
||||
|
||||
Tmp.v1.trns(rotdeg(), size * tilesize/2f);
|
||||
Fx.smeltsmoke.at(x + Tmp.v1.x, y + Tmp.v1.y);
|
||||
|
||||
if(!net.client() && payload != null){
|
||||
Unit unit = payload.unit;
|
||||
unit.set(x, y);
|
||||
unit.rotation(rotdeg());
|
||||
unit.vel().trns(rotdeg(), payloadSpeed * 2f).add(Mathf.range(0.3f), Mathf.range(0.3f));
|
||||
unit.trns(Tmp.v1.trns(rotdeg(), size * tilesize/2f));
|
||||
unit.trns(unit.vel());
|
||||
unit.add();
|
||||
Events.fire(new UnitCreateEvent(unit));
|
||||
}
|
||||
|
||||
payload = null;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.*;
|
||||
@ -228,6 +229,7 @@ public class UnitFactory extends UnitBlock{
|
||||
payload = new UnitPayload(plan.unit.create(team));
|
||||
payVector.setZero();
|
||||
consume();
|
||||
Events.fire(new UnitCreateEvent(payload.unit, this));
|
||||
}
|
||||
|
||||
progress = Mathf.clamp(progress, 0, plan.time);
|
||||
|
Loading…
Reference in New Issue
Block a user