Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package panda.glassworks.gui;
- import java.util.List;
- import java.util.Map;
- import javax.annotation.Nullable;
- import panda.glassworks.init.Recipes;
- import panda.glassworks.util.GlassBlowingRecipes;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.inventory.ClickType;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.InventoryBasic;
- import net.minecraft.inventory.InventoryCraftResult;
- import net.minecraft.inventory.InventoryCrafting;
- import net.minecraft.inventory.ItemStackHelper;
- import net.minecraft.inventory.Slot;
- import net.minecraft.inventory.SlotCrafting;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.crafting.CraftingManager;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import javax.annotation.Nullable;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.text.ITextComponent;
- import net.minecraft.util.text.TextComponentString;
- import net.minecraft.util.text.TextComponentTranslation;
- public class ContainerBlowpipe extends Container{
- /** The crafting matrix inventory (3x3). */
- private final IInventory outputSlot;
- /** The 2slots where you put your items in that you want to merge and/or rename. */
- public final IInventory inputSlot;
- private final World worldObj;
- /** Position of the workbench */
- private final BlockPos pos;
- private int selection;
- public ContainerBlowpipe(InventoryPlayer playerInventory, World worldIn, BlockPos posIn)
- {
- this.inputSlot = new InventoryBasic("Blowpipe", true, 1);
- this.outputSlot = new InventoryResult();
- this.selection = 0;
- this.addSlotToContainer(new Slot(this.inputSlot, 0, 110, 22));
- this.addSlotToContainer(new Slot(this.outputSlot, 1, 138, 22));
- this.worldObj = worldIn;
- this.pos = posIn;
- for (int i = 0; i < 3; ++i)
- {
- for (int j = 0; j < 9; ++j)
- {
- this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18-26));
- }
- }
- for (int k = 0; k < 9; ++k)
- {
- this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142-26));
- }
- this.onCraftMatrixChanged();
- }
- @Override
- public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn,EntityPlayer player) {
- System.out.println("DOOT");
- this.onCraftMatrixChanged();
- return super.slotClick(slotId, dragType, clickTypeIn, player);
- }
- @Override
- public void putStackInSlot(int slotID, ItemStack stack) {
- // TODO Auto-generated method stub
- super.putStackInSlot(slotID, stack);
- }
- @Override
- public void setCanCraft(EntityPlayer player, boolean canCraft) {
- // TODO Auto-generated method stub
- super.setCanCraft(player, canCraft);
- }
- public void onCraftMatrixChanged()
- {
- if(hasInput()){
- List<ItemStack> recipes = GlassBlowingRecipes.getGlassBlowingResultList(inputStack());
- if(!recipes.isEmpty()){
- if(selection < recipes.size()){
- if(recipes.get(selection) != null){
- System.out.println(selection);
- System.out.println(recipes.get(selection));
- this.putStackInSlot(1, recipes.get(selection));
- }else{
- this.outputSlot.clear();
- }
- }else{
- this.outputSlot.clear();
- this.selection = recipes.size()-1;
- }
- }else{
- this.outputSlot.clear();
- }
- }else{
- this.outputSlot.clear();
- }
- }
- boolean hasInput(){
- return (this.inputSlot.getStackInSlot(0) != null);
- }
- ItemStack inputStack(){
- return (this.inputSlot.getStackInSlot(0));
- }
- public void setCurrentRecipeIndex(int currentRecipeIndexIn)
- {
- if (hasInput())
- {
- List<ItemStack> recipes = GlassBlowingRecipes.getGlassBlowingResultList(inputStack());
- if(!recipes.isEmpty()){
- if(recipes.get(selection) != null){
- if(currentRecipeIndexIn > GlassBlowingRecipes.getGlassBlowingResultList(inputStack()).size()-1){
- this.selection = GlassBlowingRecipes.getGlassBlowingResultList(inputStack()).size();
- }else{
- this.selection = currentRecipeIndexIn;
- }
- if (this.selection < 0)
- {
- this.selection = 0;
- }else{
- this.selection = currentRecipeIndexIn;
- }
- }else{
- this.outputSlot.clear();
- this.selection =0;
- }
- }else{
- this.outputSlot.clear();
- this.selection =0;
- }
- }else{
- this.outputSlot.clear();
- this.selection =0;
- }
- onCraftMatrixChanged();
- }
- @Override
- public void detectAndSendChanges() {
- super.detectAndSendChanges();
- }
- @Override
- protected void retrySlotClick(int slotId, int clickedButton, boolean mode,EntityPlayer playerIn) {
- super.retrySlotClick(slotId, clickedButton, mode, playerIn);
- }
- /**
- * Called when the container is closed.
- */
- public void onContainerClosed(EntityPlayer playerIn)
- {
- super.onContainerClosed(playerIn);
- if (!this.worldObj.isRemote)
- {
- ItemStack itemstack = this.inputSlot.removeStackFromSlot(0);
- if (itemstack != null)
- {
- playerIn.dropItem(itemstack, false);
- }
- }
- }
- public boolean canInteractWith(EntityPlayer playerIn)
- {
- return true;
- }
- /**
- * Take a stack from the specified inventory slot.
- */
- @Nullable
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
- {
- ItemStack itemstack = null;
- Slot slot = (Slot)this.inventorySlots.get(index);
- if (slot != null && slot.getHasStack())
- {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- if (index == 0)
- {
- if (!this.mergeItemStack(itemstack1, 2, 38, true))
- {
- return null;
- }
- slot.onSlotChange(itemstack1, itemstack);
- }
- else if (index >= 2 && index < 29)
- {
- if (!this.mergeItemStack(itemstack1, 29, 38, false))
- {
- return null;
- }
- }
- else if (index >= 29 && index < 38)
- {
- if (!this.mergeItemStack(itemstack1, 2, 29, false))
- {
- return null;
- }
- }
- else if (!this.mergeItemStack(itemstack1, 2, 38, false))
- {
- return null;
- }
- if (itemstack1.stackSize == 0)
- {
- slot.putStack((ItemStack)null);
- }
- else
- {
- slot.onSlotChanged();
- }
- if (itemstack1.stackSize == itemstack.stackSize)
- {
- return null;
- }
- slot.onPickupFromSlot(playerIn, itemstack1);
- }
- return itemstack;
- }
- /**
- * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
- * is null for the initial slot that was double-clicked.
- */
- public boolean canMergeSlot(ItemStack stack, Slot slotIn)
- {
- return slotIn.inventory != this.outputSlot && super.canMergeSlot(stack, slotIn);
- }
- static class InventoryResult implements IInventory
- {
- /** A list of one item containing the result of the crafting formula */
- private final ItemStack[] stackResult = new ItemStack[1];
- /**
- * Returns the number of slots in the inventory.
- */
- public int getSizeInventory()
- {
- return 1;
- }
- /**
- * Returns the stack in the given slot.
- */
- @Nullable
- public ItemStack getStackInSlot(int index)
- {
- return this.stackResult[0];
- }
- /**
- * Get the name of this object. For players this returns their username
- */
- public String getName()
- {
- return "Result";
- }
- /**
- * Returns true if this thing is named
- */
- public boolean hasCustomName()
- {
- return false;
- }
- /**
- * Get the formatted ChatComponent that will be used for the sender's username in chat
- */
- public ITextComponent getDisplayName()
- {
- return (ITextComponent)(this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName(), new Object[0]));
- }
- /**
- * Removes up to a specified number of items from an inventory slot and returns them in a new stack.
- */
- @Nullable
- public ItemStack decrStackSize(int index, int count)
- {
- return ItemStackHelper.getAndRemove(this.stackResult, 0);
- }
- /**
- * Removes a stack from the given slot and returns it.
- */
- @Nullable
- public ItemStack removeStackFromSlot(int index)
- {
- return ItemStackHelper.getAndRemove(this.stackResult, 0);
- }
- /**
- * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
- */
- public void setInventorySlotContents(int index, @Nullable ItemStack stack)
- {
- this.stackResult[0] = stack;
- }
- /**
- * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
- */
- public int getInventoryStackLimit()
- {
- return 64;
- }
- /**
- * For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
- * hasn't changed and skip it.
- */
- public void markDirty()
- {
- }
- /**
- * Do not make give this method the name canInteractWith because it clashes with Container
- */
- public boolean isUseableByPlayer(EntityPlayer player)
- {
- return false;
- }
- public void openInventory(EntityPlayer player)
- {
- }
- public void closeInventory(EntityPlayer player)
- {
- }
- /**
- * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
- */
- public boolean isItemValidForSlot(int index, ItemStack stack)
- {
- return true;
- }
- public int getField(int id)
- {
- return 0;
- }
- public void setField(int id, int value)
- {
- }
- public int getFieldCount()
- {
- return 0;
- }
- public void clear()
- {
- for (int i = 0; i < this.stackResult.length; ++i)
- {
- this.stackResult[i] = null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement