tModLoader Hammerator & Spacerator | auto hammer and auto space blocks - Makes Hoiks Easy!

-Q-

Terrarian
Releasing 1.0 of the Hammerator & Spacerator tools. For this release the tools are accessed via hotkeys not items.


Do you like hoiks but hate how incredibly tedious they are to create. Block, ,hammer, hammer, hammer, <space> , Block , hammer, hammer, hammer, <space>, Block, ,hammer, hammer, hammer, <space> , (my eyes are watering!!)

Or do you just want to quickly make regular patterns with no fuss? a wall every 20 blocks? rows of horizontal platforms every 3 blocks? a torch every 6 blocks?

Then these tools are for you!

EDIT: having trouble with the media here's the imgur album
Hammerator will hammer a shape as you place it based on what you set with the HammeratorState Hotkey
NOTE: placing adjacent tiles can still unhammer blocks

HOTKEYS:

HammeratorToggle:
Toggles Hammerator On and Off


HammeratorStateHotKey:
changes the Hammerator state, depending on the state
the block placed will be automatically hammered to the
selected shape:

States:
Bottom Left /|
Bottom Right |\
Top Left |/
Top Right \|
Half Block
Full Block


Spacerator will not allow you to place tiles in regular intervals
defined by it's "gap" size

To use it turn it on, then place a block at the Origin, Spacerator
will then block placement unless it falls on an interval.

No more counting out spaces!!!

HOTKEYS:

Spacerator Toggle:
Toggles Spacerator On and Off


SpaceratorStateEffectToggle:
Changes the restriction behavior

X & Y - Forces gaps in both directions, good for laying grids of single blocks
X Only - Allows placement at any Y coordinate. good for creating walls at intervals
Y Only - Allows placement at any X coordinate. Good for creating platforms at height intervals

SpaceratorStateIncrement:
Increases the gap between blocks

SpaceratorStateDecrement:
Decreases the gap between blocks







Using these two tools you can make hoiks in an instant:






This is a 1.0, no known bugs , feel free to report any you get. If there's interest in it I might pursue my original plans of integrating these as an item with a UI (like Grand Design)

EDIT: added the source code if anyone wants to develop their own.
 

Attachments

  • Hammerator.zip
    16.1 KB · Views: 261
  • HammeratorSource.zip
    4.4 KB · Views: 77
Last edited:

-Q-

Terrarian
Very useful for builders!

Indeed, it started with the hammerator idea for hoiks but now i'm using the spacerator more for easily measuring things out as well as placing torches at regular intervals in tunnels without having to think about it or worry about the smart cursor doing funny things.
 

ThyAbusiveSmile

Terrarian
Thanks for putting the source code here so I can attempt to understand it and add to it.

From what I understand
public class <Variable name> : <Class type>
Variable name representing the name of the file, such as HammeratorPlayer. Can be called upon in other code and files such as on line 17, when it assigns a "local" variable to the file variable. is that correct?
Reference on line 17: HammeratorPlayer myPlayer = player.GetModPlayer<HammeratorPlayer>();
Which This means "local variable" and This means the File variable. Is that correct?


can this be imagined as a function? If I relate it to lua coding

