Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xyz.ajp.fluxfyre.item;
- import java.util.List;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemFood;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.crafting.FurnaceRecipes;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.server.MinecraftServer;
- import net.minecraft.util.IIcon;
- import net.minecraft.world.World;
- import cofh.api.energy.IEnergyContainerItem;
- import xyz.ajp.fluxfyre.util.CommonUtils;
- public class ItemPortableStove extends Item implements IEnergyContainerItem {
- public static int fuelPerTick;
- public static int maxReceive;
- public static int maxStore;
- public static int ticksPerOperation;
- public final IIcon[] icons = new IIcon[2];
- public ItemPortableStove() {
- this.setCreativeTab(CreativeTabs.tabMisc);
- this.setMaxStackSize(1);
- this.setTextureName("fluxfyre:Pan_Off");
- this.setUnlocalizedName("portableStove");
- }
- @SuppressWarnings("unchecked")
- public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
- super.addInformation(stack, player, list, advanced);
- int energy;
- if (stack.stackTagCompound != null) {
- if (!stack.stackTagCompound.hasKey("RFEnergy")) {
- energy = 0;
- } else {
- energy = stack.stackTagCompound.getInteger("RFEnergy");
- }
- } else {
- energy = 0;
- }
- list.add(Integer.toString(energy) + " RF");
- if (advanced) {
- list.add("so leet");
- }
- }
- public int extractEnergy(ItemStack stack, int request, boolean simulate) {
- return 0;
- }
- public int getEnergyStored(ItemStack stack) {
- return CommonUtils.getEnergyStoredUtil(stack);
- }
- @Override public IIcon getIcon(ItemStack stack, int pass) {
- if (stack.hasTagCompound()) {
- if (stack.stackTagCompound.hasKey("ProcessingItem")) {
- return icons[1];
- }
- }
- return icons[0];
- }
- public int getMaxEnergyStored(ItemStack stack) {
- return maxStore;
- }
- public boolean hasContainerItem() {
- return true;
- }
- public boolean hasContainerItem(ItemStack stack) {
- return true;
- }
- @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
- if (!stack.hasTagCompound()) {
- stack.stackTagCompound = new NBTTagCompound();
- }
- if (stack.stackTagCompound.hasKey("ProcessingItem")) {
- return stack;
- }
- if (!stack.stackTagCompound.hasKey("RFEnergy")) {
- return stack;
- }
- if (stack.stackTagCompound.getInteger("RFEnergy") < fuelPerTick * ticksPerOperation) {
- return stack;
- }
- ItemStack toCook;
- if (player.inventory.currentItem == InventoryPlayer.getHotbarSize() - 1) {
- toCook = player.inventory.getStackInSlot(0);
- } else {
- toCook = player.inventory.getStackInSlot(player.inventory.currentItem + 1);
- }
- if (toCook == null) {
- return stack;
- }
- if (!(FurnaceRecipes.smelting().getSmeltingResult(toCook).getItem() instanceof ItemFood)) {
- return stack;
- }
- stack.stackTagCompound.setTag("ProcessingItem", toCook.writeToNBT(new NBTTagCompound()));
- stack.stackTagCompound.setInteger("ProcessingStartTime", MinecraftServer.getServer().getTickCounter());
- return stack;
- }
- @Override public void onUpdate(ItemStack stack, World world, Entity player, int slot, boolean selected) {
- super.onUpdate(stack, world, player, slot, selected);
- if (!stack.hasTagCompound()) {
- return;
- }
- if (!stack.stackTagCompound.hasKey("ProcessingItem")) {
- return;
- }
- if (!stack.stackTagCompound.hasKey("RFEnergy")) {
- return;
- }
- stack.stackTagCompound.setInteger("RFEnergy", stack.stackTagCompound.getInteger("RFEnergy") - fuelPerTick);
- if (!stack.stackTagCompound.hasKey("ProcessingStartTime")) {
- stack.stackTagCompound.setInteger("ProcessingStartTime", MinecraftServer.getServer().getTickCounter());
- }
- if (MinecraftServer.getServer().getTickCounter() < stack.stackTagCompound.getInteger("ProcessingStartTime")) {
- stack.stackTagCompound.setInteger("ProcessingStartTime", MinecraftServer.getServer().getTickCounter());
- }
- if (stack.stackTagCompound.getInteger("ProcessingStartTime") + ticksPerOperation < MinecraftServer.getServer().getTickCounter()) {
- return;
- }
- if ((!(player instanceof EntityPlayer))) {
- return;
- }
- if (((EntityPlayer) player).inventory == null) {
- return;
- }
- if (((EntityPlayer) player).inventory.getFirstEmptyStack() == -1) {
- return;
- }
- ((EntityPlayer) player).inventory.addItemStackToInventory(FurnaceRecipes.smelting().getSmeltingResult(ItemStack.loadItemStackFromNBT((NBTTagCompound) stack.stackTagCompound.getTag("ProcessingItem"))));
- stack.stackTagCompound.removeTag("ProcessingItem");
- stack.stackTagCompound.removeTag("ProcessingStartTime");
- }
- public int receiveEnergy(ItemStack stack, int offer, boolean simulate) {
- return CommonUtils.receiveEnergyUtil(stack, offer, simulate, maxReceive, maxStore);
- }
- @Override public void registerIcons(IIconRegister register) {
- this.icons[0] = register.registerIcon("fluxfyre:Pan_Off");
- this.icons[1] = register.registerIcon("fluxfyre:Pan_On");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement