tModLoader WireMod

Djago

Terrarian
Welcome to WireMod!

icon.png

This mod reinvents the existing wiring system, allowing the construction of complicated circuits using a range of simple logic/maths/comparison devices.

The project wiki contains the basic information about the base mechanics of the mod and about each device. It will be updated and maintained far better than this thread, so please check it out first: Project Wiki

Getting Started

Craft:
  • an Electronics Manual at a Tinkerer's Workbench with 1x Book and 50x Wire.
  • a stack of Microchips at any Workbench with 1x Wire, 1x Actuator and 1x Copper Coin each.
Hold the Electronics Manual to open the Menu.

Examples (in no particular order)

62822671-931dfc00-bb7e-11e9-97c0-0cbd09cba842.gif


No pressure plates required!

62822710-07589f80-bb7f-11e9-8e46-08cec1e32148.gif


Fires endless flaming bunnies!

62822713-0d4e8080-bb7f-11e9-9e44-b54120cfd446.png

(NPC Spawner + Repulsor + Buffer)

62822760-7df59d00-bb7f-11e9-97e7-86560b117b4f.gif


Locks you in a room with a spawned NPC until you defeat it.

62822759-7cc47000-bb7f-11e9-941e-9655f4993752.png

sdqrB64.gif

Download

Source code available on GitHub
Also available via Mod Browser

TODO
  • Add some form of level progression
  • Add a configurable permission system
NOTE: This mod is still under development, so expect bugs, occasionally dodgy UI and the odd breaking change.

Please watch out for the following bugs:

  • Only works at 100% Zoom and UI Scale. Now works at any scale, as long as Zoom and UI Scale are identical.
  • User inputted numbers in textboxes are still propogated, resulting in unwanted behaviour
If anyone has any experience in these areas, please let me know.
 
Last edited:
Excellent idea and work !

I don't know your politics when it comes to suggestions but , even tho they aren't directly linked to wire logic itself, they would become extremely reliable combined to your int logic and extended player and team detection:
A kind of actuator (that could be enabled/disabled) to turn blocks behind it indestructible.
Or even an item taking an X/Y int size input turning blocks in its rectangle indestructible. (Not sure if it's even possible to turn stuff indestructible tho)
An RGB tile taking an int as input.
A tile with 36 (52?) different shapes(0-9,a-Z), connecting automatically to the ones of the same kind to its right, taking a string as input to display texts.

Couldn't test yet, so I'm not sure if it is compatible with some wireless mods out there...
But a wi-fi system using an int ID with two inputs (message to send / modify ID) and an output (message received) would turn this into a true wonder.

If needed, I could create some sprites if you think it would help.
 
@holeow Thanks for your input! I created this thread precisely to get feedback/suggestions, so by all means keep them coming :)

I like the idea of a player/team-bound indestructible area, and had already half-planned something similar. From a quick look at the Tile class reference, it seems like it absolutely is possible. Allowing only certain players to destroy the tiles is trickier, but should still be possible.

The RGB tile idea is certainly possible with a bit of custom draw logic, though I must admit I'm not sure what it would be useful for...

The text tile idea is also certainly possible, and I have a few ideas how to go about it - probably with a 'controller' device, which would detect a row of tiles to its right and change their sprites.

As for compatibility, there simply is none because this mod does not use the vanilla wiring system (with one exception - see Project Wiki - Flip/Flop Device). As it stands, the vanilla wiring system works by sending a 'pulse' down a wire, which other tiles receive - and that's about it. I've had to add a whole new wiring system from scratch to be able to introduce the concept of data types and for a device to actually know what other devices it's connected to.

Could you explain in a bit more detail what you're imagining for a WiFi system? I didn't quite get what you were suggesting there. As the wires in this mod are purely visual and the actual connecting of devices is achieved by simply storing a reference to the other device, it already is a 'wireless' system of sorts, which also means it does not suffer from the same distance limitation as the vanilla wiring system.
 
I'm not sure if it's because it was impossible when I tested the mod or if it's because I wasn't good enough to do it (I didn't have enough time to test the mod properly :/), but here is what i had in mind:

1566063200-wf.png


(Sorry about the names, I don't have that much knowledge about terminologies)

Let's say i got three of those. Their "input name" respectively are "A" "B" "C".

"A" output name is "C".
"C" output name is "B".
"B" output name is "A".

When I "read" A "self output", i should get what's in "B" data entry.
When i read B, i get what's in "C".

Now i change the value that is connected to "C" output name to "A".
When I read A, i get the value connected to "C" data entry.

If i change the value that is connected to "B" input name to "A", well it is now called A.
When i read either "A" or "formerly known as B but now A" i get the value of C.
____________________________________________________________________________

About the RGB tiles, I guess its use would be to create RGB screens, by sending the color of each pixel it could render a picture.
In a "MOBA-like" pvp game, it could be used to turn into a special color depending on which team won.

For indestructible tiles it would be awesome to have only a certain player able to destroy them, but even with my low knowledge of the API, I can understand it might be hard.
But just being able to set/unset the indestructibility of those tiles with an "actuator" can make them being destructible only if one player with the correct name is present (and combined with other player sensors in a triangle check if there are any other close player to disable it),
or create multiple "tagged" blocks with team colors in single player, so you can destroy blocks tagged with team blue only if you're in this team, and prevent yourself from destroying your buildings by mistake, but still destroy other blocks).


A sensor capable of counting the amount of players of a team const in a range could help in a moba map, as you could make certain blocks indestructible unless there is more players of the ennemy team than allies close to it.

A sensor capable of counting in an area the amount of blocks of a const block ID could make a team "loose" if all their blocks get destroyed.

The amount of possibilities in adventure maps would become big too.
 
The idea of 'storage' devices is definitely on the todo list, but nothing at all like you've described. Could you give me a "real-world" example of what you'd use it for? It's possible I already have / have plans for something else that could achieve the same result.

As for RGB blocks, I get the idea, and it would be neat to have full pixel art screens, but the way it's done right now you'd need a 3x3 space for each tile to accomodate all the input pins for each of the three RGB values, so you couldn't have them right next to each other (unless you made them 3x3 tiles, which would become huge). One large block of a single colour, however, would be possible.

I had a quick go at creating a text display tile like you suggested in your first reply, here combined with a Player Distance Sensor to get my player name when I'm within a given radius:

qAS53IH.gif

Is this more or less what you had in mind?

On the subject of counting players within a certain radius, there's already a device that does exactly that but for NPCs, so it should be trivial to copy it for players (and add a Team Colour filter to it). Same again with counting tiles. I'll add them very soon.
 
The text display is awesome !
I guess RGB tiles could use only one int32 and use maybe bit-shifting to get all three 8bits (+8 bits alpha? 8 bits lightning ?), or even a string holding hex values of colors working just like the text display ( not sure about the performances of that tho, but also would make it exceptionnally difficult to change only one or only a few colors comprised in a picture).

About the device i had in mind, my real world use would be to use those when I need to implement a "Method". It would allow passing parameters by reference, among other things.

I'll just pick my moba example again, I have a text display screen with multiple lines requiring multiple strings. I could create a "method" somewhere to determine which strings to pick depending on which team wins, or which team controls the checkpoint where the display is, or other data.
I could then store all of my strings in an "array" called WinnerTexts, which would be a bunch of those devices linked to string holders, each one having a name such as "WinnerTexts0","WinnerTexts1" and so on. The game ends, and i need to display the winner names, the method does its thing to figure out who the winner is, then can send to the text screen the references of the needed objects contained in the array, the screen then can find by itself the actual name of the player by reading the name that is inside "WinnerTexts7" for example.

Also, I could create a method that calls one by one every method by their reference in an array of references using a timer, in a infinite loop, to spawn monsters / npc / blocks / disable repulsors (I love those) depending on some events that happens during the game (a player destroys an ennemy construction, etc...). Sometimes, one of those methods might hold a reference to another method, and if the conditions are all true, add that reference to the loop so it gets checked every time the timer ticks.



(Well, when i think about it, that kind of uses of such devices maybe would fit better directly as a mod than as in world devices, but maybe there are real world uses for this i can't think of, or would simplify someone's work wanting to create such an elaborate system by implementing a special microchip as an add-on then using those)
 
Last edited:
Bit-shifting would help to cut it down, but it still sounds like it would get out of hand very quickly. I've been toying with have a List data type, but that adds more complexity than I am comfortable with at this stage of the mod's development.

Elements of your moba example are certainly possible (among others, a scoreboard displaying which team controls which checkpoint, or displaying the winning team's name and colour), but the idea of storing methods with possible nested references to other methods sounds to me like it would be incredibly difficult to achieve by wiring together tiles in-game, and most likely goes beyond the scope of this mod.

Have you considered writing your own dedicated mod in C#? You'd have a lot more control, use all the fancy data types you could ever want, access the WorldGen methods, hardcode a bunch of stuff to reset each game, have different stages with changing landscape and upgraded defences, really anything you can imagine. I've had some more complicated ideas myself that would benefit from being combined with WireMod, but which would be impossible/way too difficult using only WireMod. Just my two pennies.

Anyhoo, I'm going to go and add the counting devices I mentioned in my last post, and then look into making tiles indestructible.
 
I'm actually working on basic mods to understand better the API. I'm pretty comfortable with c# so the learning curve is kind of smooth.

(still on the topic of that chip)
With a simpler example, the wiring gets simpler :
I have 50 locked doors, numerated from 0 to 49. Each door has a password.

I have only one place that has two inputs, one for the door, and one for the password.

I first input from 0 to 49 to pick the door, and the microchip links to the microchip of the chosen door.
I then input the password, and it is sent to microchip of the door, if the password is correct, the door opens.


In an even simpler example, it could get used to control pipes that are linked to water, lava, and honey (or more in certain mods).

Creating that kind of stuff with other chips might require to use a lot more logic steps.

(Of course I'm not forcing you to do it, those are just ideas i came up with, I'll certainly come back with more from time to time, as your mod is the one that has the best potential when it comes to breaking actual terraria world rules [but also because you implemented that text display in like, half a second, and have one of the quickest commit rate on github I've ever seen])
 
Disregarding one small mod that I threw together in about 3 hours, this is the first "proper" mod I've ever made. It's taught me a great deal about the API, so my advice is to just go for it :)

The idea of a 'selector' device that takes a numerical index to pick an input is one I've been planning for a while (and already exists (somewhat) for outputs - see Project Wiki: Trigger Device). At the moment, input pins can only be connected to a single other device (otherwise how will it know which value to use?) so I'll probably add a 'MultiIn' pin type to get around that without too much modification of the existing code, but for now I'm trying to keep under-the-hood changes to a minimum while I wrap up loose ends (testing interesting ideas notwithstanding).

Another substantial under-the-hood modification I've been contemplating is that of player/team-bound device visibility. Simply put, at the moment the devices have no concept of who placed them, so anyone can see/edit/delete any device. I've been hesitating back and forth as to whether to keep it like this or add a (at least rudimentary) ownership/permission system. This seems like the sort of things that would be almost essential for PvP situations, but could also get in the way of shared world-building. Any thoughts?

As for indestructible tiles, I may have spoken too early. I was looking at the ModTile class reference, not the base Tile class, and the only potential solutions I have right now are either so dirty and hacky I would need a thousand showers to feel clean again (if it even worked), or require writing a patch for the vanilla source code, which is not something I want to jump into any time soon. For now I think it may have to be shelved alongside the other less easily accomplished ideas I have in mind, but it's definitely one I want to come back to.

The "rule-breaking potential" is more or less what I was aiming for - the original inspiration for this mod was WireMod for GMod (I'm not good at coming up with original names :p), which in my opinion elevated the potential of an already abusable game to entirely new levels. The quick turnaround and number of commits has a lot more to do with my terrible habit of procrastinating instead of doing real work, but thanks :)
 
There might be other ways to prevent players from destroying devices while in pvp, like preventing the use of the book while in pvp mode or something.
Even in shared world building, the ability to prevent it might be useful, as with big maps mods or mods that allows to have multiple worlds, you might want to prevent other player from destroying your constructs, maybe with the help of a "Moderator/Server owner/Server automated code" special device that let a player own a certain area. Hard to say where is the right direction here, it would maybe require some user decisions and safety choices (to prevent from having a device placed by someone that stopped playing here forever and impossible to remove, or a rogue player deciding to break everything forcing the server owner to rollback the server).

In themed maps, those devices might be placed there with an impossibility to get the book required to edit them, so it might not be a problem in there.

For indestructible tiles... what if ... you replace every little tile by a modded one ? :D
 
Disallowing the use of the book is certainly the quick and simple solution, but given the world-breaking (or just world-upsetting) functionality and the seemingly limitless potential of humans to cause chaos, it may require something a bit more concrete. As for replacing every tile, that's precisely what I decided earlier would lead to a thousand showers :p

I've pushed the TextTile (+Controller), PlayerCounter and TileCounter devices to GitHub, but not yet to ModBrowser.

I'm currently working on some AreaInput and ConstantPoint devices, so that devices such as the counters and distance sensors can have a detection area located away from the logic circuit, as well as having multiple devices share the same detection centre point. This is mostly for my own sanity, as the idea of having a Player Sensor and an NPC Sensor for the same door not quite share the same detection circle has been lurking angrily in the back of my mind for too long.
 
I'm pretty sure replacing all of the tiles would just lead to a chain reaction of bugs anyway, even more if you include the other mods that might be installed ^^'. I guess that if something like that really becomes needed for someone, creating a new standalone mod that isn't meant to be mixed with "foreign" mods would be the way to go. But if I ever come across something that might work during my learning session, I'll let you know ^^.

I would divide in multiple parts the devices available into multiple tiers, with multiple book, with different rights maybe. One server might prevent their users from using some of the possible game breaking such as the buffer, spawner and repulsor (unless they are maybe in an area that allows them to do so, or their name is hardcoded in one place in the [world / server file] to create moderators / ranks), maybe another chip that is team colored, and one chip that is player linked could be there, with the same kind of limitations, and a master book that can still see and access them all. The ability to maybe prevent one user from putting thousands of chips and make the server crash, either using their name, or using an ID created by the game owner somehow (the player must ask the owner to give him an [unique/ team/ guild] ID before being able to use the book, then put it in the book somehow, to prevent reroll spam).

A server master device could do it during runtime and could be modified by the ones that are allowed to access it (maybe in a modulable way), or a config file if only the server owner can modify it by changing the file, or using in game chat commands.

It makes everything a bit more complex, so I guess it'd require some premade configs / different master server chips available for users that don't want to dive deep into learning all of it, but still can modify those if they have one special requirement one day.

With that kind of thing, it becomes possible to debug who is using which chip, and figure out if there is some cheesy stuff going on.

I got one issue tho, maybe it's just me, but the "buffer" name is kind of weird to me, as in computer stuffs a buffer refers to something completely different from giving buffs, maybe a BuffGiver or something alike could be more appropriate ?

Also, a new idea came to me, which is a bitmask device, being able to translate [8/16/32?] terraria pulses into an int, and the opposite ? Once again, i'm not sure i have a lot of real world uses coming to mind with that one, and it would require a somehow big device.
 
I'm thinking that patching in one extra 'Destructible' property and a line in the Kill method to prevent the tile's destruction if the property is False would be the cleanest solution, but I've never looked into patching so I have no idea if that's actually possible.

There is already Multiplayer sync support (for mostly everything, and mostly bug-free), so having server-side restrictions is totally possible, it just requires a bunch of config.

The dividing into multiple books was already planned as a form of level progression, i.e. have the basic devices available after Skeletron to match the Mechanic NPC, then the Steampunker for the more advanced devices, etc., so restricting which book is available to which player would already take care of some of it.

I'll add the concept of device ownership soon for later use - it can't hurt to add it in any case, even if it isn't used for anything yet.

And I agree about the Buffer device, the name is rather misleading for anyone who knows what a buffer is in computing terminology, it was just the simplest name I could come up with. Side note: I need to add the ability to toggle it to Debuff mode.

The bitmask device could certainly work. There's nothing preventing a bigger chip with more than 4 pins - I haven't needed one yet, but I always figured there would eventually be a need for it. If there's a real use for it, then I don't mind adding it.
 
The bitmask would be useful only when there is multiple stuffs like torches to light in a certain way depending on another value. Like making something as "If the player name is Jack, turn on torches 1,4,9 and 13", but if the player is not jack, turn on 5 and 8 instead.
The opposite would be useful to store multiple values such as multiple terraria vanilla sensors in one place.

I think it lives in the "advanced user" group, it might not be used in every cases.

Something else that really annoys me with terraria, is that it's impossible to check if a torch (or anything actually) is on or off, i don't know how it would be possible to implement such a thing, but I just hate when an NPC opens one door and don't close it, as my automatic door will now close instead of opening when i get close. It would help to be able to close it only if it's open, or to open it only if it's closed.

(With native terraria wiring, if the door was sending a pulse whenever it's state was changing, it should be possible to store the door state in a logic door lamp)
 
Last edited:
I'll add it to the 'potential future devices' list, but it probably won't appear for a while in any case.

I definitely remember writing some code to keep track of a door's state changing outside of the system, but it must have not worked for whatever reason if I removed it. I'll take another look at it. Personally, this is just another reason why I opt for actuated blocks over doors.
 
Yes, actuated blocks are safer ^^. Even with that tho, I ended up having hard time controlling nicely some stuffs in an underwater base, as I always needed to add a bunch of checks and place stuffs far away to make sure my friends wouldn't try to touch them manually , else it would be ending up with all my npc drowned, while being able to directly know if a block or a timer is physically on or off would have made this trivial.
 
Ah yes, the underwater base... My own ended up with an airlock using two actuated block doors and a water pump. It worked for the most part, but that MP server wasn't far enough along to have access to liquid sensors.

I just added a new If (conditional) device that outputs one of two inputs based on a third boolean input. With it, I was able to cobble together this, based on a previous example you gave:

cRPRpTx.png


The bottom-most String Concat device (blue plus) outputs either "Red Team", "Blue Team" or "No Team" based on which team has the most players standing inside the green square. Incidentally, this also demonstrates two different player counters sharing the same detection area.
 
I can't wait 'til i can test again all of that (probably in 48 hours).

But I came across some interesting stuffs after reading some things about TShock. Basically, it doesn't support tmodloader, so i then searched for tshock+tmodloader on google, and found this : https://forums.terraria.org/index.php?threads/serversidecharacter-a-server-management-mod.55847/
Bad news is, I believe it's outdated.
But if region management means what i think it means, it might hold some leads to create a tile indestructibility system, and a permission management for your devices.

Also, a device that might be able to teleport a player somewhere using your wire system could be interesting.
 
Last edited:
I used to run a server using TShock, and currently a server running tModLoader, so I've already looked into combining them with little success. This investigation also led me to SSC, which I couldn't get running on a Linux server under Docker, so I gave up on it pretty quick.

The mod already sends messages between clients and the server to sync devices and actuate doors, so the foundations are already there for server commands with different permission levels, it's just a lot of extra work so it's going on the ever-expanding todo list.

A teleportation device is certainly on its way - as far as I've seen, the code for it is very simple, and I can think of many great uses for it, I just haven't gotten around to it yet. For the time being, I'm trying to fill in the gaps in the more basic devices, such as the conditional value device I just added (called 'If' but that doesn't completely apply terminology-wise).

Real work is intruding on my procrastination time, so work on this mod will slow down for a few days / a week, but I'll try to do bits and pieces when I can.
 
I didn't dig deep enough to make sure, but the region system in SSC seems to be "simple", there are region permissions stored in json files containing names and coordinates for the area, with some checks to make sure region don't overlap and such, and a check to get if the player complies with the permissions when he tries to change a tile in the world (Not sure exactly of the steps it does to prevent the change from happening).
You could maybe grab that part as it's under MIT license and store region data in some of your devices instead of the json files.

Have a nice working week! (as nice as a working week can be)
 
Back
Top Bottom