e5c6ca157c
commit 053dd09df6c426ab5e570f42a1edb5df3d0fbd01 Merge: 6d1e1c71decc645eba
Author: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue May 9 18:22:42 2023 +0200 Merge branch '1.18/api' of https://github.com/Layers-of-Railways/Create into pr/4692 commitecc645eba7
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue May 9 11:24:11 2023 +0100 Implemented support for creating and removing individual blockstate models commit 6d1e1c71de7ce20f6fd9fc8ed4ed9bdd1072829a Author: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue May 9 12:16:54 2023 +0200 Less error logging when migrating old worlds commit205e47352e
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 21:02:19 2023 -0700 Fix up ItemOutline commit6cf204f6af
Merge:fe049bc77
2e3c906ce
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:28:56 2023 -0700 Merge remote-tracking branch 'upstream/mc1.18/dev' into 1.18/api # Conflicts: # src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageCouplingRenderer.java commitfe049bc771
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:26:16 2023 -0700 Revert "Revert "Rewrite outline buffering"" This reverts commit726bfaf0
commit435b4c1c16
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:20:23 2023 -0700 Clean up last bits of upside down rendering commit662da6bab1
Merge:122fe77af
d83285e8a
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:16:32 2023 -0700 Merge remote-tracking branch 'origin/1.18/api' into 1.18/api # Conflicts: # src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java commit122fe77afa
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:15:46 2023 -0700 Fix up upside down rendering commitd83285e8a4
Merge:00e953a58
cdb0ad210
Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Sun May 7 07:02:18 2023 -0700 Merge pull request #3 from Layers-of-Railways/1.18/bogey-api Cleanup cycle groups and unused imports commitcdb0ad210b
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:15:47 2023 +0100 Fixed merge artifact commit457d5f33ed
Merge:4e4e227a3
00e953a58
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:14:07 2023 +0100 Merge remote-tracking branch 'origin/1.18/api' into 1.18/api commit00e953a585
Merge:1e4d5504e
a7a25896c
Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 10:13:49 2023 +0100 Merge pull request #2 from Rabbitminers/mc1.18/dev Added Return Values and Small Cleanup commita7a25896c1
Merge:7622128be
1e4d5504e
Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 10:13:40 2023 +0100 Merge branch '1.18/api' into mc1.18/dev commit4e4e227a35
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:10:30 2023 +0100 Cleanup to cycle groups commitaa94fc97d1
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 09:50:50 2023 +0100 Removed unused import of Railways commit7622128bec
Merge:81eeadb85
d52065808
Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 09:11:59 2023 +0100 Merge branch 'Layers-of-Railways:mc1.18/dev' into mc1.18/dev commit1e4d5504ee
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 18:03:39 2023 -0700 Don't revert non-buggy changes commitb306cf2124
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 18:00:59 2023 -0700 Take materials into consideration when trains pathfind commitfca02ae4bf
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 10:25:51 2023 -0700 Add materials to track graph commit726bfaf0b5
Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 21:16:49 2023 -0700 Revert "Rewrite outline buffering" This reverts commitd4106d545b
. commit171897bed2
Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 20:55:25 2023 -0700 Fix up style cycling commitcbd0cf20da
Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 07:32:06 2023 -0700 clean up nether portal carriage handling commitd556f08876
Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 07:06:02 2023 -0700 upside down bogeys work in nether portals fixed coupling anchor offsets commitda26c0ccbf
Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu May 4 09:32:53 2023 -0700 working on upside down bogeys in nether portals commit81eeadb853
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 16:15:28 2023 +0100 Small cleanup commitc7e9df973c
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 16:13:51 2023 +0100 Fixed issue raised in #1 commit2f285b6eb7
Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 1 08:13:27 2023 -0700 add data gen commit206de01311
Merge:e91753a33
6564f4fa7
Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Mon May 1 06:49:21 2023 -0700 Merge pull request #1 from Rabbitminers/mc1.18/dev Bogey API commit6564f4fa73
Merge:e5d759582
e91753a33
Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Mon May 1 10:40:32 2023 +0100 Merge branch '1.18/api' into mc1.18/dev commite5d7595822
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 10:09:03 2023 +0100 Connected Custom Bogey Particle Types To CarriageParticles commite91753a33c
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 30 19:51:26 2023 -0700 Fix up some problems commit9815f1490f
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:12:43 2023 +0100 Implemented default data when shifting styles commitda30e78815
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:12:14 2023 +0100 Added Particles To Bogey Style (And Respective Builder) commit08c000b8ba
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:01:19 2023 +0100 Added Backup Rendering If A Size Is Not Present commit2b76e8d7b3
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:00:40 2023 +0100 Added Common Renderer To Remove Function commit411ec36f57
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:59:50 2023 +0100 Added Display Name To Standard Bogey Style commit112306d5d4
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:59:30 2023 +0100 Displayed new style name when changing betweeen them commit5634670b27
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:06:00 2023 +0100 General Cleanup commit0f7a8b7b24
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:05:50 2023 +0100 Implemented Changes To Remaining Classes commit8aedc00f96
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:02:06 2023 +0100 Removed Bogey Style Handling From Registrate commitedf8079abf
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:40 2023 +0100 Removed Unused Registry Handling commit6a185c4e72
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:16 2023 +0100 Refactored Bogey Sizes commite10d07ddc3
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:00 2023 +0100 Overhauled Bogey Style commit74d98a2ad5
Merge:e629d02f5
4ebcf8201
Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Sun Apr 23 07:16:33 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into 1.18/api commite629d02f50
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 9 07:18:22 2023 -0700 Track API Clean up code a bit commitd9ce6ce995
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 9 07:14:46 2023 -0700 Track API? Fix placement commit7fbf08ba54
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat Apr 8 11:11:24 2023 -0700 Track API? Fix up some placement issues commit35644f1434
Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat Apr 8 08:11:13 2023 -0700 Track API maybe? Datagen Seems to be working commitf7c56b867a
Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu Apr 6 21:24:31 2023 -0700 Track API maybe? Fix build - broken generic Not yet tested, but it is progress commit2a59fd7e8a
Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu Apr 6 21:13:54 2023 -0700 Track API maybe? Not yet tested, but it is progress commit5ba30d6a85
Merge:e4e5ac1c4
c2977bbff
Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu Apr 6 17:10:39 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into 1.18/api commitd52065808c
Merge:e4e5ac1c4
c2977bbff
Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu Apr 6 17:10:26 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into mc1.18/dev commit53240bd42f
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 21:42:29 2023 +0100 Corrected Bogey InteractionResult To Pass commit69326e361a
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 21:30:28 2023 +0100 Fixed Default Values When Used Styles Are Removed commit4f176979de
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 19:33:17 2023 +0100 Fixed Carriage Sounds (Again) commit1e80af3303
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 19:27:58 2023 +0100 Refactored Bogey Sizes To Seperate Class commit129be61fee
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 17:20:17 2023 +0100 Fixed Bogey Sound Loading commit2543185a55
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 09:45:23 2023 +0100 Added Bogey Sound Customisation commit1ad5ae9514
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 00:44:53 2023 +0100 Added Size Transforms If Size Is Not Available For New Style commit96566b1614
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 23:02:02 2023 +0100 Moved Bogey Style Inside Of Bogey Data And Implemented Bogey Data Communication commiteedd984738
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:53:55 2023 +0100 Fixed Large Bogey Size commit68ca0974c6
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:47:58 2023 +0100 Implemented Style Cycling & Default Values commita55ba4267a
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:46:15 2023 +0100 Implemented renderer instance creator commit43523302c2
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:45:33 2023 +0100 Removed Unused Standard Bogey Instance commit773e084422
Merge:0c0b5a1ed
d1e1f7ec5
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:50:15 2023 +0100 Merge remote-tracking branch 'origin/mc1.18/dev' into mc1.18/dev # Conflicts: # src/main/java/com/simibubi/create/AllBogeyStyles.java # src/main/java/com/simibubi/create/content/logistics/trains/BogeyTileEntityRenderer.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/StandardBogeyInstance.java # src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java commit0c0b5a1ed6
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:39:58 2023 +0100 Linked Style Registry To Bogey Blocks commit71f839ee51
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:39:03 2023 +0100 Replaced size boolean with direct use of size enum commit50ff081704
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:47:13 2023 +0100 Added Resource Location To NBT helper methods commitd1e1f7ec5a
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:47:13 2023 +0100 Re-worked BogeyStyles commitda593fccb1
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:46:02 2023 +0100 Refactored IBogeyBlock to AbstractBogeyBlock and extracted relevant StandardBogeyBlock implementations commit17432c9113
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Mar 25 10:20:50 2023 +0000 Fixed Incorrect Registry Loading commitc7d899369a
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:44:03 2023 +0000 Registered Registers commit6d862290d7
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:43:23 2023 +0000 Added BogeyStyleBuilder To Registrate commit3dfb9e3b3b
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:43:08 2023 +0000 Implemented AllBogeyStyles commitc9e71b462d
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:42:56 2023 +0000 Created BogeyStyleBuilder commita90977d642
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:42:25 2023 +0000 Created AllRegistries and BogeyStyle Registry commit154d455f3f
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:41:56 2023 +0000 Added BogeyStyle Wrapper commitdfb7640bfc
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:50:41 2023 +0000 Removed left over logging statement commit9920536cc3
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:50:18 2023 +0000 Implemented Secondary Shaft To Large Renderer commit6cd40cc6f9
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:49:56 2023 +0000 Prevented Overwrite When Using Two BlockStates Of The Same Type With Different Properties commit06fb901144
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:39:11 2023 +0000 Implemented Common Rendering For StandardBogeyRenderer commit435b0f8266
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:38:40 2023 +0000 Added Common Renderer commit96a0623dab
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:38:29 2023 +0000 Implemented BlockState Models For Rendering commit469d9d592b
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:42:28 2023 +0000 Added Standard Bogey Instance (Might be redundant) commit2661d260d8
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:42:06 2023 +0000 Refactored Changes To Existing Methods commit9ded16fbab
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:41:15 2023 +0000 Integrated BogeyRenderer To BogeyInstance (Also Corrected Rendering In Contraption) commit4a82fcbca1
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:40:13 2023 +0000 Implemented Changes To StandardBogeyBlock commit7238fb93f3
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:39:51 2023 +0000 Added Renderer To IBogeyBlock commitded4c1f613
Merge:91727cc84
3c02fe6ec
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:37 2023 +0000 Merge remote-tracking branch 'origin/mc1.18/dev' into mc1.18/dev commit91727cc84a
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:28 2023 +0000 Implemented Model Data Initializer to StandardBogeyRenderer commit6d98a1f469
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:00 2023 +0000 Added Contraption Model Instance Initializer commit3c02fe6ecc
Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Tue Mar 21 22:45:34 2023 +0000 Added missing render type check commit6672c49649
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue Mar 21 22:37:36 2023 +0000 Re-created standard bogey with test api commita8a9491fa0
Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue Mar 21 22:34:54 2023 +0000 Implemented Proof Of Concept Generic Bogey Renderer commite4e5ac1c40
Author: SpottyTheTurtle <69260662+SpottyTheTurtle@users.noreply.github.com> Date: Sat Mar 11 21:34:59 2023 +0000 init
458 lines
14 KiB
Java
458 lines
14 KiB
Java
package com.simibubi.create.content.logistics.trains.entity;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Map.Entry;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import java.util.Vector;
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.BiFunction;
|
|
import java.util.function.BiPredicate;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Predicate;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import com.simibubi.create.Create;
|
|
import com.simibubi.create.content.logistics.trains.DimensionPalette;
|
|
import com.simibubi.create.content.logistics.trains.GraphLocation;
|
|
import com.simibubi.create.content.logistics.trains.TrackEdge;
|
|
import com.simibubi.create.content.logistics.trains.TrackGraph;
|
|
import com.simibubi.create.content.logistics.trains.TrackNode;
|
|
import com.simibubi.create.content.logistics.trains.TrackNodeLocation;
|
|
import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgeData;
|
|
import com.simibubi.create.content.logistics.trains.management.edgePoint.signal.TrackEdgePoint;
|
|
import com.simibubi.create.foundation.utility.Couple;
|
|
import com.simibubi.create.foundation.utility.Pair;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.nbt.Tag;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class TravellingPoint {
|
|
|
|
public TrackNode node1, node2;
|
|
public TrackEdge edge;
|
|
public double position;
|
|
public boolean blocked;
|
|
public boolean upsideDown;
|
|
|
|
public static enum SteerDirection {
|
|
NONE(0), LEFT(-1), RIGHT(1);
|
|
|
|
float targetDot;
|
|
|
|
private SteerDirection(float targetDot) {
|
|
this.targetDot = targetDot;
|
|
}
|
|
}
|
|
|
|
public static interface ITrackSelector
|
|
extends BiFunction<TrackGraph, Pair<Boolean, List<Entry<TrackNode, TrackEdge>>>, Entry<TrackNode, TrackEdge>> {
|
|
};
|
|
|
|
public static interface IEdgePointListener extends BiPredicate<Double, Pair<TrackEdgePoint, Couple<TrackNode>>> {
|
|
};
|
|
|
|
public static interface ITurnListener extends BiConsumer<Double, TrackEdge> {
|
|
};
|
|
|
|
public static interface IPortalListener extends Predicate<Couple<TrackNodeLocation>> {
|
|
};
|
|
|
|
public TravellingPoint() {}
|
|
|
|
public TravellingPoint(TrackNode node1, TrackNode node2, TrackEdge edge, double position, boolean upsideDown) {
|
|
this.node1 = node1;
|
|
this.node2 = node2;
|
|
this.edge = edge;
|
|
this.position = position;
|
|
this.upsideDown = upsideDown;
|
|
}
|
|
|
|
public IEdgePointListener ignoreEdgePoints() {
|
|
return (d, c) -> false;
|
|
}
|
|
|
|
public ITurnListener ignoreTurns() {
|
|
return (d, c) -> {
|
|
};
|
|
}
|
|
|
|
public IPortalListener ignorePortals() {
|
|
return $ -> false;
|
|
}
|
|
|
|
public ITrackSelector random() {
|
|
return (graph, pair) -> pair.getSecond()
|
|
.get(Create.RANDOM.nextInt(pair.getSecond()
|
|
.size()));
|
|
}
|
|
|
|
public ITrackSelector follow(TravellingPoint other) {
|
|
return follow(other, null);
|
|
}
|
|
|
|
public ITrackSelector follow(TravellingPoint other, @Nullable Consumer<Boolean> success) {
|
|
return (graph, pair) -> {
|
|
List<Entry<TrackNode, TrackEdge>> validTargets = pair.getSecond();
|
|
boolean forward = pair.getFirst();
|
|
TrackNode target = forward ? other.node1 : other.node2;
|
|
TrackNode secondary = forward ? other.node2 : other.node1;
|
|
|
|
for (Entry<TrackNode, TrackEdge> entry : validTargets)
|
|
if (entry.getKey() == target || entry.getKey() == secondary) {
|
|
if (success != null)
|
|
success.accept(true);
|
|
return entry;
|
|
}
|
|
|
|
Vector<List<Entry<TrackNode, TrackEdge>>> frontiers = new Vector<>(validTargets.size());
|
|
Vector<Set<TrackEdge>> visiteds = new Vector<>(validTargets.size());
|
|
|
|
for (int j = 0; j < validTargets.size(); j++) {
|
|
ArrayList<Entry<TrackNode, TrackEdge>> e = new ArrayList<>();
|
|
Entry<TrackNode, TrackEdge> entry = validTargets.get(j);
|
|
e.add(entry);
|
|
frontiers.add(e);
|
|
HashSet<TrackEdge> e2 = new HashSet<>();
|
|
e2.add(entry.getValue());
|
|
visiteds.add(e2);
|
|
}
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
for (int j = 0; j < validTargets.size(); j++) {
|
|
Entry<TrackNode, TrackEdge> entry = validTargets.get(j);
|
|
List<Entry<TrackNode, TrackEdge>> frontier = frontiers.get(j);
|
|
if (frontier.isEmpty())
|
|
continue;
|
|
|
|
Entry<TrackNode, TrackEdge> currentEntry = frontier.remove(0);
|
|
for (Entry<TrackNode, TrackEdge> nextEntry : graph.getConnectionsFrom(currentEntry.getKey())
|
|
.entrySet()) {
|
|
TrackEdge nextEdge = nextEntry.getValue();
|
|
if (!visiteds.get(j)
|
|
.add(nextEdge))
|
|
continue;
|
|
if (!currentEntry.getValue()
|
|
.canTravelTo(nextEdge))
|
|
continue;
|
|
|
|
TrackNode nextNode = nextEntry.getKey();
|
|
if (nextNode == target) {
|
|
if (success != null)
|
|
success.accept(true);
|
|
return entry;
|
|
}
|
|
|
|
frontier.add(nextEntry);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (success != null)
|
|
success.accept(false);
|
|
return validTargets.get(0);
|
|
};
|
|
}
|
|
|
|
public ITrackSelector steer(SteerDirection direction, Vec3 upNormal) {
|
|
return (graph, pair) -> {
|
|
List<Entry<TrackNode, TrackEdge>> validTargets = pair.getSecond();
|
|
double closest = Double.MAX_VALUE;
|
|
Entry<TrackNode, TrackEdge> best = null;
|
|
|
|
for (Entry<TrackNode, TrackEdge> entry : validTargets) {
|
|
Vec3 trajectory = edge.getDirection(false);
|
|
Vec3 entryTrajectory = entry.getValue()
|
|
.getDirection(true);
|
|
Vec3 normal = trajectory.cross(upNormal);
|
|
double dot = normal.dot(entryTrajectory);
|
|
double diff = Math.abs(direction.targetDot - dot);
|
|
if (diff > closest)
|
|
continue;
|
|
|
|
closest = diff;
|
|
best = entry;
|
|
}
|
|
|
|
if (best == null) {
|
|
Create.LOGGER.warn("Couldn't find steer target, choosing first");
|
|
return validTargets.get(0);
|
|
}
|
|
|
|
return best;
|
|
};
|
|
}
|
|
|
|
public double travel(TrackGraph graph, double distance, ITrackSelector trackSelector) {
|
|
return travel(graph, distance, trackSelector, ignoreEdgePoints());
|
|
}
|
|
|
|
public double travel(TrackGraph graph, double distance, ITrackSelector trackSelector,
|
|
IEdgePointListener signalListener) {
|
|
return travel(graph, distance, trackSelector, signalListener, ignoreTurns());
|
|
}
|
|
|
|
public double travel(TrackGraph graph, double distance, ITrackSelector trackSelector,
|
|
IEdgePointListener signalListener, ITurnListener turnListener) {
|
|
return travel(graph, distance, trackSelector, signalListener, turnListener, ignorePortals());
|
|
}
|
|
|
|
public double travel(TrackGraph graph, double distance, ITrackSelector trackSelector,
|
|
IEdgePointListener signalListener, ITurnListener turnListener, IPortalListener portalListener) {
|
|
blocked = false;
|
|
if (edge == null)
|
|
return 0;
|
|
double edgeLength = edge.getLength();
|
|
if (Mth.equal(distance, 0))
|
|
return 0;
|
|
|
|
double prevPos = position;
|
|
double traveled = distance;
|
|
double currentT = edgeLength == 0 ? 0 : position / edgeLength;
|
|
double incrementT = edge.incrementT(currentT, distance);
|
|
position = incrementT * edgeLength;
|
|
|
|
// FIXME: using incrementT like this becomes inaccurate at medium-long distances
|
|
// travelling points would travel only 50m instead of 100m due to the low
|
|
// incrementT at their starting position (e.g. bezier turn)
|
|
// In an ideal scenario the amount added to position would iterate the traversed
|
|
// edges for context first
|
|
|
|
// A workaround was added in TrackEdge::incrementT
|
|
|
|
List<Entry<TrackNode, TrackEdge>> validTargets = new ArrayList<>();
|
|
|
|
boolean forward = distance > 0;
|
|
double collectedDistance = forward ? -prevPos : -edgeLength + prevPos;
|
|
|
|
Double blockedLocation =
|
|
edgeTraversedFrom(graph, forward, signalListener, turnListener, prevPos, collectedDistance);
|
|
if (blockedLocation != null) {
|
|
position = blockedLocation.doubleValue();
|
|
traveled = position - prevPos;
|
|
return traveled;
|
|
}
|
|
|
|
if (forward) {
|
|
// Moving forward
|
|
while (position > edgeLength) {
|
|
validTargets.clear();
|
|
|
|
for (Entry<TrackNode, TrackEdge> entry : graph.getConnectionsFrom(node2)
|
|
.entrySet()) {
|
|
TrackNode newNode = entry.getKey();
|
|
if (newNode == node1)
|
|
continue;
|
|
|
|
TrackEdge newEdge = entry.getValue();
|
|
if (!edge.canTravelTo(newEdge))
|
|
continue;
|
|
|
|
validTargets.add(entry);
|
|
}
|
|
|
|
if (validTargets.isEmpty()) {
|
|
traveled -= position - edgeLength;
|
|
position = edgeLength;
|
|
blocked = true;
|
|
break;
|
|
}
|
|
|
|
Entry<TrackNode, TrackEdge> entry = validTargets.size() == 1 ? validTargets.get(0)
|
|
: trackSelector.apply(graph, Pair.of(true, validTargets));
|
|
|
|
if (entry.getValue()
|
|
.getLength() == 0 && portalListener.test(
|
|
Couple.create(node2.getLocation(), entry.getKey()
|
|
.getLocation()))) {
|
|
traveled -= position - edgeLength;
|
|
position = edgeLength;
|
|
blocked = true;
|
|
break;
|
|
}
|
|
|
|
node1 = node2;
|
|
node2 = entry.getKey();
|
|
edge = entry.getValue();
|
|
position -= edgeLength;
|
|
|
|
collectedDistance += edgeLength;
|
|
if (edge.isTurn())
|
|
turnListener.accept(collectedDistance, edge);
|
|
|
|
blockedLocation = edgeTraversedFrom(graph, forward, signalListener, turnListener, 0, collectedDistance);
|
|
|
|
if (blockedLocation != null) {
|
|
traveled -= position;
|
|
position = blockedLocation.doubleValue();
|
|
traveled += position;
|
|
break;
|
|
}
|
|
|
|
prevPos = 0;
|
|
edgeLength = edge.getLength();
|
|
}
|
|
|
|
} else {
|
|
// Moving backwards
|
|
while (position < 0) {
|
|
validTargets.clear();
|
|
|
|
for (Entry<TrackNode, TrackEdge> entry : graph.getConnectionsFrom(node1)
|
|
.entrySet()) {
|
|
TrackNode newNode = entry.getKey();
|
|
if (newNode == node2)
|
|
continue;
|
|
if (!graph.getConnectionsFrom(newNode)
|
|
.get(node1)
|
|
.canTravelTo(edge))
|
|
continue;
|
|
|
|
validTargets.add(entry);
|
|
}
|
|
|
|
if (validTargets.isEmpty()) {
|
|
traveled -= position;
|
|
position = 0;
|
|
blocked = true;
|
|
break;
|
|
}
|
|
|
|
Entry<TrackNode, TrackEdge> entry = validTargets.size() == 1 ? validTargets.get(0)
|
|
: trackSelector.apply(graph, Pair.of(false, validTargets));
|
|
|
|
if (entry.getValue()
|
|
.getLength() == 0 && portalListener.test(
|
|
Couple.create(entry.getKey()
|
|
.getLocation(), node1.getLocation()))) {
|
|
traveled -= position;
|
|
position = 0;
|
|
blocked = true;
|
|
break;
|
|
}
|
|
|
|
node2 = node1;
|
|
node1 = entry.getKey();
|
|
edge = graph.getConnectionsFrom(node1)
|
|
.get(node2);
|
|
collectedDistance += edgeLength;
|
|
edgeLength = edge.getLength();
|
|
position += edgeLength;
|
|
|
|
blockedLocation =
|
|
edgeTraversedFrom(graph, forward, signalListener, turnListener, edgeLength, collectedDistance);
|
|
|
|
if (blockedLocation != null) {
|
|
traveled -= position;
|
|
position = blockedLocation.doubleValue();
|
|
traveled += position;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return traveled;
|
|
}
|
|
|
|
private Double edgeTraversedFrom(TrackGraph graph, boolean forward, IEdgePointListener edgePointListener,
|
|
ITurnListener turnListener, double prevPos, double totalDistance) {
|
|
if (edge.isTurn())
|
|
turnListener.accept(Math.max(0, totalDistance), edge);
|
|
|
|
double from = forward ? prevPos : position;
|
|
double to = forward ? position : prevPos;
|
|
|
|
EdgeData edgeData = edge.getEdgeData();
|
|
List<TrackEdgePoint> edgePoints = edgeData.getPoints();
|
|
|
|
double length = edge.getLength();
|
|
for (int i = 0; i < edgePoints.size(); i++) {
|
|
int index = forward ? i : edgePoints.size() - i - 1;
|
|
TrackEdgePoint nextBoundary = edgePoints.get(index);
|
|
double locationOn = nextBoundary.getLocationOn(edge);
|
|
double distance = forward ? locationOn : length - locationOn;
|
|
if (forward ? (locationOn < from || locationOn >= to) : (locationOn <= from || locationOn > to))
|
|
continue;
|
|
Couple<TrackNode> nodes = Couple.create(node1, node2);
|
|
if (edgePointListener.test(totalDistance + distance, Pair.of(nextBoundary, forward ? nodes : nodes.swap())))
|
|
return locationOn;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void reverse(TrackGraph graph) {
|
|
TrackNode n = node1;
|
|
node1 = node2;
|
|
node2 = n;
|
|
position = edge.getLength() - position;
|
|
edge = graph.getConnectionsFrom(node1)
|
|
.get(node2);
|
|
}
|
|
|
|
public Vec3 getPosition() {
|
|
return getPosition(false);
|
|
}
|
|
|
|
public Vec3 getPosition(boolean flipped) {
|
|
return getPositionWithOffset(0, flipped);
|
|
}
|
|
|
|
public Vec3 getPositionWithOffset(double offset) {
|
|
return getPositionWithOffset(offset, false);
|
|
}
|
|
|
|
public Vec3 getPositionWithOffset(double offset, boolean flipUpsideDown) {
|
|
double t = (position + offset) / edge.getLength();
|
|
return edge.getPosition(t)
|
|
.add(edge.getNormal(node1, node2, t)
|
|
.scale(upsideDown^flipUpsideDown ? -1 : 1));
|
|
}
|
|
|
|
public void migrateTo(List<GraphLocation> locations) {
|
|
GraphLocation location = locations.remove(0);
|
|
TrackGraph graph = location.graph;
|
|
node1 = graph.locateNode(location.edge.getFirst());
|
|
node2 = graph.locateNode(location.edge.getSecond());
|
|
position = location.position;
|
|
edge = graph.getConnectionsFrom(node1)
|
|
.get(node2);
|
|
}
|
|
|
|
public CompoundTag write(DimensionPalette dimensions) {
|
|
CompoundTag tag = new CompoundTag();
|
|
Couple<TrackNode> nodes = Couple.create(node1, node2);
|
|
if (nodes.either(Objects::isNull))
|
|
return tag;
|
|
tag.put("Nodes", nodes.map(TrackNode::getLocation)
|
|
.serializeEach(loc -> loc.write(dimensions)));
|
|
tag.putDouble("Position", position);
|
|
tag.putBoolean("UpsideDown", upsideDown);
|
|
return tag;
|
|
}
|
|
|
|
public static TravellingPoint read(CompoundTag tag, TrackGraph graph, DimensionPalette dimensions) {
|
|
if (graph == null)
|
|
return new TravellingPoint(null, null, null, 0, false);
|
|
|
|
Couple<TrackNode> locs = tag.contains("Nodes")
|
|
? Couple.deserializeEach(tag.getList("Nodes", Tag.TAG_COMPOUND), c -> TrackNodeLocation.read(c, dimensions))
|
|
.map(graph::locateNode)
|
|
: Couple.create(null, null);
|
|
|
|
if (locs.either(Objects::isNull))
|
|
return new TravellingPoint(null, null, null, 0, false);
|
|
|
|
double position = tag.getDouble("Position");
|
|
return new TravellingPoint(locs.getFirst(), locs.getSecond(), graph.getConnectionsFrom(locs.getFirst())
|
|
.get(locs.getSecond()), position, tag.getBoolean("UpsideDown"));
|
|
}
|
|
|
|
}
|