From a956b80597e27b8e9d63240b1a01a341f29ffd26 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 23 Apr 2018 16:04:35 +0200 Subject: [PATCH] working animation --- cannon.lua | 124 ++++++++++++++++++++++++++++++++++++++ depends.txt | 3 + init.lua | 17 ++++++ textures/cannon.png | Bin 0 -> 190 bytes textures/cannon_front.png | Bin 0 -> 227 bytes textures/spark.png | Bin 0 -> 253 bytes 6 files changed, 144 insertions(+) create mode 100644 cannon.lua create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 textures/cannon.png create mode 100644 textures/cannon_front.png create mode 100644 textures/spark.png diff --git a/cannon.lua b/cannon.lua new file mode 100644 index 0000000..6c04082 --- /dev/null +++ b/cannon.lua @@ -0,0 +1,124 @@ +local has_technic_mod = minetest.get_modpath("technic") + + +minetest.register_entity("spacecannon:energyball", { + initial_properties = { + visual = "cube", + visual_size = {x=0.25, y=0.25}, + textures = {"spark.png"}, + collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25}, + physical = false, + timer=0 + }, + + on_step = function(self, dtime) + if self.timer == nil then + return --XXX + end + self.timer=self.timer+dtime + if self.timer >= 0.3 then + local pos = self.object:getpos() + local node = minetest.get_node(pos) + + if node.name == "air" then + local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 3) + for k, obj in pairs(objs) do + if obj:get_luaentity() ~= nil then + if obj:get_luaentity().name ~= self.name and obj:get_luaentity().name ~= "__builtin:item" then --something other found + local mob = obj + -- self.on_mob_hit(self,pos,mob) + end + elseif obj:is_player() then --player found + local player = obj + -- self.on_player_hit(self,pos,player) + end + end + elseif node.name ~= "air" then + + end + end + end, + + on_activate = function(self, staticdata) + minetest.after(8.0, + function(self) + self.object:remove() + end, + self) + end, + + on_rightclick=function(self, clicker) + end, + + on_punch = function(self, hitter) + end, +}) + + + +minetest.register_node("spacecannon:cannon", { + description = "Spacecannon", + tiles = {"cannon.png","cannon_front.png","cannon.png","cannon.png","cannon.png","cannon.png"}, + groups = {cracky=3,oddly_breakable_by_hand=3,technic_machine = 1, technic_hv = 1}, + drop = "spacecannon:cannon", + sounds = default.node_sound_glass_defaults(), + + mesecons = {effector = { + action_on = function (pos, node) + local obj = minetest.add_entity({x=pos.x, y=pos.y, z=pos.z+1}, "spacecannon:energyball") + obj:setvelocity({x=0, y=0, z=1}) + -- obj:setacceleration({x=dir.x*-3, y=-settings.gravity, z=dir.z*-3}) + end + }}, + + connects_to = {"group:technic_hv_cable"}, + connect_sides = {"bottom", "top", "left", "right", "front", "back"}, + + after_place_node = function(pos, placer) + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name() or "") + end, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_int("powerstorage", 0) + + if has_technic_mod then + meta:set_int("HV_EU_input", 0) + meta:set_int("HV_EU_demand", 0) + end + end, + + technic_run = function(pos, node) + local meta = minetest.get_meta(pos) + local eu_input = meta:get_int("HV_EU_input") + local demand = meta:get_int("HV_EU_demand") + local store = meta:get_int("powerstorage") + + meta:set_string("infotext", "Power: " .. eu_input .. "/" .. demand .. " Store: " .. store) + + if store < spacecannon.config.powerstorage then + -- charge + meta:set_int("HV_EU_demand", spacecannon.config.powerrequirement) + store = store + eu_input + meta:set_int("powerstorage", store) + else + -- charged + meta:set_int("HV_EU_demand", 0) + end + end +}) + +if has_technic_mod then + technic.register_machine("HV", "spacecannon:cannon", technic.receiver) +end + +minetest.register_craft({ + output = 'spacecannon:cannon', + recipe = { + {'', 'default:tnt', ''}, + {'default:diamond', 'default:mese_block', 'default:diamond'}, + {'', 'default:tnt', ''} + } +}) + diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..a77d267 --- /dev/null +++ b/depends.txt @@ -0,0 +1,3 @@ +default +technic? +mesecons? diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..219a888 --- /dev/null +++ b/init.lua @@ -0,0 +1,17 @@ + +spacecannon = { + config = { + -- technic EU storage value + powerstorage = 100000, + + -- charge value in EU + powerrequirement = 2500, + + } +} + +local MP = minetest.get_modpath("spacecannon") + +dofile(MP.."/cannon.lua") + +print("[OK] Spacecannon") \ No newline at end of file diff --git a/textures/cannon.png b/textures/cannon.png new file mode 100644 index 0000000000000000000000000000000000000000..4315b5ac7928850807544071e646ce9e3eef10b1 GIT binary patch literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1SJ1Ryj={WI14-?iy0XB4ude`@%$AjKtc8r zPhVH|M=avJT8#S_ZBqgY#d^9phIkx*d(DvRfB_G)gX+5*OZkmny!;tBz0b6Sv(cwj zh@Umn%<94ur%Pu(XbOI;+RRu`{$$D4u-%*Gvsb$(vcG#B!`*YJ>j{T|fwZq1d0FpXTinJHVTgw7^heYr+HFgoDcI8&kO_E}Qe=qvCNUpuX4X z=Q(E8g?MF|Omf!+s=2~+OSFvTw4|5rfnc{jw@)irXNd7UT&BFZxtZCwnS-J1nvA4N Su|*}&H4L7velF{r5}E*aOiW?` literal 0 HcmV?d00001 diff --git a/textures/spark.png b/textures/spark.png new file mode 100644 index 0000000000000000000000000000000000000000..80a192048bc515b1c8df636a1a4ce6e52f5d448e GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPdi#RVIi=Dz^ZlF+?r;B5V#p&cJ$v@6Ja3&-sBqZEW z^qiO0|D1=%hew3zmehjE^ndkdtv`Qc6XMqUpM7uU|Np;FCuz)n_`h_ji`$~uhBY%A z8yg=2#n@u>5P4q^Rq=Q35yn8a)Sdmg#8~UPn?pp2>Px q9bYQBp0UN`lDeu8vxMf^a|{hj%p?t`+4KWl#o+1c=d#Wzp$P!E?p6E% literal 0 HcmV?d00001