Converted Chemical Extractor to scala

This commit is contained in:
Robert S 2014-09-29 15:17:56 -04:00
parent 888bd05345
commit 6deff382af
10 changed files with 528 additions and 630 deletions

View file

@ -1,40 +0,0 @@
package resonantinduction.atomic.machine.extractor;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import resonant.lib.gui.ContainerBase;
import resonant.lib.prefab.slot.SlotEnergyItem;
/**
* Chemical extractor container
*/
public class ContainerChemicalExtractor extends ContainerBase
{
private static final int slotCount = 5;
private TileChemicalExtractor tileEntity;
public ContainerChemicalExtractor(InventoryPlayer par1InventoryPlayer, TileChemicalExtractor tileEntity)
{
super(tileEntity);
this.tileEntity = tileEntity;
// Battery
addSlotToContainer(new SlotEnergyItem(tileEntity, 0, 80, 50));
// Process Input (Cell or Uranium)
addSlotToContainer(new Slot(tileEntity, 1, 53, 25));
// Process Output
addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, tileEntity, 2, 107, 25));
// Fluid input fill
addSlotToContainer(new Slot(tileEntity, 3, 25, 19));
// Fluid input drain
addSlotToContainer(new Slot(tileEntity, 4, 25, 50));
// Fluid output fill
addSlotToContainer(new Slot(tileEntity, 5, 135, 19));
// Fluid output drain
addSlotToContainer(new Slot(tileEntity, 6, 135, 50));
addPlayerInventory(par1InventoryPlayer.player);
}
}

View file

@ -0,0 +1,29 @@
package resonantinduction.atomic.machine.extractor
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.{Slot, SlotFurnace}
import resonant.lib.gui.ContainerBase
import resonant.lib.prefab.slot.SlotEnergyItem
/**
* Chemical extractor container
*/
object ContainerChemicalExtractor
{
private final val slotCount: Int = 5
}
class ContainerChemicalExtractor(par1InventoryPlayer: InventoryPlayer, tileEntity: TileChemicalExtractor) extends ContainerBase(tileEntity)
{
//Constructor
addSlotToContainer(new SlotEnergyItem(tileEntity, 0, 80, 50))
addSlotToContainer(new Slot(tileEntity, 1, 53, 25))
addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, tileEntity, 2, 107, 25))
addSlotToContainer(new Slot(tileEntity, 3, 25, 19))
addSlotToContainer(new Slot(tileEntity, 4, 25, 50))
addSlotToContainer(new Slot(tileEntity, 5, 135, 19))
addSlotToContainer(new Slot(tileEntity, 6, 135, 50))
addPlayerInventory(par1InventoryPlayer.player)
}

View file

@ -1,56 +0,0 @@
package resonantinduction.atomic.machine.extractor;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.lib.gui.GuiContainerBase;
import universalelectricity.api.UnitDisplay;
public class GuiChemicalExtractor extends GuiContainerBase
{
private TileChemicalExtractor tileEntity;
public GuiChemicalExtractor(InventoryPlayer par1InventoryPlayer, TileChemicalExtractor tileEntity)
{
super(new ContainerChemicalExtractor(par1InventoryPlayer, tileEntity));
this.tileEntity = tileEntity;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
@Override
public void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
this.fontRendererObj.drawString("Chemical Extractor", 45, 6, 4210752);
this.renderUniversalDisplay(8, 112, TileChemicalExtractor.ENERGY * 20, mouseX, mouseY, UnitDisplay.Unit.WATT);
this.renderUniversalDisplay(100, 112, this.tileEntity.electricNode().getVoltage(ForgeDirection.UNKNOWN), mouseX, mouseY, UnitDisplay.Unit.VOLTAGE);
this.fontRendererObj.drawString("The extractor can extract", 8, 75, 4210752);
this.fontRendererObj.drawString("uranium, deuterium and tritium.", 8, 85, 4210752);
this.fontRendererObj.drawString("Place them in the input slot.", 8, 95, 4210752);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int x, int y)
{
super.drawGuiContainerBackgroundLayer(par1, x, y);
drawSlot(79, 49, SlotType.BATTERY);
drawSlot(52, 24);
drawSlot(106, 24);
drawBar(75, 24, (float) tileEntity.time / (float) TileChemicalExtractor.TICK_TIME);
drawMeter(8, 18, (float) tileEntity.inputTank.getFluidAmount() / (float) tileEntity.inputTank.getCapacity(), tileEntity.inputTank.getFluid());
drawSlot(24, 18, SlotType.LIQUID);
drawSlot(24, 49, SlotType.LIQUID);
drawMeter(154, 18, (float) tileEntity.outputTank.getFluidAmount() / (float) tileEntity.outputTank.getCapacity(), tileEntity.outputTank.getFluid());
drawSlot(134, 18, SlotType.LIQUID);
drawSlot(134, 49, SlotType.LIQUID);
}
}

View file

@ -0,0 +1,42 @@
package resonantinduction.atomic.machine.extractor
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.util.StatCollector
import resonant.lib.gui.GuiContainerBase
import resonant.lib.gui.GuiContainerBase.SlotType
import universalelectricity.api.UnitDisplay
class GuiChemicalExtractor(par1InventoryPlayer: InventoryPlayer, tileEntity: TileChemicalExtractor) extends GuiContainerBase(new ContainerChemicalExtractor(par1InventoryPlayer, tileEntity))
{
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int)
{
this.fontRendererObj.drawString("Chemical Extractor", 45, 6, 4210752)
this.renderUniversalDisplay(8, 112, TileChemicalExtractor.ENERGY * 20, mouseX, mouseY, UnitDisplay.Unit.WATT)
this.renderUniversalDisplay(100, 112, this.tileEntity.getVoltage, mouseX, mouseY, UnitDisplay.Unit.VOLTAGE)
this.fontRendererObj.drawString("The extractor can extract", 8, 75, 4210752)
this.fontRendererObj.drawString("uranium, deuterium and tritium.", 8, 85, 4210752)
this.fontRendererObj.drawString("Place them in the input slot.", 8, 95, 4210752)
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752)
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected override def drawGuiContainerBackgroundLayer(par1: Float, x: Int, y: Int)
{
super.drawGuiContainerBackgroundLayer(par1, x, y)
drawSlot(79, 49, SlotType.BATTERY)
drawSlot(52, 24)
drawSlot(106, 24)
drawBar(75, 24, tileEntity.time.asInstanceOf[Float] / TileChemicalExtractor.TICK_TIME.asInstanceOf[Float])
drawMeter(8, 18, tileEntity.inputTank.getFluidAmount.asInstanceOf[Float] / tileEntity.inputTank.getCapacity.asInstanceOf[Float], tileEntity.inputTank.getFluid)
drawSlot(24, 18, SlotType.LIQUID)
drawSlot(24, 49, SlotType.LIQUID)
drawMeter(154, 18, tileEntity.outputTank.getFluidAmount.asInstanceOf[Float] / tileEntity.outputTank.getCapacity.asInstanceOf[Float], tileEntity.outputTank.getFluid)
drawSlot(134, 18, SlotType.LIQUID)
drawSlot(134, 49, SlotType.LIQUID)
}
}

View file

@ -1,54 +0,0 @@
package resonantinduction.atomic.machine.extractor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11;
import resonant.lib.render.RenderUtility;
import resonant.lib.render.model.FixedTechneModel;
import resonantinduction.core.Reference;
@SideOnly(Side.CLIENT)
public class RenderChemicalExtractor extends TileEntitySpecialRenderer
{
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "chemicalExtractor.tcn"));
public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "chemicalExtractor.png");
public void render(TileChemicalExtractor tileEntity, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
if (tileEntity.getWorldObj() != null)
{
RenderUtility.rotateBlockBasedOnDirection(tileEntity.getDirection());
}
bindTexture(TEXTURE);
if (MODEL instanceof FixedTechneModel)
{
GL11.glPushMatrix();
((FixedTechneModel) MODEL).renderOnlyAroundPivot(Math.toDegrees(tileEntity.rotation), 0, 0, 1, "MAIN CHAMBER-ROTATES", "MAGNET 1-ROTATES", "MAGNET 2-ROTATES");
GL11.glPopMatrix();
MODEL.renderAllExcept("MAIN CHAMBER-ROTATES", "MAGNET 1-ROTATES", "MAGNET 2-ROTATES");
}
else
{
MODEL.renderAll();
}
GL11.glPopMatrix();
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.render((TileChemicalExtractor) tileEntity, var2, var4, var6, var8);
}
}

View file

@ -0,0 +1,50 @@
package resonantinduction.atomic.machine.extractor
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.IModelCustom
import org.lwjgl.opengl.GL11
import resonant.lib.render.RenderUtility
import resonant.lib.render.model.FixedTechneModel
import resonantinduction.core.Reference
@SideOnly(Side.CLIENT) object RenderChemicalExtractor
{
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "chemicalExtractor.tcn"))
final val TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "chemicalExtractor.png")
}
@SideOnly(Side.CLIENT) class RenderChemicalExtractor extends TileEntitySpecialRenderer
{
def render(tileEntity: TileChemicalExtractor, x: Double, y: Double, z: Double, f: Float)
{
GL11.glPushMatrix
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
if (tileEntity.getWorldObj != null)
{
RenderUtility.rotateBlockBasedOnDirection(tileEntity.getDirection)
}
bindTexture(RenderChemicalExtractor.TEXTURE)
if (RenderChemicalExtractor.MODEL.isInstanceOf[FixedTechneModel])
{
GL11.glPushMatrix
(RenderChemicalExtractor.MODEL.asInstanceOf[FixedTechneModel]).renderOnlyAroundPivot(Math.toDegrees(tileEntity.rotation), 0, 0, 1, "MAIN CHAMBER-ROTATES", "MAGNET 1-ROTATES", "MAGNET 2-ROTATES")
GL11.glPopMatrix
RenderChemicalExtractor.MODEL.renderAllExcept("MAIN CHAMBER-ROTATES", "MAGNET 1-ROTATES", "MAGNET 2-ROTATES")
}
else
{
RenderChemicalExtractor.MODEL.renderAll
}
GL11.glPopMatrix
}
def renderTileEntityAt(tileEntity: TileEntity, var2: Double, var4: Double, var6: Double, var8: Float)
{
this.render(tileEntity.asInstanceOf[TileChemicalExtractor], var2, var4, var6, var8)
}
}

View file

@ -1,366 +0,0 @@
package resonantinduction.atomic.machine.extractor;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import resonant.engine.ResonantEngine;
import resonant.lib.network.Synced;
import resonant.lib.network.discriminator.PacketAnnotation;
import resonantinduction.atomic.Atomic;
import resonantinduction.atomic.AtomicContent;
import resonantinduction.core.Settings;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.transform.vector.Vector3;
/**
* Chemical extractor TileEntity
*/
public class TileChemicalExtractor extends TileProcess implements IFluidHandler
{
public static final int TICK_TIME = 20 * 14;
public static final int EXTRACT_SPEED = 100;
public static final long ENERGY = 5000;
@Synced
public final FluidTank inputTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10);
@Synced
public final FluidTank outputTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10);
// How many ticks has this item been extracting for?
@Synced
public int time = 0;
public float rotation = 0;
public TileChemicalExtractor()
{
super(Material.iron);
energy().setCapacity(ENERGY * 2);
this.setSizeInventory(7);
this.isOpaqueCube(false);
this.normalRender(false);
inputSlot = 1;
outputSlot = 2;
tankInputFillSlot = 3;
tankInputDrainSlot = 4;
tankOutputFillSlot = 5;
tankOutputDrainSlot = 6;
}
@Override
public void update()
{
super.update();
if (time > 0)
{
rotation += 0.2f;
}
if (!worldObj.isRemote)
{
if (canUse())
{
discharge(getStackInSlot(0));
if (energy().checkExtract(ENERGY))
{
if (time == 0)
{
time = TICK_TIME;
}
if (time > 0)
{
time--;
if (time < 1)
{
if (!refineUranium())
{
if (!extractTritium())
{
extractDeuterium();
}
}
time = 0;
}
}
else
{
time = 0;
}
}
energy().extractEnergy(ENERGY, true);
}
else
{
time = 0;
}
if (ticks() % 10 == 0)
{
//for (EntityPlayer player : getPlayersUsing())
//{
// PacketDispatcher.sendPacketToPlayer(getDescriptionPacket(), (Player) player);
//}
}
}
}
@Override
public Packet getDescriptionPacket()
{
return ResonantEngine.instance.packetHandler.toMCPacket(new PacketAnnotation(this));
}
@Override
public boolean use(EntityPlayer player, int side, Vector3 hit)
{
openGui(player, Atomic.INSTANCE());
return true;
}
public boolean canUse()
{
if (inputTank.getFluid() != null)
{
if (inputTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME && Atomic.isItemStackUraniumOre(getStackInSlot(inputSlot)))
{
if (isItemValidForSlot(outputSlot, new ItemStack(AtomicContent.itemYellowCake())))
{
return true;
}
}
if (outputTank.getFluidAmount() < outputTank.getCapacity())
{
if (inputTank.getFluid().getFluid().getID() == AtomicContent.FLUID_DEUTERIUM().getID() && inputTank.getFluid().amount >= Settings.deutermiumPerTritium() * EXTRACT_SPEED)
{
if (outputTank.getFluid() == null || AtomicContent.FLUIDSTACK_TRITIUM().equals(outputTank.getFluid()))
{
return true;
}
}
if (inputTank.getFluid().getFluid().getID() == FluidRegistry.WATER.getID() && inputTank.getFluid().amount >= Settings.waterPerDeutermium() * EXTRACT_SPEED)
{
if (outputTank.getFluid() == null || AtomicContent.FLUIDSTACK_DEUTERIUM().equals(outputTank.getFluid()))
{
return true;
}
}
}
}
return false;
}
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack.
*/
public boolean refineUranium()
{
if (canUse())
{
if (Atomic.isItemStackUraniumOre(getStackInSlot(inputSlot)))
{
inputTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
incrStackSize(outputSlot, new ItemStack(AtomicContent.itemYellowCake(), 3));
decrStackSize(inputSlot, 1);
return true;
}
}
return false;
}
public boolean extractDeuterium()
{
if (canUse())
{
FluidStack drain = inputTank.drain(Settings.waterPerDeutermium() * EXTRACT_SPEED, false);
if (drain != null && drain.amount >= 1 && drain.getFluid().getID() == FluidRegistry.WATER.getID())
{
if (outputTank.fill(new FluidStack(AtomicContent.FLUIDSTACK_DEUTERIUM(), EXTRACT_SPEED), true) >= EXTRACT_SPEED)
{
inputTank.drain(Settings.waterPerDeutermium() * EXTRACT_SPEED, true);
return true;
}
}
}
return false;
}
public boolean extractTritium()
{
if (canUse())
{
int waterUsage = Settings.deutermiumPerTritium();
FluidStack drain = inputTank.drain(Settings.deutermiumPerTritium() * EXTRACT_SPEED, false);
if (drain != null && drain.amount >= 1 && drain.getFluid().getID() == AtomicContent.FLUID_DEUTERIUM().getID())
{
if (outputTank.fill(new FluidStack(AtomicContent.FLUIDSTACK_TRITIUM(), EXTRACT_SPEED), true) >= EXTRACT_SPEED)
{
inputTank.drain(Settings.deutermiumPerTritium() * EXTRACT_SPEED, true);
return true;
}
}
}
return false;
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
time = nbt.getInteger("time");
NBTTagCompound water = nbt.getCompoundTag("inputTank");
inputTank.setFluid(FluidStack.loadFluidStackFromNBT(water));
NBTTagCompound deuterium = nbt.getCompoundTag("outputTank");
outputTank.setFluid(FluidStack.loadFluidStackFromNBT(deuterium));
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("time", time);
if (inputTank.getFluid() != null)
{
NBTTagCompound compound = new NBTTagCompound();
inputTank.getFluid().writeToNBT(compound);
nbt.setTag("inputTank", compound);
}
if (outputTank.getFluid() != null)
{
NBTTagCompound compound = new NBTTagCompound();
outputTank.getFluid().writeToNBT(compound);
nbt.setTag("outputTank", compound);
}
}
/**
* Tank Methods
*/
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if (resource != null && canFill(from, resource.getFluid()))
{
return inputTank.fill(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
return drain(from, resource.amount, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return outputTank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return FluidRegistry.WATER.getID() == fluid.getID() || AtomicContent.FLUID_DEUTERIUM().getID() == fluid.getID();
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return outputTank.getFluid() != null && outputTank.getFluid().getFluid().getID() == fluid.getID();
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[]
{ this.inputTank.getInfo(), this.outputTank.getInfo() };
}
@Override
public boolean isItemValidForSlot(int slotID, ItemStack itemStack)
{
// Water input for machine.
if (slotID == 0)
{
return Compatibility.isHandler(itemStack.getItem(), null);
}
if (slotID == 1)
{
return Atomic.isItemStackWaterCell(itemStack);
}
// Empty cell to be filled with deuterium or tritium.
if (slotID == 2)
{
return Atomic.isItemStackDeuteriumCell(itemStack) || Atomic.isItemStackTritiumCell(itemStack);
}
// Uranium to be extracted into yellowcake.
if (slotID == 3)
{
return Atomic.isItemStackEmptyCell(itemStack) || Atomic.isItemStackUraniumOre(itemStack) || Atomic.isItemStackDeuteriumCell(itemStack);
}
return false;
}
@Override
public int[] getAccessibleSlotsFromSide(int side)
{
return new int[]
{ 1, 2, 3 };
}
@Override
public boolean canInsertItem(int slotID, ItemStack itemStack, int side)
{
return this.isItemValidForSlot(slotID, itemStack);
}
@Override
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
{
return slotID == 2;
}
@Override
public FluidTank getInputTank()
{
return inputTank;
}
@Override
public FluidTank getOutputTank()
{
return outputTank;
}
}

View file

@ -0,0 +1,308 @@
package resonantinduction.atomic.machine.extractor
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.network.Packet
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.engine.ResonantEngine
import resonant.lib.network.Synced
import resonant.lib.network.discriminator.PacketAnnotation
import resonantinduction.atomic.{Atomic, AtomicContent}
import resonantinduction.core.Settings
import universalelectricity.compatibility.Compatibility
import universalelectricity.core.transform.vector.Vector3
/**
* Chemical extractor TileEntity
*/
object TileChemicalExtractor
{
final val TICK_TIME: Int = 20 * 14
final val EXTRACT_SPEED: Int = 100
final val ENERGY: Long = 5000
}
class TileChemicalExtractor extends TileProcess(Material.iron) with IFluidHandler
{
energy.setCapacity(TileChemicalExtractor.ENERGY * 2)
this.setSizeInventory(7)
this.isOpaqueCube(false)
this.normalRender(false)
inputSlot = 1
outputSlot = 2
tankInputFillSlot = 3
tankInputDrainSlot = 4
tankOutputFillSlot = 5
tankOutputDrainSlot = 6
override def update
{
super.update
if (time > 0)
{
rotation += 0.2f
}
if (!worldObj.isRemote)
{
if (canUse)
{
discharge(getStackInSlot(0))
if (energy.checkExtract(TileChemicalExtractor.ENERGY))
{
if (time == 0)
{
time = TileChemicalExtractor.TICK_TIME
}
if (time > 0)
{
time -= 1
if (time < 1)
{
if (!refineUranium)
{
if (!extractTritium)
{
extractDeuterium
}
}
time = 0
}
}
else
{
time = 0
}
}
energy.extractEnergy(TileChemicalExtractor.ENERGY, true)
}
else
{
time = 0
}
if (ticks % 10 == 0)
{
}
}
}
override def getDescriptionPacket: Packet =
{
return ResonantEngine.instance.packetHandler.toMCPacket(new PacketAnnotation(this))
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
openGui(player, Atomic.INSTANCE)
return true
}
def canUse: Boolean =
{
if (inputTank.getFluid != null)
{
if (inputTank.getFluid.amount >= FluidContainerRegistry.BUCKET_VOLUME && Atomic.isItemStackUraniumOre(getStackInSlot(inputSlot)))
{
if (isItemValidForSlot(outputSlot, new ItemStack(AtomicContent.itemYellowCake)))
{
return true
}
}
if (outputTank.getFluidAmount < outputTank.getCapacity)
{
if (inputTank.getFluid.getFluid.getID == AtomicContent.FLUID_DEUTERIUM.getID && inputTank.getFluid.amount >= Settings.deutermiumPerTritium * TileChemicalExtractor.EXTRACT_SPEED)
{
if (outputTank.getFluid == null || (AtomicContent.FLUIDSTACK_TRITIUM == outputTank.getFluid))
{
return true
}
}
if (inputTank.getFluid.getFluid.getID == FluidRegistry.WATER.getID && inputTank.getFluid.amount >= Settings.waterPerDeutermium * TileChemicalExtractor.EXTRACT_SPEED)
{
if (outputTank.getFluid == null || (AtomicContent.FLUIDSTACK_DEUTERIUM == outputTank.getFluid))
{
return true
}
}
}
}
return false
}
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack.
*/
def refineUranium: Boolean =
{
if (canUse)
{
if (Atomic.isItemStackUraniumOre(getStackInSlot(inputSlot)))
{
inputTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true)
incrStackSize(outputSlot, new ItemStack(AtomicContent.itemYellowCake, 3))
decrStackSize(inputSlot, 1)
return true
}
}
return false
}
def extractDeuterium: Boolean =
{
if (canUse)
{
val drain: FluidStack = inputTank.drain(Settings.waterPerDeutermium * TileChemicalExtractor.EXTRACT_SPEED, false)
if (drain != null && drain.amount >= 1 && drain.getFluid.getID == FluidRegistry.WATER.getID)
{
if (outputTank.fill(new FluidStack(AtomicContent.FLUIDSTACK_DEUTERIUM, TileChemicalExtractor.EXTRACT_SPEED), true) >= TileChemicalExtractor.EXTRACT_SPEED)
{
inputTank.drain(Settings.waterPerDeutermium * TileChemicalExtractor.EXTRACT_SPEED, true)
return true
}
}
}
return false
}
def extractTritium: Boolean =
{
if (canUse)
{
val waterUsage: Int = Settings.deutermiumPerTritium
val drain: FluidStack = inputTank.drain(Settings.deutermiumPerTritium * TileChemicalExtractor.EXTRACT_SPEED, false)
if (drain != null && drain.amount >= 1 && drain.getFluid.getID == AtomicContent.FLUID_DEUTERIUM.getID)
{
if (outputTank.fill(new FluidStack(AtomicContent.FLUIDSTACK_TRITIUM, TileChemicalExtractor.EXTRACT_SPEED), true) >= TileChemicalExtractor.EXTRACT_SPEED)
{
inputTank.drain(Settings.deutermiumPerTritium * TileChemicalExtractor.EXTRACT_SPEED, true)
return true
}
}
}
return false
}
/**
* Reads a tile entity from NBT.
*/
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
time = nbt.getInteger("time")
val water: NBTTagCompound = nbt.getCompoundTag("inputTank")
inputTank.setFluid(FluidStack.loadFluidStackFromNBT(water))
val deuterium: NBTTagCompound = nbt.getCompoundTag("outputTank")
outputTank.setFluid(FluidStack.loadFluidStackFromNBT(deuterium))
}
/**
* Writes a tile entity to NBT.
*/
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("time", time)
if (inputTank.getFluid != null)
{
val compound: NBTTagCompound = new NBTTagCompound
inputTank.getFluid.writeToNBT(compound)
nbt.setTag("inputTank", compound)
}
if (outputTank.getFluid != null)
{
val compound: NBTTagCompound = new NBTTagCompound
outputTank.getFluid.writeToNBT(compound)
nbt.setTag("outputTank", compound)
}
}
/**
* Tank Methods
*/
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
if (resource != null && canFill(from, resource.getFluid))
{
return inputTank.fill(resource, doFill)
}
return 0
}
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
return drain(from, resource.amount, doDrain)
}
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
{
return outputTank.drain(maxDrain, doDrain)
}
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
return FluidRegistry.WATER.getID == fluid.getID || AtomicContent.FLUID_DEUTERIUM.getID == fluid.getID
}
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return outputTank.getFluid != null && outputTank.getFluid.getFluid.getID == fluid.getID
}
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](this.inputTank.getInfo, this.outputTank.getInfo)
}
override def isItemValidForSlot(slotID: Int, itemStack: ItemStack): Boolean =
{
if (slotID == 0)
{
return Compatibility.isHandler(itemStack.getItem, null)
}
if (slotID == 1)
{
return Atomic.isItemStackWaterCell(itemStack)
}
if (slotID == 2)
{
return Atomic.isItemStackDeuteriumCell(itemStack) || Atomic.isItemStackTritiumCell(itemStack)
}
if (slotID == 3)
{
return Atomic.isItemStackEmptyCell(itemStack) || Atomic.isItemStackUraniumOre(itemStack) || Atomic.isItemStackDeuteriumCell(itemStack)
}
return false
}
override def getAccessibleSlotsFromSide(side: Int): Array[Int] =
{
return Array[Int](1, 2, 3)
}
override def canInsertItem(slotID: Int, itemStack: ItemStack, side: Int): Boolean =
{
return this.isItemValidForSlot(slotID, itemStack)
}
override def canExtractItem(slotID: Int, itemstack: ItemStack, side: Int): Boolean =
{
return slotID == 2
}
def getInputTank: FluidTank =
{
return inputTank
}
def getOutputTank: FluidTank =
{
return outputTank
}
@Synced final val inputTank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10)
@Synced final val outputTank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10)
@Synced var time: Int = 0
var rotation: Float = 0
}

View file

@ -1,114 +0,0 @@
package resonantinduction.atomic.machine.extractor;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import resonant.api.recipe.MachineRecipes;
import resonant.api.recipe.RecipeResource;
import resonant.lib.content.prefab.java.TileElectricInventory;
/**
* General class for all machines that do traditional recipe processing
*
* @author Calclavia
*/
public abstract class TileProcess extends TileElectricInventory
{
protected int inputSlot;
protected int outputSlot;
protected int tankInputFillSlot;
protected int tankInputDrainSlot;
protected int tankOutputFillSlot;
protected int tankOutputDrainSlot;
protected String machineName;
public TileProcess(Material material)
{
super(material);
}
@Override
public void update()
{
super.update();
if (getInputTank() != null)
{
fillOrDrainTank(tankInputFillSlot, tankInputDrainSlot, getInputTank());
}
if (getOutputTank() != null)
{
fillOrDrainTank(tankOutputFillSlot, tankOutputDrainSlot, getOutputTank());
}
}
/**
* Takes an fluid container item and try to fill the tank, dropping the remains in the output slot.
*/
public void fillOrDrainTank(int containerInput, int containerOutput, FluidTank tank)
{
ItemStack inputStack = getStackInSlot(containerInput);
ItemStack outputStack = getStackInSlot(containerOutput);
if (FluidContainerRegistry.isFilledContainer(inputStack))
{
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(inputStack);
ItemStack result = inputStack.getItem().getContainerItem(inputStack);
if (result != null && tank.fill(fluidStack, false) >= fluidStack.amount && (outputStack == null || result.isItemEqual(outputStack)))
{
tank.fill(fluidStack, true);
decrStackSize(containerInput, 1);
incrStackSize(containerOutput, result);
}
}
else if (FluidContainerRegistry.isEmptyContainer(inputStack))
{
FluidStack avaliable = tank.getFluid();
if (avaliable != null)
{
ItemStack result = FluidContainerRegistry.fillFluidContainer(avaliable, inputStack);
FluidStack filled = FluidContainerRegistry.getFluidForFilledItem(result);
if (result != null && filled != null && (outputStack == null || result.isItemEqual(outputStack)))
{
decrStackSize(containerInput, 1);
incrStackSize(containerOutput, result);
tank.drain(filled.amount, true);
}
}
}
}
/**
* Gets the current result of the input set up.
*
* @return
*/
public RecipeResource[] getResults()
{
ItemStack inputStack = getStackInSlot(inputSlot);
RecipeResource[] mixedResult = MachineRecipes.INSTANCE.getOutput(machineName, inputStack, getInputTank().getFluid());
if (mixedResult.length > 0)
{
return mixedResult;
}
return MachineRecipes.INSTANCE.getOutput(machineName, inputStack);
}
public boolean hasResult()
{
return getResults().length > 0;
}
public abstract FluidTank getInputTank();
public abstract FluidTank getOutputTank();
}

