From ee48aef81203ec675bb28ec3ec8170079fbdb713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Wed, 28 Jun 2017 11:39:44 +0200 Subject: First commit --- LICENSE | 26 +++ depends.txt | 1 + init.lua | 266 +++++++++++++++++++++++++++++ textures/factory_belt_bottom.png | Bin 0 -> 18991 bytes textures/factory_belt_bottom_clean.png | Bin 0 -> 3018 bytes textures/factory_belt_side.png | Bin 0 -> 18872 bytes textures/factory_belt_side_upward.png | Bin 0 -> 3109 bytes textures/factory_belt_st_top.png | Bin 0 -> 2812 bytes textures/factory_belt_st_top_animation.png | Bin 0 -> 2876 bytes textures/factory_belt_top.png | Bin 0 -> 19623 bytes textures/factory_belt_top_animation.png | Bin 0 -> 19783 bytes 11 files changed, 293 insertions(+) create mode 100644 LICENSE create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 textures/factory_belt_bottom.png create mode 100644 textures/factory_belt_bottom_clean.png create mode 100644 textures/factory_belt_side.png create mode 100644 textures/factory_belt_side_upward.png create mode 100644 textures/factory_belt_st_top.png create mode 100644 textures/factory_belt_st_top_animation.png create mode 100644 textures/factory_belt_top.png create mode 100644 textures/factory_belt_top_animation.png diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5121648 --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +This mod is based on Factory by Drew Lemmy and theFox6, licensed under this same license +MIT License + +Copyright (c) 2017 Gabriel PĂ©rez-Cerezo +Copyright (c) 2017 theFox6 +Copyright (c) 2014 Drew Lemmy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..c0d5e26 --- /dev/null +++ b/init.lua @@ -0,0 +1,266 @@ +walkway = {} +local speed = 0.4 +minetest.register_entity("walkway:moving_dummy",{ + initial_properties = { + hp_max = 1, + physical = false, + collisionbox = {0.025, 0.025, 0.025, 0.025, 0.025, 0.025}, + visual = "wielditem", + visual_size = {x = 1, y = 1}, + textures = {""}, + spritediv = {x = 1, y = 1}, + initial_sprite_basepos = {x = 0, y = 0}, + is_visible = false, + }, + player = nil, + on_step = function (self, dtime) + local name = "" + if self.player then + name = self.player:get_player_name() + else + self.object:remove() + end + local pos = self.object:getpos() + local napos = minetest.get_node(pos) + local dir = vector.new(minetest.facedir_to_dir(napos.param2)) -- a copy of the facedir so we don't overwrite the facedir table + local vx=0 + local vz=0 + if self.player then + -- based on code from the tower crane mod -- + local ctrl = self.player:get_player_control() + local yaw = self.player:get_look_horizontal() + local pos = self.player:getpos() + local walk_speed = minetest.settings:get("movement_speed_walk") or 4 + local speed_forward = 0 + local speed_right= 0 + + if ctrl.up then -- forward + speed_forward = walk_speed + elseif ctrl.down then -- backward + speed_forward = -walk_speed + end + + if ctrl.right then -- right + speed_right = walk_speed + elseif ctrl.left then -- left + speed_right = -walk_speed + end + + -- calculate the direction vector + vx = math.cos(yaw+math.pi/2) * speed_forward + math.cos(yaw) * speed_right + vz = math.sin(yaw+math.pi/2) * speed_forward + math.sin(yaw) * speed_right + if dir.x == 0 then + vx = 0 + elseif dir.z == 0 then + vz = 0 + end + end + + + if napos.name == "walkway:belt_straight" then + self.object:setvelocity({x = dir.x / speed, y = 0, z = dir.z / speed}) + elseif napos.name == "walkway:belt" then + if dir.x == 0 then + dir.x = (math.floor(pos.x + 0.5) - pos.x) * 2 + elseif dir.z == 0 then + dir.z = (math.floor(pos.z + 0.5) - pos.z) * 2 + end + self.object:setvelocity({x = dir.x / speed + vx, y = 0, z = dir.z / speed+vz}) + else + self.player:set_detach() + default.player_attached[name] = false + self.object:remove() + end + end +}) + + +minetest.register_node("walkway:belt", { + description = "Moving Walkway", + tiles = {{name="factory_belt_top_animation.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png", + "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"}, + groups = {cracky=1}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + legacy_facedir_simple = true, + node_box = { + type = "fixed", + fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},} + }, +}) + +-- minetest.register_node("walkway:belt_straight", { +-- description = "straight Conveyor Belt", +-- tiles = {{name="factory_belt_top_animation.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.4}}, "factory_belt_bottom.png", "factory_belt_side.png", +-- "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"}, +-- groups = {cracky=1}, +-- drawtype = "nodebox", +-- paramtype = "light", +-- paramtype2 = "facedir", +-- is_ground_content = true, +-- legacy_facedir_simple = true, +-- node_box = { +-- type = "fixed", +-- fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},} +-- }, +-- }) + +minetest.register_abm({ + nodenames = {"walkway:belt", "walkway:belt_straight"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local all_objects = minetest.get_objects_inside_radius(pos, 0.75) + local _,obj + for _,obj in ipairs(all_objects) do + if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then + walkway.do_moving_item({x = pos.x, y = pos.y + 0.15, z = pos.z}, obj:get_luaentity().itemstring) + obj:get_luaentity().itemstring = "" + obj:remove() + end + end + end, +}) + +minetest.register_abm({ + nodenames = {"walkway:belt", "walkway:belt_straight"}, + neighbors = nil, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local all_objects = minetest.get_objects_inside_radius(pos, 0.75) + local _,obj + for _,obj in ipairs(all_objects) do + if obj:is_player() and not obj:get_attach() then + dum = walkway.do_moving_dummy({x = pos.x, y = pos.y + 0.15, z = pos.z}, obj):get_luaentity() + dum.player = obj + obj:set_attach(dum.object, "", {x=0,y=15,z=-3}, {x=0,y=0,z=0}) + local name = obj:get_player_name() + default.player_attached[name] = true +-- obj:get_luaentity().itemstring = "" +-- obj:remove() + end + end + end, +}) + +-- Based off of the pipeworks item code + +function walkway.do_moving_item(pos, item) + if item==":" then + return + end + local stack = ItemStack(item) + local obj = minetest.add_entity(pos, "walkway:moving_item") + obj:get_luaentity():set_item(stack:to_string()) + return obj +end + +function walkway.do_moving_dummy(pos, player) + local stack = ItemStack(item) + local obj = minetest.add_entity(pos, "walkway:moving_dummy") + -- obj:attach(player) + return obj +end + + +minetest.register_entity("walkway:moving_item", { + initial_properties = { + hp_max = 1, + physical = false, + collisionbox = {0.125, 0.125, 0.125, 0.125, 0.125, 0.125}, + visual = "wielditem", + visual_size = {x = 0.5, y = 0.5}, + textures = {""}, + spritediv = {x = 1, y = 1}, + initial_sprite_basepos = {x = 0, y = 0}, + is_visible = false, + }, + + physical_state = true, + itemstring = '', + set_item = function(self, itemstring) + self.itemstring = itemstring + local stack = ItemStack(itemstring) + local count = stack:get_count() + local max_count = stack:get_stack_max() + if count > max_count then + count = max_count + self.itemstring = stack:get_name().." "..max_count + end + local s = 0.15 + 0.15 * (count / max_count) + local c = 0.8 * s + local itemtable = stack:to_table() + local itemname = nil + if itemtable then + itemname = stack:to_table().name + end + local item_texture = nil + local item_type = "" + if core.registered_items[itemname] then + item_texture = core.registered_items[itemname].inventory_image + item_type = core.registered_items[itemname].type + end + prop = { + is_visible = true, + visual = "wielditem", + textures = {itemname}, + visual_size = {x = s, y = s}, + collisionbox = {-c, -c, -c, c, c, c}, + automatic_rotate = math.pi * 0.2, + } + self.object:set_properties(prop) + end, + + get_staticdata = function(self) + return core.serialize({ + itemstring = self.itemstring + }) + end, + + on_activate = function(self, staticdata, dtime_s) + if string.sub(staticdata, 1, string.len("return")) == "return" then + local data = core.deserialize(staticdata) + if data and type(data) == "table" then + self.itemstring = data.itemstring + end + else + self.itemstring = staticdata + end + self.object:set_armor_groups({immortal = 1}) + self:set_item(self.itemstring) + end, + + on_step = function(self, dtime) + local pos = self.object:getpos() + local napos = minetest.get_node(pos) + local dir = vector.new(minetest.facedir_to_dir(napos.param2)) -- a copy of the facedir so we don't overwrite the facedir table + if napos.name == "walkway:belt_straight" then + self.object:setvelocity({x = dir.x / speed, y = 0, z = dir.z / speed}) + elseif napos.name == "walkway:belt" then + if dir.x == 0 then + dir.x = (math.floor(pos.x + 0.5) - pos.x) * 2 + elseif dir.z == 0 then + dir.z = (math.floor(pos.z + 0.5) - pos.z) * 2 + end + self.object:setvelocity({x = dir.x / speed, y = 0, z = dir.z / speed}) + else + local stack = ItemStack(self.itemstring) + local veldir = self.object:getvelocity(); + minetest.item_drop(stack, walkway.no_player, {x = pos.x + veldir.x / 3, y = pos.y, z = pos.z + veldir.z / 3}) + self.object:remove() + end + end +}) + +minetest.register_craft({ + output = "walkway:belt 12", + recipe = { + {"", "default:gold_ingot", ""}, + {"default:stone", "default:mese_crystal", "default:stone"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"} + } +}) diff --git a/textures/factory_belt_bottom.png b/textures/factory_belt_bottom.png new file mode 100644 index 0000000..42a7fb1 Binary files /dev/null and b/textures/factory_belt_bottom.png differ diff --git a/textures/factory_belt_bottom_clean.png b/textures/factory_belt_bottom_clean.png new file mode 100644 index 0000000..e513ea0 Binary files /dev/null and b/textures/factory_belt_bottom_clean.png differ diff --git a/textures/factory_belt_side.png b/textures/factory_belt_side.png new file mode 100644 index 0000000..6d60e06 Binary files /dev/null and b/textures/factory_belt_side.png differ diff --git a/textures/factory_belt_side_upward.png b/textures/factory_belt_side_upward.png new file mode 100644 index 0000000..e56fddd Binary files /dev/null and b/textures/factory_belt_side_upward.png differ diff --git a/textures/factory_belt_st_top.png b/textures/factory_belt_st_top.png new file mode 100644 index 0000000..6026053 Binary files /dev/null and b/textures/factory_belt_st_top.png differ diff --git a/textures/factory_belt_st_top_animation.png b/textures/factory_belt_st_top_animation.png new file mode 100644 index 0000000..7b32a39 Binary files /dev/null and b/textures/factory_belt_st_top_animation.png differ diff --git a/textures/factory_belt_top.png b/textures/factory_belt_top.png new file mode 100644 index 0000000..fe55359 Binary files /dev/null and b/textures/factory_belt_top.png differ diff --git a/textures/factory_belt_top_animation.png b/textures/factory_belt_top_animation.png new file mode 100644 index 0000000..d703e3b Binary files /dev/null and b/textures/factory_belt_top_animation.png differ -- cgit v1.2.3