diff --git a/resources/assets/gendustry/gendustry-tuning.cfg b/resources/assets/gendustry/gendustry-tuning.cfg index 55e3268..0245697 100644 --- a/resources/assets/gendustry/gendustry-tuning.cfg +++ b/resources/assets/gendustry/gendustry-tuning.cfg @@ -114,6 +114,29 @@ cfg Machines { BaseMjPerTick = 2 // Base run cost in MJ/t, before any modifiers } + + cfg Extractor { + Enabled = Yes + MaxReceivedEnergy = 500 + PowerUseRate = 0.001 + MjPerItem = 80000 + MaxStoredEnergy = 400000 + ActivationEnergy = 40 + + TankSize = 5000 // Output tank size in milibuckets + LabwareConsumeChance = 10 // Chance that the Genetic Labware will be consumed, 0-100 + } + + cfg Liquifier { + Enabled = Yes + MaxReceivedEnergy = 500 + PowerUseRate = 0.002 + MjPerItem = 20000 + MaxStoredEnergy = 100000 + ActivationEnergy = 20 + + TankSize = 5000 // Output tank size in milibuckets + } } cfg Items { diff --git a/resources/assets/gendustry/lang/en_US.lang b/resources/assets/gendustry/lang/en_US.lang index 9d85139..3433d09 100644 --- a/resources/assets/gendustry/lang/en_US.lang +++ b/resources/assets/gendustry/lang/en_US.lang @@ -6,6 +6,8 @@ tile.gendustry.mutatron.adv.name=Advanced Mutatron tile.gendustry.apiary.name=Industrial Apiary tile.gendustry.imprinter.name=Genetic Imprinter tile.gendustry.sampler.name=Genetic Sampler +tile.gendustry.extractor.name=DNA Extractor +tile.gendustry.liquifier.name=Protein Liquifier # ==== GENERAL ITEMS ==== diff --git a/resources/assets/gendustry/textures/blocks/extractor/extractor.psd b/resources/assets/gendustry/textures/blocks/extractor/extractor.psd index 787262f..828a40e 100644 Binary files a/resources/assets/gendustry/textures/blocks/extractor/extractor.psd and b/resources/assets/gendustry/textures/blocks/extractor/extractor.psd differ diff --git a/resources/assets/gendustry/textures/blocks/extractor/side.png b/resources/assets/gendustry/textures/blocks/extractor/side.png index fd8d104..3c388b6 100644 Binary files a/resources/assets/gendustry/textures/blocks/extractor/side.png and b/resources/assets/gendustry/textures/blocks/extractor/side.png differ diff --git a/resources/assets/gendustry/textures/blocks/liquifier/liquifier.psd b/resources/assets/gendustry/textures/blocks/liquifier/liquifier.psd index a415edd..05eabc4 100644 Binary files a/resources/assets/gendustry/textures/blocks/liquifier/liquifier.psd and b/resources/assets/gendustry/textures/blocks/liquifier/liquifier.psd differ diff --git a/resources/assets/gendustry/textures/blocks/liquifier/side.png b/resources/assets/gendustry/textures/blocks/liquifier/side.png index 783b8e3..8600e43 100644 Binary files a/resources/assets/gendustry/textures/blocks/liquifier/side.png and b/resources/assets/gendustry/textures/blocks/liquifier/side.png differ diff --git a/resources/assets/gendustry/textures/items/hints/hints.psd b/resources/assets/gendustry/textures/items/hints/hints.psd index 0ff7b6a..0b0d938 100644 Binary files a/resources/assets/gendustry/textures/items/hints/hints.psd and b/resources/assets/gendustry/textures/items/hints/hints.psd differ diff --git a/resources/assets/gendustry/textures/items/hints/meat.png b/resources/assets/gendustry/textures/items/hints/meat.png new file mode 100644 index 0000000..8fc9758 Binary files /dev/null and b/resources/assets/gendustry/textures/items/hints/meat.png differ diff --git a/src/net/bdew/gendustry/config/Machines.scala b/src/net/bdew/gendustry/config/Machines.scala index 910761d..c471462 100644 --- a/src/net/bdew/gendustry/config/Machines.scala +++ b/src/net/bdew/gendustry/config/Machines.scala @@ -17,6 +17,8 @@ import net.bdew.gendustry.machines.sampler.MachineSampler import net.bdew.lib.config.MachineManager import net.bdew.gendustry.Gendustry import net.bdew.gendustry.machines.advmutatron.MachineMutatronAdv +import net.bdew.gendustry.machines.liquifier.MachineLiquifier +import net.bdew.gendustry.machines.extractor.MachineExtractor object Machines extends MachineManager(Config.IDs, Tuning.getSection("Machines"), Config.guiHandler) { val mutagenProducer = registerMachine(new MachineMutagenProducer) @@ -25,6 +27,8 @@ object Machines extends MachineManager(Config.IDs, Tuning.getSection("Machines") val imprinter = registerMachine(new MachineImprinter) val sampler = registerMachine(new MachineSampler) val mutatronAdv = registerMachine(new MachineMutatronAdv) + val liquifier = registerMachine(new MachineLiquifier) + val extractor = registerMachine(new MachineExtractor) Gendustry.logInfo("Machines loaded") } diff --git a/src/net/bdew/gendustry/gui/HintIcons.scala b/src/net/bdew/gendustry/gui/HintIcons.scala index 95868cb..c9b0e89 100644 --- a/src/net/bdew/gendustry/gui/HintIcons.scala +++ b/src/net/bdew/gendustry/gui/HintIcons.scala @@ -26,4 +26,5 @@ object HintIcons extends IconPreloader(1) { val drone = TextureLoc("gendustry:hints/drone") val upgrade = TextureLoc("gendustry:hints/upgrade") + val meat = TextureLoc("gendustry:hints/meat") } diff --git a/src/net/bdew/gendustry/machines/extractor/BlockExtractor.scala b/src/net/bdew/gendustry/machines/extractor/BlockExtractor.scala new file mode 100644 index 0000000..dcf9136 --- /dev/null +++ b/src/net/bdew/gendustry/machines/extractor/BlockExtractor.scala @@ -0,0 +1,50 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.extractor + +import net.bdew.gendustry.Gendustry +import net.minecraft.block.Block +import net.minecraft.block.material.Material +import net.minecraft.client.renderer.texture.IconRegister +import net.minecraft.util.Icon +import cpw.mods.fml.relauncher.Side +import cpw.mods.fml.relauncher.SideOnly +import net.bdew.lib.block.HasTE +import net.bdew.lib.tile.inventory.BreakableInventoryBlock +import net.bdew.gendustry.config.Machines +import net.bdew.gendustry.gui.BlockGuiWrenchable + +class BlockExtractor(id: Int) extends Block(id, Material.rock) with HasTE[TileExtractor] with BreakableInventoryBlock with BlockGuiWrenchable { + private var icons: Array[Icon] = null + val TEClass = classOf[TileExtractor] + lazy val guiId = Machines.extractor.guiId + + setUnlocalizedName(Gendustry.modId + ".extractor") + setHardness(5) + + override def getIcon(side: Int, meta: Int): Icon = { + side match { + case 0 => + return icons(0) + case 1 => + return icons(1) + case _ => + return icons(2) + } + } + + @SideOnly(Side.CLIENT) + override def registerIcons(reg: IconRegister) { + icons = new Array[Icon](3) + icons(0) = reg.registerIcon(Gendustry.modId + ":extractor/bottom") + icons(1) = reg.registerIcon(Gendustry.modId + ":extractor/top") + icons(2) = reg.registerIcon(Gendustry.modId + ":extractor/side") + } +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/extractor/ContainerExtractor.scala b/src/net/bdew/gendustry/machines/extractor/ContainerExtractor.scala new file mode 100644 index 0000000..c46fd0d --- /dev/null +++ b/src/net/bdew/gendustry/machines/extractor/ContainerExtractor.scala @@ -0,0 +1,24 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.extractor + +import net.minecraft.entity.player.EntityPlayer +import net.bdew.lib.gui.{BaseContainer, SlotValidating} +import net.bdew.lib.data.base.ContainerDataSlots + +class ContainerExtractor(val te: TileExtractor, player: EntityPlayer) extends BaseContainer(te) with ContainerDataSlots { + lazy val dataSource = te + + addSlotToContainer(new SlotValidating(te, te.slots.inIndividual, 44, 41)) + addSlotToContainer(new SlotValidating(te, te.slots.inLabware, 94, 19)) + bindPlayerInventory(player.inventory, 8, 84, 142) + + def canInteractWith(entityplayer: EntityPlayer): Boolean = te.isUseableByPlayer(entityplayer) +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/extractor/GuiExtractor.scala b/src/net/bdew/gendustry/machines/extractor/GuiExtractor.scala new file mode 100644 index 0000000..c697e09 --- /dev/null +++ b/src/net/bdew/gendustry/machines/extractor/GuiExtractor.scala @@ -0,0 +1,32 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.extractor + +import net.bdew.gendustry.Gendustry +import net.minecraft.entity.player.EntityPlayer +import net.bdew.lib.gui.{Texture, Color, Rect, BaseScreen} +import net.bdew.lib.gui.widgets.{WidgetLabel, WidgetFluidGauge} +import net.bdew.lib.Misc +import net.bdew.gendustry.gui.{HintIcons, WidgetPowerCustom, WidgetProgressBarNEI, Textures} + +class GuiExtractor(val te: TileExtractor, player: EntityPlayer) extends BaseScreen(new ContainerExtractor(te, player), 176, 166) { + val background = Texture(Gendustry.modId, "textures/gui/extractor.png", rect) + + override def initGui() { + super.initGui() + widgets.add(new WidgetProgressBarNEI(new Rect(79, 41, 53, 15), Textures.greenProgress(53), te.progress, "Extractor")) + widgets.add(new WidgetPowerCustom(new Rect(8, 19, 16, 58), Textures.powerFill, te.power)) + widgets.add(new WidgetFluidGauge(new Rect(152, 19, 16, 58), Textures.tankOverlay, te.tank)) + widgets.add(new WidgetLabel(Misc.toLocal("tile.gendustry.extractor.name"), 8, 6, Color.darkgray)) + + inventorySlots.getSlotFromInventory(te, te.slots.inIndividual).setBackgroundIcon(HintIcons.droneOrSapling) + inventorySlots.getSlotFromInventory(te, te.slots.inLabware).setBackgroundIcon(HintIcons.labware) + } +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/extractor/MachineExtractor.scala b/src/net/bdew/gendustry/machines/extractor/MachineExtractor.scala new file mode 100644 index 0000000..efc5007 --- /dev/null +++ b/src/net/bdew/gendustry/machines/extractor/MachineExtractor.scala @@ -0,0 +1,27 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.extractor + +import net.minecraft.entity.player.EntityPlayer +import cpw.mods.fml.relauncher.{SideOnly, Side} +import net.bdew.lib.machine.{Machine, ProcessorMachine} +import net.bdew.lib.gui.GuiProvider + +class MachineExtractor extends Machine("Extractor", new BlockExtractor(_)) with GuiProvider with ProcessorMachine { + def guiId = 8 + type TEClass = TileExtractor + + lazy val tankSize = tuning.getInt("TankSize") + lazy val labwareConsumeChance = tuning.getInt("LabwareConsumeChance") + + @SideOnly(Side.CLIENT) + def getGui(te: TileExtractor, player: EntityPlayer) = new GuiExtractor(te, player) + def getContainer(te: TileExtractor, player: EntityPlayer) = new ContainerExtractor(te, player) +} diff --git a/src/net/bdew/gendustry/machines/extractor/TileExtractor.scala b/src/net/bdew/gendustry/machines/extractor/TileExtractor.scala new file mode 100644 index 0000000..9a118e2 --- /dev/null +++ b/src/net/bdew/gendustry/machines/extractor/TileExtractor.scala @@ -0,0 +1,87 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.extractor + +import net.bdew.gendustry.config.{Items, Fluids, Machines} +import net.bdew.gendustry.fluids.LiquidDNASources +import net.minecraft.item.ItemStack +import net.minecraft.tileentity.TileEntity +import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.fluids._ +import net.bdew.lib.data._ +import net.bdew.lib.tile.ExposeTank +import net.bdew.lib.data.base.UpdateKind +import net.bdew.lib.power.TileBaseProcessor +import net.bdew.gendustry.power.TilePowered + +class TileExtractor extends TileBaseProcessor with TilePowered with ExposeTank { + lazy val cfg = Machines.extractor + + object slots { + val inIndividual = 0 + val inLabware = 1 + } + + val tank = DataSlotTankRestricted("tank", this, cfg.tankSize, Fluids.dna.getID).setUpdate(UpdateKind.GUI, UpdateKind.SAVE) + val output = DataSlotInt("output", this).setUpdate(UpdateKind.SAVE) + + def getSizeInventory = 2 + + def getTankFromDirection(dir: ForgeDirection): IFluidTank = tank + + def isWorking = output > 0 + + def tryStart(): Boolean = { + if (getStackInSlot(slots.inIndividual) != null && getStackInSlot(slots.inLabware) != null) { + output := LiquidDNASources.getValue(getStackInSlot(0)) + if (worldObj.rand.nextInt(100) < cfg.labwareConsumeChance) + decrStackSize(slots.inLabware, 1) + decrStackSize(0, 1) + return true + } else return false + } + + def tryFinish(): Boolean = { + if (tank.fill(output, false) == output.cval) { + tank.fill(output, true) + output := -1 + return true + } else return false + } + + def sendFluid() { + for (dir <- ForgeDirection.VALID_DIRECTIONS) { + val te: TileEntity = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ) + if (te != null && te.isInstanceOf[IFluidHandler]) { + val pumped = te.asInstanceOf[IFluidHandler].fill(dir.getOpposite, tank.getFluid, true) + if (pumped > 0) { + tank.drain(pumped, true) + if (tank.getFluidAmount <= 0) return + } + } + } + } + + override def tickServer() { + super.tickServer() + if (tank.getFluidAmount > 0) sendFluid() + } + + allowSided = true + override def isItemValidForSlot(slot: Int, itemstack: ItemStack): Boolean = slot match { + case slots.inIndividual => LiquidDNASources.getValue(itemstack) > 0 + case slots.inLabware => itemstack.getItem == Items.labware + case _ => false + } + override def canExtractItem(slot: Int, item: ItemStack, side: Int): Boolean = false + + override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean) = 0 + override def canFill(from: ForgeDirection, fluid: Fluid) = false +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/liquifier/BlockLiquifier.scala b/src/net/bdew/gendustry/machines/liquifier/BlockLiquifier.scala new file mode 100644 index 0000000..8c82806 --- /dev/null +++ b/src/net/bdew/gendustry/machines/liquifier/BlockLiquifier.scala @@ -0,0 +1,50 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.liquifier + +import net.bdew.gendustry.Gendustry +import net.minecraft.block.Block +import net.minecraft.block.material.Material +import net.minecraft.client.renderer.texture.IconRegister +import net.minecraft.util.Icon +import cpw.mods.fml.relauncher.Side +import cpw.mods.fml.relauncher.SideOnly +import net.bdew.lib.block.HasTE +import net.bdew.lib.tile.inventory.BreakableInventoryBlock +import net.bdew.gendustry.config.Machines +import net.bdew.gendustry.gui.BlockGuiWrenchable + +class BlockLiquifier(id: Int) extends Block(id, Material.rock) with HasTE[TileLiquifier] with BreakableInventoryBlock with BlockGuiWrenchable { + private var icons: Array[Icon] = null + val TEClass = classOf[TileLiquifier] + lazy val guiId = Machines.liquifier.guiId + + setUnlocalizedName(Gendustry.modId + ".liquifier") + setHardness(5) + + override def getIcon(side: Int, meta: Int): Icon = { + side match { + case 0 => + return icons(0) + case 1 => + return icons(1) + case _ => + return icons(2) + } + } + + @SideOnly(Side.CLIENT) + override def registerIcons(reg: IconRegister) { + icons = new Array[Icon](3) + icons(0) = reg.registerIcon(Gendustry.modId + ":liquifier/bottom") + icons(1) = reg.registerIcon(Gendustry.modId + ":liquifier/top") + icons(2) = reg.registerIcon(Gendustry.modId + ":liquifier/side") + } +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/liquifier/ContainerLiquifier.scala b/src/net/bdew/gendustry/machines/liquifier/ContainerLiquifier.scala new file mode 100644 index 0000000..e33f79f --- /dev/null +++ b/src/net/bdew/gendustry/machines/liquifier/ContainerLiquifier.scala @@ -0,0 +1,23 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.liquifier + +import net.minecraft.entity.player.EntityPlayer +import net.bdew.lib.gui.{BaseContainer, SlotValidating} +import net.bdew.lib.data.base.ContainerDataSlots + +class ContainerLiquifier(val te: TileLiquifier, player: EntityPlayer) extends BaseContainer(te) with ContainerDataSlots { + lazy val dataSource = te + + addSlotToContainer(new SlotValidating(te, te.slots.inMeat, 44, 41)) + bindPlayerInventory(player.inventory, 8, 84, 142) + + def canInteractWith(entityplayer: EntityPlayer): Boolean = te.isUseableByPlayer(entityplayer) +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/liquifier/GuiLiquifier.scala b/src/net/bdew/gendustry/machines/liquifier/GuiLiquifier.scala new file mode 100644 index 0000000..48628dd --- /dev/null +++ b/src/net/bdew/gendustry/machines/liquifier/GuiLiquifier.scala @@ -0,0 +1,31 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.liquifier + +import net.bdew.gendustry.Gendustry +import net.minecraft.entity.player.EntityPlayer +import net.bdew.lib.gui.{Texture, Color, Rect, BaseScreen} +import net.bdew.lib.gui.widgets.{WidgetLabel, WidgetFluidGauge} +import net.bdew.lib.Misc +import net.bdew.gendustry.gui.{HintIcons, WidgetPowerCustom, WidgetProgressBarNEI, Textures} + +class GuiLiquifier(val te: TileLiquifier, player: EntityPlayer) extends BaseScreen(new ContainerLiquifier(te, player), 176, 166) { + val background = Texture(Gendustry.modId, "textures/gui/liquifier.png", rect) + + override def initGui() { + super.initGui() + widgets.add(new WidgetProgressBarNEI(new Rect(79, 41, 53, 15), Textures.greenProgress(53), te.progress, "Liquifier")) + widgets.add(new WidgetPowerCustom(new Rect(8, 19, 16, 58), Textures.powerFill, te.power)) + widgets.add(new WidgetFluidGauge(new Rect(152, 19, 16, 58), Textures.tankOverlay, te.tank)) + widgets.add(new WidgetLabel(Misc.toLocal("tile.gendustry.liquifier.name"), 8, 6, Color.darkgray)) + + inventorySlots.getSlotFromInventory(te, te.slots.inMeat).setBackgroundIcon(HintIcons.meat) + } +} \ No newline at end of file diff --git a/src/net/bdew/gendustry/machines/liquifier/MachineLiquifier.scala b/src/net/bdew/gendustry/machines/liquifier/MachineLiquifier.scala new file mode 100644 index 0000000..ced0cfe --- /dev/null +++ b/src/net/bdew/gendustry/machines/liquifier/MachineLiquifier.scala @@ -0,0 +1,26 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.liquifier + +import net.minecraft.entity.player.EntityPlayer +import cpw.mods.fml.relauncher.{SideOnly, Side} +import net.bdew.lib.machine.{Machine, ProcessorMachine} +import net.bdew.lib.gui.GuiProvider + +class MachineLiquifier extends Machine("Liquifier", new BlockLiquifier(_)) with GuiProvider with ProcessorMachine { + def guiId = 7 + type TEClass = TileLiquifier + + lazy val tankSize = tuning.getInt("TankSize") + + @SideOnly(Side.CLIENT) + def getGui(te: TileLiquifier, player: EntityPlayer) = new GuiLiquifier(te, player) + def getContainer(te: TileLiquifier, player: EntityPlayer) = new ContainerLiquifier(te, player) +} diff --git a/src/net/bdew/gendustry/machines/liquifier/TileLiquifier.scala b/src/net/bdew/gendustry/machines/liquifier/TileLiquifier.scala new file mode 100644 index 0000000..a0df916 --- /dev/null +++ b/src/net/bdew/gendustry/machines/liquifier/TileLiquifier.scala @@ -0,0 +1,79 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/gendustry + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt + */ + +package net.bdew.gendustry.machines.liquifier + +import net.bdew.gendustry.config.{Fluids, Machines} +import net.bdew.gendustry.fluids.ProteinSources +import net.minecraft.item.ItemStack +import net.minecraft.tileentity.TileEntity +import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.fluids._ +import net.bdew.lib.data._ +import net.bdew.lib.tile.ExposeTank +import net.bdew.lib.data.base.UpdateKind +import net.bdew.lib.power.TileBaseProcessor +import net.bdew.gendustry.power.TilePowered + +class TileLiquifier extends TileBaseProcessor with TilePowered with ExposeTank { + lazy val cfg = Machines.liquifier + + val tank = DataSlotTankRestricted("tank", this, cfg.tankSize, Fluids.protein.getID).setUpdate(UpdateKind.GUI, UpdateKind.SAVE) + val output = DataSlotInt("output", this).setUpdate(UpdateKind.SAVE) + + object slots { + val inMeat = 0 + } + + def getSizeInventory = 1 + + def getTankFromDirection(dir: ForgeDirection): IFluidTank = tank + + def isWorking = output > 0 + def tryStart(): Boolean = { + if (getStackInSlot(slots.inMeat) != null) { + output := ProteinSources.getValue(getStackInSlot(0)) + decrStackSize(slots.inMeat, 1) + return true + } else return false + } + + def tryFinish(): Boolean = { + if (tank.fill(output, false) == output.cval) { + tank.fill(output, true) + output := -1 + return true + } else return false + } + + def sendFluid() { + for (dir <- ForgeDirection.VALID_DIRECTIONS) { + val te: TileEntity = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ) + if (te != null && te.isInstanceOf[IFluidHandler]) { + val pumped = te.asInstanceOf[IFluidHandler].fill(dir.getOpposite, tank.getFluid, true) + if (pumped > 0) { + tank.drain(pumped, true) + if (tank.getFluidAmount <= 0) return + } + } + } + } + + override def tickServer() { + super.tickServer() + if (tank.getFluidAmount > 0) sendFluid() + } + + allowSided = true + override def isItemValidForSlot(slot: Int, itemstack: ItemStack): Boolean = ProteinSources.getValue(itemstack) > 0 + override def canExtractItem(slot: Int, item: ItemStack, side: Int): Boolean = false + + override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean) = 0 + override def canFill(from: ForgeDirection, fluid: Fluid) = false +} \ No newline at end of file