aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-10-07 15:19:55 +0200
committerorwell96 <orwell@bleipb.de>2020-10-07 15:19:55 +0200
commita73236d7eb6ff79476d0187ff46e83872fc798be (patch)
tree6d4b672eb5225d5350af29b85ae98e6f8a63bbdc
parentd89b8b1c8963e7dde59590efbdb2862c2a431c3d (diff)
downloadadvtrains-a73236d7eb6ff79476d0187ff46e83872fc798be.tar.gz
advtrains-a73236d7eb6ff79476d0187ff46e83872fc798be.tar.bz2
advtrains-a73236d7eb6ff79476d0187ff46e83872fc798be.zip
Don't allow wagons with non-empty inventories to be destroyed (H#164)
-rw-r--r--advtrains/locale/advtrains.de.tr1
-rw-r--r--advtrains/wagons.lua15
2 files changed, 16 insertions, 0 deletions
diff --git a/advtrains/locale/advtrains.de.tr b/advtrains/locale/advtrains.de.tr
index ca67a7e..520b200 100644
--- a/advtrains/locale/advtrains.de.tr
+++ b/advtrains/locale/advtrains.de.tr
@@ -63,3 +63,4 @@ Detailed Steam Engine=detaillierte Dampflokomotive
Passenger Wagon=Passagierwaggon
Box wagon=Güterwaggon
Subway Passenger Wagon=U-Bahn-Waggon
+The wagon's inventory is not empty!=Das Inventar dieses Waggons ist nicht leer!
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 6f72d92..90615a5 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -187,6 +187,21 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
self:set_livery(puncher, itemstack, data)
return
end
+ -- check whether wagon has an inventory. Is is empty?
+ if self.has_inventory then
+ local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.id})
+ if not inv then -- inventory is not initialized when wagon was never loaded - should never happen
+ atwarn("Destroying wagon with inventory, but inventory is not found? Shouldn't happen!")
+ return
+ end
+ for listname, _ in pairs(inv:get_lists()) do
+ if not inv:is_empty(listname) then
+ minetest.chat_send_player(puncher:get_player_name(), attrans("The wagon's inventory is not empty!"));
+ return
+ end
+ end
+ end
+
if #(self:train().trainparts)>1 then
minetest.chat_send_player(puncher:get_player_name(), attrans("Wagon needs to be decoupled from other wagons in order to destroy it."));
return