Jump to content

Cant Insert Items and Items duplicate


camerpon900

Recommended Posts

When i insert items into my energy cube i cant insert items into the top slot but i can on the bottom and it shows in the bottom and top however if i then pull items out of the top it duplicates the items.

 

TileEntity

 

package com.camerpon900.realauto2.blocks.TileEntities;

 

import com.camerpon900.realauto2.blocks.Blocks;

import com.camerpon900.realauto2.utils.WorldHelper;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.ISidedInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import net.minecraft.world.biome.BiomeGenDesert;

import net.minecraftforge.common.util.ForgeDirection;

 

public class TileEntityEnergyCube extends TileEntity implements ISidedInventory {

 

    private ItemStack[] slots = new ItemStack[2];

 

    public int power = 0;

    private int maxPower = 5000000;

 

    public void updateEntity() {

        System.out.println("Slots: " + this.slots.length);

    }

 

    public void readFromNBT(NBTTagCompound nbt) {

        super.readFromNBT(nbt);

 

        System.out.println("slots "  + this.slots);

 

        System.out.println("reading nbt");

 

        NBTTagList list = nbt.getTagList("Slots", 10);

        NBTTagList powerList = nbt.getTagList("Power",power);

        this.slots = new ItemStack[getSizeInventory()];

 

        for(int i = 0; i < list.tagCount(); i++) {

            NBTTagCompound item = list.getCompoundTagAt(i);

            NBTTagCompound power = list.getCompoundTagAt(i);

            byte b = item.getByte("Item");

            int p = item.getInteger("Power");

 

            if (b >= 0 && b < this.slots.length) {

                this.slots = ItemStack.loadItemStackFromNBT(item);

            }

 

            if(p >= 0 && p < this.maxPower) {

                this.power = power.getInteger("Power");

            }

        }

    }

 

    public void writeToNBT(NBTTagCompound nbt) {

        super.writeToNBT(nbt);

        System.out.println("Writing To NBT at x: " + xCoord + " y: " + yCoord + " z: " + zCoord);

 

        NBTTagList list = new NBTTagList();

 

        for(int i = 0; i < slots.length; i++) {

            if(this.slots != null) {

                NBTTagCompound item = new NBTTagCompound();

                item.setByte("Item", (byte)i);

                this.slots.writeToNBT(item);

                list.appendTag(item);

            }

        }

 

        if(power >= 1) {

            NBTTagCompound power = new NBTTagCompound();

            power.setInteger("Power", this.power);

            list.appendTag(power);

        }

        nbt.setTag("Power", list);

        nbt.setTag("Slots", list);

    }

 

    public int getSizeInventory() {

        return this.slots.length;

    }

 

    public int[] getAccessibleSlotsFromSide(int p_94128_1_) {

        return new int[0];

    }

 

    public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {

        return this.isItemValidForSlot(p_102007_1_,p_102007_2_);

    }

 

    public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {

        return true;

    }

 

    public ItemStack getStackInSlot(int i) {

        if(i <= 2) {

            return this.slots[1];

        }

        return this.slots;

    }

 

    public ItemStack decrStackSize(int i, int j) {

        if(this.slots != null) {

            System.out.println(this.slots);

            ItemStack itemStack;

            if(this.slots.stackSize <= j) {

                itemStack = this.slots;

                this.slots = null;

                return itemStack;

            } else {

                itemStack = this.slots.splitStack(j);

                if(this.slots.stackSize == 0) {

                    this.slots = null;

                }

            }

            return itemStack;

        }

 

        return null;

    }

 

    public ItemStack getStackInSlotOnClosing(int p_70304_1_) {

        return null;

    }

 

    public void setInventorySlotContents(int i, ItemStack itemStack) {

        this.slots = itemStack;

 

        if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) {

            itemStack.stackSize = this.getInventoryStackLimit();

        }

    }

 

    public String getInventoryName() {

        return null;

    }

 

    public boolean hasCustomInventoryName() {

        return false;

    }

 

    public int getInventoryStackLimit() {

        return 64;

    }

 

    public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {

        return true;

    }

 

    public void openInventory() {

 

    }

 

    public void closeInventory() {

 

    }

 

    public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {

        return true;

    }

}

 

 

 

Container

 

package com.camerpon900.realauto2.container;

 

import com.camerpon900.realauto2.blocks.TileEntities.TileEntityCompressor;

import com.camerpon900.realauto2.blocks.TileEntities.TileEntityEnergyCube;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.Slot;

 

public class ContainerEnergyCube extends Container {

 

    private TileEntityEnergyCube energyCube;

 

    public static final int INPUT = 0, OUTPUT = 1;

 

    public ContainerEnergyCube(InventoryPlayer invPlayer, TileEntityEnergyCube tileEntity) {

        this.energyCube = tileEntity;

 

        //0 = Input, 2 = Output

        this.addSlotToContainer(new Slot(energyCube, INPUT, 56, 23));

        this.addSlotToContainer(new Slot(energyCube, OUTPUT, 56, 53));

 

        for(int i = 0; i < 3; i++) {

            for(int j = 0; j < 9; j++) {

                this.addSlotToContainer(new Slot(invPlayer,9+j+i*9,8+18*j,84+i*18));

            }

        }

 

        for(int i = 0; i < 9; i++) {

            this.addSlotToContainer(new Slot(invPlayer,i,8 + i*18,142));

        }

    }

 

    public boolean canInteractWith(EntityPlayer p_75145_1_) {

        return true;

    }

}

 

 

 

GUIHandler

 

package com.camerpon900.realauto2.gui;

 

import com.camerpon900.realauto2.RealAuto2;

import com.camerpon900.realauto2.blocks.Machines.Machines;

import com.camerpon900.realauto2.blocks.TileEntities.TileEntityCompressor;

import com.camerpon900.realauto2.blocks.TileEntities.TileEntityEnergyCube;

import com.camerpon900.realauto2.container.ContainerCompressor;

import com.camerpon900.realauto2.container.ContainerEnergyCube;

import cpw.mods.fml.common.network.IGuiHandler;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class GUIHandler implements IGuiHandler {

 

    @Override

    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

        TileEntity tileEntity = world.getTileEntity(x,y,z);

 

        switch (ID) {

            case Machines.guiIdCompressor:

                if(tileEntity instanceof TileEntityCompressor) {

                    return new ContainerCompressor(player.inventory, (TileEntityCompressor)tileEntity);

                }

                break;

 

            case Machines.guiIdEnergyCube:

                if(tileEntity instanceof TileEntityEnergyCube) {

                    return new ContainerEnergyCube(player.inventory, (TileEntityEnergyCube)tileEntity);

                }

                break;

        }

        return null;

    }

 

    @Override

    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

        TileEntity tileEntity = world.getTileEntity(x,y,z);

 

        switch (ID) {

            case Machines.guiIdCompressor:

                if(tileEntity instanceof TileEntityCompressor) {

                    return new GuiCompressor(player.inventory, (TileEntityCompressor)tileEntity);

                }

                break;

 

            case Machines.guiIdEnergyCube:

                if(tileEntity instanceof TileEntityEnergyCube) {

                    return new GuiEnergyCube(player.inventory, (TileEntityEnergyCube)tileEntity);

                }

                break;

        }

 

        return null;

    }

 

}

 

 

Link to comment
Share on other sites

Use [code ] tags, please.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.