Skip to content

JayexDesigns/cc-tweaked-potato-amazon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CC: Tweaked Potato Amazon

This is a dumb project, if you are not Michael Reeves or you're not interested in the ComputerCraft Minecraft Mod don't read this because it's written in Lua and I want as few people as possible to get a seizure



First Things To Address

  • Everything that uses the rednet API is done with wireless modems in my testing world, it can be changed for wired modems except for the deploying section
  • One great person once said: "there is no need for exception handling if you write the code right every time"
  • This project made me create a centralized cryptocurrency, a database API, an on-screen keyboard, a drone deploy system and more entirely in Lua, to compensate for the amount of brain cells I've lost doing this I would appreciate if you check my profile and other projects I've done, maybe even follow me on Twitter

Try It

The world folder in this repository compressed in a zip file, is the one I used to test all of this, the entire facility and store, you need the OfflineTV Better Minecraft mod that you can get here.




Pastebin

All the code can also be found in my Pastebin project folder for an easier connection with ComputerCraft.




Harvest

The code of the harvest section is mainly Michael Reeves' although I made some tweaks. In essence, it's 4 rows of turtles that stay in place until the potato in front of them grows, then they collect the entire row and throw the potatoes down the water stream which goes to the furnaces and then to the storage. The code for all 4 turtles is harvest.lua, it's recommendable to add the program to the startup files of each turtle:

edit startup
shell.run("harvest")




Store

There are three different zones of the store, only one accessible to the clients, the main store has a futuristic look and contains the vending machine and the ATM, the rear store contains the baked potatoes storage and some ladders to the server and pipes room.




Vending Machine

The vending machine consists of 4 parts, the dispenser front, back, display and the pipe system.


Dispenser Front

This turtle is the one in charge of collecting the resources used as a payment option and giving the baked potatoes. The dispenseFront.lua program has to be called with two arguments, the dispenser back turtle's ID and the display computer's ID, then it waits for any change on its inventory. If the item is an approved payment option it will communicate with the dispenser back and the display to process that information while it sends the items through the pipe system, if it's any other item it drops it up. It also has a pay limit, if it's exceeded the client will have to wait some time until the vending machine can be used again. The startup code should look like this:

edit startup
shell.run("dispenseFront", "(ReceiverId) (DisplayId)")



Dispenser Back

The dispenser front sends the information of each transaction to the dispenser back turtle which should be below the main baked potato chest. The dispenseBack.lua program has to be called with one argument, the server's ID which is discussed later, then it waits for any rednet message, after it receives one it will grab the baked potatoes specified on the message and sends them through the pipe system. It also communicates with the server about the transaction. The startup code should look like this:

edit startup
shell.run("dispenseBack", "(ServerId)")



Dispenser Display

The display is connected to a computer next to the dispenser front and it's in charge of drawing on screen the prices of the potatoes, how the transaction is going and if the limit is activated how much time is left. The dispenser display uses the dispenseDisplay.lua program. The startup code should look like this:

edit startup
shell.run("dispenseDisplay")



Pipe System

The pipe system is just a bunch of computers one next to each other that sends the items through them. The pipe.lua program expects two arguments although only the first one is required, the direction of the baked potatoes and the direction of the resources, the options are "f" for front, "u" for up and "d" for down. The startup code should look like this:

edit startup
shell.run("pipe", "(potatoDirection) (resourcesDirection)")




Server

The server has the function of controlling everything from only a single computer, it will not only show useful information but also manage the communication between sectors. The code for the entire server is in the server.lua file. The startup code should look like this:

edit startup
shell.run("server")



Potato Counter

The potato counter turtle is next to the dispenser back one, its only purpose is to send the amount of potatoes stored in the chest to the server, it's definitely expendable but I find it kinda useful. Its code is potatoCounter.lua requires one argument which is the server's id so the startup code should look like this:

edit startup
shell.run("potatoCounter", "(ServerId)")


Database API

To store the users and their data I had to make my own database API based on plain text files, there are some functions to interact with the database, to add users, check if a user and a password matches, check a user's balance or change their balance. Those are already handled by the other systems on the project but if for any reason you want to add or change something the API can be used pretty easily.



ATM

The ATM is the way the clients can add balance to their accounts, as the screen says there are no refunds because I didn't implement them.


ATM Front

The ATM front takes the resources and sends them through the pipes system and then communicates with the display just like the dispenser front does, the difference is that this one will not give potatoes and it will only accept resources if the client has logged in, to accomplish that it uses asynchronous code. The atmFront.lua program will wait until the display computer sends a rednet request to the front indicating that the user has either registered or logged in. The startup code should look like this:

edit startup
shell.run("atmFront")



ATM Display

The ATM Display will show two buttons, one to register and the other to login, both buttons will lead to a form that once completed will verify the information on the server. If everything is correct the client will be redirected to the logged in screen which will show the amount of potato coins he/she has and the ATM front will be unlocked. If resources are thrown to the floor turtle the potato coins on the screen will update as well as the database. Once the user has finished the done button should be pressed, which will prevent the ATM front from sucking and the display will return to the main screen. The code for the ATM display is the atmDisplay.lua and it requires two arguments, the id of the server and the id of the ATM front turtle. The startup code should look like this:

edit startup
shell.run("atmDisplay", "(ServerId) (ReceiverId)")



On-Screen Keyboard

ComputerCraft displays can get the user's mouse input but not the keyboard input so my idea was to make an on-screen keyboard so the users could easily write their usernames and passwords.




Drone Deploy

The potato coins are completely useless for now as you might have realized, that's why I made a drone deployment code so the store could deliver baked potatoes to the door of the clients in exchange for their potato coins.


GPS

ComputerCraft has a default GPS API that lets you create a GPS host that any other turtle can send a request to get its position based on the distance to the cluster of computers, here is a simple video explaining how to do so.


Client

The client would have a computer with a modem attached with the client.lua program in it, calling that program will send a drone to deliver potatoes to the computer's location as long as you execute it with the correct arguments, the first one must be the server's id, the second one the username of the client, the third one the password and finally, the fourth one must be the quantity of potatoes that will be delivered, if the quantity is greater than the balance of the user the drone will not be sent.


Deployer

The deployer is a mining turtle with a modem that has in its storage more turtles with modems and coal, it's code is deployer.lua and takes only one argument, the server's id. When it receives a petition from the server it will place a turtle and give it coal, after that, it will turn the turtle on and get its id so it can send the delivery information. The drone functions because there is a disk drive with a startup file in it next to the place where the drones are deployed. The startup code should look like this:

edit startup
shell.run("deployer", "(ServerId)")


Drone

The drone will deploy as soon as the deployer places it on the ground, the code of the drone is drone.lua and it must be stored in a disk drive with the name "startup.lua". When the drone starts it will go up to grab the requested potatoes after that it will leave the facility and fly up to the delivery height, then it will calculate the route to the delivery location, go down to the ground and throw the potatoes. After that, it will go to the return height to minimize collisions and return to the facility where the deployer will break it and store it again.

About

A ComputerCraft potato farm high tech facility

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages