[Mod] Computers and Robots [0.2.9][lwcomputers]

Post Reply
loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

[Mod] Computers and Robots [0.2.9][lwcomputers]

by loosewheel » Post

LWComputers provides programmable computers and robots, floppy disks, printers, graphical screens, touch response monitors, a digilines controlled mesecons power switch, solid conductor blocks, vertical moving floor and a trash item.

Image

Image

Version
0.2.9

Minetest Version
This mod was developed on version 5.3.0
Compiled with LuaJIT is required

Dependencies
default

Optional Dependencies
intllib
mesecons
digilines
digistuff
unifieddyes
mesecons_mvps
lwcomponents
lwwires

Licence
  • Code licence: LGPL 2.1
  • Font images: Are derived from Liberation Mono licensed under the Liberation Fonts license.
  • Media licence: CC-BY-SA 3.0
  • Sound licence: CC BY 4.0
Features
  • GUI has keyboard and responds to mouse clicks.
  • Each computer and robot can be persistent (remain loaded).
  • Robots can move, detect, dig, place, craft and work with inventories.
  • Hard drive and floppies use folder under world folder for storage (can be edited externally).
  • Running computers restart (clean boot) when world is re-entered.
  • Clipboard item to facilitate copy/paste.
  • Support for mesecon and digilines.
  • Computer's programming language is lua.
  • Each computer runs in its own environment (sand-boxed).
  • Computers retain hard drive data when being moved.
  • No inherent os, looks for file "boot" at startup.
  • Los disk item boots to command prompt.
  • Lua disk item boots to lua prompt.
  • Character terminal display, supporting 16 colors.
  • Display resolution can be changed (mod setting - affects all).
  • Printers, pages and books.
  • Digiswitch, digilines controlled mesecons power. - Depreciated
  • Movefloor, similar to vertical mesecons movestone. - Depreciated
  • Solid color conductor blocks, same as Solid Color Block but also mesecons and digilines conductor. - Depreciated
  • Graphical screens in 16 and 32 resolutions (based on cheapie's digiscreen).
  • Monitors supporting 7 display resolutions, 16 colors and touch (right click) digilines message.
If a disked item is removed from the world (permanently) the disk's contents will likely remain in the world save folder.

The world save folder for an item with a disk will be removed if:
  • The trash item from this mod is used to dispose of it.
  • Calling robot.trash ()
  • The item is blown up.
Crafts
Spoiler
Computer
Image

Robot
Image

Black floppy disk
Image

Yellow floppy disk
Image

Red floppy disk
Image

Green floppy disk
Image

Blue floppy disk
Image

White floppy disk
Image

Lua disk
Image

Los disk
Image

Ink Cartridge
Image

Printer
Image

Digilines Switch
Image

Trash
Image

Touchscreen
Image

Control Panel
Image

Moving Floor
Image

Solid Color Conductor
Image

Solid Color Horizontal Conductor
Image

Digilines Graphical Panel 16
Image

Digilines Graphical Display 16
Image

Digilines Graphical Panel 32
Image

Digilines Graphical Display 32
Image

Monitor
Image
Github
Download, extract to mods folder and rename to "lwcomputers".

Tutorial videos
Computer basics
Computer interfaces
Computer programming
Last edited by loosewheel on Sat Jun 18, 2022 17:06, edited 37 times in total.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Example robot program

by loosewheel » Post

Robot farming program

Image

Code: Select all

local args = { ... }

local crops =
{
   ["farming:barley_7"] = { sow = { "farming:seed_barley" } },
   ["farming:beanpole_5"] = { sow = { "farming:beanpole", "farming:beans" } },
   ["farming:beetroot_5"] = { sow = { "farming:beetroot" } },
   ["farming:blueberry_4"] = { sow = { "farming:blueberries" } },
   ["farming:carrot_8"] = { sow = { "farming:carrot" } },
   ["farming:chili_8"] = { sow = { "farming:chili_pepper" } },
   ["farming:cocoa_4"] = { sow = { "farming:cocoa_beans" } },
   ["farming:coffee_5"] = { sow = { "farming:coffee_beans" } },
   ["farming:corn_8"] = { sow = { "farming:corn" } },
   ["farming:cotton_8"] = { sow = { "farming:seed_cotton" } },
   ["farming:cucumber_4"] = { sow = { "farming:cucumber" } },
   ["farming:garlic_5"] = { sow = { "farming:garlic_clove" } },
   ["farming:grapes_8"] = { sow = { "farming:trellis", "farming:grapes" } },
   ["farming:hemp_8"] = { sow = { "farming:seed_hemp" } },
   ["farming:melon_8"] = { sow = { "farming:melon_slice" } },
   ["farming:onion_5"] = { sow = { "farming:onion" } },
   ["farming:pea_5"] = { sow = { "farming:pea_pod" } },
   ["farming:pepper_5"] = { sow = { "farming:peppercorn" } },
   ["farming:pepper_6"] = { sow = { "farming:peppercorn" } },
   ["farming:pepper_7"] = { sow = { "farming:peppercorn" } },
   ["farming:pineapple_8"] = { sow = { "farming:pineapple_top" }, craft = { "farming:pineapple_ring" } },
   ["farming:potato_4"] = { sow = { "farming:potato" } },
   ["farming:pumpkin_8"] = { sow = { "farming:pumpkin_slice" } },
   ["farming:raspberry_4"] = { sow = { "farming:raspberries" } },
   ["farming:rice_8"] = { sow = { "farming:seed_rice" } },
   ["farming:rhubarb_3"] = { sow = { "farming:rhubarb" } },
   ["farming:rye_8"] = { sow = { "farming:seed_rye" } },
   ["farming:tomato_8"] = { sow = { "farming:tomato" } },
   ["farming:wheat_8"] = { sow = { "farming:seed_wheat" } },
   ["farming:oat_8"] = { sow = { "farming:seed_oat" } },
   ["farming:mint_4"] = { sow = { "farming:seed_mint" } },
   ["farming:cabbage_6"] = { sow = { "farming:cabbage" } },
   ["farming:artichoke_5"] = { sow = { "farming:artichoke" } },
   ["farming:blackberry_4"] = { sow = { "farming:blackberry" } },
   ["farming:lettuce_5"] = { sow = { "farming:lettuce" } },
   ["farming:parsley_3"] = { sow = { "farming:parsley" } },
   ["farming:soy_7"] = { sow = { "farming:soy_pod" } },
   ["farming:vanilla_8"] = { sow = { "farming:vanilla" } },
}


local farm = { }


-- constructor
function farm:new (length, width, delay)
	local obj = { }

	setmetatable(obj, self)
	self.__index = self

	obj.help = length and length == "-h"

	obj.length = tonumber (length or 0) or 0
	obj.width = tonumber (width or 0) or 0
	obj.delay = tonumber (delay or 0) or 0
	obj.harvest_now = true

	return obj
end



function farm:harvest ()
	local node = robot.detect_down ()

	if node then
		local crop = crops[node]

		if crop then
			if robot.dig_down () then
				for i = 1, #crop.sow do
					local sow = crop.sow[i]
					local craft = (crop.craft and crop.craft[i]) or crop.sow[i]

					if not robot.contains (sow) then
						robot.craft (craft)
					end

					if not robot.contains (sow) then
						print ("\r         \rout of %s\n", sow)

						return
					end

					robot.place_down (sow, "down")
				end
			end
		end
	end
end



function farm:check_quit ()
	local event = { os.peek_event ("key") }

	if event and event[2] == keys.KEY_ESCAPE then
		os.get_event ("key")
		print ("\r         \rStopped\n")

		return true
	end

	return false
end



function farm:do_harvest ()
	if os.peek_event ("timer") then
		os.get_event ("timer")
		self.harvest_now = true
	end

	if self.harvest_now then
		self.harvest_now = false

		print ("\r         \rRunning")

		return true
	else
		os.sleep (2.0)
	end

	return false
end



function farm:set_timer ()
	if self.delay > 0 then
		os.start_timer (self.delay)

		print ("\r         \rWaiting")

		return true
	end

	print ("\r         \rFinished\n")

	return false
end



function farm:move_front ()
	if not robot.move_front () then
		print ("\r         \rCan't move\n")

		return false
	end

	return true
end



function farm:move_back ()
	if not robot.move_back () then
		print ("\r         \rCan't move\n")

		return false
	end

	return true
end



function farm:discharge ()
	local inv = robot.find_inventory ("main")
	if inv and inv.front then
		local slots = robot.slots ()

		for s = 1, slots do
			robot.put_front (s)
		end

		robot.pull_front ("farming:cutting_board")
	end
end



function farm:run ()
	if self.help or self.length < 1 or self.width < 1 then
		print ("   farm [-h] length width [delay]\n"..
				 "Harvest and plant a rectangle patch.\n"..
				 " -h      show help\n"..
				 " length  nodes forward from robot\n"..
				 " width   nodes width, to right of robot\n"..
				 " delay   if given, number of seconds before\n"..
				 "         re-harvest. if not harvests once\n"..
				 "place robot one back from start position\n"..
				 "escape to quit\n")

		return (self.help and 0) or 1
	end

	while true do
		if self:check_quit () then
			return 0
		end

		if self:do_harvest () then
			local length = self.length - 1
			local width = self.width

			if not self:move_front () then
				return 1
			end

			self:harvest ()

			for w = 1, width do
				for l = 1, length do
					if not self:move_front () then
						return 1
					end

					self:harvest ()

					if self:check_quit () then
						return 0
					end
				end

				farm:discharge ()

				if self:check_quit () then
					return 0
				end

				if w < width then
					if (w % 2) == 1 then
						robot.turn_right ()

						if not self:move_front () then
							return 1
						end

						robot.turn_right ()
						self:harvest ()
					else
						robot.turn_left ()

						if not self:move_front () then
							return 1
						end

						robot.turn_left ()
						self:harvest ()
					end
				end
			end

			if (width % 2) == 1 then
				robot.turn_right ()
				robot.turn_right ()
				for l = 1, length do
					if not self:move_front () then
						return 1
					end
				end
			end

			robot.turn_right ()
			for w = 1, width - 1 do
				self:move_front ()
			end
			robot.turn_right ()

			if not self:move_back () then
				return 1
			end

			if not self:set_timer () then
				return 0
			end
		end
	end

	return 0
end



return farm:new (unpack (args)):run ()
If a chest is at the end of a run in a front direction, the robot will empty its storage into it.
If harvesting pumpkin or melon a cutting board needs to be in the robot's storage.

Create the program file:
  • boot robot on LOS disk.
  • copy the example program and paste it into a clipboard item.
  • place the clipboard item into a slot in the robot.
  • on the terminal, from root, enter edit farm.
  • press ctrl+alt+V.
  • press ctrl+S.
  • press ctrl+Q.
To run the program:
farm [-h] length width [delay]

-h - Show help.
length - The node length of the farm patch.
width - The node width of the farm patch.
delay - Seconds to wait until running again, if omitted or zero runs once.
Last edited by loosewheel on Wed Nov 10, 2021 18:21, edited 1 time in total.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.1.15][lwcomputers]

by loosewheel » Post

Video of 2x2 Elevator.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.1.16][lwcomputers]

by loosewheel » Post

Slide Show Example

Image

Video

App to convert images for digilines screens (works for cheapie's digiscreens as well).

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.1.23][lwcomputers]

by loosewheel » Post

DigiSwitch, MoveFloor, Solid Color Conductors, lwcomputers:touchscreen and lwcomputers:panel have been depreciated. They have been moved to lwcomponents.

If lwcomponents is loaded any nodes from this mod in the world will still work, but cannot be crafted nor are available in the creative inventory. If not loaded everything remains the same.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.1.24][lwcomputers]

by loosewheel » Post

Improved the item placement and added Use mod on_place setting, which is enabled by default. This attemps to use the mods on_place handler before doing a manual placement. Not all mods interpret the pointed_thing the same way. If nodes are not placing properly turn this off and use the place_substitute.lua file for substitutions.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.0][lwcomputers]

by loosewheel » Post

With update to version 0.2.0 some internal changes were made which may affect existing worlds.

Any existing printed books and pages wont work. If you try to open or drop them it could cause the game to crash. With this update books can be a maximum of 12 pages.

Any clipboards with more than 48kb in them could crash the game if dropped. If their contents is reduced they are still usable.

The metadata disk storage option was removed. The disk data of any disked items (computers, robots and floppies) will not be accessible, and if they are dropped they will likely crash the game.

There are a few things that will remove the disk data for a disked item when its destroy, but most reliable is to use the trash item from this mod.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Computers and Robots [0.2.0][lwcomputers]

by MisterE » Post

could you please make some way to prevent the crashes:
one possibility, give the new books a new itemname, and alias the old books to something harmless. because I'm pretty sure there are books and pages on my server and I would like to stay updated, but not with a crash that can be prevented

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.0][lwcomputers]

by loosewheel » Post

MisterE wrote:
Sun Dec 05, 2021 13:14
could you please make some way to prevent the crashes:
one possibility, give the new books a new itemname, and alias the old books to something harmless. because I'm pretty sure there are books and pages on my server and I would like to stay updated, but not with a crash that can be prevented
That wont make any difference. The lwdrops api was avoiding the potential of the crashes and I had to discontinue that api. What I might be able to do is detect if a book is the old encoding and convert it if it is. You lose pages beyond 12 but should avoid a crash. This will take a bit of experimenting and tested. The new version doesn't provide any new features, so just use the previous version until I post an update.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.0][lwcomputers]

by loosewheel » Post

MisterE wrote:
Sun Dec 05, 2021 13:14
could you please make some way to prevent the crashes:
one possibility, give the new books a new itemname, and alias the old books to something harmless. because I'm pretty sure there are books and pages on my server and I would like to stay updated, but not with a crash that can be prevented
Implemented conversion to new page/book encoding:
  • If a page or book is used it is converted.
  • If a page or book is dropped by a player it is converted.
  • If a page or book is dropped by a mod component that calls on_drop it is converted.
Any books that are converted will only retain the first 12 pages.

I had reworked my mods to not call the on_drop handler to make it consistent with minetest standards. But in testing this out I used a pipeworks dispenser and it called this handler. The on_drop handler appears to not be implemented consistently throughout mods, so I put it back in my mods. So there is no greater risk of a game crash than there was with the lwdrops api. If something (not a player) drops a book with more than about 5 pages and does not call the on_drop handler the game will crash. Once all the items in your world have been converted or disposed of, that risk should be gone.

Printers only have 12 out tray slots from 0.2.0. Unless an existing printer is dug and placed it will still show 16 but the last 4 are ignored.

If currently using the metadata disk storage, this is just way to much data to consider doing anything with. Your only choice is the copy everything you want out through a clipboard and scrap everything with a disk. If anyone was using this option and wants to keep the data, let me know and I'll see what I can do. Otherwise I would prefer not to bloat out the mod with the legacy code.

The lwdrops api the most substantially implemented the handler to remove disk data from the world folder when the item was destroyed. The handler is still implemented but less significantly. The best way to ensure the data is removed is to use the trash from this mod.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Computers and Robots [0.2.1][lwcomputers]

by MisterE » Post

great work, thanks. this will allow me to keep the mod up to date!

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [Mod] Computers and Robots [0.2.1][lwcomputers]

by MisterE » Post

would it be possible to add a textbox input for the computer formspec? it can be annoying especially with lag to type out each letter. However if this would cause a security hole that is unavoidable then better not

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.1][lwcomputers]

by loosewheel » Post

MisterE wrote:
Thu Jan 06, 2022 01:56
would it be possible to add a textbox input for the computer formspec? it can be annoying especially with lag to type out each letter. However if this would cause a security hole that is unavoidable then better not
It would be, but the problem is the form is already so big, trying to fit it in somewhere useful is difficult. Someone on github also expressed their frustration over the interface being clunky to use. I made a version that had a single line input field at the bottom of the form with an 'Input' button.

I didn't go with this because it is not a 'true input device', and it didn't make a lot of difference in real use.

I know the 'not a true input device' thing sounds pedantic, but it has to do with how the events are generated so a program can trap the input. The keyboard sends key and then char events when appropriate, and the running program traps these events. An entry field is just a string. This would require an event similar to the clipboard event, and the running program would have to trap it to use the input. To avoid a program having to trap multiple input events the above implementation just sent a char event for each character of the input string (no key events). While it was novel to watch the input appear on the terminal a character at a time, for a multi-line input where you could paste 40kb, this would take a really long time.

I don't know how others use it, but I only use the keyboard to enter a line or two. For a few lines I type it into a clipboard and paste, and for more than that I use an external editor and paste it into a clipboard and then the computer. A single line input where you have to click the Input button, and usually then the Enter key, is a bit easier for entering more than 'ls -l'. But was still a lot easier to use a clipboard for more than a couple of lines.

If you have any ideas of how to implement it without complicating code events, or if you think the single line input is still useful I can find the code and put it in.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.8][lwcomputers]

by loosewheel » Post

Support for lwwires added. Bundle cables can be controlled per side of the computer. Also added utils.dump () to computer's api.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.9][lwcomputers]

by loosewheel » Post

v0.2.9
  • Added os.version () to computer's api.
  • Added error check for file class when not called as class.
  • Added parameter validation to monitor.get_char () and monitors.get_char ().
  • Added visible cursor to monitor interface (inverted colors, doesn't blink).
  • Added os.remove_event () to computer's api.
  • Fixed printer's empty slot query.
  • Added Clear button to printers (ejects page when started but not finished).
  • Shift key automatically cancels on next character key press. If double clicked stays on, only first of double click sends key event.
  • Fixed bug with error message failing to prep floppy.
  • Added scale 0.3 and 0.6 to monitors (res 3x2 and 6x4).
  • Added os.has_clipboard () to computer's api.
  • Increased width of clipboard. If mt ver >= 5.4.0 font is mono.
  • Added Awake on event setting. If true, the computer processes events when unloaded. This allows computers to process wireless, digilines, mesecons, timer, bundle_on and bundle_off messages without making the computer persistent. Running continues until the computer's event queue is empty.
  • Added os.clock_speed () to computer's api.
  • Improved file opening time.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: [Mod] Computers and Robots [0.2.9][lwcomputers]

by loosewheel » Post

Due to actions by some members of the maintenance team of Minetest it appears obvious that this is not a FOSS project. ContentDB stopped updating from Github weeks ago. Continuing with the mod appears pointless as they are primarily inaccessible, and I have no interest contributing to an exclusive interest project. This mod was released under an open license so it can obviously be forked, if there is any interest to do so.

viewtopic.php?p=415477#p415477

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests