Skip to content

Instantly share code, notes, and snippets.

@MasonGulu
MasonGulu / cc_term.js
Last active August 10, 2024 09:18
A basic CC terminal renderer written in JS for HTML canvas
/*
Copyright 2024 Mason Gulu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- Very simple Lua program packager.
-- This program takes in a single filename, your entry point.
-- Then it will scan that program for all of its requires, and all of its require-es requires.
-- After doing this for all required files it packages them up into a single file.
-- There are a few special rules you MUST follow for this program to work
-- 1) The FIRST line of ALL files you import must be an initialization of your module's table.
--- For example, `local data = {}`
--- 1.a) This variable name MUST be the same variable name used everywhere this module is.
-- 2) The LAST code line of your file MUST be a return, returning this module table.
@MasonGulu
MasonGulu / fileloader.lua
Created February 21, 2024 05:13
Useful scripts for managing resource loading across multiple disks in ComputerCraft
-- overwrite _G.fs.open to search all disks connected to the computer for the file
-- create a cache of filenames -> locations
---@type table<string,string>
local filePaths = {}
local function cacheDir(dir)
for k,v in pairs(fs.list(dir)) do
local fn = fs.combine(dir, v)
@MasonGulu
MasonGulu / staple.lua
Last active March 10, 2024 17:50
Attach multiple CC monitors together in a grid
---@diagnostic disable: duplicate-set-field
-- Modern recreation of stitch
-- This can be used as a library or as a command-line tool
-- Scrolling requires buffering to be enabled, pass layout.buffer = true
-- This significantly slows down staple, enabling literally just wraps staple in a window
local function getNative()
local i = 1
while true do
local n, v = debug.getupvalue(peripheral.call, i)
@MasonGulu
MasonGulu / audio.lua
Created March 12, 2023 22:25
Audio playback library for ComputerCraft
-- Basic audio playback library for CC
-- Loads audio from DFPWM
-- Maintains a seperate audio playback channel for each attached speaker
-- Supports a priority system allowing sounds to be overwritten by higher priority ones
-- To setup your audio system
-- local audio = require "audio"
-- local audioSys = audio.new()
-- To start running your audio system
---This is a library to handle mass 16 color printing in ComputerCraft.
-- This requires abstractInvLib https://gist.github.com/MasonGulu/57ef0f52a93304a17a9eaea21f431de6
-- Copyright 2023 Mason Gulu
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
@MasonGulu
MasonGulu / profile.lua
Last active December 11, 2022 05:41
CC performance profiler
--- This program will time the execution of a program you pass in
-- It takes a variety of arguments
-- Use the -help flag to see them all, or since you're in here, peek below.
-- The times reported do NOT include the time waiting for events. It is removed from ALL calculations and numbers.
-- This INCLUDES all times reported in the saved files
-- Copyright 2022 Mason Gulu
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMP
--- Inventory Abstraction Library
-- Inventory Peripheral API compatible library that caches the contents of chests, and allows for very fast transfers of items between AbstractInventory objects.
-- Transfers can occur from slot to slot, or by item name and nbt data.
-- This can also transfer to / from normal inventories, just pass in the peripheral name.
-- Use {optimal=false} to transfer to / from non-inventory peripherals.
-- Now you can wrap arbritrary slot ranges
-- To do so, rather than passing in the inventory name when constructing (or adding/removing inventories)
-- you simply pass in a table of the following format
-- {name: string, minSlot: integer?, maxSlot: integer?, slots: integer[]?}
@MasonGulu
MasonGulu / fe.lua
Last active October 4, 2022 16:03
A simple wrapper for CC's os.pullEvent
--- FriendlyEvents
-- A CC event wrapper
-- Licensed under CC0
local expect = require("cc.expect").expect
-- CC Event Lookup Table
-- This should be tables of named indicies as a map from
-- {2, 3, 4, ...} to string name indices into the event table
local eventLUT = {
@MasonGulu
MasonGulu / LuaTable.java
Created September 11, 2022 16:57
Very simple implementation of a Lua table in Java, not meant as a datastructure for using in Java programs, but as an export format.
/**
* SIMPLE Java implementation of Lua tables
* Mainly meant as an export format
*
* @author https://github.com/MasonGulu
*/
/**
* MIT License
*