Paste
Powered by
Mojopaste
local MyEntity = { initial_properties = { visual = "cube", visual_size = {x = 1, y = 1, z = 1}, collisionbox = { -0.45, -0.45, -0.45, 0.45, 0.45, 0.45 }, textures = {"bla-line-123456789.png", "bla-line-123456789.png", "bla-line-123456789.png","bla-line-123456789.png", "bla-line-123456789.png","bla-line-123456789.png"}, physical = true, damage_texture_modifier = nil, }, current_color = 0, frequency = 0.250, last_run = -1, message = "Default message", x = -1, y = -1, owner = nil, numbers = { true, true, true, true, true, true, true, true, true, } } ... function MyEntity:on_punch(hitter) local hitter_name = hitter:get_player_name() local hitter_pos = hitter:get_pos() local object_pos = self.object:get_pos() --minetest.log(("punched %s - %d x %d"):format(self.owner, self.x, self.y)) --minetest.chat_send_player(hitter_name, ("punched %s - %d x %d"):format(self.owner, self.x, self.y)) local face_pos = minetest.pointed_thing_to_face_pos(hitter, { above = { x=object_pos.x, y=object_pos.y+1, z=object_pos.z }, under = object_pos }) minetest.log(dump(face_pos)) self.last_run = self.last_run + 1 local adjusted_pos = vector.subtract(object_pos, face_pos) local number = -1 local updown = adjusted_pos.z local leftright = adjusted_pos.x local cutoff = 0.15 local cutoff_n = cutoff * (-1) if(leftright > cutoff and updown < cutoff_n) then number = 1 elseif(leftright < cutoff and leftright > cutoff_n and updown < cutoff_n) then number = 2 elseif(leftright < cutoff_n and updown < cutoff_n) then number = 3 elseif(leftright > cutoff and updown < cutoff and updown > cutoff_n) then number = 4 elseif(leftright < cutoff and leftright > cutoff_n and updown < cutoff and updown > cutoff_n) then number = 5 elseif(leftright < cutoff_n and updown < cutoff and updown > cutoff_n) then number = 6 elseif(leftright > cutoff and updown > cutoff) then number = 7 elseif(leftright < cutoff and leftright > cutoff_n and updown > cutoff) then number = 8 elseif(leftright < cutoff_n and updown > cutoff) then number = 9 end minetest.chat_send_all(("%s %d hpos %s opos %s fpos %s norm %s number: %d"):format(hitter_name, self.last_run, minetest.pos_to_string(hitter_pos, 3), minetest.pos_to_string(object_pos, 4), minetest.pos_to_string(face_pos, 4), minetest.pos_to_string(adjusted_pos, 4), number)) self:flipnumber(number) self:set_number_texture() local ray = minetest.raycast(object_pos, hitter_pos, true, true) local pointed_thing = ray:next() while pointed_thing do minetest.log(dump(pointed_thing)) local ip_pos = pointed_thing.intersection_point -- local face_pos = minetest.pointed_thing_to_face_pos(hitter, pointed_thing) local number = -1 local norm = vector.subtract(object_pos, ip_pos) -- local norm3 = vector.subtract(object_pos, face_pos) self.last_run = self.last_run + 1 minetest.chat_send_all(("%s %d hpos %s ippos %s norm %s number: %d"):format(hitter_name, self.last_run, minetest.pos_to_string(hitter_pos, 3), minetest.pos_to_string(ip_pos, 4), minetest.pos_to_string(norm, 4), number)) break end return true end