View file

@ -0,0 +1,99 @@
package resonantinduction.atomic.machine.extractor
import net.minecraft.block.material.Material
import net.minecraft.item.ItemStack
import net.minecraftforge.fluids.FluidContainerRegistry
import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.fluids.FluidTank
import resonant.api.recipe.MachineRecipes
import resonant.api.recipe.RecipeResource
import resonant.lib.content.prefab.java.TileElectricInventory
/**
* General class for all machines that do traditional recipe processing
*
* @author Calclavia
*/
abstract class TileProcess(material: Material) extends TileElectricInventory(material)
{
protected var inputSlot: Int = 0
protected var outputSlot: Int = 0
protected var tankInputFillSlot: Int = 0
protected var tankInputDrainSlot: Int = 0
protected var tankOutputFillSlot: Int = 0
protected var tankOutputDrainSlot: Int = 0
protected var machineName: String = null
override def update
{
super.update
if (getInputTank != null)
{
fillOrDrainTank(tankInputFillSlot, tankInputDrainSlot, getInputTank)
}
if (getOutputTank != null)
{
fillOrDrainTank(tankOutputFillSlot, tankOutputDrainSlot, getOutputTank)
}
}
/**
* Takes an fluid container item and try to fill the tank, dropping the remains in the output slot.
*/
def fillOrDrainTank(containerInput: Int, containerOutput: Int, tank: FluidTank)
{
val inputStack: ItemStack = getStackInSlot(containerInput)
val outputStack: ItemStack = getStackInSlot(containerOutput)
if (FluidContainerRegistry.isFilledContainer(inputStack))
{
val fluidStack: FluidStack = FluidContainerRegistry.getFluidForFilledItem(inputStack)
val result: ItemStack = inputStack.getItem.getContainerItem(inputStack)
if (result != null && tank.fill(fluidStack, false) >= fluidStack.amount && (outputStack == null || result.isItemEqual(outputStack)))
{
tank.fill(fluidStack, true)
decrStackSize(containerInput, 1)
incrStackSize(containerOutput, result)
}
}
else if (FluidContainerRegistry.isEmptyContainer(inputStack))
{
val avaliable: FluidStack = tank.getFluid
if (avaliable != null)
{
val result: ItemStack = FluidContainerRegistry.fillFluidContainer(avaliable, inputStack)
val filled: FluidStack = FluidContainerRegistry.getFluidForFilledItem(result)
if (result != null && filled != null && (outputStack == null || result.isItemEqual(outputStack)))
{
decrStackSize(containerInput, 1)
incrStackSize(containerOutput, result)
tank.drain(filled.amount, true)
}
}
}
}
/**
* Gets the current result of the input set up.
*
* @return
*/
def getResults: Array[RecipeResource] =
{
val inputStack: ItemStack = getStackInSlot(inputSlot)
val mixedResult: Array[RecipeResource] = MachineRecipes.INSTANCE.getOutput(machineName, inputStack, getInputTank.getFluid)
if (mixedResult.length > 0)
{
return mixedResult
}
return MachineRecipes.INSTANCE.getOutput(machineName, inputStack)
}
def hasResult: Boolean =
{
return getResults.length > 0
}
def getInputTank: FluidTank
def getOutputTank: FluidTank
}