Advertisement
Rallias

Untitled

Oct 13th, 2015
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.28 KB | None | 0 0
  1. package xyz.ajp.fluxfyre.item;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.client.renderer.texture.IIconRegister;
  6. import net.minecraft.creativetab.CreativeTabs;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.entity.player.InventoryPlayer;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemFood;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.item.crafting.FurnaceRecipes;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.server.MinecraftServer;
  16. import net.minecraft.util.IIcon;
  17. import net.minecraft.world.World;
  18.  
  19. import cofh.api.energy.IEnergyContainerItem;
  20.  
  21. import xyz.ajp.fluxfyre.util.CommonUtils;
  22.  
  23. public class ItemPortableStove extends Item implements IEnergyContainerItem {
  24.     public static int fuelPerTick;
  25.     public static int maxReceive;
  26.     public static int maxStore;
  27.     public static int ticksPerOperation;
  28.     public final IIcon[] icons = new IIcon[2];
  29.  
  30.     public ItemPortableStove() {
  31.         this.setCreativeTab(CreativeTabs.tabMisc);
  32.         this.setMaxStackSize(1);
  33.         this.setTextureName("fluxfyre:Pan_Off");
  34.         this.setUnlocalizedName("portableStove");
  35.     }
  36.  
  37.     @SuppressWarnings("unchecked")
  38.     public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
  39.         super.addInformation(stack, player, list, advanced);
  40.         int energy;
  41.         if (stack.stackTagCompound != null) {
  42.             if (!stack.stackTagCompound.hasKey("RFEnergy")) {
  43.                 energy = 0;
  44.             } else {
  45.                 energy = stack.stackTagCompound.getInteger("RFEnergy");
  46.             }
  47.         } else {
  48.             energy = 0;
  49.         }
  50.         list.add(Integer.toString(energy) + " RF");
  51.         if (advanced) {
  52.             list.add("so leet");
  53.         }
  54.     }
  55.  
  56.     public int extractEnergy(ItemStack stack, int request, boolean simulate) {
  57.         return 0;
  58.     }
  59.  
  60.     public int getEnergyStored(ItemStack stack) {
  61.         return CommonUtils.getEnergyStoredUtil(stack);
  62.     }
  63.  
  64.     @Override public IIcon getIcon(ItemStack stack, int pass) {
  65.         if (stack.hasTagCompound()) {
  66.             if (stack.stackTagCompound.hasKey("ProcessingItem")) {
  67.                 return icons[1];
  68.             }
  69.         }
  70.  
  71.         return icons[0];
  72.     }
  73.  
  74.     public int getMaxEnergyStored(ItemStack stack) {
  75.         return maxStore;
  76.     }
  77.  
  78.     public boolean hasContainerItem() {
  79.         return true;
  80.     }
  81.  
  82.     public boolean hasContainerItem(ItemStack stack) {
  83.         return true;
  84.     }
  85.  
  86.     @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
  87.         if (!stack.hasTagCompound()) {
  88.             stack.stackTagCompound = new NBTTagCompound();
  89.         }
  90.  
  91.         if (stack.stackTagCompound.hasKey("ProcessingItem")) {
  92.             return stack;
  93.         }
  94.  
  95.         if (!stack.stackTagCompound.hasKey("RFEnergy")) {
  96.             return stack;
  97.         }
  98.  
  99.         if (stack.stackTagCompound.getInteger("RFEnergy") < fuelPerTick * ticksPerOperation) {
  100.             return stack;
  101.         }
  102.  
  103.         ItemStack toCook;
  104.         if (player.inventory.currentItem == InventoryPlayer.getHotbarSize() - 1) {
  105.             toCook = player.inventory.getStackInSlot(0);
  106.         } else {
  107.             toCook = player.inventory.getStackInSlot(player.inventory.currentItem + 1);
  108.         }
  109.  
  110.         if (toCook == null) {
  111.             return stack;
  112.         }
  113.  
  114.         if (!(FurnaceRecipes.smelting().getSmeltingResult(toCook).getItem() instanceof ItemFood)) {
  115.             return stack;
  116.         }
  117.  
  118.         stack.stackTagCompound.setTag("ProcessingItem", toCook.writeToNBT(new NBTTagCompound()));
  119.         stack.stackTagCompound.setInteger("ProcessingStartTime", MinecraftServer.getServer().getTickCounter());
  120.  
  121.         return stack;
  122.     }
  123.  
  124.     @Override public void onUpdate(ItemStack stack, World world, Entity player, int slot, boolean selected) {
  125.         super.onUpdate(stack, world, player, slot, selected);
  126.         if (!stack.hasTagCompound()) {
  127.             return;
  128.         }
  129.  
  130.         if (!stack.stackTagCompound.hasKey("ProcessingItem")) {
  131.             return;
  132.         }
  133.  
  134.         if (!stack.stackTagCompound.hasKey("RFEnergy")) {
  135.             return;
  136.         }
  137.  
  138.         stack.stackTagCompound.setInteger("RFEnergy", stack.stackTagCompound.getInteger("RFEnergy") - fuelPerTick);
  139.  
  140.         if (!stack.stackTagCompound.hasKey("ProcessingStartTime")) {
  141.             stack.stackTagCompound.setInteger("ProcessingStartTime", MinecraftServer.getServer().getTickCounter());
  142.         }
  143.  
  144.         if (MinecraftServer.getServer().getTickCounter() < stack.stackTagCompound.getInteger("ProcessingStartTime")) {
  145.             stack.stackTagCompound.setInteger("ProcessingStartTime", MinecraftServer.getServer().getTickCounter());
  146.         }
  147.  
  148.         if (stack.stackTagCompound.getInteger("ProcessingStartTime") + ticksPerOperation < MinecraftServer.getServer().getTickCounter()) {
  149.             return;
  150.         }
  151.  
  152.         if ((!(player instanceof EntityPlayer))) {
  153.             return;
  154.         }
  155.  
  156.         if (((EntityPlayer) player).inventory == null) {
  157.             return;
  158.         }
  159.  
  160.         if (((EntityPlayer) player).inventory.getFirstEmptyStack() == -1) {
  161.             return;
  162.         }
  163.  
  164.         ((EntityPlayer) player).inventory.addItemStackToInventory(FurnaceRecipes.smelting().getSmeltingResult(ItemStack.loadItemStackFromNBT((NBTTagCompound) stack.stackTagCompound.getTag("ProcessingItem"))));
  165.         stack.stackTagCompound.removeTag("ProcessingItem");
  166.         stack.stackTagCompound.removeTag("ProcessingStartTime");
  167.     }
  168.  
  169.     public int receiveEnergy(ItemStack stack, int offer, boolean simulate) {
  170.         return CommonUtils.receiveEnergyUtil(stack, offer, simulate, maxReceive, maxStore);
  171.     }
  172.  
  173.     @Override public void registerIcons(IIconRegister register) {
  174.         this.icons[0] = register.registerIcon("fluxfyre:Pan_Off");
  175.         this.icons[1] = register.registerIcon("fluxfyre:Pan_On");
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement