Skip to content

Commit 5d09aa6

Browse files
authored
Merge pull request #1 from SamsonAllen13/1.4
1.4 Port
2 parents 595f9be + feca4a0 commit 5d09aa6

File tree

10 files changed

+201
-114
lines changed

10 files changed

+201
-114
lines changed

ClickerClassExampleMod.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ namespace ClickerClassExampleMod
44
{
55
public class ClickerClassExampleMod : Mod
66
{
7-
public override void Load()
8-
{
9-
ClickerCompat.Load();
10-
}
117

12-
public override void Unload()
13-
{
14-
ClickerCompat.Unload();
15-
}
168
}
179
}

ClickerClassExampleMod.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
3-
<Import Project="..\..\references\tModLoader.targets" />
3+
<Import Project="../tModLoader.targets" />
44
<PropertyGroup>
55
<AssemblyName>ClickerClassExampleMod</AssemblyName>
6-
<TargetFramework>net45</TargetFramework>
7-
<PlatformTarget>x86</PlatformTarget>
8-
<LangVersion>7.3</LangVersion>
6+
<TargetFramework>net6.0</TargetFramework>
7+
<PlatformTarget>AnyCPU</PlatformTarget>
8+
<LangVersion>latest</LangVersion>
99
</PropertyGroup>
10-
<Target Name="BuildMod" AfterTargets="Build">
11-
<Exec Command="&quot;$(tMLBuildServerPath)&quot; -build $(ProjectDir) -eac $(TargetPath) -define $(DefineConstants) -unsafe $(AllowUnsafeBlocks)" />
12-
</Target>
1310
<ItemGroup>
1411
<PackageReference Include="tModLoader.CodeAssist" Version="0.1.*" />
1512
</ItemGroup>

ClickerCompat.cs

Lines changed: 99 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using Terraria;
5+
using Terraria.DataStructures;
56
using Terraria.ModLoader;
67

78
namespace ClickerClassExampleMod
@@ -10,7 +11,7 @@ namespace ClickerClassExampleMod
1011
/// <summary>
1112
/// Central file used for mod.Call wrappers.
1213
/// </summary>
13-
internal static class ClickerCompat
14+
internal class ClickerCompat : ModSystem
1415
{
1516
//GENERAL INFO - PLEASE READ THIS FIRST!
1617
//-----------------------
@@ -22,7 +23,7 @@ internal static class ClickerCompat
2223

2324
//This is the version of the calls that are used for the mod.
2425
//If Clicker Class updates, it will keep working on the outdated calls, but new features might not be available
25-
internal static readonly Version apiVersion = new Version(1, 2, 6);
26+
internal static readonly Version apiVersion = new Version(1, 3, 2);
2627

2728
internal static string versionString;
2829

@@ -32,22 +33,20 @@ internal static Mod ClickerClass
3233
{
3334
get
3435
{
35-
if (clickerClass == null)
36+
if (clickerClass == null && ModLoader.TryGetMod("ClickerClass", out var mod))
3637
{
37-
clickerClass = ModLoader.GetMod("ClickerClass");
38+
clickerClass = mod;
3839
}
3940
return clickerClass;
4041
}
4142
}
4243

43-
//Call this in your main Mod class in the Load hook like this: ClickerCompat.Load();
44-
internal static void Load()
44+
public override void Load()
4545
{
4646
versionString = apiVersion.ToString();
4747
}
4848

49-
//Call this in your main Mod class in the Unload hook like this: ClickerCompat.Unload();
50-
internal static void Unload()
49+
public override void Unload()
5150
{
5251
clickerClass = null;
5352
versionString = null;
@@ -59,7 +58,7 @@ internal static void Unload()
5958
#region General Calls
6059
/// <summary>
6160
/// Call in <see cref="ModItem.SetDefaults"/> to set important default fields for a clicker weapon. Set fields:
62-
/// useTime, useAnimation, useStyle, holdStyle, noMelee, shoot, shootSpeed.
61+
/// DamageType, useTime, useAnimation, useStyle, holdStyle, noMelee, shoot, shootSpeed.
6362
/// Only change them afterwards if you know what you are doing!
6463
/// </summary>
6564
/// <param name="item">The <see cref="Item"/> to set the defaults for</param>
@@ -68,6 +67,17 @@ internal static void SetClickerWeaponDefaults(Item item)
6867
ClickerClass?.Call("SetClickerWeaponDefaults", versionString, item);
6968
}
7069

70+
/// <summary>
71+
/// Call in <see cref="ModProjectile.SetDefaults"/> to set important default fields for a clicker projectile. Set fields:
72+
/// DamageType.
73+
/// Only change them afterwards if you know what you are doing!
74+
/// </summary>
75+
/// <param name="proj">The <see cref="Projectile"/> to set the defaults for</param>
76+
internal static void SetClickerProjectileDefaults(Projectile proj)
77+
{
78+
ClickerClass?.Call("SetClickerProjectileDefaults", versionString, proj);
79+
}
80+
7181
/// <summary>
7282
/// Call this in <see cref="ModProjectile.SetStaticDefaults"/> to register this projectile into the "clicker class" category
7383
/// </summary>
@@ -77,6 +87,17 @@ internal static void RegisterClickerProjectile(ModProjectile modProj)
7787
ClickerClass?.Call("RegisterClickerProjectile", versionString, modProj);
7888
}
7989

90+
/// <summary>
91+
/// Call this in <see cref="ModProjectile.SetStaticDefaults"/> to register this projectile into the "clicker weapon" category.
92+
/// <br>This is only for projectiles spawned by clickers directly (Item.shoot). Clicker Class only uses one such projectile for all it's clickers. Only use this if you know what you are doing!</br>
93+
/// <br>Various effects will only proc "on click" by checking this category instead of "all clicker class projectiles"</br>
94+
/// </summary>
95+
/// <param name="modProj">The <see cref="ModProjectile"/> that is to be registered</param>
96+
internal static void RegisterClickerWeaponProjectile(ModProjectile modProj)
97+
{
98+
ClickerClass?.Call("RegisterClickerWeaponProjectile", versionString, modProj);
99+
}
100+
80101
/// <summary>
81102
/// Call this in <see cref="ModItem.SetStaticDefaults"/> to register this item into the "clicker class" category
82103
/// </summary>
@@ -105,11 +126,29 @@ internal static void RegisterClickerWeapon(ModItem modItem, string borderTexture
105126
/// <param name="displayName">The name of the effect, null if you use lang keys (Defaults to ClickEffect.[internalName].Name)</param>
106127
/// <param name="description">The basic description of the effect, string.Empty for none, null if you use lang keys (Defaults to ClickEffect.[internalName].Description)</param>
107128
/// <param name="amount">The amount of clicks required to trigger the effect</param>
129+
/// <param name="colorFunc">The (dynamic) text color representing the effect in the tooltip</param>
130+
/// <param name="action">The method that runs when the effect is triggered</param>
131+
/// <returns>The unique identifier, null if an exception occured. READ THE LOGS!</returns>
132+
internal static string RegisterClickEffect(Mod mod, string internalName, string displayName, string description, int amount, Func<Color> colorFunc, Action<Player, EntitySource_ItemUse_WithAmmo, Vector2, int, int, float> action)
133+
{
134+
return ClickerClass?.Call("RegisterClickEffect", versionString, mod, internalName, displayName, description, amount, colorFunc, action) as string;
135+
}
136+
137+
/// <summary>
138+
/// Call this in <see cref="Mod.PostSetupContent"/> or <see cref="ModItem.SetStaticDefaults"/> to register this click effect
139+
/// </summary>
140+
/// <param name="mod">The mod this effect belongs to. ONLY USE YOUR OWN MOD INSTANCE FOR THIS!</param>
141+
/// <param name="internalName">The internal name of the effect. Turns into the unique name combined with the associated mod</param>
142+
/// <param name="displayName">The name of the effect, null if you use lang keys (Defaults to ClickEffect.[internalName].Name)</param>
143+
/// <param name="description">The basic description of the effect, string.Empty for none, null if you use lang keys (Defaults to ClickEffect.[internalName].Description)</param>
144+
/// <param name="amount">The amount of clicks required to trigger the effect</param>
145+
/// <param name="color">The text color representing the effect in the tooltip</param>
108146
/// <param name="action">The method that runs when the effect is triggered</param>
147+
/// <remarks>For dynamic colors, use the Func[Color] overload</remarks>
109148
/// <returns>The unique identifier, null if an exception occured. READ THE LOGS!</returns>
110-
internal static string RegisterClickEffect(Mod mod, string internalName, string displayName, string description, int amount, Color color, Action<Player, Vector2, int, int, float> action)
149+
internal static string RegisterClickEffect(Mod mod, string internalName, string displayName, string description, int amount, Color color, Action<Player, EntitySource_ItemUse_WithAmmo, Vector2, int, int, float> action)
111150
{
112-
return ClickerClass?.Call("RegisterClickEffect", versionString, mod, internalName, displayName, description, amount, color, action) as string;
151+
return RegisterClickEffect(mod, internalName, displayName, description, amount, () => color, action);
113152
}
114153

115154
/// <summary>
@@ -133,14 +172,14 @@ internal static List<string> GetAllEffectNames()
133172

134173
/// <summary>
135174
/// Access an effect's stats. <see cref="null"/> if not found.
136-
/// "Mod": The mod the effect belongs to (string).
175+
/// "Mod": The mod the effect belongs to (Mod).
137176
/// | "InternalName": The internal name (string).
138-
/// | "UniqueName": The unique name (string).
177+
/// | "UniqueName": The unique name (string) (should match the input string).
139178
/// | "DisplayName": The displayed name (string).
140179
/// | "Description": The description (string).
141180
/// | "Amount": The amount of clicks to trigger the effect (int).
142-
/// | "Color": The color (Color).
143-
/// | "Action": The method ran when triggered (Action[Player, Vector2, int, int, float]).
181+
/// | "ColorFunc": The color (Color) if invoked.
182+
/// | "Action": The method ran when triggered (Action[Player, EntitySource_ItemUse_WithAmmo, Vector2, int, int, float]).
144183
/// </summary>
145184
/// <param name="effect">The unique effect name</param>
146185
/// <returns>Dictionary[string, object]</returns>
@@ -179,6 +218,28 @@ internal static bool IsClickerProj(Projectile proj)
179218
return ClickerClass?.Call("IsClickerProj", versionString, proj) as bool? ?? false;
180219
}
181220

221+
/// <summary>
222+
/// Call this to check if a projectile type belongs to the "clicker weapon" category.
223+
/// <br>Various effects will only proc "on click" by checking this category instead of "all clicker class projectiles"</br>
224+
/// </summary>
225+
/// <param name="type">The item type to be checked</param>
226+
/// <returns><see langword="true"/> if that category</returns>
227+
internal static bool IsClickerWeaponProj(int type)
228+
{
229+
return ClickerClass?.Call("IsClickerWeaponProj", versionString, type) as bool? ?? false;
230+
}
231+
232+
/// <summary>
233+
/// Call this to check if a projectile belongs to the "clicker weapon" category.
234+
/// <br>Various effects will only proc "on click" by checking this category instead of "all clicker class projectiles"</br>
235+
/// </summary>
236+
/// <param name="proj">The <see cref="Projectile"/> to be checked</param>
237+
/// <returns><see langword="true"/> if that category</returns>
238+
internal static bool IsClickerWeaponProj(Projectile proj)
239+
{
240+
return ClickerClass?.Call("IsClickerWeaponProj", versionString, proj) as bool? ?? false;
241+
}
242+
182243
/// <summary>
183244
/// Call this to check if an item type belongs to the "clicker class" category
184245
/// </summary>
@@ -331,7 +392,7 @@ internal static int GetClickerAmountTotal(Player player, Item item, string effec
331392

332393
/// <summary>
333394
/// Call to check if the player is wearing a specific set. Supported sets:
334-
/// Motherboard, Overclock, Precursor, Mice
395+
/// Motherboard, Overclock, Precursor, Mice, RGB
335396
/// </summary>
336397
/// <param name="player">The player</param>
337398
internal static bool GetArmorSet(Player player, string set)
@@ -341,8 +402,7 @@ internal static bool GetArmorSet(Player player, string set)
341402

342403
/// <summary>
343404
/// Call to check if a specific accessory effect is enabled (i.e. "Gamer Crate" will have multiple effects enabled). Supported accessories:
344-
/// ChocolateChip, EnchantedLED, HandCream, StickyKeychain, GlassOfMilk, Cookie, ClickingGlove, AncientClickingGlove, RegalClickingGlove, GoldenTicket, PortableParticleAccelerator.
345-
/// Visual variants (i.e. EnchantedLED2) are not gettable
405+
/// ChocolateChip, EnchantedLED, EnchantedLED2, HandCream, StickyKeychain, GlassOfMilk, CookieVisual, CookieVisual2, ClickingGlove, AncientClickingGlove, RegalClickingGlove, GoldenTicket, PortableParticleAccelerator, IcePack, MouseTrap, HotKeychain, TriggerFinger, ButtonMasher, AimAssistModule, AimbotModule.
346406
/// </summary>
347407
/// <param name="player">The player</param>
348408
internal static bool GetAccessory(Player player, string accessory)
@@ -352,15 +412,34 @@ internal static bool GetAccessory(Player player, string accessory)
352412

353413
/// <summary>
354414
/// Call to set a specific player accessory effect (i.e. to emulate "Gamer Crate" you need to have set multiple effects). Supported accessories:
355-
/// ChocolateChip, EnchantedLED, HandCream, StickyKeychain, GlassOfMilk, Cookie, ClickingGlove, AncientClickingGlove, RegalClickingGlove.
356-
/// EnchantedLED and Cookie have a variant with "2" added to them that is a visual variation.
415+
/// ChocolateChip, EnchantedLED, EnchantedLED2, HandCream, StickyKeychain, GlassOfMilk, CookieVisual, CookieVisual2, ClickingGlove, AncientClickingGlove, RegalClickingGlove, GoldenTicket, PortableParticleAccelerator, IcePack, MouseTrap, HotKeychain, TriggerFinger, ButtonMasher, AimAssistModule, AimbotModule.
357416
/// </summary>
358417
/// <param name="player">The player</param>
359418
internal static void SetAccessory(Player player, string accessory)
360419
{
361420
ClickerClass?.Call("SetAccessory", versionString, player, accessory);
362421
}
363422

423+
/// <summary>
424+
/// Call to check if a specific accessory effect that spawns projectiles is enabled. Returns the item if enabled. Supported accessories:
425+
/// Cookie, AMedal, SMedal, FMedal, BottomlessBoxOfPaperclips.
426+
/// </summary>
427+
/// <param name="player">The player</param>
428+
internal static Item GetAccessoryItem(Player player, string accessory)
429+
{
430+
return ClickerClass?.Call("GetAccessoryItem", versionString, player, accessory) as Item ?? null;
431+
}
432+
433+
/// <summary>
434+
/// Call to set a specific player accessory effect that spawns projectiles. Supported accessories:
435+
/// Cookie, AMedal, SMedal, FMedal, BottomlessBoxOfPaperclips.
436+
/// </summary>
437+
/// <param name="player">The player</param>
438+
internal static void SetAccessoryItem(Player player, string accessory, Item item)
439+
{
440+
ClickerClass?.Call("SetAccessoryItem", versionString, player, accessory, item);
441+
}
442+
364443
/// <summary>
365444
/// Call to add to the players' clicker crit value
366445
/// </summary>
@@ -453,7 +532,6 @@ internal static bool HasClickEffect(Player player, string effect)
453532
{
454533
return ClickerClass?.Call("HasClickEffect", versionString, player, effect) as bool? ?? false;
455534
}
456-
457535
#endregion
458536
}
459537
}

