Terraria ModLoader  0.11.7.8
A mod to make and play Terraria mods
MountLoader.cs
Go to the documentation of this file.
1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
3 using System;
4 using System.Collections.Generic;
5 using Terraria.DataStructures;
6 using Terraria.ID;
7 
8 namespace Terraria.ModLoader
9 {
13  public static class MountLoader
14  {
15  private static int nextMount = MountID.Count;
16  internal static readonly IDictionary<int, ModMountData> mountDatas = new Dictionary<int, ModMountData>();
17 
23  public static ModMountData GetMount(int type) {
24  if (mountDatas.ContainsKey(type)) {
25  return mountDatas[type];
26  }
27  return null;
28  }
29 
30  internal static int ReserveMountID() {
31  if (ModNet.AllowVanillaClients) throw new Exception("Adding mounts breaks vanilla client compatibility");
32 
33  int reserveID = nextMount;
34  nextMount++;
35  return reserveID;
36  }
37 
38  internal static void ResizeArrays() {
39  Array.Resize(ref MountID.Sets.Cart, nextMount);
40  Array.Resize(ref Mount.mounts, nextMount);
41  }
42 
43  internal static void Unload() {
44  mountDatas.Clear();
45  nextMount = MountID.Count;
46  }
47 
48  internal static bool IsModMountData(Mount.MountData mountData) {
49  return mountData.modMountData != null;
50  }
51 
52  internal static void SetupMount(Mount.MountData mount) {
53  if (IsModMountData(mount)) {
54  GetMount(mount.modMountData.Type).SetupMount(mount);
55  }
56  }
57 
58  public static void JumpHeight(Player mountedPlayer, Mount.MountData mount, ref int jumpHeight, float xVelocity) {
59  if (IsModMountData(mount)) {
60  mount.modMountData.JumpHeight(ref jumpHeight, xVelocity);
61  mount.modMountData.JumpHeight(mountedPlayer, ref jumpHeight, xVelocity);
62  }
63  }
64 
65  public static void JumpSpeed(Player mountedPlayer, Mount.MountData mount, ref float jumpSpeed, float xVelocity) {
66  if (IsModMountData(mount)) {
67  mount.modMountData.JumpSpeed(ref jumpSpeed, xVelocity);
68  mount.modMountData.JumpSpeed(mountedPlayer, ref jumpSpeed, xVelocity);
69  }
70  }
71 
72  internal static void UpdateEffects(Player mountedPlayer) {
73  if (IsModMountData(Mount.mounts[mountedPlayer.mount.Type])) {
74  GetMount(mountedPlayer.mount.Type).UpdateEffects(mountedPlayer);
75  }
76  }
77 
78  internal static bool UpdateFrame(Player mountedPlayer, int state, Vector2 velocity) {
79  if (IsModMountData(Mount.mounts[mountedPlayer.mount.Type])) {
80  return GetMount(mountedPlayer.mount.Type).UpdateFrame(mountedPlayer, state, velocity);
81  }
82  return true;
83  }
84 
85  //todo: this is never called, why is this in here?
86  internal static bool CustomBodyFrame(Mount.MountData mount) {
87  if (IsModMountData(mount) && mount.modMountData.CustomBodyFrame()) {
88  return true;
89  }
90  return false;
91  }
98  public static void UseAbility(Player player, Vector2 mousePosition, bool toggleOn) {
99  if (IsModMountData(player.mount._data)) {
100  player.mount._data.modMountData.UseAbility(player, mousePosition, toggleOn);
101  }
102  }
109  public static void AimAbility(Mount mount, Player player, Vector2 mousePosition) {
110  if (IsModMountData(mount._data)) {
111  mount._data.modMountData.AimAbility(player, mousePosition);
112  }
113  }
114 
122  public static void SetMount(Mount mount, Player player, ref bool skipDust) {
123  if (IsModMountData(mount._data)) {
124  mount._data.modMountData.SetMount(player, ref skipDust);
125  }
126  }
127 
135  public static void Dismount(Mount mount, Player player, ref bool skipDust) {
136  if (IsModMountData(mount._data)) {
137  mount._data.modMountData.Dismount(player, ref skipDust);
138  }
139  }
140 
144  public static bool Draw(Mount mount, List<DrawData> playerDrawData, int drawType, Player drawPlayer, ref Texture2D texture, ref Texture2D glowTexture, ref Vector2 drawPosition, ref Rectangle frame, ref Color drawColor, ref Color glowColor, ref float rotation, ref SpriteEffects spriteEffects, ref Vector2 drawOrigin, ref float drawScale, float shadow) {
145  if (IsModMountData(mount._data)) {
146  return mount._data.modMountData.Draw(playerDrawData, drawType, drawPlayer, ref texture, ref glowTexture, ref drawPosition, ref frame, ref drawColor, ref glowColor, ref rotation, ref spriteEffects, ref drawOrigin, ref drawScale, shadow);
147  }
148  return true;
149  }
150  }
151 }
static ModMountData GetMount(int type)
Gets the ModMountData instance corresponding to the given type. Returns null if no ModMountData has t...
Definition: MountLoader.cs:23
static bool AllowVanillaClients
Definition: ModNet.cs:53
static void JumpHeight(Player mountedPlayer, Mount.MountData mount, ref int jumpHeight, float xVelocity)
Definition: MountLoader.cs:58
static void UseAbility(Player player, Vector2 mousePosition, bool toggleOn)
Allows you to make things happen while the mouse is pressed while the mount is active. Called each tick the mouse is pressed.
Definition: MountLoader.cs:98
static bool Draw(Mount mount, List< DrawData > playerDrawData, int drawType, Player drawPlayer, ref Texture2D texture, ref Texture2D glowTexture, ref Vector2 drawPosition, ref Rectangle frame, ref Color drawColor, ref Color glowColor, ref float rotation, ref SpriteEffects spriteEffects, ref Vector2 drawOrigin, ref float drawScale, float shadow)
See ModMountData.Draw(List<DrawData>, int, Player, ref Texture2D, ref Texture2D, ref Vector2...
Definition: MountLoader.cs:144
This class serves as a place for you to place all your properties and hooks for each mount...
Definition: ModMountData.cs:14
static void AimAbility(Mount mount, Player player, Vector2 mousePosition)
Allows you to make things happen when the mount ability is aiming (while charging).
Definition: MountLoader.cs:109
static void SetMount(Mount mount, Player player, ref bool skipDust)
Allows you to make things happen when this mount is spawned in. Useful for player-specific initializa...
Definition: MountLoader.cs:122
static void JumpSpeed(Player mountedPlayer, Mount.MountData mount, ref float jumpSpeed, float xVelocity)
Definition: MountLoader.cs:65
This serves as the central place from which mounts are stored and mount-related functions are carried...
Definition: MountLoader.cs:13
static void Dismount(Mount mount, Player player, ref bool skipDust)
Allows you to make things happen when this mount is de-spawned. Useful for player-specific cleanup...
Definition: MountLoader.cs:135