Prepare electric item when it has a valid electric item definition
This commit is contained in:
@@ -95,7 +95,11 @@ function industrialtest.ElectricMachine.onTimer(self,pos,elapsed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function industrialtest.ElectricMachine.allowMetadataInventoryMove(self,pos,fromList,fromIndex,toList,toIndex,count)
|
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
|
local found=false
|
||||||
|
|
||||||
if self.powerLists then
|
if self.powerLists then
|
||||||
for _,value in ipairs(self.powerLists) do
|
for _,value in ipairs(self.powerLists) do
|
||||||
if value.list==toList then
|
if value.list==toList then
|
||||||
@@ -104,7 +108,7 @@ function industrialtest.ElectricMachine.allowMetadataInventoryMove(self,pos,from
|
|||||||
end
|
end
|
||||||
end
|
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
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -121,7 +125,7 @@ function industrialtest.ElectricMachine.allowMetadataInventoryPut(self,pos,listn
|
|||||||
end
|
end
|
||||||
end
|
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
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -205,6 +209,11 @@ function industrialtest.ElectricMachine.powerExchange(self,pos)
|
|||||||
local powerFlow=meta:get_int("industrialtest.powerFlow")
|
local powerFlow=meta:get_int("industrialtest.powerFlow")
|
||||||
for _,listDesc in ipairs(self.powerLists) do
|
for _,listDesc in ipairs(self.powerLists) do
|
||||||
local slot=inv:get_stack(listDesc.list,1)
|
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 slot:get_count()>0 then
|
||||||
if listDesc.direction=="o" then
|
if listDesc.direction=="o" then
|
||||||
if meta:get_int("industrialtest.powerAmount")<=0 then
|
if meta:get_int("industrialtest.powerAmount")<=0 then
|
||||||
@@ -235,6 +244,12 @@ function industrialtest.ElectricMachine.powerExchange(self,pos)
|
|||||||
return shouldRerunTimer
|
return shouldRerunTimer
|
||||||
end
|
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)
|
function industrialtest.ElectricMachine.createPowerIndicatorWidget(charged,x,y)
|
||||||
return table.concat({
|
return table.concat({
|
||||||
string.format("box[%f,%f;0.3,4.8;#202020]",x,y),
|
string.format("box[%f,%f;0.3,4.8;#202020]",x,y),
|
||||||
|
|||||||
Reference in New Issue
Block a user