Skip to content

Commit

Permalink
changed how some tile hooks work
Browse files Browse the repository at this point in the history
  • Loading branch information
blushiemagic committed Jul 30, 2015
1 parent 8d2b926 commit e184a66
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
1 change: 0 additions & 1 deletion Terraria.ModLoader/ErrorLogger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace Terraria.ModLoader {
Expand Down
8 changes: 4 additions & 4 deletions Terraria.ModLoader/GlobalTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public virtual void SetDefaults() { }

public virtual bool KillSound(int i, int j, int type)
{
return false;
return true;
}

public virtual void NumDust(int i, int j, int type, ref int num) { }
public virtual void NumDust(int i, int j, int type, bool fail, ref int num) { }

public virtual bool CreateDust(int i, int j, int type, ref int dustType)
{
return false;
return true;
}

public virtual void DropCritterChance(int i, int j, int type, ref int wormChance, ref int grassHopperChance, ref int jungleGrubChance) { }

public virtual bool Drop(int i, int j, int type)
{
return false;
return true;
}

public virtual void KillTile(int i, int j, int type, ref bool fail, ref bool effectOnly, ref bool noItem) { }
Expand Down
9 changes: 4 additions & 5 deletions Terraria.ModLoader/ModTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public ushort Type

public int soundType = 0;
public int soundStyle = 1;
public int numDust = 10;
public int dustType = 0;
public int drop = 0;

Expand All @@ -43,22 +42,22 @@ public virtual void SetDefaults() { }

public virtual bool KillSound(int i, int j)
{
return false;
return true;
}

public virtual void NumDust(int i, int j, ref int num) { }
public virtual void NumDust(int i, int j, bool fail, ref int num) { }

public virtual bool CreateDust(int i, int j, ref int type)
{
type = dustType;
return false;
return true;
}

public virtual void DropCritterChance(int i, int j, ref int wormChance, ref int grassHopperChance, ref int jungleGrubChance) { }

public virtual bool Drop(int i, int j)
{
return false;
return true;
}

public virtual void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) { }
Expand Down
45 changes: 22 additions & 23 deletions Terraria.ModLoader/TileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Terraria.ObjectData;

namespace Terraria.ModLoader {
public class TileLoader
public static class TileLoader
{
//make Terraria.ObjectData.TileObjectData._data internal
//make all static Terraria.ObjectData.TileObjectData.StyleName fields public
Expand Down Expand Up @@ -280,44 +280,43 @@ internal static void SetDefaults(ModTile tile)
}

//in Terraria.WorldGen.KillTile inside if (!effectOnly && !WorldGen.stopDrops) for playing sounds
// add if(TileLoader.KillSound(i, j, tile.type)) { } to beginning of if/else chain and turn first if into else if
// add if(!TileLoader.KillSound(i, j, tile.type)) { } to beginning of if/else chain and turn first if into else if
internal static bool KillSound(int i, int j, int type)
{
foreach(Mod mod in ModLoader.mods.Values)
{
if(mod.globalTile != null && mod.globalTile.KillSound(i, j, type))
if(mod.globalTile != null && !mod.globalTile.KillSound(i, j, type))
{
return true;
return false;
}
}
ModTile modTile = GetTile(type);
if(modTile != null)
{
if(modTile.KillSound(i, j))
if(!modTile.KillSound(i, j))
{
return true;
return false;
}
Main.PlaySound(modTile.soundType, i * 16, j * 16, modTile.soundStyle);
return true;
return false;
}
return false;
return true;
}

//in Terraria.WorldGen.KillTile before num14 (num dust iteration) is declared, add
// TileLoader.NumDust(i, j, tile.type, ref num13);
internal static void NumDust(int i, int j, int type, ref int numDust)
internal static void NumDust(int i, int j, int type, bool fail, ref int numDust)
{
ModTile modTile = GetTile(type);
if(modTile != null)
{
numDust = modTile.numDust;
modTile.NumDust(i, j, ref numDust);
modTile.NumDust(i, j, fail, ref numDust);
}
foreach(Mod mod in ModLoader.mods.Values)
{
if(mod.globalTile != null)
{
mod.globalTile.NumDust(i, j, type, ref numDust);
mod.globalTile.NumDust(i, j, type, fail, ref numDust);
}
}
}
Expand All @@ -328,17 +327,17 @@ internal static bool CreateDust(int i, int j, int type, ref int dustType)
{
foreach(Mod mod in ModLoader.mods.Values)
{
if(mod.globalTile != null && mod.globalTile.CreateDust(i, j, type, ref dustType))
if(mod.globalTile != null && !mod.globalTile.CreateDust(i, j, type, ref dustType))
{
return true;
return false;
}
}
ModTile modTile = GetTile(type);
if(modTile != null)
{
return modTile.CreateDust(i, j, ref dustType);
}
return false;
return true;
}

//in Terraria.WorldGen.KillTile before if statement checking num43 call
Expand All @@ -360,28 +359,28 @@ internal static void DropCritterChance(int i, int j, int type, ref int wormChanc
}

//in Terraria.WorldGen.KillTile before if statements checking num49 and num50
// add bool modDrop = TileLoader.Drop(i, j, tile.type);
// add "!modDrop && " to beginning of these if statements
// add bool vanillaDrop = TileLoader.Drop(i, j, tile.type);
// add "vanillaDrop && " to beginning of these if statements
internal static bool Drop(int i, int j, int type)
{
foreach(Mod mod in ModLoader.mods.Values)
{
if(mod.globalTile != null && mod.globalTile.Drop(i, j, type))
if(mod.globalTile != null && !mod.globalTile.Drop(i, j, type))
{
return true;
return false;
}
}
ModTile modTile = GetTile(type);
if(modTile != null)
{
if(modTile.Drop(i, j))
if(!modTile.Drop(i, j))
{
return true;
return false;
}
Item.NewItem(i * 16, j * 16, 16, 16, modTile.drop, 1, false, -1, false, false);
return true;
return false;
}
return false;
return true;
}

//in Terraria.WorldGen.KillTile before if (!effectOnly && !WorldGen.stopDrops) add
Expand Down

0 comments on commit e184a66

Please sign in to comment.