Prepare electric item when it has a valid electric item definition

This commit is contained in:
2026-02-28 19:01:04 +01:00
parent 4ed120bea3
commit 5b2a9b09e8

View File

@@ -95,7 +95,11 @@ function industrialtest.ElectricMachine.onTimer(self,pos,elapsed)
end
function industrialtest.ElectricMachine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
local movedItemStack=inv:get_stack(fromList,fromIndex)
local found=false
if self.powerLists then
for _,value in ipairs(self.powerLists) do
if value.list==toList then
@@ -104,7 +108,7 @@ function industrialtest.ElectricMachine.allowMetadataInventoryMove(self,pos,from
end
end
end
if found and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) then
if found and not industrialtest.api.hasPowerStorage(movedItemStack:get_meta()) and not self.isValidElectricItemDef(movedItemStack) then
return 0
end
@@ -121,7 +125,7 @@ function industrialtest.ElectricMachine.allowMetadataInventoryPut(self,pos,listn
end
end
end
if found and not industrialtest.api.hasPowerStorage(stack:get_meta()) then
if found and not industrialtest.api.hasPowerStorage(stack:get_meta()) and not self.isValidElectricItemDef(stack) then
return 0
end
@@ -205,6 +209,11 @@ function industrialtest.ElectricMachine.powerExchange(self,pos)
local powerFlow=meta:get_int("industrialtest.powerFlow")
for _,listDesc in ipairs(self.powerLists) do
local slot=inv:get_stack(listDesc.list,1)
if not industrialtest.api.hasPowerStorage(slot:get_meta()) and self.isValidElectricItemDef(slot) then
local def=slot:get_definition()
def._industrialtest_self:prepare(slot)
inv:set_stack(listDesc.list,1,slot)
end
if slot:get_count()>0 then
if listDesc.direction=="o" then
if meta:get_int("industrialtest.powerAmount")<=0 then
@@ -235,6 +244,12 @@ function industrialtest.ElectricMachine.powerExchange(self,pos)
return shouldRerunTimer
end
-- Checks if itemstack has a valid electric item definition, even if it's not prepared
function industrialtest.ElectricMachine.isValidElectricItemDef(itemstack)
local def=itemstack:get_definition()
return def._industrialtest_self and def._industrialtest_self.flow and def._industrialtest_self.flow and def._industrialtest_self.prepare
end
function industrialtest.ElectricMachine.createPowerIndicatorWidget(charged,x,y)
return table.concat({
string.format("box[%f,%f;0.3,4.8;#202020]",x,y),