Skip to content

Commit

Permalink
A splattering of Generics example.
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Dec 11, 2016
1 parent 7f7c734 commit 162a872
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ExampleMod/Buffs/CarMount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override void SetDefaults()

public override void Update(Player player, ref int buffIndex)
{
player.mount.SetMount(mod.MountType("Car"), player);
player.mount.SetMount(mod.MountType<Mounts.Car>(), player);
player.buffTime[buffIndex] = 10;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ExampleMod/ExampleMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public override Matrix ModifyTransformMatrix(Matrix Transform)
{
if (!Main.gameMenu)
{
ExampleWorld world = (ExampleWorld)GetModWorld("ExampleWorld");
ExampleWorld world = GetModWorld<ExampleWorld>();
if (world.VolcanoTremorTime > 0)
{
if (world.VolcanoTremorTime % ShakeLength == 0)
Expand Down Expand Up @@ -532,7 +532,7 @@ public override void HandlePacket(BinaryReader reader, int whoAmI)
// This message sent by the server to initialize the Volcano Tremor on clients
case ExampleModMessageType.SetTremorTime:
int tremorTime = reader.ReadInt32();
ExampleWorld world = (ExampleWorld)GetModWorld("ExampleWorld");
ExampleWorld world = GetModWorld<ExampleWorld>();
world.VolcanoTremorTime = tremorTime;
break;
// This message sent by the server to initialize the Volcano Rubble.
Expand Down
2 changes: 1 addition & 1 deletion ExampleMod/ExamplePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public override void PreUpdateBuffs()
}
if (heroLives == 1)
{
player.AddBuff(mod.BuffType("HeroOne"), 2);
player.AddBuff(mod.BuffType<Buffs.HeroOne>(), 2); // Consider using this alternate method call for maintainable code.
}
else if (heroLives == 2)
{
Expand Down
2 changes: 1 addition & 1 deletion ExampleMod/Items/SparklingSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void HoldItem(Player player)
Vector2 position = GetLightPosition(player) - new Vector2(20f, 20f);
if (Main.rand.Next(10) == 0)
{
Dust.NewDust(player.position, player.width, player.height, mod.DustType("Sparkle"));
Dust.NewDust(player.position, player.width, player.height, mod.DustType<Dusts.Sparkle>());
}
if (Main.rand.Next(3) == 0)
{
Expand Down
5 changes: 3 additions & 2 deletions ExampleMod/RecipeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public static void AddBossRecipes(Mod mod)
recipe.AddTile(null, "ExampleWorkbench");
recipe.SetResult(ItemID.MechanicalSkull, 20);
recipe.AddRecipe();
// Here we see another way to retrieve type ids from classnames. Useful for those who program in an IDE who wish to avoid spelling mistakes.
recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "BossItem", 10);
recipe.AddTile(null, "ExampleWorkbench");
recipe.AddIngredient(mod.ItemType<Items.BossItem>(), 10);
recipe.AddTile(mod.TileType<Tiles.ExampleWorkbench>());
recipe.SetResult(ItemID.LihzahrdPowerCell, 20);
recipe.AddRecipe();
}
Expand Down

0 comments on commit 162a872

Please sign in to comment.