From 4ff697e19bd0b8444506b31e45694112d0c4a5b9 Mon Sep 17 00:00:00 2001 From: WayZer Date: Thu, 3 Mar 2022 00:26:37 +0800 Subject: [PATCH] API: add DropDownEvent (#6611) * API: add DropDownEvent (cherry picked from commit d44a45c916da391200f1ffad3f98b15a99abb1aa) * request changes --- .../mindustry/entities/comp/PayloadComp.java | 2 ++ core/src/mindustry/game/EventType.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/src/mindustry/entities/comp/PayloadComp.java b/core/src/mindustry/entities/comp/PayloadComp.java index 5bd52e7165..68d1dc8786 100644 --- a/core/src/mindustry/entities/comp/PayloadComp.java +++ b/core/src/mindustry/entities/comp/PayloadComp.java @@ -156,6 +156,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{ if(!u.isAdded()) u.team.data().updateCount(u.type, -1); u.add(); u.unloaded(); + Events.fire(new PayloadDropEvent(self(), u)); return true; } @@ -168,6 +169,7 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{ if(on != null && Build.validPlace(tile.block, tile.team, tx, ty, tile.rotation, false)){ int rot = (int)((rotation + 45f) / 90f) % 4; payload.place(on, rot); + Events.fire(new PayloadDropEvent(self(), tile)); if(getControllerName() != null){ payload.build.lastAccessed = getControllerName(); diff --git a/core/src/mindustry/game/EventType.java b/core/src/mindustry/game/EventType.java index 26d7dcb740..74fa50582e 100644 --- a/core/src/mindustry/game/EventType.java +++ b/core/src/mindustry/game/EventType.java @@ -242,6 +242,24 @@ public class EventType{ } } + public static class PayloadDropEvent{ + public final Unit carrier; + public final @Nullable Unit unit; + public final @Nullable Building build; + + public PayloadDropEvent(Unit carrier, Unit unit){ + this.carrier = carrier; + this.unit = unit; + this.build = null; + } + + public PayloadDropEvent(Unit carrier, Building build){ + this.carrier = carrier; + this.build = build; + this.unit = null; + } + } + public static class UnitControlEvent{ public final Player player; public final @Nullable Unit unit;