private static bool Patch_BlockEntityTeleporter_OnEntityCollide_Prefix( ref BlockEntityTeleporter __instance, ref Dictionary <long, TeleportingEntity> ___tpingEntities, ref TeleporterLocation ___tpLocation) { // TODO: Still very hacky. It would be very nice to get a proper way of setting this waypoint. // // Developer's Notes: As of Game Version 1.14.10. There is currently no way to gather information // about the target side of a Teleporter block, other than its name, from the // Client API. In order for this to work, I would need to trick the server into // sending the client the updated list of teleporters on the server. // // This should be possible by mimicking the action of refreshing the GUI dialogue // without the dialogue box needing to be opened. However, parts of the dialogue // logic is locked behind a GameMode check. I could, internally switch the player // to creative and back, purely for this check, and it might even be possible to // do this check at player login, before the user has control of the player character. // // I'd then store the list of teleporters in memory, ready for use, if needed. if (JustTeleported > 0) { return(true); } if (!Settings.AutoTranslocatorWaypoints) { return(true); } if (!___tpingEntities.ContainsKey(Api.World.Player.Entity.EntityId)) { return(true); } // Add Source TP Waypoint. if (Api.WaypointExistsAtPos(__instance.Pos, p => p.Icon == "spiral")) { return(true); } var title = LangEx.Message("TeleporterWaypoint", ___tpLocation?.TargetName?.IfNullOrWhitespace("Unknown")); var sourcePos = __instance.Pos.RelativeToSpawn(Api.World); Api.AddWaypointAtPos(sourcePos, "spiral", "SpringGreen", title, false); Api.Logger.VerboseDebug($"Added Waypoint: {title}"); JustTeleported = 1; Task.Factory.StartNew(() => { Thread.Sleep(1000 * 10); JustTeleported = 0; Api.Logger.VerboseDebug("Teleporter Waypoint Cooldown Reset."); }); return(true); }
// Make the contents of the window void DoMainWindow(int windowID) { GUI.DragWindow(new Rect(0, 0, 10000, 20)); GUILayout.BeginVertical(); { GUILayout.BeginHorizontal(); { saveName = GUILayout.TextField(saveName); if (GUILayout.Button("Save", GUILayout.Width(80f))) { var t = new TeleporterLocation(saveName); t.SaveToDirectory(Main.MarkerSavesDirectory); UpdateMarkerList(); } } GUILayout.EndHorizontal(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); TeleportDirectly = GUILayout.Toggle(TeleportDirectly, "Directly teleport to marker"); if (GUILayout.Button("↺", GUILayout.Width(20f))) { UpdateMarkerList(); } GUILayout.EndHorizontal(); GUILayout.Space(10f); scrollPosition = GUILayout.BeginScrollView(scrollPosition); { foreach (string path in MarkerPaths) { DrawGUIForMarker(path); } } GUILayout.EndScrollView(); } GUILayout.EndVertical(); }
void DrawGUIForMarker(string path) { string name = path.Substring(path.LastIndexOf('\\') + 1); name = name.Remove(name.LastIndexOf(".json")); GUILayout.BeginHorizontal(); { if (GUILayout.Button(name)) { TeleporterLocation.LoadFromFile(path).Apply(); if (TeleportDirectly) { PlayerController.Instance.respawn.DoRespawn(); } } if (GUILayout.Button("X", GUILayout.Width(20f))) { toDeleteName = name; toDeletePath = path; } } GUILayout.EndHorizontal(); }