aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorDániel Juhász <juhdanad@gmail.com>2017-03-10 18:25:58 +0100
committerAuke Kok <sofar@foo-projects.org>2017-04-08 18:39:15 -0700
commit58d83a7bb2f992194c3df304b1dcbb81f98f78c0 (patch)
tree4beedb69ac8b9b74352ef52c3a1d27004e77bc1d /builtin
parentd4e9dd4643607192f5adebeecda86f25074f02cd (diff)
downloadminetest-58d83a7bb2f992194c3df304b1dcbb81f98f78c0.tar.gz
minetest-58d83a7bb2f992194c3df304b1dcbb81f98f78c0.tar.bz2
minetest-58d83a7bb2f992194c3df304b1dcbb81f98f78c0.zip
Hardware coloring for itemstacks
Adds the possibility to colorize item stacks based on their metadata. In the item/node definition you can specify palette (an image file) and color (fallback color if the item has no palette or metadata). Then you can add palette_index to the metadata. Dropped itemstacks with different colors do not merge.
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/item_entity.lua31
1 files changed, 22 insertions, 9 deletions
diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua
index be158c119..7b8247116 100644
--- a/builtin/game/item_entity.lua
+++ b/builtin/game/item_entity.lua
@@ -53,6 +53,8 @@ core.register_entity(":__builtin:item", {
if itemtable then
itemname = stack:to_table().name
end
+ -- Backwards compatibility: old clients use the texture
+ -- to get the type of the item
local item_texture = nil
local item_type = ""
if core.registered_items[itemname] then
@@ -66,6 +68,7 @@ core.register_entity(":__builtin:item", {
visual_size = {x = s, y = s},
collisionbox = {-c, -c, -c, c, c, c},
automatic_rotate = math.pi * 0.5,
+ wield_item = itemstring,
}
self.object:set_properties(prop)
end,
@@ -101,31 +104,39 @@ core.register_entity(":__builtin:item", {
self:set_item(self.itemstring)
end,
+ -- moves items from this stack to an other stack
try_merge_with = function(self, own_stack, object, obj)
+ -- other item's stack
local stack = ItemStack(obj.itemstring)
- if own_stack:get_name() == stack:get_name() and stack:get_free_space() > 0 then
+ -- only merge if items are the same
+ if own_stack:get_name() == stack:get_name() and
+ own_stack:get_meta() == stack:get_meta() and
+ own_stack:get_wear() == stack:get_wear() and
+ stack:get_free_space() > 0 then
local overflow = false
local count = stack:get_count() + own_stack:get_count()
local max_count = stack:get_stack_max()
if count > max_count then
overflow = true
+ stack:set_count(max_count)
count = count - max_count
+ own_stack:set_count(count)
else
self.itemstring = ''
+ stack:set_count(count)
end
local pos = object:getpos()
pos.y = pos.y + (count - stack:get_count()) / max_count * 0.15
object:moveto(pos, false)
local s, c
- local max_count = stack:get_stack_max()
- local name = stack:get_name()
if not overflow then
- obj.itemstring = name .. " " .. count
+ obj.itemstring = stack:to_string()
s = 0.2 + 0.1 * (count / max_count)
c = s
object:set_properties({
visual_size = {x = s, y = s},
- collisionbox = {-c, -c, -c, c, c, c}
+ collisionbox = {-c, -c, -c, c, c, c},
+ wield_item = obj.itemstring
})
self.object:remove()
-- merging succeeded
@@ -133,18 +144,20 @@ core.register_entity(":__builtin:item", {
else
s = 0.4
c = 0.3
+ obj.itemstring = stack:to_string()
object:set_properties({
visual_size = {x = s, y = s},
- collisionbox = {-c, -c, -c, c, c, c}
+ collisionbox = {-c, -c, -c, c, c, c},
+ wield_item = obj.itemstring
})
- obj.itemstring = name .. " " .. max_count
s = 0.2 + 0.1 * (count / max_count)
c = s
+ self.itemstring = own_stack:to_string()
self.object:set_properties({
visual_size = {x = s, y = s},
- collisionbox = {-c, -c, -c, c, c, c}
+ collisionbox = {-c, -c, -c, c, c, c},
+ wield_item = self.itemstring
})
- self.itemstring = name .. " " .. count
end
end
-- merging didn't succeed