Some fixes in Machine and ActivatedMachine

This commit is contained in:
mrkubax10 2024-10-24 16:32:57 +02:00
parent 442d3a42b1
commit d799b10242
2 changed files with 47 additions and 28 deletions

View File

@ -43,13 +43,21 @@ function industrialtest.ActivatedMachine.createActiveDefinitionTable(self)
local def=self:createDefinitionTable() local def=self:createDefinitionTable()
def.description=nil def.description=nil
def.drop=def.drop or self.name def.drop=def.drop or self.name
if self.active then
def.tiles=self.active.tiles or def.tiles
def.light_source=self.active.lightSource
end
def.on_timer=function(pos,elapsed) def.on_timer=function(pos,elapsed)
return self:activeOnTimer(pos,elapsed) return self:activeOnTimer(pos,elapsed)
end end
if industrialtest.mclAvailable then if industrialtest.mclAvailable then
def.groups.not_in_creative_inventory=1 def.groups.not_in_creative_inventory=1
def._doc_items_create_entry=false def._doc_items_create_entry=false
end end
return def return def
end end

View File

@ -17,6 +17,7 @@
industrialtest.Machine={} industrialtest.Machine={}
function industrialtest.Machine.onConstruct(self,pos) function industrialtest.Machine.onConstruct(self,pos)
local meta=minetest.get_meta(pos)
meta:set_string("formspec",self:getFormspec(pos)) meta:set_string("formspec",self:getFormspec(pos))
minetest.get_node_timer(pos):start(industrialtest.updateDelay) minetest.get_node_timer(pos):start(industrialtest.updateDelay)
end end
@ -96,9 +97,42 @@ function industrialtest.Machine.allowMetadataInventoryPut(self,pos,listname,inde
return stack:get_count() return stack:get_count()
end end
function industrialtest.Machine.allowMetadataInventoryTake(self,pos,listname,index,stack,player)
return stack:get_count()
end
function industrialtest.Machine.onMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count)
if toList=="upgrades" then
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local stack=inv:get_stack(fromList,fromIndex)
industrialtest.internal.applyUpgrade(pos,meta,stack)
elseif fromList=="upgrades" then
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local stack=inv:get_stack(fromList,fromIndex)
industrialtest.internal.removeUpgrade(pos,meta,stack)
end
end
function industrialtest.Machine.onMetadataInventoryPut(self,pos,listname,index,stack)
if listname=="upgrades" then
local meta=minetest.get_meta(pos)
industrialtest.internal.applyUpgrade(pos,meta,stack)
end
end
function industrialtest.Machine.onMetadataInventoryTake(self,pos,listname,index,stack)
if listname=="upgrades" then
local meta=minetest.get_meta(pos)
industrialtest.internal.removeUpgrade(pos,meta,stack)
end
end
function industrialtest.Machine.createDefinitionTable(self) function industrialtest.Machine.createDefinitionTable(self)
local def={ local def={
description=self.description, description=self.description,
tiles=self.tiles,
on_construct=function(pos) on_construct=function(pos)
self:onConstruct(pos) self:onConstruct(pos)
end, end,
@ -181,6 +215,11 @@ function industrialtest.Machine.createDefinitionTable(self)
def.drop="industrialtest:machine_block" def.drop="industrialtest:machine_block"
end end
if self.facedir then
def.paramtype2="facedir"
def.legacy_facedir_simple=true
end
return def return def
end end
@ -190,34 +229,6 @@ function industrialtest.Machine.register(self)
industrialtest.api.addTag(self.name,"usesTimer") industrialtest.api.addTag(self.name,"usesTimer")
end end
function industrialtest.Machine.onMetadataInventoryMove(pos,fromList,fromIndex,toList,toIndex,count)
if toList=="upgrades" then
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local stack=inv:get_stack(fromList,fromIndex)
industrialtest.internal.applyUpgrade(pos,meta,stack)
elseif fromList=="upgrades" then
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local stack=inv:get_stack(fromList,fromIndex)
industrialtest.internal.removeUpgrade(pos,meta,stack)
end
end
function industrialtest.Machine.onMetadataInventoryPut(pos,listname,index,stack)
if listname=="upgrades" then
local meta=minetest.get_meta(pos)
industrialtest.internal.applyUpgrade(pos,meta,stack)
end
end
function industrialtest.Machine.onMetadataInventoryTake(pos,listname,index,stack)
if listname=="upgrades" then
local meta=minetest.get_meta(pos)
industrialtest.internal.removeUpgrade(pos,meta,stack)
end
end
function industrialtest.Machine.allowMoveToUpgradeSlot(pos,toIndex,stack) function industrialtest.Machine.allowMoveToUpgradeSlot(pos,toIndex,stack)
local def=minetest.registered_items[stack:get_name()] local def=minetest.registered_items[stack:get_name()]
if not def or not def.groups or not def.groups._industrialtest_machineUpgrade then if not def or not def.groups or not def.groups._industrialtest_machineUpgrade then