-
-
Save anonymous/62df4638182dcc2bef59e9ef12788346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.koopamillion.tile_entity; | |
import com.koopamillion.blocks.BlockType; | |
import com.koopamillion.energy.EnergyBar; | |
import com.koopamillion.energy.IEnergy; | |
import com.koopamillion.item.Mitems; | |
import com.koopamillion.util.InventoryUtil; | |
import com.koopamillion.util.MachineUtil; | |
import com.koopamillion.util.NBTUtil; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.inventory.ICrafting; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.item.crafting.FurnaceRecipes; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.network.NetworkManager; | |
import net.minecraft.network.Packet; | |
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; | |
import net.minecraft.world.World; | |
import net.minecraftforge.common.util.ForgeDirection; | |
public class TileEntityElectricFurnace extends TileEntityBasicBlock implements IEnergy, IInventory{ | |
private int amount; | |
private EnergyBar energyBar = new EnergyBar(1200); | |
private ItemStack[] inventory = new ItemStack[18]; | |
private int energyUsePerSmelt = 300; | |
private int defaultEnergyPerSmelt = 300; | |
public int rotation = 3; | |
public boolean isSmelting; | |
public boolean update = true; | |
private int hasBefore; | |
public boolean other = true; | |
public boolean other1 = true; | |
private int smeltStatus; | |
private int smeltTime = 80; | |
private int defaultSmeltTime = 80; | |
//UPGRADE INFO: | |
//Speed Upgrade: -5 SmeltTime, + 50 EUS; Stackable: 15 (-60 SmeltTime) (+600 EUS) | |
//Eco Upgrade: - 19 EUS; + 5 SmeltTime; Stackable : 15 (-285 EUS) (+60 SmeltTime) | |
//Battery Upgrade: + 200 EnergyStorage; Stackable : 15 (+4200 ES) | |
public void updateEntity(){ | |
updateSmelting(); | |
updateUpgrade(); | |
updateBatteryDisCharge(); | |
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); | |
} | |
private void updateBatteryDisCharge(){ //ITEM COUNT META | |
ItemStack itemstack = this.getStackInSlot(0); | |
if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() != 0 && energyBar.getEnergyLevel() <= 2000){ | |
this.setInventorySlotContents(0, new ItemStack(Mitems.basicBattery, 1, itemstack.getItemDamage() - 1)); | |
energyBar.addEnergy(2000); | |
} | |
} | |
private void updateUpgrade(){ | |
ItemStack itemstack = this.getStackInSlot(3); | |
ItemStack batteryStack = this.getStackInSlot(4); | |
ItemStack speedStack = this.getStackInSlot(5); | |
//speed | |
if(itemstack != null && itemstack.getItem() == Mitems.upgrades && itemstack.getItemDamage() == 0 && this.smeltTime > 10){ | |
this.smeltTime = 80 - (itemstack.stackSize * 5); | |
this.energyUsePerSmelt = 300 + (itemstack.stackSize * 50); | |
if(other1 == true){ | |
this.setInventorySlotContents(5, new ItemStack(Mitems.upgrades, itemstack.stackSize, 0)); | |
this.other1 = false; | |
}else{ | |
this.setInventorySlotContents(5, new ItemStack(Mitems.upgrades, itemstack.stackSize + speedStack.stackSize, 0)); | |
} | |
this.setInventorySlotContents(3, null); | |
}else{ | |
if(speedStack == null){ | |
this.smeltTime = 80; | |
this.energyUsePerSmelt = 300; | |
this.other1 = true; | |
} | |
} | |
//battery | |
if(itemstack != null && itemstack.getItem() == Mitems.upgrades && itemstack.getItemDamage() == 1 ){ | |
this.amount = 1200 + (itemstack.stackSize * 200); | |
this.hasBefore = this.energyBar.getEnergyLevel(); | |
energyBar = new EnergyBar(amount); | |
this.energyBar.addEnergy(hasBefore); | |
if(other == true){ | |
this.setInventorySlotContents(4, new ItemStack(Mitems.upgrades, itemstack.stackSize, 1)); | |
this.other = false; | |
}else{ | |
this.setInventorySlotContents(4, new ItemStack(Mitems.upgrades, itemstack.stackSize + batteryStack.stackSize, 1)); | |
} | |
this.setInventorySlotContents(3, null); | |
this.update = true; | |
}else{ | |
this.amount = 1200; | |
this.hasBefore = this.energyBar.getEnergyLevel(); | |
if(batteryStack == null && this.update == true){ | |
energyBar = new EnergyBar(amount); | |
if(this.hasBefore > 1200){ | |
this.energyBar.addEnergy(1200); | |
}else{ | |
this.energyBar.addEnergy(hasBefore); | |
} | |
this.update = false; | |
this.other = true; | |
} | |
} | |
} | |
private void updateSmelting(){ | |
boolean modified = isSmelting; | |
this.isSmelting = canSmelt(); | |
if(this.isSmelting){ | |
this.smeltStatus += 1; | |
}else{ | |
this.smeltStatus = 0; | |
} | |
if(this.smeltStatus >= this.smeltTime){ | |
smelt(); | |
this.smeltStatus = 0; | |
} | |
if(modified != isSmelting){ | |
worldObj.markBlockForUpdate(xCoord, yCoord, xCoord); | |
} | |
} | |
private boolean canSmelt(){ | |
if(inventory[0] == null) return false; | |
return MachineUtil.canOperate(inventory, energyBar, FurnaceRecipes.smelting().getSmeltingResult(inventory[0]), this, energyUsePerSmelt, 1); | |
} | |
private void smelt(){ | |
MachineUtil.operate(inventory, energyBar, FurnaceRecipes.smelting().getSmeltingResult(inventory[0]), this, smeltStatus, isSmelting, energyUsePerSmelt, 1); | |
} | |
@Override | |
public boolean canAddEnergyOnSide(ForgeDirection direction){ | |
return true; | |
} | |
@Override | |
public boolean canConnect(ForgeDirection direction){ | |
return true; | |
} | |
@Override | |
public EnergyBar getEnergyBar(){ | |
return energyBar; | |
} | |
@Override | |
public void setLastReceivedDirection(ForgeDirection direction){ | |
} | |
@Override | |
public int getEnergyTransferRate(){ | |
return 100; | |
} | |
@Override | |
public int getSizeInventory(){ | |
return InventoryUtil.getSizeInventory(inventory); | |
} | |
@Override | |
public ItemStack getStackInSlot(int slot){ | |
return InventoryUtil.getStackInSlot(inventory, slot); | |
} | |
@Override | |
public ItemStack decrStackSize(int slot, int count){ | |
return InventoryUtil.decrStackSize(inventory, slot, count); | |
} | |
@Override | |
public ItemStack getStackInSlotOnClosing(int slot){ | |
return InventoryUtil.getStackInSlotOnClosing(inventory, slot); | |
} | |
@Override | |
public void setInventorySlotContents(int slot, ItemStack itemstack){ | |
InventoryUtil.setInventorySlotContents(this, inventory, slot, itemstack); | |
} | |
@Override | |
public String getInventoryName(){ | |
return "container.electricFurnace"; | |
} | |
@Override | |
public boolean hasCustomInventoryName(){ | |
return false; | |
} | |
@Override | |
public int getInventoryStackLimit(){ | |
return 64; | |
} | |
@Override | |
public boolean isUseableByPlayer(EntityPlayer player){ | |
return true; | |
} | |
@Override | |
public void openInventory(){ | |
} | |
@Override | |
public void closeInventory(){ | |
} | |
@Override | |
public boolean isItemValidForSlot(int slot, ItemStack itemstack){ | |
return true; | |
} | |
public int getCookProgress(int scale){ | |
return this.smeltStatus * scale / smeltTime; | |
} | |
@Override | |
public BlockType getTypeOfBlock(){ | |
return BlockType.MACHINE; | |
} | |
public Packet getDescriptionPacket(){ | |
NBTTagCompound tag = new NBTTagCompound(); | |
writeToNBT(tag); | |
return new S35PacketUpdateTileEntity(); | |
} | |
public void onDataPacket(NetworkManager manager, S35PacketUpdateTileEntity packet){ | |
readFromNBT(packet.func_148857_g()); | |
} | |
public void writeToNBT(NBTTagCompound tag){ | |
super.writeToNBT(tag); | |
energyBar.writeToNBT(tag); | |
tag.setInteger("rotation", rotation); | |
tag.setInteger("smeltStatus", smeltStatus); | |
NBTUtil.writeItemStackArrayToNBT(inventory, tag); | |
} | |
public void readFromNBT(NBTTagCompound tag){ | |
super.readFromNBT(tag); | |
energyBar.readFromNBT(tag); | |
rotation = tag.getInteger("rotation"); | |
smeltStatus = tag.getInteger("smeltStatus"); | |
NBTUtil.readItemStackArrayFromNBT(inventory, tag); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment