CC: Tweaked

CC: Tweaked

42M Downloads

Tool to Change Name of Network Peripherals

shelbykauth opened this issue ยท 7 comments

commented

A tool, like a wrench but please for the love of god don't call it a wrench.
When you right click on anything that could be considered a peripheral (chest, TConstruct smeltery, etc), it brings up a little GUI to let you name the peripheral.

If something else has already been named that, it won't let you name it that.
But you could name the peripherals all sorts of things,
"minecraft:chest_1337",
"ShelbysChest",
"SmelterSouth",
"Bob",
"A","B","C",
"SpeakerE",
"Redstone_Door_CargoBay_5"

And then in the code, you can do `peripheral.wrap("SmelterSouth") instead of trying to remember if the south smelter was "minecraft:tconstruct_smeltery_component_24" or "minecraft:tconstruct_smeltery_component_42", and whether Smeltery is spelled "smeltry" or "smeltery"
Or which of the 82 Nesting Pens contains your ender pearl chicken. Or which door is hooked up to which redstone integrator.

Side Note: You say that we should try posting it on the main CC repo. But Dan says that he doesn't want feature requests on his issue page. So... yeah... I'm putting it here...

commented
commented

Still have to disconnect and reconnect to get the names.

Yeah, this is definitely something I'd like to get improve on, I'm just not sure the best approach. I'd really like to have it so shift-clicking would display a list of attached peripherals, but really shift-click should be reserved for placing.

This is where something like a wrench would come in useful, though I would like to avoid adding an item just for this.

As for uniqueness of names, I was thinking that either it wouldn't let you name it the same thing as a previous peripheral, or it would append a string to the end of anything with the attempted same name

Half the issue is keeping track of which names have been used - or rather, when names are no longer used.

I guess a compromise here would be allowing allowing changing the prefix, so you could get the modem to call the attached peripheral smeltery_[0-9]+ instead of minecraft:tcon.smeltery_controller[0-9] or whatever. Could do something like right-clicking with a nametag changes the peripheral's prefix - I'm not sure, I'm rather spitballing here.

commented

I definitely agree that more could be done to make wired networks more user friendly, especially when you have the ridiculous names that Plethora tends to generate.

However, I'm not quite sure whether allowing custom names is the way forward here: I definitely have some concerns about how uniqueness of names would be handled. It's going to have to be something I need to think about more.

For the time being, I've added the ability to copy peripheral names from the attachment/detachment chat messages. It doesn't make them any more memorable, but at least means you don't have to write them out yourselves:

Copy to clipboard for peripheral names

One other possibility would be completion within edit and lua for peripheral names, but that's going to be something I'll have to play with a little more first: the current implementation doesn't lend itself very well.

commented

This is where something like a wrench would come in useful, though I would like to avoid adding an item just for this.

Agreed. However, I notice you saying this a lot. What if you added a computer wrench (or a computer screwdriver, haven't seen a 'screwdriver' in a long time) that does a lot of the stuff you don't want to add an item "just for that". Left click could turn the block, Right click could open up a multi-purpose GUI with name, connected peripherals, physical location, and more.

I'm not sure, I'm rather spitballing here.

Yup. Spitballing is the game here. If the id naming was changed from incrementing for just that type to incrementing for all peripherals, then it wouldn't matter what the prefix was. Because you would have "minecraft:tcon.smeltery_controller_0", "mincraft:chest_1", "bob_2", etc. It would make the ids stack up faster, but I think anyone who uses CC enough for that to be an issue would find use in what that allows. And then we could call peripheral.wrap("minecraft:chest_1") or peripheral.wrap(1) to wrap the same peripheral. But peripheral.getNames() would return what each prefix is. And the type is still available so it doesn't break that.

commented

Personally I think this issue can be solved ingame by making a DNS like server. You send the server a request for the actual name of mainSmelterMine. The server then replies with minecraft:tconstruct_smeltery_component_42 which can be used to connect with.

A similar system I've used a few years back on a server with some programmer friends. We mapped each network peripheral including it's location in a server. Then we could send our turtles to that location directly after sending commands to that peripheral. It's a bit more work, but when you have so many peripherals around you don't lack the resources for a system like that either.

commented

You could do your own peripheral alias names like this:

local p = peripheral.getNames()
local peripheralAlias = {}
local aliasIndex = {}
for _, v in pairs(p) do
  peripheralAlias[v] = v
  aliasIndex[v] = v
end

local handlePeripheralAttachDetach(event, side)
  if type(event) == "table" then
    side = event[2]
    event = event[1]
  end

  if event == "peripheral" then
    peripheralAlias[side] = side
    aliasIndex[side] = side
  elseif event == "peripheral_detach" then
    peripheralAlias[aliasIndex[side]] = nil
    aliasIndex[side] = nil
  end
end

local pipeableHandlePeripheralEvent(...)
  handlePeripheralAttachDetach(...)
  return ...
end

local setAlias(side, alias)
  peripheralAlias[alias] = side
  aliasIndex[side] = alias
end

peripheralAlias.aliasIndex  = aliasIndex
peripheralAlias.handlePeripheralAttachDetach = handlePeripheralAttachDetach
peripheralAlias.pipeableHandlePeripheralEvent = pipeableHandlePeripheralEvent
peripheralAlias.setAlias = setAlias

return peripheralAlias

License: Public Domain, Unlicense and MIT (you get to pick which you want to use it under)
Usage:

local peripheralAlias = require("peripheralAlias")
-- attach a chest or something, let's assume it's assigned the name "top"
print(peripheralAlias.top) --> nil -- peripheralAlias doesn't know of the peripheral yet
peripheralAlias.handlePeripheralAttachDetach(os.pullEvent("peripheral")) -- this is how you update peripheralAlias about peripheral attaches and peripheral detaches (the detach event is peripheral_detach)
print(peripheralAlias.top) --> top -- the default alias is the peripheral name
peripheralAlias.setAlias(peripheralAlias.top, "aboveChest") -- this is how you 'rebind' the peripheral name
print(peripheralAlias.aboveChest) --> top -- the alias still points the original peripheral name
commented

Related work done in OC2, and the commit implementing it: fnuecke/oc2@40a2c5f.

I think this is done by peripherals/devices having multiple types, and one of them being user-specified? Haven't dug into this closely enough.