UnitCreateEvent / UnitDeployEvent split
This commit is contained in:
@@ -351,10 +351,22 @@ public class EventType{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called when a unit is created in a reconstructor or factory. */
|
||||||
public static class UnitCreateEvent{
|
public static class UnitCreateEvent{
|
||||||
public final Unit unit;
|
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;
|
this.unit = unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.world.blocks.payloads;
|
package mindustry.world.blocks.payloads;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
@@ -9,6 +10,7 @@ import arc.util.io.*;
|
|||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.entities.EntityCollisions.*;
|
import mindustry.entities.EntityCollisions.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
@@ -67,6 +69,7 @@ public class UnitPayload implements Payload{
|
|||||||
//prevents stacking
|
//prevents stacking
|
||||||
unit.vel.add(Mathf.range(0.5f), Mathf.range(0.5f));
|
unit.vel.add(Mathf.range(0.5f), Mathf.range(0.5f));
|
||||||
unit.add();
|
unit.add();
|
||||||
|
Events.fire(new UnitUnloadEvent(unit));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ public class Reconstructor extends UnitBlock{
|
|||||||
Effect.shake(2f, 3f, this);
|
Effect.shake(2f, 3f, this);
|
||||||
Fx.producesmoke.at(this);
|
Fx.producesmoke.at(this);
|
||||||
consume();
|
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(){
|
public void spawned(){
|
||||||
progress = 0f;
|
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;
|
payload = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import arc.util.io.*;
|
|||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.logic.*;
|
import mindustry.logic.*;
|
||||||
@@ -228,6 +229,7 @@ public class UnitFactory extends UnitBlock{
|
|||||||
payload = new UnitPayload(plan.unit.create(team));
|
payload = new UnitPayload(plan.unit.create(team));
|
||||||
payVector.setZero();
|
payVector.setZero();
|
||||||
consume();
|
consume();
|
||||||
|
Events.fire(new UnitCreateEvent(payload.unit, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
progress = Mathf.clamp(progress, 0, plan.time);
|
progress = Mathf.clamp(progress, 0, plan.time);
|
||||||
|
|||||||
Reference in New Issue
Block a user