public void SetHammeratorState()
{
hammeratorState++;
if (hammeratorState > 4)
{
hammeratorState = -1;
}
Main.PlaySound(12, player.Center);
switch (hammeratorState)
{
case 0:
Main.NewText("Hammerator: Full-Block" ,155, 155, 155);
break;
case -1:
Main.NewText("Hammerator: Half-Block", 155, 155, 155);
break;
case 1:
Main.NewText("Hammerator: |\\", 155, 155, 155);
break;
case 2:
Main.NewText("Hammerator: /|", 155, 155, 155);
break;
case 3:
Main.NewText("Hammerator: |/", 155, 155, 155);
break;
case 4:
Main.NewText("Hammerator: \\|", 155, 155, 155);
break;
}

as everytime the bind associated with it is pressed, it runs this code.



I also have some confusion with this code.

public void SpaceratorStateEffectToggle()
{

if (restrictOnX && restrictOnY)
{
restrictOnX = true;
restrictOnY = false;
Main.NewText("Space on X only", 155, 155, 155);
return;
}

if (restrictOnX && !restrictOnY)
{
restrictOnX = false;
restrictOnY = true;
Main.NewText("Space on Y only", 155, 155, 155);
return;
}

if (!restrictOnX && restrictOnY)
{
restrictOnX = true;
restrictOnY = true;
Main.NewText("Space on X & Y", 155, 155, 155);
return;
}


If I read it correctly, then for the third if statement, it checks if restrictOnX is false (! being not) and (&&) restricOnY being true.
Then if not restricting X but restricting y, why are both set to true?


Nvm, everytime it runs this code, it changes the state. So if it was already restricting X and Y, then it will now only restrict X, then on next state change it will only restrict Y, then back to restricting both.

I'll be seeing if I can use what you did for Hammerator state change


public void SetHammeratorState()
{
hammeratorState++;
if (hammeratorState > 4)
{
hammeratorState = -1;
}
Main.PlaySound(12, player.Center);
switch (hammeratorState)
{
case 0:
Main.NewText("Hammerator: Full-Block" ,155, 155, 155);
break;
case -1:
Main.NewText("Hammerator: Half-Block", 155, 155, 155);
break;
case 1:
Main.NewText("Hammerator: |\\", 155, 155, 155);
break;
case 2:
Main.NewText("Hammerator: /|", 155, 155, 155);
break;
case 3:
Main.NewText("Hammerator: |/", 155, 155, 155);
break;
case 4:
Main.NewText("Hammerator: \\|", 155, 155, 155);
break;
}


and apply that to Spacerator state change, where it has 0-2 states. 0 Being both, 1 being X, and 2 being Y, and use cases. This will also allow me to add a bind that goes back once to the previous state change for spacerator. Hopefully.


I have 5 questions regarding 2 classes in Hammerator.cs

public override void Load()
and
public override void Unload()

From what I understand from the names, it will load the keybinds, then upon exiting the world, it will Unload it.

What is the purpose of loading and unloading the keybinds?
Why can't you just keep them loaded in?
What happens when the variables get set to null? (From what I understand from null, this means absolutely nothing, not a integer, not a string, just nothing.)
What does "internal static" mean? (I assume static means frozen, unable to be changed)
"Autoload = true;" what does that exactly mean? (From what I get from the name, it just enables autoloading which does what?)

Reference for above:
namespace Hammerator
{
public class Hammerator : Mod
{
//
internal static ModHotKey HammeratorStateHotKey;
internal static ModHotKey HammeratorToggle;
internal static ModHotKey SpaceratorStateIncrement;
internal static ModHotKey SpaceratorStateDecrement;
internal static ModHotKey SpaceratorToggle;
internal static ModHotKey SpaceratorStateEffectToggle;


public Hammerator()
{
Properties = new ModProperties()
{
Autoload = true,
};
}

public override void Load()
{
HammeratorStateHotKey = RegisterHotKey("HammeratorState", "");
HammeratorToggle = RegisterHotKey("HammeratorToggle", "");

SpaceratorStateIncrement = RegisterHotKey("SpaceratorStateIncrement", "");
SpaceratorStateDecrement = RegisterHotKey("SpaceratorStateDecrement", "");
SpaceratorToggle = RegisterHotKey("SpaceratorToggle", "");
SpaceratorStateEffectToggle = RegisterHotKey("SpaceratorStateEffectToggle", "");

}

public override void Unload()
{
HammeratorStateHotKey = null;
HammeratorToggle = null;
SpaceratorStateIncrement = null;
SpaceratorStateDecrement = null;
SpaceratorToggle = null;
SpaceratorStateEffectToggle = null;
}




}
}

And my last question is regarding the code
public override void SyncPlayer
Which is not in this source code.

Does the code break at all if used in multiplayer? as it appears to not be synced.
What exactly does SyncPlayer do? (From what i assume, it just sends information to the server about each player and what they did)

reference from what I got this from: Youtube

Code:

public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
{
ModPacket packet = mod.GetPacket();
packet.Write(HPRegenAdd);
packet.Send(toWho, fromWho);
}

So will I need to add this sync player to allow multiplayer building?
or to put it simply: If Player A enables Spacerator, and sets the spacing to 2, and player B does not want to use spacerator, will it force spacerator for player B along with the spaced tiles by 2?
And will it also lock the globaltile for everyone?


Questions so you don't have to look for them:
Variable name representing the name of the file, such as HammeratorPlayer. Can be called upon in other code and files such as on line 17, when it assigns a "local" variable to the file variable. is that correct?

Which This means "local variable" and This means the File variable. Is that correct?
Reference on line 17: HammeratorPlayer myPlayer = player.GetModPlayer<HammeratorPlayer>();

Can this be imagined as a function?
>
in regards to: public void SetHammeratorState()

What is the purpose of loading and unloading the keybinds?
Why can't you just keep them loaded in?

> reference
public override void Load()
and
public override void Unload()


What happens when the variables get set to null? (From what I understand from null, this means absolutely nothing, not a integer, not a string, just nothing.)
>
from
HammeratorStateHotKey = null;
HammeratorToggle = null;
SpaceratorStateIncrement = null;
SpaceratorStateDecrement = null;
SpaceratorToggle = null;
SpaceratorStateEffectToggle = null;
What does "internal static" mean? (I assume static means frozen, unable to be changed)
>
regarding
internal static ModHotKey HammeratorStateHotKey;
internal static ModHotKey HammeratorToggle;
internal static ModHotKey SpaceratorStateIncrement;
internal static ModHotKey SpaceratorStateDecrement;
internal static ModHotKey SpaceratorToggle;
internal static ModHotKey SpaceratorStateEffectToggle;

"Autoload = true;" what does that exactly mean? (From what I get from the name, it just enables autoloading which does what?)
>
from
public Hammerator()
{
Properties = new ModProperties()
{
Autoload = true,
};
}

Lastly, in the source code for HammeratorPlayer.cs
I get this pop up
1622042672620.png

What does "line endings" mean? As I see no change when I apply it.
 

-Q-

Terrarian
Uhh that's a lot. Skimming through i can hit the high notes

HammeratorGlobalTile.cs is pretty much all that does the actual work. 3/4 of the source is just rote mod stuff, registering hotkeys, cycling through some variable states when you press hotkeys, storing said states on the player object.

A lot of your questions are more general modding questions, I don't know how much has changed in the tmod structure since I wrote this but probably best to start with the example project. IIRC they had a wonderful example project that had code for doing all kinds of stuff and you'll find most of your answers in the Tmod documentation.

It should work in multiplayer. I don't believe you need to sync the player because the player state isn't important. For hammerator the NetMessage.SendData() calls should be syncing the modified world state (when a slope is applied to a placed block). There may be a better way to do that now, SendData() was a pretty dense function and I never really figured out what all the argumetns did. I probably just stole that line from some other mod and it worked.


For spacerator there is no network component, the CanPlace() hook is blocking you from placing in the world locally, if canPlace() returns true then your player places the object and syncing is handled just like anything you place.


as for the line ending not sure how a different one got in there but shoulden't matter , you can convert them all to CRLF.
 
Top Bottom