From 6b0af48e99c2811f990362ad0033e078584f1287 Mon Sep 17 00:00:00 2001 From: DaComputerNerd Date: Fri, 10 Feb 2023 10:32:15 -0500 Subject: [PATCH] Add track merge event Can't test it due to java shenanigans, but I think this will work. It's worth noting that this will only be specific to merging as long as transferAll is. If anything else ends up using transferAll, all that needs to happen is adding an intermediate method that posts the event instead of transferAll doing it, then calls transferAll --- .../api/event/TrackGraphMergeEvent.java | 22 +++++++++++++++++++ .../content/logistics/trains/TrackGraph.java | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/com/simibubi/create/api/event/TrackGraphMergeEvent.java diff --git a/src/main/java/com/simibubi/create/api/event/TrackGraphMergeEvent.java b/src/main/java/com/simibubi/create/api/event/TrackGraphMergeEvent.java new file mode 100644 index 000000000..af58070d2 --- /dev/null +++ b/src/main/java/com/simibubi/create/api/event/TrackGraphMergeEvent.java @@ -0,0 +1,22 @@ +package com.simibubi.create.api.event; + +import com.simibubi.create.content.logistics.trains.TrackGraph; + +import net.minecraftforge.eventbus.api.Event; + +public class TrackGraphMergeEvent extends Event{ + private TrackGraph mergedInto, mergedFrom; + + public TrackGraphMergeEvent(TrackGraph from, TrackGraph into) { + mergedInto = into; + mergedFrom = from; + } + + public TrackGraph getGraphMergedInto() { + return mergedInto; + } + + public TrackGraph getGraphMergedFrom() { + return mergedFrom; + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraph.java b/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraph.java index 897713e94..cda0e5f2f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraph.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraph.java @@ -19,6 +19,7 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; import com.simibubi.create.Create; +import com.simibubi.create.api.event.TrackGraphMergeEvent; import com.simibubi.create.content.logistics.trains.TrackNodeLocation.DiscoveredLocation; import com.simibubi.create.content.logistics.trains.entity.Train; import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgeData; @@ -41,6 +42,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.MinecraftForge; public class TrackGraph { @@ -247,6 +249,7 @@ public class TrackGraph { } public void transferAll(TrackGraph toOther) { + MinecraftForge.EVENT_BUS.post(new TrackGraphMergeEvent(this, toOther)); nodes.forEach((loc, node) -> { if (toOther.addNodeIfAbsent(node)) Create.RAILWAYS.sync.nodeAdded(toOther, node);