Items/Accessories/ExampleClickerAccessory.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ClickerClassExampleMod.Items.Accessories
99
public class ExampleClickerAccessory : ModItem
1010
{
1111
//Optional, if you want this item to exist only when Clicker Class is enabled
12-
public override bool Autoload(ref string name)
12+
public override bool IsLoadingEnabled(Mod mod)
1313
{
1414
return ClickerCompat.ClickerClass != null;
1515
}
@@ -30,11 +30,11 @@ public override void SetStaticDefaults()
3030

3131
public override void SetDefaults()
3232
{
33-
item.width = 28;
34-
item.height = 20;
35-
item.value = 100000;
36-
item.rare = ItemRarityID.LightRed;
37-
item.accessory = true;
33+
Item.width = 28;
34+
Item.height = 20;
35+
Item.value = 100000;
36+
Item.rare = ItemRarityID.LightRed;
37+
Item.accessory = true;
3838
}
3939

4040
public override void UpdateAccessory(Player player, bool hideVisual)
@@ -48,6 +48,10 @@ public override void UpdateAccessory(Player player, bool hideVisual)
4848
//Enables the special effect of the "Glass Of Milk" accessory
4949
ClickerCompat.SetAccessory(player, "GlassOfMilk");
5050

51+
//For the Cookie effect, you would need to set both the item and one of the visual variants
52+
//ClickerCompat.SetAccessoryItem(player, "Cookie", Item);
53+
//ClickerCompat.SetAccessory(player, "CookieVisual");
54+
5155
//Enabled the click effect given by Chocolate Chip
5256
//You can use Clicker Classes base effects (you can find them in the source code), or your own ones
5357
ClickerCompat.EnableClickEffect(player, "ClickerClass:ChocolateChip");

Items/Weapons/Clickers/ExampleClicker.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ClickerClassExampleMod.Items.Weapons.Clickers
88
public class ExampleClicker : ModItem
99
{
1010
//Optional, if you only want this item to exist only when Clicker Class is enabled
11-
public override bool Autoload(ref string name)
11+
public override bool IsLoadingEnabled(Mod mod)
1212
{
1313
return ClickerCompat.ClickerClass != null;
1414
}
@@ -24,31 +24,27 @@ public override void SetStaticDefaults()
2424
public override void SetDefaults()
2525
{
2626
//This call is mandatory as it sets common stats like useStyle which is shared between all clickers
27-
ClickerCompat.SetClickerWeaponDefaults(item);
27+
ClickerCompat.SetClickerWeaponDefaults(Item);
2828

2929
//Use these methods to adjust clicker weapon specific stats
30-
ClickerCompat.SetRadius(item, 0.3f);
31-
ClickerCompat.SetColor(item, Color.White);
32-
ClickerCompat.SetDust(item, DustID.Fire);
30+
ClickerCompat.SetRadius(Item, 0.3f);
31+
ClickerCompat.SetColor(Item, Color.White);
32+
ClickerCompat.SetDust(Item, 6);
3333

3434
//You can use Clicker Classes base effects (you can find them in the source code), or your own ones
35-
ClickerCompat.AddEffect(item, "ClickerClass:DoubleClick");
36-
37-
item.damage = 4;
38-
item.width = 30;
39-
item.height = 30;
40-
item.knockBack = 0.5f;
41-
item.value = 20;
42-
item.rare = ItemRarityID.White;
35+
ClickerCompat.AddEffect(Item, "ClickerClass:DoubleClick");
36+
37+
Item.damage = 4;
38+
Item.width = 30;
39+
Item.height = 30;
40+
Item.knockBack = 0.5f;
41+
Item.value = 20;
42+
Item.rare = ItemRarityID.White;
4343
}
4444

4545
public override void AddRecipes()
4646
{
47-
ModRecipe recipe = new ModRecipe(mod);
48-
recipe.AddIngredient(ItemID.Wood, 10);
49-
recipe.AddTile(TileID.WorkBenches);
50-
recipe.SetResult(this);
51-
recipe.AddRecipe();
47+
CreateRecipe(1).AddIngredient(ItemID.Wood, 10).AddTile(TileID.WorkBenches).Register();
5248
}
5349
}
5450
}

0 commit comments

Comments
 (0)