summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeblate <noreply@weblate.org>2017-06-03 12:00:18 +0200
committerWeblate <noreply@weblate.org>2017-06-03 12:00:18 +0200
commite994889baae5458d14e8f8af232a90a3637463fd (patch)
tree638b50a7e1f88332062ef3af5c8daba5a99f9b50
parentbafd7333e5ffd4e59c62eb284807280886494f35 (diff)
parent1f0fdf832b5a24ee80df01b0f08a0902bad8e978 (diff)
Merge remote-tracking branch 'origin/master'
-rw-r--r--LICENSE.txt4
-rwxr-xr-xlua/visual.lua75
-rw-r--r--sounds/drawers_interact.1.oggbin0 -> 18173 bytes
-rw-r--r--sounds/drawers_interact.2.oggbin0 -> 17053 bytes
4 files changed, 62 insertions, 17 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
index d9a2e12..8f7c7fd 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -59,6 +59,10 @@ https://creativecommons.org/publicdomain/zero/1.0/
License of media:
-----------------
+Copyright (C) 2012 ultradust (https://www.freesound.org/people/ultradust/) (CC BY 3.0):
+ sounds/drawers_interact.1.ogg (edited by tacotexmex)
+ sounds/drawers_interact.2.ogg (edited by tacotexmex)
+
Copyright (C) 2014 Justin Aquadro (MIT):
textures/drawers_acacia_wood_mcl_front_1.png
textures/drawers_acacia_wood_mcl_front_2.png
diff --git a/lua/visual.lua b/lua/visual.lua
index a92a29b..5098a63 100755
--- a/lua/visual.lua
+++ b/lua/visual.lua
@@ -150,10 +150,37 @@ core.register_entity("drawers:visual", {
local leftover = self.try_insert_stack(self, clicker:get_wielded_item(),
not clicker:get_player_control().sneak)
+ -- if smth. was added play the interact sound
+ if clicker:get_wielded_item():get_count() > leftover:get_count() then
+ self:play_interact_sound()
+ end
+ -- set the leftover as new wielded item for the player
clicker:set_wielded_item(leftover)
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
+ local add_stack = not puncher:get_player_control().sneak
+
+ local inv = puncher:get_inventory()
+ local spaceChecker = ItemStack(self.itemName)
+ if add_stack then
+ spaceChecker:set_count(spaceChecker:get_stack_max())
+ end
+ if not inv:room_for_item("main", spaceChecker) then
+ return
+ end
+
+ stack = self:take_items(add_stack)
+ if stack ~= nil then
+ -- add removed stack to player's inventory
+ inv:add_item("main", stack)
+
+ -- play the interact sound
+ self:play_interact_sound()
+ end
+ end,
+
+ take_items = function(self, take_stack)
local meta = core.get_meta(self.drawer_pos)
if self.count <= 0 then
@@ -161,44 +188,50 @@ core.register_entity("drawers:visual", {
end
local removeCount = 1
- if not puncher:get_player_control().sneak then
+ if take_stack then
removeCount = ItemStack(self.itemName):get_stack_max()
end
- if removeCount > self.count then removeCount = self.count end
+ if removeCount > self.count then
+ removeCount = self.count
+ end
local stack = ItemStack(self.itemName)
stack:set_count(removeCount)
- local inv = puncher:get_inventory()
- if not inv:room_for_item("main", stack) then
- return
- end
-
- inv:add_item("main", stack)
+ -- update the drawer count
self.count = self.count - removeCount
- meta:set_int("count"..self.visualId, self.count)
-
- -- update infotext
- local itemDescription = ""
- if core.registered_items[self.itemName] then
- itemDescription = core.registered_items[self.itemName].description
- end
-
+ -- clean up drawer, if empty
if self.count <= 0 then
self.itemName = ""
meta:set_string("name"..self.visualId, self.itemName)
self.texture = "blank.png"
+ end
+
+
+
+ -- build info
+ local itemDescription = ""
+ if self.count <= 0 then
itemDescription = S("Empty")
+ elseif core.registered_items[self.itemName] then
+ itemDescription = core.registered_items[self.itemName].description
end
local infotext = drawers.gen_info_text(itemDescription,
self.count, self.stackMaxFactor, self.itemStackMax)
- meta:set_string("entity_infotext"..self.visualId, infotext)
+ -- set new infotext and texture
self.object:set_properties({
infotext = infotext .. "\n\n\n\n\n",
textures = {self.texture}
})
+
+ -- save everything to meta
+ meta:set_string("entity_infotext"..self.visualId, infotext)
+ meta:set_int("count"..self.visualId, self.count)
+
+ -- return the stack that was removed from the drawer
+ return stack
end,
try_insert_stack = function(self, itemstack, insert_stack)
@@ -272,6 +305,14 @@ core.register_entity("drawers:visual", {
return itemstack
end,
+ play_interact_sound = function(self)
+ core.sound_play("drawers_interact", {
+ pos = self.pos,
+ max_hear_distance = 6,
+ gain = 2.0
+ })
+ end,
+
saveMetaData = function(self, meta)
meta:set_int("count"..self.visualId, self.count)
meta:set_string("name"..self.visualId, self.itemName)
diff --git a/sounds/drawers_interact.1.ogg b/sounds/drawers_interact.1.ogg
new file mode 100644
index 0000000..4e50559
--- /dev/null
+++ b/sounds/drawers_interact.1.ogg
Binary files differ
diff --git a/sounds/drawers_interact.2.ogg b/sounds/drawers_interact.2.ogg
new file mode 100644
index 0000000..572c595
--- /dev/null
+++ b/sounds/drawers_interact.2.ogg
Binary files differ