re
Paste
Login
JavaScript needs to be enabled for the correct display of the page.
local foods = { ["minecraft:apple"] = {hunger = 4, satMod = 0.3, cost = 2}, ["minecraft:baked_potato"] = {hunger = 5, satMod = 0.6, cost = 1}, ["minecraft:beetroot_soup"] = {hunger = 6, satMod = 1.2, cost = 2}, ["minecraft:bread"] = {hunger = 5, satMod = 0.6, cost = 1}, ["minecraft:carrot"] = {hunger = 3, satMod = 0.6, cost = 1}, ["minecraft:cooked_beef"] = {hunger = 8, satMod = 0.8, cost = 1}, ["minecraft:cooked_porkchop"] = {hunger = 8, satMod = 0.8, cost = 1}, ["minecraft:cooked_chicken"] = {hunger = 6, satMod = 0.6, cost = 1}, ["minecraft:cooked_mutton"] = {hunger = 6, satMod = 0.8, cost = 1}, ["minecraft:cooked_cod"] = {hunger = 5, satMod = 0.6, cost = 2}, ["minecraft:cooked_salmon"] = {hunger = 6, satMod = 0.8, cost = 2}, ["minecraft:cookie"] = {hunger = 2, satMod = 0.1, cost = 1}, ["minecraft:dried_kelp"] = {hunger = 1, satMod = 0.3, cost = 1}, ["minecraft:melon_slice"] = {hunger = 2, satMod = 0.3, cost = 1}, ["minecraft:pumpkin_pie"] = {hunger = 8, satMod = 0.3, cost = 2}, ["minecraft:rabbit_stew"] = {hunger = 10, satMod = 1.2, cost = 3}, ["minecraft:mushroom_stew"] = {hunger = 6, satMod = 0.6, cost = 2}, ["minecraft:sweet_berries"] = {hunger = 2, satMod = 0.1, cost = 1}, ["minecraft:golden_carrot"] = {hunger = 6, satMod = 1.2, cost = 5}, ["minecraft:golden_apple"] = {hunger = 4, satMod = 1.2, cost = 6}, ["minecraft:honey_bottle"] = {hunger = 6, satMod = 0.1, cost = 4} } local function chooseFood(startHunger, startSat, inventory) local MAX = 20 local bestName, bestCount local bestScore = math.huge for name, amount in pairs(inventory) do local food = foods[name] if food then local hunger, sat = startHunger, startSat local count = 0 local satGain = food.hunger * food.satMod * 2 while hunger < MAX or sat < hunger do if hunger >= MAX or count >= amount then count = math.huge break end count = count + 1 hunger = math.min(MAX, hunger + food.hunger) sat = math.min(hunger, sat + satGain) end if count ~= math.huge then local score = count * 1000 + food.cost if score < bestScore then bestScore = score bestName = name bestCount = count end end end end return bestName, bestCount end package.path = package.path .. ";/storage-solution/?.lua" local ra = require("storage-solution/tiny_ra_library") local modules = peripheral.wrap("back") local yourManipulator = "manipulator_76" ra.init(peripheral.find("modem"), 32000, "ratest123") while true do local meta = modules.getMetaOwner() local amounts = ra.listItemAmounts(true) local bestFood, bestCount = chooseFood(meta.food.hunger, meta.food.saturation, amounts) if meta.health <= 10 and meta.food.saturation == 0 and (bestFood == nil or bestCount == ni) then local bestItem = "" local bestSatGain = 0 for name, amount in pairs(amounts) do local food = foods[name] if food then local satGain = food.hunger * food.satMod * 2 if bestSatGain < satGain then bestSatGain = satGain bestItem = name end end end bestFood = bestItem bestCount = 1 end if bestFood == nil or bestCount == nil then goto continue end ra.withdrawToManipulator(yourManipulator, bestFood, bestCount, true) local inv = modules.getInventory() for slot, item in pairs(inv.list()) do if item then if item.name == bestFood then for i = 1, bestCount do inv.consume(slot) end end end end ::continue:: end
Syntax
Auto Detect
Apache Access Log
Apache config
Arduino
ARM Assembly
AsciiDoc
AutoHotkey
Bash
BASIC
Brainfuck
C
Clojure
CMake
CoffeeScript
C++
C#
CSS
D
Dart
Delphi
Diff
Django
DNS Zone
Dockerfile
Batch file (DOS)
dsconfig
Dust
Erlang
Excel formulae
Fortran
F#
G-code (ISO 6983)
GLSL
GML
Go
Gradle
Groovy
Handlebars
Haskell
Haxe
HTML
HTMLbars
HTTP
INI
Java
Javascript
JSON
Julia
Kotlin
Lasso
LaTeX
Leaf
Less
Lisp
Lua
Makefile
Markdown
Mathematica
Matlab
MoonScript
Nginx config
Objective-C
OpenSCAD
Perl
PostgreSQL
php
PHP template
Plain text
PowerShell
.properties
Python
Q
QML
R
Ruby
Rust
Scala
Scheme
SCSS
Shell Session
SQL
Swift
TypeScript
Visual Basic .NET
VBScript
VBScript in HTML
VHDL
Vim Script
Intel x86 Assembly
XML
YAML
Exposure
Public
Unlisted
Folder
No folder
Create Paste
Create as guest