Upload of first basic mod version
26
LICENSE.md
Normal file
@ -0,0 +1,26 @@
|
||||
License for Code
|
||||
----------------
|
||||
|
||||
Copyright (C) 2016 Birgit Lachner <birgit@lachner-net.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
License for Textures, Models and Sounds
|
||||
---------------------------------------
|
||||
... will be added after there are some textures that are under a License that need that. Till then, everything is licensed CC-0.
|
||||
|
||||
|
||||
CC-BY-SA 3.0 UNPORTED. Created by Birgit Lachner
|
1
depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
1
description.txt
Normal file
@ -0,0 +1 @@
|
||||
A Mod to let Kids start programming with a turtle that can move around in the world, and dig and build what the user wants.
|
165
init.lua
Normal file
@ -0,0 +1,165 @@
|
||||
|
||||
minetest.register_craftitem("turtle_miner:remotecontrol", {
|
||||
description = "A remote control for Miner-Turtles",
|
||||
inventory_image = "turtle_miner_remotecontrol.png",
|
||||
})
|
||||
|
||||
local turtle_formspec_positions = {}
|
||||
|
||||
minetest.register_node("turtle_miner:firstturtle", {
|
||||
description = "First Turtle for Trials",
|
||||
tiles = {"turtle_miner_firstturtle_top.png", "turtle_miner_firstturtle_buttom.png", "turtle_miner_firstturtle_right.png", "turtle_miner_firstturtle_left.png", "turtle_miner_firstturtle_back.png", "turtle_miner_firstturtle_front.png"},
|
||||
groups={oddly_breakable_by_hand=1},
|
||||
paramtype2 = "facedir",
|
||||
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
local wielditem = clicker:get_wielded_item()
|
||||
local wieldname = wielditem:get_name()
|
||||
if wieldname ~= "turtle_miner:remotecontrol" then
|
||||
minetest.chat_send_player(clicker:get_player_name(), "Nimm die Fernbedienung!")
|
||||
else
|
||||
-- When the player does a right click on this node
|
||||
local player_name = clicker:get_player_name()
|
||||
-- Save the last turtle in a table
|
||||
turtle_formspec_positions[player_name] = pos
|
||||
|
||||
minetest.show_formspec(player_name, "turtle_miner:control_formspec",
|
||||
"size[9,4]" ..
|
||||
"label[0,0;Click buttons to move the turtle around!]" ..
|
||||
"button_exit[5,1;2,1;exit;Exit]" ..
|
||||
"image_button[1,1;1,1;arrow_up.png;up;]" ..
|
||||
"image_button[2,1;1,1;arrow_fw.png;forward;]" ..
|
||||
"image_button[1,2;1,1;arrow_left.png;turnleft;]"..
|
||||
"image_button[3,2;1,1;arrow_right.png;turnright;]" ..
|
||||
"image_button[1,3;1,1;arrow_down.png;down;]" ..
|
||||
"image_button[2,3;1,1;arrow_bw.png;backward;]"
|
||||
)
|
||||
return itemstack
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
})
|
||||
|
||||
-- image_button[X,Y;W,H;image;name;label]
|
||||
|
||||
local function nextrangeright(x)
|
||||
x = x + 1
|
||||
if x > 3 then
|
||||
x = 0
|
||||
end
|
||||
return x
|
||||
end
|
||||
|
||||
local function nextrangeleft(x)
|
||||
x = x - 1
|
||||
if x < 0 then
|
||||
x = 3
|
||||
end
|
||||
return x
|
||||
end
|
||||
|
||||
-- Catch user inputs from the formspec
|
||||
minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
||||
if formname ~= "turtle_miner:control_formspec" then
|
||||
return -- Not a turtle formspec
|
||||
end
|
||||
local player_name = sender:get_player_name()
|
||||
local pos = turtle_formspec_positions[player_name]
|
||||
|
||||
if not pos then
|
||||
return -- Something went wrong. No position found for this player
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if node.name ~= "turtle_miner:firstturtle" then
|
||||
turtle_formspec_positions[player_name] = nil
|
||||
return -- Data invalid. There's no turtle at the given position
|
||||
end
|
||||
|
||||
local new_pos = vector.new(pos)
|
||||
|
||||
if fields.up then
|
||||
new_pos.y = new_pos.y + 1
|
||||
end
|
||||
|
||||
if fields.down then
|
||||
new_pos.y = new_pos.y - 1
|
||||
end
|
||||
|
||||
if fields.forward then
|
||||
new_pos.z = new_pos.z + 1
|
||||
end
|
||||
|
||||
if fields.backward then
|
||||
new_pos.z = new_pos.z - 1
|
||||
end
|
||||
|
||||
if fields.turnright then
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
-- Compute param2
|
||||
local rotationPart = node.param2 % 32 -- get first 4 bits
|
||||
local preservePart = node.param2 - rotationPart
|
||||
local axisdir = math.floor(rotationPart / 4)
|
||||
local rotation = rotationPart - axisdir * 4
|
||||
rotationPart = axisdir * 4 + nextrangeright(rotation)
|
||||
|
||||
local new_param2 = preservePart + rotationPart
|
||||
|
||||
node.param2 = new_param2
|
||||
minetest.swap_node(pos, node)
|
||||
minetest.sound_play("moveokay", {to_player = player_name,gain = 1.0,})
|
||||
return
|
||||
end
|
||||
|
||||
if fields.turnleft then
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
-- Compute param2
|
||||
local rotationPart = node.param2 % 32 -- get first 4 bits
|
||||
local preservePart = node.param2 - rotationPart
|
||||
local axisdir = math.floor(rotationPart / 4)
|
||||
local rotation = rotationPart - axisdir * 4
|
||||
rotationPart = axisdir * 4 + nextrangeleft(rotation)
|
||||
|
||||
local new_param2 = preservePart + rotationPart
|
||||
|
||||
node.param2 = new_param2
|
||||
minetest.swap_node(pos, node)
|
||||
minetest.sound_play("moveokay",{to_player = player_name,gain = 1.0,})
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- Check new position if empty
|
||||
local newposchecktable = minetest.get_node(new_pos)
|
||||
local newposcheck = newposchecktable.name
|
||||
local walkable = minetest.registered_nodes[newposcheck].walkable
|
||||
local dir = minetest.facedir_to_dir(node.param2)
|
||||
|
||||
minetest.chat_send_all(newposcheck)
|
||||
minetest.chat_send_all(tostring(dir.x))
|
||||
minetest.chat_send_all(tostring(walkable))
|
||||
|
||||
if not walkable then
|
||||
if not vector.equals(pos, new_pos) then
|
||||
-- Move node to new position
|
||||
minetest.remove_node(pos)
|
||||
minetest.set_node(new_pos, node) --move node to new position
|
||||
minetest.get_meta(new_pos):from_table(meta) --set metadata of new node
|
||||
|
||||
-- Update formspec reference position, wait for next instructions
|
||||
turtle_formspec_positions[player_name] = new_pos
|
||||
|
||||
minetest.sound_play("moveokay", {to_player = player_name,gain = 1.0,})
|
||||
end
|
||||
else
|
||||
minetest.sound_play("moveerror", {
|
||||
to_player = player_name,
|
||||
gain = 1.0,
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
1
readme.md
Normal file
@ -0,0 +1 @@
|
||||
Installation as always for Mods in Minetest: Extract the downloaded ZIP-Master file and move ot to mods folfer of Minetest. Enable the Mod in the settings for the world.
|
BIN
sounds/moveerror.ogg
Normal file
BIN
sounds/moveokay.ogg
Normal file
BIN
textures/arrow_bw.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
textures/arrow_down.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
textures/arrow_fw.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
textures/arrow_left.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
textures/arrow_right.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
textures/arrow_up.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
textures/turtle_miner_firstturtle_back.png
Normal file
After Width: | Height: | Size: 307 B |
BIN
textures/turtle_miner_firstturtle_buttom.png
Normal file
After Width: | Height: | Size: 304 B |
BIN
textures/turtle_miner_firstturtle_front.png
Normal file
After Width: | Height: | Size: 366 B |
BIN
textures/turtle_miner_firstturtle_left.png
Normal file
After Width: | Height: | Size: 311 B |
BIN
textures/turtle_miner_firstturtle_right.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
textures/turtle_miner_firstturtle_top.png
Normal file
After Width: | Height: | Size: 351 B |
BIN
textures/turtle_miner_remotecontrol.png
Normal file
After Width: | Height: | Size: 322 B |