From 05c78126859231a68e199dc34613689bd0978e2f Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Mon, 11 Apr 2016 19:44:54 +0300 Subject: Initial commit --- .../chemistry/ElectricEvaporatorTileEntity.java | 444 +++++++++++++++++++++ 1 file changed, 444 insertions(+) create mode 100644 ihl/processing/chemistry/ElectricEvaporatorTileEntity.java (limited to 'ihl/processing/chemistry/ElectricEvaporatorTileEntity.java') diff --git a/ihl/processing/chemistry/ElectricEvaporatorTileEntity.java b/ihl/processing/chemistry/ElectricEvaporatorTileEntity.java new file mode 100644 index 0000000..3505cda --- /dev/null +++ b/ihl/processing/chemistry/ElectricEvaporatorTileEntity.java @@ -0,0 +1,444 @@ +package ihl.processing.chemistry; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.ForgeDirection; +import ic2.api.energy.event.EnergyTileLoadEvent; +import ic2.api.energy.event.EnergyTileUnloadEvent; +import ic2.api.energy.tile.IEnergySink; +import ic2.api.item.IC2Items; +import ic2.api.network.INetworkTileEntityEventListener; +import ic2.core.ContainerBase; +import ic2.core.IC2; +import ic2.core.IHasGui; +import ic2.core.audio.AudioSource; +import ic2.core.block.invslot.InvSlot; +import ic2.core.block.invslot.InvSlotUpgrade; +import ic2.core.block.invslot.InvSlot.Access; +import ic2.core.network.NetworkManager; +import ic2.core.upgrade.IUpgradableBlock; +import ic2.core.upgrade.IUpgradeItem; +import ic2.core.upgrade.UpgradableProperty; +import ihl.IHLMod; +import ihl.utils.IHLInvSlotDischarge; +import ihl.utils.IHLUtils; + +public class ElectricEvaporatorTileEntity extends EvaporatorTileEntity implements IEnergySink, IUpgradableBlock, INetworkTileEntityEventListener +{ + public final InvSlotUpgrade upgradeSlot; + private int tier; + private int lastTier; + public int maxStorage; + private int defaultMaxStorage; + private double energy; + public final int defaultEnergyConsume; + public final int defaultOperationLength; + public final int defaultTier; + public int energyConsume; + public AudioSource audioSource; + private static final int EventStart = 0; + private static final int EventInterrupt = 1; + private static final int EventStop = 2; + private int updateChecksum=0; + private boolean addedToEnergyNet=false; + + public ElectricEvaporatorTileEntity() + { + super(); + this.defaultEnergyConsume = this.energyConsume = 8; + this.defaultOperationLength = this.maxProgress = 400; + this.energy=0D; + this.lastTier = this.tier = this.defaultTier = 1; + this.maxStorage = this.defaultMaxStorage = defaultEnergyConsume * defaultOperationLength; + this.fuelSlot = new IHLInvSlotDischarge(this, 1, Access.IO, this.tier, InvSlot.InvSide.BOTTOM); + this.upgradeSlot = new InvSlotUpgrade(this, "upgrade", 4, 4); + } + + @Override + public void onLoaded() + { + super.onLoaded(); + if (IC2.platform.isSimulating()&&!this.addedToEnergyNet) + { + MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); + this.addedToEnergyNet = true; + } + } + + @Override + public List getNetworkedFields() + { + List fields = super.getNetworkedFields(); + fields.add("tier"); + fields.add("maxStorage"); + return fields; + } + + public void setOverclockRates() + { + int speedUp=0; + int tierUp=0; + int capacityUp=0; + int checksum=0; + for(int i=0;i 1.0D) + { + double amount = ((IHLInvSlotDischarge)this.fuelSlot).discharge(this.getDemandedEnergy(), false); + this.energy += amount; + } + if (this.needsFluid()) + { + IHLUtils.handleFluidSlotsBehaviour(null, fluidItemsSlot, emptyFluidItemsSlot, fluidTank); + } + + if (this.canOperate() && this.energy >= this.energyConsume) + { + this.setActive(true); + + if (this.progress == 0) + { + IC2.network.get().initiateTileEntityEvent(this, 0, true); + } + ++this.progress; + this.energy -= this.energyConsume; + if (this.progress >= this.maxProgress) + { + this.operate(); + needsInvUpdate = true; + this.progress = 0; + IC2.network.get().initiateTileEntityEvent(this, 2, true); + } + } + else + { + if (this.progress != 0 && this.getActive()) + { + IC2.network.get().initiateTileEntityEvent(this, 1, true); + } + if (!this.canOperate()) + { + this.progress = 0; + } + this.setActive(false); + } + for (int i = 0; i < this.upgradeSlot.size(); ++i) + { + ItemStack stack = this.upgradeSlot.get(i); + + if (stack != null && stack.getItem() instanceof IUpgradeItem && ((IUpgradeItem)stack.getItem()).onTick(stack, this)) + { + needsInvUpdate = true; + } + } + } + } + + private static int applyModifier(int base, int extra, double multiplier) + { + double ret = Math.round(((double)base + (double)extra) * multiplier); + return ret > 2.147483647E9D ? Integer.MAX_VALUE : (int)ret; + } + + @Override + public void onNetworkEvent(int event) + { + if (this.audioSource == null && this.getStartSoundFile() != null) + { + this.audioSource = IC2.audioManager.createSource(this, this.getStartSoundFile()); + } + + switch (event) + { + case 0: + if (this.audioSource != null) + { + this.audioSource.play(); + } + + break; + + case 1: + if (this.audioSource != null) + { + this.audioSource.stop(); + } + + break; + + case 2: + if (this.audioSource != null) + { + this.audioSource.stop(); + } + + } + } + + public String getStartSoundFile() + { + return "Machines/Electro Furnace/ElectroFurnaceLoop.ogg"; + } + + /** + * Returns the name of the inventory + */ + @Override + public String getInventoryName() + { + return "Electric evaporator"; + } + + @Override + public ContainerBase getGuiContainer(EntityPlayer entityPlayer) + { + return new ElectricEvaporatorContainer(entityPlayer, this); + } + + @Override + @SideOnly(Side.CLIENT) + public GuiScreen getGui(EntityPlayer entityPlayer, boolean isAdmin) + { + return new ElectricEvaporatorGui(new ElectricEvaporatorContainer(entityPlayer, this)); + } + + @Override + public boolean getGui(EntityPlayer player) + { + return this instanceof IHasGui ? (IC2.platform.isSimulating() ? IC2.platform.launchGui(player, this) : true) : false; + } + + @Override + public int mX() + { + switch(this.getFacing()) + { + case 4: + return -1; + case 5: + return 1; + default: + return 0; + } + } + + @Override + public int mZ() + { + switch(this.getFacing()) + { + case 2: + return -1; + case 3: + return 1; + default: + return 0; + } + } + + @Override + public double getEnergy() + { + return this.energy; + } + + @Override + public boolean useEnergy(double amount) { + if (this.energy >= amount) + { + this.energy -= amount; + return true; + } + else + { + return false; + } + } + + public void setEnergy(double i) { + this.energy=i; + } + + @Override + public double getDemandedEnergy() + { + return this.maxStorage - this.energy; + } + + @Override + public int getSinkTier() + { + return this.tier; + } + + @Override + public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) + { + if (this.energy >= this.maxStorage) + { + return amount; + } + else + { + this.energy += amount; + return 0.0D; + } + } + + @Override + public boolean acceptsEnergyFrom(TileEntity emitter, + ForgeDirection direction) { + return true; + } + + public ItemStack getOutput(int arg0) + { + return this.outputSlot.get(arg0); + } + + public int getOutputSize() { + return this.outputSlot.size(); + } + + public void setOutput(int arg0, ItemStack arg1) + { + this.outputSlot.put(arg0, arg1); + } + + @Override + public Set getUpgradableProperties() + { + Set properties = new HashSet(); + properties.add(UpgradableProperty.ItemProducing); + properties.add(UpgradableProperty.EnergyStorage); + properties.add(UpgradableProperty.Transformer); + return properties; + } +} \ No newline at end of file -- cgit v1.2.3