]> git.lizzy.rs Git - Crafter.git/commitdiff
Add in prototype iron boat which only works in the nether
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 17 May 2020 21:17:04 +0000 (17:17 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 17 May 2020 21:17:04 +0000 (17:17 -0400)
mods/boat/init.lua
mods/boat/textures/boatitem.png
mods/boat/textures/iron_boat.png [new file with mode: 0644]
mods/boat/textures/iron_boatitem.png [new file with mode: 0644]

index 7e7273b5a0c1db49d22a3a6ededfe27cb87aaaf7..6477bc0448b294a6d194ba134aec0c2537632284 100644 (file)
@@ -233,3 +233,202 @@ minetest.register_craft({
                {"main:wood", "main:wood", "main:wood"},
        },
 })
+
+
+
+
+
+
+
+
+
+
+
+
+
+--minetest.get_node_level(pos)
+minetest.register_entity("boat:iron_boat", {
+       initial_properties = {
+               hp_max = 1,
+               physical = true,
+               collide_with_objects = false,
+               collisionbox = {-0.4, 0, -0.4, 0.4, 0.5, 0.4},
+               visual = "mesh",
+               mesh = "boat.x",
+               textures = {"iron_boat.png"},
+               visual_size = {x=1,y=1,z=1},
+               is_visible = true,
+               automatic_face_movement_dir = -90.0,
+               automatic_face_movement_max_rotation_per_sec = 600,
+       },
+       
+       rider = nil,
+
+
+       get_staticdata = function(self)
+               return minetest.serialize({
+                       --itemstring = self.itemstring,
+               })
+       end,
+
+       on_activate = function(self, staticdata, dtime_s)
+               if string.sub(staticdata, 1, string.len("return")) == "return" then
+                       local data = minetest.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.object:set_velocity({x = 0, y = 0, z = 0})
+               self.object:set_acceleration({x = 0, y = -9.81, z = 0})
+       end,
+       on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
+               local pos = self.object:getpos()
+               minetest.add_item(pos, "boat:boat")
+               self.object:remove()
+       end,
+       
+       
+       on_rightclick = function(self,clicker)
+               if not clicker or not clicker:is_player() then
+                       return
+               end
+               local player_name = clicker:get_player_name()
+               
+               if self.rider and player_name == self.rider then
+                       clicker:set_detach()
+                       self.rider = nil
+               elseif not self.rider then
+                       self.rider = player_name
+                       clicker:set_attach(self.object, "", {x=0, y=-4.5, z=0}, {x=0, y=0, z=0})
+                       minetest.after(0.2, function()
+                               player_api.set_animation(clicker, "sit" , 30)
+                       end)
+                       --player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
+                       --carts:manage_attachment(clicker, self.object)
+
+                       -- player_api does not update the animation
+                       -- when the player is attached, reset to default animation
+                       
+                       --player_api.set_animation(clicker, "stand")
+               end
+       end,
+       
+       --players drive the baot
+       drive = function(self)
+               if self.rider and not self.on_land == true then
+                       local rider = minetest.get_player_by_name(self.rider)
+                       local move = rider:get_player_control().up
+                       self.moving = nil
+                       if move then
+                               local currentvel = self.object:getvelocity()
+                               local goal = rider:get_look_dir()
+                               goal = vector.multiply(goal,20)
+                               local acceleration = vector.new(goal.x-currentvel.x,0,goal.z-currentvel.z)
+                               acceleration = vector.multiply(acceleration, 0.05)
+                               self.object:add_velocity(acceleration)
+                               self.moving = true
+                       end
+               else
+                       self.moving = nil
+               end
+       end,
+       
+       --players push boat
+       push = function(self)
+               local pos = self.object:getpos()
+               for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
+                       if object:is_player() and object:get_player_name() ~= self.rider then
+                               local player_pos = object:getpos()
+                               pos.y = 0
+                               player_pos.y = 0
+                               
+                               local currentvel = self.object:getvelocity()
+                               local vel = vector.subtract(pos, player_pos)
+                               vel = vector.normalize(vel)
+                               local distance = vector.distance(pos,player_pos)
+                               distance = (1-distance)*10
+                               vel = vector.multiply(vel,distance)
+                               local acceleration = vector.new(vel.x-currentvel.x,0,vel.z-currentvel.z)
+                               self.object:add_velocity(acceleration)
+                               acceleration = vector.multiply(acceleration, -1)
+                               object:add_player_velocity(acceleration)
+                       end
+               end
+       end,
+       
+       --makes the boat float
+       float = function(self)
+               local pos = self.object:getpos()
+               local pos2 = vector.new(pos.x,pos.y-3,pos.z)
+
+               local ray = minetest.raycast(pos, pos2, false, true)
+
+               local pointed_thing = ray:next()
+
+               if pointed_thing then
+                       self.swimming = true
+                       local vel = self.object:getvelocity()
+                       local goal = 3
+                       local acceleration = vector.new(0,goal-vel.y,0)
+                       self.object:add_velocity(acceleration)
+               else
+                       print("nothing")
+               end
+       end,
+
+       --slows the boat down
+       slowdown = function(self)
+               if not self.moving == true then
+                       local vel = self.object:getvelocity()
+                       local deceleration = vector.multiply(vel, -0.01)
+                       self.object:add_velocity(deceleration)
+               end
+       end,
+
+       on_step = function(self, dtime)
+               self.push(self)
+               self.drive(self)
+               self.float(self)
+               self.slowdown(self)
+       end,
+})
+
+minetest.register_craftitem("boat:iron_boat", {
+       description = "Iron Boat",
+       inventory_image = "iron_boatitem.png",
+       wield_image = "iron_boatitem.png",
+       liquids_pointable = true,
+       on_place = function(itemstack, placer, pointed_thing)
+               if not pointed_thing.type == "node" then
+                       return
+               end
+               
+               local sneak = placer:get_player_control().sneak
+               local noddef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
+               if not sneak and noddef.on_rightclick then
+                       minetest.item_place(itemstack, placer, pointed_thing)
+                       return
+               end
+               
+               if pointed_thing.above.y < -10000 and pointed_thing.above.y > -20000 then
+                       minetest.add_entity(pointed_thing.under, "boat:iron_boat")
+               else
+                       return
+               end
+
+               itemstack:take_item()
+
+               return itemstack
+       end,
+})
+
+minetest.register_craft({
+       output = "boat:iron_boat",
+       recipe = {
+               {"main:iron", "main:coal", "main:iron"},
+               {"main:iron", "main:iron", "main:iron"},
+       },
+})
\ No newline at end of file
index 3ba00911738d6d7b444dbff2ddef510b7f09c5e9..840559dc1080995a54c5fb408ac8162b1cd6ec3e 100644 (file)
Binary files a/mods/boat/textures/boatitem.png and b/mods/boat/textures/boatitem.png differ
diff --git a/mods/boat/textures/iron_boat.png b/mods/boat/textures/iron_boat.png
new file mode 100644 (file)
index 0000000..4bfa2fc
Binary files /dev/null and b/mods/boat/textures/iron_boat.png differ
diff --git a/mods/boat/textures/iron_boatitem.png b/mods/boat/textures/iron_boatitem.png
new file mode 100644 (file)
index 0000000..a574f45
Binary files /dev/null and b/mods/boat/textures/iron_boatitem.png differ