Add sliced bread, bread no longer centred

This commit is contained in:
SmallJoker 2018-06-05 14:49:23 +02:00
parent 198def6ea2
commit 157022ff25
2 changed files with 33 additions and 8 deletions

View File

@ -30,8 +30,9 @@ local function try_staple(itemstack, placer, pointed)
-- Staple to the tree
local dir = vector.direction(pointed.above, pointed.under)
local pos = minetest.pointed_thing_to_face_pos(placer, pointed)
local obj = minetest.add_entity(
vector.add(vector.multiply(dir, 0.49), pointed.above),
vector.add(pos, vector.multiply(dir, -0.01)),
"stapled_bread:bread_slice"
)
if obj then
@ -41,21 +42,45 @@ local function try_staple(itemstack, placer, pointed)
itemstack:take_item(1)
end
entity.object:set_yaw(math.atan2(-dir.x, dir.z))
entity.object:set_properties({
textures = { itemstack:get_name() }
})
end
return itemstack
end
local function staple_place_wrapper(itemstack, placer, pointed_thing)
return try_staple(itemstack, placer, pointed_thing) or itemstack
end
local extent = 0.12
local box = {-extent, -extent, -extent, extent, extent, extent}
minetest.register_entity("stapled_bread:bread_slice", {
visual = "wielditem",
textures = { "farming:bread" },
textures = { "unknown_node.png" },
visual_size = {x = 0.2, y = 0.2},
physical = false,
collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
selectionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1}
collisionbox = box,
selectionbox = box
})
-- REGISTER BREAD STUFF
minetest.override_item("farming:bread", {
on_place = function(itemstack, placer, pointed_thing)
return try_staple(itemstack, placer, pointed_thing) or itemstack
end
})
on_place = staple_place_wrapper
})
minetest.register_craftitem("stapled_bread:bread_slice", {
description = "Bread Slice",
inventory_image = "stapled_bread_slice.png",
on_use = minetest.item_eat(1),
on_place = staple_place_wrapper
})
minetest.register_craft({
type = "shapeless",
output = "stapled_bread:bread_slice 5",
recipe = {
"farming:bread"
}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B