Merge pull request #4443 from DaComputerNerd717/mc1.18/dev

Add TrackGraph merge event to API
This commit is contained in:
simibubi 2023-05-10 16:01:35 +02:00 committed by GitHub
commit c86c10f1b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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);