Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ComputerCraft integrations to more devices #6849

Open
wants to merge 7 commits into
base: mc1.18/dev
Choose a base branch
from

Conversation

ElementW
Copy link

@ElementW ElementW commented Aug 24, 2024

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
  • 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)

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

- 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
@IThundxr IThundxr added the pr type: feature PR adds a new feature or changes an existing feature label Aug 24, 2024
@IThundxr IThundxr added the pr status: conflicts PR has merge conflicts or is targeting the wrong branch label Sep 2, 2024
Copy link

github-actions bot commented Sep 2, 2024

@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!

@PepperCode1
Copy link
Member

Note that this pull request will not be merged before 0.5.2, meaning it will have to be rebased onto the 0.5.2 1.20.1 branch closer to 0.5.2's release, so don't worry about fixing conflicts right now as there will more conflicts when the target branch is changed.

@ElementW
Copy link
Author

ElementW commented Sep 2, 2024

@PepperCode1 Thanks for the heads up. It gives me more time to add a few more features I might need to automate what I'm building, where the use cases add up over time to reveal APIs that may still be lacking in my implementation.
For example I'll be adding distanceTo(station_filter) to Stations soon™.

As for the 1.20 rebase I've already tried on my side and it was an almost trivial rebase so I'm not too worried.

- 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.
@ElementW ElementW changed the title Add ComputerCraft integrations to more train devices Add ComputerCraft integrations to more devices Sep 5, 2024
- 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)
@tizu69
Copy link

tizu69 commented Oct 10, 2024

actually I'd have a suggestion: CC should be able to get the arrivals like display boards do ykyk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr status: conflicts PR has merge conflicts or is targeting the wrong branch 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.

4 participants