Skip to content

Conversation

@ElementW
Copy link
Contributor

@ElementW ElementW commented Mar 1, 2025

Note

1.20.1 rebase of #6849. I haven't probed extensively for breakage, so testing is more than welcome.

Adds a handful of ComputerCraft integrations to mostly train-related devices.
If merged I will expand the repo's wiki to document these APIs.

Train Station

  • Emit CC events train_imminent, train_arrival and train_departure when these occur on the station
    • 1 argument: train name
  • Add CC canTrainReach(destination) function to test if the train stopped at the station can reach a (schedule-compatible) destination
  • Add CC distanceTo(destination) function to get the shortest distance to a (schedule-compatible) destination at the moment, using the train stopped in the station

Train Signal

  • Makes computer-controlled signals unable to be changed by external factors
  • Emit CC event train_signal_state_change with the new state as parameter whenever the signal changes
  • Add CC getState() function to get the current signal state
  • Add CC isForcedRed()/setForcedRed(forced) functions to force the signal to be red, replacing redstone control
  • Add CC getSignalType()/cycleSignalType() function to change the signal signal type in the same manner as using the wrench
  • Add CC listBlockingTrainNames() function to list names of trains blocking the track group ahead of the signal

Train Observer

  • Emit CC events train_passing & train_passed with the name of the train originating these events
  • Add CC isTrainPassing() function to check passing train presence
  • Add CC getPassingTrainName() function to get the passing train name, or nil failing that

Creative Motor

  • Add CC {get,set}GeneratedSpeed() function get/set motor speed

Sticker

  • Add CC isExtended() function to check extension state
  • Add CC extend()/retract()/toggle() to change the Sticker extension state, returning state change success

Speedometer

  • Emit CC event speed_change
    • 1 argument: speed (RPM)

Stressometer

  • Emit CC event overstressed
  • Emit CC event stress_change
    • 2 arguments: stress (SU), capacity (SU)

Nixie Tubes

The big feature

  • Makes computer-controlled Nixie Tubes unable to be changed by external factors (but can still be used as a Display Link source)
  • Add CC setText(text[, colour]) function
  • Add CC setTextColour(colour) function
  • Add CC setSignal(first, second) function taking 2 tables describing the appearance of the first and second tube as custom train signals
    • Has controls for Red, Green, Blue, glow dot size (1-4 pixels on each axis), and blink interval (in a PWM fashion)
      • setSignal() does partial display state update. Might be confusing, feedback welcome.

Direct nixie control, no need for a display link

Now featuring colour!

Nixie_text_cycling.mp4

Custom signals!

Nixie_custom_color_and_glow_size.mp4
Code

Rotates the left tube through the Oklch hue wheel, and the right tube through the valid glow sizes

function oklch2oklab(l, c, h)
    if h ~= h then -- Checks for NaN
        return l, 0, 0
    end
    return  l, c * math.cos(h * math.pi / 180), c * math.sin(h * math.pi / 180)
end
function oklab2rgb(l, a, b)
    -- Convert OKLab to linear RGB
    local l_ = l + 0.3963377774 * a + 0.2158037573 * b
    local m_ = l - 0.1055613458 * a - 0.0638541728 * b
    local s_ = l - 0.0894841775 * a - 1.2914855480 * b

    local l_3 = l_ ^ 3
    local m_3 = m_ ^ 3
    local s_3 = s_ ^ 3

    local r = 4.0767416621 * l_3 - 3.3077115913 * m_3 + 0.2309699292 * s_3
    local g = -1.2684380046 * l_3 + 2.6097574011 * m_3 - 0.3413193965 * s_3
    local b = -0.0041960863 * l_3 - 0.7034186147 * m_3 + 1.7076147010 * s_3

    -- Convert linear RGB to sRGB
    local function linearToSrgb(c)
        if c <= 0.0031308 then
            return 12.92 * c
        else
            return 1.055 * (c ^ (1 / 2.4)) - 0.055
        end
    end

    r = linearToSrgb(r)
    g = linearToSrgb(g)
    b = linearToSrgb(b)

    -- Clamp values to [0, 1] range
    r = math.min(math.max(r, 0), 1)
    g = math.min(math.max(g, 0), 1)
    b = math.min(math.max(b, 0), 1)

    return r * 255, g * 255, b * 255
end

t=peripheral.wrap("top")
i=0
gw = {
    {1, 1},
    {1, 2},
    {1, 3},
    {1, 4},
    {2, 4},
    {3, 4},
    {4, 4},
    {4, 3},
    {4, 2},
    {4, 1},
    {3, 1},
    {2, 1},
}
while true do
    i = (i + 4) % 360
    local r, g, b = oklab2rgb(oklch2oklab(0.5, 0.23, i))
    local j = math.floor(i/16) % #gw
    t.setSignal({r=r, g=g, b=b, glowWidth=1, glowHeight=1}, {glowWidth=gw[j+1][1], glowHeight=gw[j+1][2]})
    sleep(0.05)
end

Clears & reset themselves when dis/connected from computers

Nixie_connect_and_reset.mp4

ElementW added 7 commits March 1, 2025 15:01
- Makes computer-controlled Nixie Tubes unable to be changed by external
  factors (but can still be used as a Display Link source)
- Add CC setText(text[, colour]) function
- Add CC setTextColour(colour) function
- Add CC setSignal(first, second) function taking 2 tables describing
  the appearance of the first and second tube as custom train signals
- Makes computer-controlled signals unable to be changed by external
  factors
- Emit CC event train_signal_state_change with the new state as
  parameter whenever the signal changes
- Add CC getState() function to get the current signal state
- Add CC isForcedRed()/setForcedRed(forced) functions to force the
  signal to be red, replacing redstone control
- Add CC getSignalType()/cycleSignalType() function to change the
  signal signal type in the same manner as using the wrench
- Add CC listBlockingTrainNames() function to list names of trains
  blocking the track group ahead of the signal
- Emit CC events train_imminent, train_arrival and train_departure when
  these occur on the station
- Add CC canTrainReach() function to test if the train stopped at the
  station can reach a (schedule-compatible) destination
- Add CC distanceTo() function to get the shortest distance to a
  (schedule-compatible) destination at the moment, using the train
  stopped in the station
- Emit CC events train_passing & train_passed with the name of the train
  originating these events
- Add CC isTrainPassing() function to check passing train presence
- Add CC getPassingTrainName() function to get the passing train name,
  or nil failing that
- Add CC {get,set}GeneratedSpeed() function get/set motor speed
- Add CC isExtended() function to check extension state
- Add CC extend()/retract()/toggle() to change the Sticker extension
  state, returning state change success.
- Emit CC event `overstressed` from Stressometers
- Emit CC event `stress_change` from Stressometers
  - 2 arguments: stress (SU), capacity (SU)
- Emit CC event `speed_change` from Speedometers
  - 1 argument: speed (RPM)
@Ordep-42
Copy link

Ordep-42 commented Mar 1, 2025

Very nice integration that opens a lot of possibilites, really hope it gets merged into the main mod!

@BirbIrl
Copy link
Contributor

BirbIrl commented Mar 1, 2025

Very cool and would love to see it merged! i'm also currently working on a PR with CC integration for the StockTicker and packagers. Are you planning to work on that as well? You seem way better than me at this so maybe i should just leave the stage entirely for you. I barely managed to add tickers as new peripherals that just print any value after a good hour of bashing my head against CC's source

@ElementW
Copy link
Contributor Author

ElementW commented Mar 1, 2025

@BirbIrl I'm not planning on adding support for the new logistics stuff (as least yet, ADHD is a bitch and who knows I might still end up adding new things). Feel free to base your work on mine however, the ComputerEvent related code is probably what's going to be the most useful to you.

@BirbIrl
Copy link
Contributor

BirbIrl commented Mar 1, 2025

@BirbIrl I'm not planning on adding support for the new logistics stuff (as least yet, ADHD is a bitch and who knows I might still end up adding new things). Feel free to base your work on mine however, the ComputerEvent related code is probably what's going to be the most useful to you.

Aye, going back to work on it (when my brain lets me, aspergers is a bitch), I'll try making it with your pr getting merged in mind 🫡

@VoidLeech VoidLeech added the pr type: feature PR adds a new feature or changes an existing feature label Mar 4, 2025
@ajh123
Copy link

ajh123 commented Mar 12, 2025

I would like a function to get a station's timetable similar to how the Display Link / Board can do:

2025-03-12_14 21 51

This will allow me to create a much smaller version by using CC monitors.


This could be like:

trainStation.getTimetable() >

{
    { arrivesIn = 0, name = "Cargo 1", destination = "Factory Land", departsIn = 10 }, -- 0 means the train is at the station.
    { arrivesIn = 1200, name = "Banana Express", destination = "Banana Land", departsIn = nil }, -- nil is used becuase the train has not arrived yet.
    { arrivesIn = 200, name = "Oak Train", destination = "The Forest", departsIn = nil }
}

@tizu69
Copy link

tizu69 commented Mar 12, 2025

@ajh123 great to see someone else asking for this :p

What would this return for ~, so when it is not aware of its time?

@ElementW
Copy link
Contributor Author

ElementW commented Mar 12, 2025

I would like a function to get a station's timetable similar to how the Display Link / Board can do

I've wanted to do this when I made the code a few months ago but then realised it was going to be more complex than anticipated. Maybe I'll revisit this, but again, no promises.

In fact I wanted to give CC access to the full train, track & junction graph of a train network, but it's a whole endeavour onto itself and I only have a limited motivation span, to my chagrin.

@svemat01
Copy link

Awesome work! Really looking forward to seeing this get merged!

@ajh123
Copy link

ajh123 commented May 15, 2025

I've made a pull request #8491 which allows computers to get more information about a train.

Whilst it isn't the full display board information or the whole track graph it seems like a good starting point.

@CrypticCubed
Copy link

First time comment on Github so forgive any noobiness or rudeness, but is this merge or any further ComputerCraft compatibility with train-related blocks still not being considered for any reason? Currently trying to achieve a live-feed for train positions but ComputerCraft integration is still really limited; only stations are a peripheral so we can't pinpoint trains along large distances of track unless we make some assumptions with redstone data from train signals/observers..

Addons offering this much integration are sparse and incompatible but now that I've found it's already being proposed & provided for Create itself, this just seems like a trivial choice for at least some better integration with ComputerCraft and Create's train system, alongside everything else included in this pull request. 🙂

@ajh123
Copy link

ajh123 commented Aug 1, 2025

Currently trying to achieve a live-feed for train positions but ComputerCraft integration is still really limited; only stations are a peripheral so we can't pinpoint trains along large distances of track unless we make some assumptions with redstone data from train signals/observers..

There is the CC:C Bridge mod which can read display link data (which means you can retreive a complete timetable for a station) but unfornatuantly it does not pinpoint the excat location of a train.

For excat positioning you could install the Create Track Map and interface with the web map with CC by using the HTTP API.

@BirbIrl
Copy link
Contributor

BirbIrl commented Aug 3, 2025

but is this merge or any further ComputerCraft compatibility with train-related blocks still not being considered for any reason?

The CC x Create Update 6 pr took like 4 months of active development/review to officially merge (still on the dev branch), which is still somehow faster than this pr since this was originally made exactly a year ago. I'm pretty sure for the longest while now the maintainers have been busy with fixing the things they've introduced in update 6 and only now slowly moving on to looking at pre update 6 features to tweak/update, so i don't think this'll get closed, just gonna take a while longer to merge.

I'm looking forward to that as well, this pr also brings a really nice set of utilities for adding events to future blocks,

@IThundxr IThundxr added the pr status: conflicts PR has merge conflicts label Sep 16, 2025
@github-actions
Copy link
Contributor

@ElementW, this pull request has merge conflicts with the target branch. Please merge the latest changes and leave a message here so we can continue with the process of reviewing and merging this pull request. Thanks!

@BirbIrl
Copy link
Contributor

BirbIrl commented Sep 22, 2025

Alright i'm available again

got this working for the current dev build here. It only required rewriting like two lines, but i found a bug regarding nixie tubes, they don't reset if you give them a custom ComputerSignal and detach a pc. Gonna add a few opinionated commits before submitting a PR on your repo @ElementW, and then you can pull it in however you wish, i'll try and make the opinionated commits small and easy to read :D

I might also add events to the new peripherals from our logistics integration pr.

I might also add these peripherals to the serial tests world, but i'll probably burn out by then.

I will update the wiki PR to include this PR as well (since i'm like 99% sure this will get pulled in)

@BirbIrl
Copy link
Contributor

BirbIrl commented Sep 22, 2025

Yo @ElementW your code for checking if the signal block is still connected to the computer is very... weird(?)
I'm not quite sure i understand it, but, it only seems to drop the setForcedRed override when you break the pc next to it. This means if you power the pc off/break the modem next to it, it's stuck in the setForcedRed state.

Hitting you up in case you instantly know how to fix it. Here's the relevant lines of code:

There seeems to be some block vs blockentity communicating weirdness that i'm not getting here. I'm too skill issued on the minecraft engine knowledge to understand this :P

@BirbIrl
Copy link
Contributor

BirbIrl commented Sep 23, 2025

My job here is done :>

Merges cleanly, patched a smol thing and added another thing in the PR on ElementW's end (ElementW#1)

Made a wiki PR, documenting all the new peripherals and events (#7453)

Didn't end up adding the events for the packager/repackager/redstone requester/stock ticker/frogpost/postbox/ or making an update to the test world because the big lazy hath struck me.

It Works ™️™ and is Documented ™️™

BirbIrl and others added 3 commits September 23, 2025 14:44
also needs to check if it's extended because it'll prock yes if there's
a block in front, but it's not extended to grab it. Should be more
intuitive.
Leaving it with the signal is kinda useful for making pretty builds, but
it breaks when you put nixie tubes in series, it just kinda overrides it
in a very unnatural way and doesn't really coorelate with how text is rendered.
@BirbIrl
Copy link
Contributor

BirbIrl commented Sep 28, 2025

Threw on a PR to @ElementW 's fork, here: ElementW#2. If it gets merged on their end it should pop up here

added events to the logistics blocks. Currently there's no easy way to check what package a packager just made, and what's inside the package, so the new package_created event should be plenty useful, letting you peek inside the package object.

Added other events as well while i was at it.

events added to the packager, repackager, frogport and postbox

rebased and cleaned
@IThundxr IThundxr removed the pr status: conflicts PR has merge conflicts label Sep 30, 2025
@IThundxr IThundxr modified the milestones: Create 6.0.8, Create 6.0.7 Oct 24, 2025
@IThundxr
Copy link
Member

Thanks!

@IThundxr IThundxr enabled auto-merge October 24, 2025 01:16
@IThundxr IThundxr added this pull request to the merge queue Oct 24, 2025
Merged via the queue into Creators-of-Create:mc1.20.1/dev with commit 75eb5cf Oct 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr type: feature PR adds a new feature or changes an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants