Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spawn turtle with correct id #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions entity/turtle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ function TurtleEntity:build(nodeLocation, turtleslot)
if node.name~="air" then return false end

--Build and consume item
local stack = self:getTurtleslot("main", turtleslot)
local stack = self:getTurtleslot(turtleslot)
if stack:is_empty() then return false end
local newstack, position_placed = minetest.item_place_node(stack, nil, { type="node", under=nodeLocation, above=self:get_pos()})
self.inv:set_stack("main", turtleslot,newstack)
local newstack, position_placed = minetest.item_place_node(stack, nil, { type="node", under=nodeLocation, above=self.object:get_pos()})
self.inv:set_stack("main", turtleslot, newstack)

if position_placed == nil then
self:yield("Building")
Expand Down Expand Up @@ -363,8 +363,13 @@ function TurtleEntity:on_activate(staticdata, dtime_s)
local data = minetest.deserialize(staticdata)
if type(data) ~= "table" or not data.complete then data = {} end
--Give ID
computertest.num_turtles = computertest.num_turtles+1
self.id = computertest.num_turtles
if data.id then
self.id = data.id
else
computertest.num_turtles = computertest.num_turtles+1
self.id = computertest.num_turtles
end

self.name = data.name or "Unnamed #"..self.id
--self.owner = minetest.get_meta(pos):get_string("owner")
self.heading = data.heading or 0
Expand Down