Giter VIP home page Giter VIP logo

gh4lua's People

Contributors

vany avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

gh4lua's Issues

Helpful information

  1. Хватит ломать черепах, они не в чем не виноваты! Прерывание программы происходит при зажатии Ctrl + T

  2. turtle.inspect()
    В своих программах ты часто сравниваешь блоки перед черепахой с предметом в слоте, или ищешь сундук при помощь perephiral. При этом есть классный метод у черепахи turtle.inspect(), turtle.inspectUp(), turtle.inspectDown(). В первую очередь, он позволяет узнать ид блока, но некоторые блоки поддерживают состояния (data.state) и тэги (data.tags), всё зависит от мода.

-- DOCS

-- Returns the ID string and metadata of the block in front of the Turtle
-- result values:
--     boolean success
--     table data / string errorMessage
turtle.inspect()

-- Returns the ID string and metadata of the block above the Turtle
-- result values:
--     boolean success
--     table data / string errorMessage
turtle.inspectUp()

-- Returns the ID string and metadata of the block below the Turtle
-- result values:
--     boolean success
--     table data / string errorMessage
turtle.inspectDown()
-- USAGE EXAMPLE

function block_has_id(id)
    local success, data = turtle.inspect()
    return success and data.name == id
end

-- true when the block in front is starmetal ore
function block_is_starmetal_ore()
    return block_has_id("astralsorcery:starmetal_ore")
end

-- find for a chest around the turtle
function find_chest()
    local success, data
    for i = 1, 4 do
        success, data = turtle.inspect()
        if success and ends_with("chest") then return true end
    end
    error("chest not found")
end

-- check if string ends with ending
function ends_with(str, ending)
   return ending == "" or str:sub(-#ending) == ending
end
  1. turtle.getItemDetail()
    Дает информацию о предмете в определенном слоте, можно использовать в твоей программе для старметала, или в любой другой программе работающей с предметами
-- DOCS

-- Returns the ID string, count and damage values of currently selected slot or, if specified, slotNum slot
-- result values:
--     table data
turtle.getItemDetail([number slotNum])
-- USAGE EXAMPLE

function item_has_id(slot, id)
	local item = turtle.getItemDetail(slot)
	-- item is nil when slot is empty
	return item and item.name == id
end

-- true when an item is found in inventory
function select_slot_with_item(id)
	for slot = 1, 16 do
		if item_has_id(slot, id) then
			turtle.select(slot)
			return true
		end
	end
	return false
end

-- starmetal loop
function starmetal()
	local success, data
	while true do
		success, data = turtle.inspect()
		if success then
			if data.name == "astralsorcery:starmetal_ore" then
				turtle.select(1)
				turtle.dig()
			else
				-- waiting for starmetal
				sleep(1)
			end
		else 
			if select_slot_with_item("minecraft:iron_ore") then
				turtle.place()
			else
				print("no iron ore found in inventory")
				sleep(5)
			end
		end
	end
end
  1. textutils
    Также заметил, что ты используешь regex для парсинга данных, передающихся по воздуху, но есть способ делать это чуть удобнее.
-- DOCS

-- Returns the ID string, count and damage values of currently selected slot or, if specified, slotNum slot
-- result values:
--     string serializedData
textutils.serialize(any data)

-- Returns the data reassembled from string serializedData. Used mainly together with textutils.serialize()
-- result values:
--     any unserializedData
textutils.unserialize(string serializedData)
-- USAGE EXAMPLE

--[[
        -- example
	local v = ...
	v:SendStat({
		name = os.getComputerLabel() or tostring(os.getComputerID()),
		value = "working",
		color = colors.green
	})
]]
function v:SendStat(data)
    data.color = data.color or colors.white
    self.modem.transmit(self.channel, self.channel, textutils.serialize(data))
end



-- server example 
function listen()
	while true do
		local _, _, channel, _, msg, _ = os.pullEvent("modem_message")
		if msg then
			local data = textutils.unserialize(msg)
		
			print(data.name)
			print(data.value)
			print(data.color)
		end
	end
end

зы. Надеюсь эта информация была написана не зря и она поможет тебе в разработке :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.