Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.container;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.ICrafting;
- import net.minecraft.inventory.Slot;
- import net.minecraft.inventory.SlotFurnace;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import com.chef.mod.crafting.CookFurnaceRecipes;
- import com.chef.mod.crafting.SauceMakerRecipes;
- import com.chef.mod.slot.SlotSauceMakerBowl;
- import com.chef.mod.tileentity.TileEntityCookFurnace;
- import com.chef.mod.tileentity.TileEntitySauceMaker;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class ContainerSauceMaker extends Container {
- private TileEntitySauceMaker sauceMaker;
- public int lastBurnTime;
- public int lastCurrentItemBurnTime;
- public int lastCookTime;
- public ContainerSauceMaker(InventoryPlayer inventory, TileEntitySauceMaker tileentity) {
- this.sauceMaker = tileentity;
- //Input slot 1
- this.addSlotToContainer(new Slot(tileentity, 0, 21, 9));
- //Input slot 2
- this.addSlotToContainer(new SlotSauceMakerBowl(tileentity, 1, 49, 51));
- //Input slot fuel
- this.addSlotToContainer(new Slot(tileentity, 2, 21, 51));
- //Output slot
- this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity, 3, 120, 29));
- //Inventory
- for(int i = 0; i < 3; i++) {
- for(int j = 0; j < 9; j++) {
- this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
- }
- }
- //Action bar
- for(int i = 0; i < 9; i++) {
- this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
- }
- }
- public void addCraftingToCrafters (ICrafting icrafting) {
- super.addCraftingToCrafters(icrafting);
- icrafting.sendProgressBarUpdate(this, 0, this.sauceMaker.cookTime);
- icrafting.sendProgressBarUpdate(this, 1, this.sauceMaker.burnTime);
- icrafting.sendProgressBarUpdate(this, 2, this.sauceMaker.currentItemBurnTime);
- }
- public void detectAndSendChanges() {
- super.detectAndSendChanges();
- for(int i = 0; i < this.crafters.size(); i++) {
- ICrafting icrafting = (ICrafting) this.crafters.get(i);
- if(this.lastCookTime != this.sauceMaker.cookTime) {
- icrafting.sendProgressBarUpdate(this, 0, this.sauceMaker.cookTime);
- }
- if(this.lastBurnTime != this.sauceMaker.burnTime) {
- icrafting.sendProgressBarUpdate(this, 1, this.sauceMaker.burnTime);
- }
- if(this.lastCurrentItemBurnTime != this.sauceMaker.currentItemBurnTime) {
- icrafting.sendProgressBarUpdate(this, 2, this.sauceMaker.currentItemBurnTime);
- }
- }
- this.lastCookTime = this.sauceMaker.cookTime;
- this.lastBurnTime = this.sauceMaker.burnTime;
- this.lastCurrentItemBurnTime = this.sauceMaker.currentItemBurnTime;
- }
- @SideOnly(Side.CLIENT)
- public void updateProgressBar(int par1, int par2)
- {
- if (par1 == 0) {
- this.sauceMaker.cookTime = par2;
- }
- if (par1 == 1) {
- this.sauceMaker.burnTime = par2;
- }
- if(par1 == 2) {
- this.sauceMaker.currentItemBurnTime = par2;
- }
- }
- public ItemStack transferStackInSlot(EntityPlayer player, int slot)
- {
- ItemStack itemstack = null;
- Slot containerslot = (Slot)this.inventorySlots.get(slot);
- Item item = null;
- Item item2 = null;
- if (containerslot != null && containerslot.getHasStack()) {
- ItemStack itemstack1 = containerslot.getStack();
- itemstack = itemstack1.copy();
- if (slot == 2)
- {
- if (!this.mergeItemStack(itemstack1, 3, 39, true))
- {
- return null;
- }
- containerslot.onSlotChange(itemstack1, itemstack);
- }
- else if (slot == 1)
- {
- if (!this.mergeItemStack(itemstack1, 3, 39, true))
- {
- return null;
- }
- containerslot.onSlotChange(itemstack1, itemstack);
- }
- else if (slot == 0)
- {
- if (!this.mergeItemStack(itemstack1, 3, 39, true))
- {
- return null;
- }
- containerslot.onSlotChange(itemstack1, itemstack);
- }
- else if (slot != 1 && slot != 0)
- {
- if (SauceMakerRecipes.getJuicingResult(item, item2) != null)
- {
- {
- return null;
- }
- }
- else if (TileEntitySauceMaker.isItemIngredient(itemstack1))
- {
- if (!this.mergeItemStack(itemstack1, 0, 1, false))
- {
- return null;
- }
- }
- else if (TileEntitySauceMaker.isItemBowl(itemstack1))
- {
- if (!this.mergeItemStack(itemstack1, 1, 2, false))
- {
- return null;
- }
- }
- else if (TileEntitySauceMaker.isItemFuel(itemstack1))
- {
- if (!this.mergeItemStack(itemstack1, 2, 3, false))
- {
- return null;
- }
- }
- else if (slot >= 3 && slot < 30)
- {
- if (!this.mergeItemStack(itemstack1, 30, 39, false))
- {
- return null;
- }
- }
- //For placing it in the output
- else if (slot >= 30 && slot < 39 && !this.mergeItemStack(itemstack1, 4, 30, false))
- {
- return null;
- }
- }
- else if (!this.mergeItemStack(itemstack1, 3, 39, false))
- {
- return null;
- }
- if (itemstack1.stackSize == 0)
- {
- containerslot.putStack((ItemStack)null);
- }
- else
- {
- containerslot.onSlotChanged();
- }
- if (itemstack1.stackSize == itemstack.stackSize)
- {
- return null;
- }
- containerslot.onPickupFromSlot(player, itemstack1);
- }
- return itemstack;
- }
- @Override
- public boolean canInteractWith(EntityPlayer player) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment