Jump to content

[1.7.10] Can't move items in container


robinch

Recommended Posts

Hello!

I'm working on a technic mod and I want to have a steam engine, that produces power. Therefor I have a Gui + Container. Everything works fine, but I can't move the items in the container. They always jump back again. Also the getServerGuiElement in my GuiHandler is never called. I don't know much about proxys so the error might be proxy-related

 

The GuiHandler

 

 

 

public class GuiHandler implements IGuiHandler{

 

 

@Override

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

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

 

switch(ID){

case AllTimesPhysics.steamEngineGuiId :

if(entity instanceof SteamEngineTileEntity){

return new SteamEngineContainer(player.inventory, (SteamEngineTileEntity) entity);

}

}

return null;

}

 

@Override

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

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

 

switch(ID){

case AllTimesPhysics.steamEngineGuiId :

if(entity instanceof SteamEngineTileEntity){

return new SteamEngineGui(player.inventory, (SteamEngineTileEntity) entity);

}

}

return null;

}

}

 

 

 

 

The TileEntity

 

 

 

public class SteamEngineTileEntity extends TileEntity implements ISidedInventory{

 

private String localiziedName;

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

public int energyStored; //max 10.000

public int waterStored; //max  6.000 | 2.000 per bucket

public int burnTime;

public int fuelTime;

public boolean isBurning;

 

public SteamEngineTileEntity(SteamEngine block){

 

}

 

public void updateEntity() {

isBurning = burnTime > 0;

 

if(isBurning){

burnTime--;

}

if(worldObj.isRemote){

if(isBurning && waterStored > 0 && energyStored < 10000){

waterStored--;

energyStored++;

}

if(burnTime == 0){

if(slots[0] != null && waterStored > 0 && energyStored < 10000){

if(getBurnTime(slots[0]) > 0){

burnTime = getBurnTime(slots[0]);

fuelTime = burnTime;

slots[0].stackSize--;

}

}

}

if(slots[1] != null){

if(slots[1].getItem() == Items.water_bucket && waterStored <= 4000){

slots[1] = new ItemStack(Items.bucket);

waterStored += 2000;

}

}

}

}

 

public void setGuiDisplayName(String displayName) {

localiziedName = displayName;

}

 

public boolean hasCustomInventoryName() {

return localiziedName != null && localiziedName.length() > 0;

}

 

public String getInventoryName() {

 

return hasCustomInventoryName() ? localiziedName : "container.SteamEngine";

}

 

public int getSizeInventory(){

return slots.length;

}

 

private int getBurnTime(ItemStack stack){

if(stack == null){

return 0;

}else{

return GameRegistry.getFuelValue(stack);

}

}

 

@Override

public ItemStack getStackInSlot(int slot) {

return slots[slot];

}

 

@Override

public ItemStack decrStackSize(int slot, int i) {

ItemStack stack = getStackInSlot(slot);

if(stack != null){

if(stack.stackSize <= i){

setInventorySlotContents(slot, null);

}else{

stack = stack.splitStack(i);

if(stack.stackSize == 0){

setInventorySlotContents(slot, null);

}

}

return stack;

}

return null;

}

 

@Override

public ItemStack getStackInSlotOnClosing(int slot) {

        ItemStack stack = getStackInSlot(slot);

        if (stack != null) {

                setInventorySlotContents(slot, null);

        }

        return stack;

}

 

@Override

public void setInventorySlotContents(int slot, ItemStack stack) {

        slots[slot] = stack;

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

                stack.stackSize = getInventoryStackLimit();

        }

}

 

@Override

public int getInventoryStackLimit() {

return 64;

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer player) {

return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64D;

}

public void openInventory() {}

public void closeInventory() {}

 

@Override

public boolean isItemValidForSlot(int slot, ItemStack item) {

return false;

}

 

@Override

public int[] getAccessibleSlotsFromSide(int side) {

int[] i = {};

return i;

}

 

@Override

public boolean canInsertItem(int slot, ItemStack stack, int side) {

return true;

}

 

@Override

public boolean canExtractItem(int slot, ItemStack stack, int side) {

return true;

}

}

 

 

 

The Container

 

 

public class SteamEngineContainer extends Container {

 

private SteamEngineTileEntity steamEngine;

private int lastburnTime;

 

public SteamEngineContainer(InventoryPlayer inventory, SteamEngineTileEntity entity) {

steamEngine = entity;

 

addSlotToContainer(new Slot(entity, 0, 80, 54));

addSlotToContainer(new Slot(entity, 1, 80, 9));

 

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

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

addSlotToContainer(new Slot(inventory, y * 9 + x + 9, 8 + x * 18, 84 + y * 18));

}

}

 

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

addSlotToContainer(new Slot(inventory, x, 8 + x * 18, 142));

}

}

 

        public boolean canInteractWith(EntityPlayer player) {

return true;

}

}

 

 

 

I also have a gui, the block itself which opens the gui with: player.openGui(AllTimesPhysics.instance, AllTimesPhysics.steamEngineGuiId, world, x, y, z);

 

In my mainclass i have:

 

public static final int steamEngineGuiId = 10;

 

GameRegistry.registerBlock(steamEngine, "SteamEngine");

GameRegistry.registerTileEntity(SteamEngineTileEntity.class, "SteamEngine");

 

steamEngine = new SteamEngine(Material.rock);

 

NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());

 

If there is anything else needed, i'll post it!

Link to comment
Share on other sites

You have to add some methods to your container:

 

 

@Override

public boolean canInteractWith(EntityPlayer player) {

return this.inventory.isUseableByPlayer(player);

}

 

@Override

public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int slotNumber) {

ItemStack itemstack = null;

Slot slot = (Slot) inventorySlots.get(slotNumber);

 

if (slot != null && slot.getHasStack()) {

ItemStack itemstack1 = slot.getStack();

itemstack = itemstack1.copy();

 

if (slotNumber < 15) {

if (!this.mergeItemStack(itemstack1, 15, 51, false)) {

return null;

}

} else if (!this.mergeItemStack(itemstack1, 0, 15, false)) {

return null;

}

 

if (itemstack1.stackSize == 0) {

slot.putStack((ItemStack) null);

} else {

slot.onSlotChanged();

}

}

        slot.onPickupFromSlot(p_82846_1_, itemstack);

return itemstack;

}

 

 

 

Link to comment
Share on other sites

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {

if(world.isRemote){

player.openGui(AllTimesPhysics.instance, AllTimesPhysics.steamEngineGuiId, world, x, y, z);

}

return true;

}

Link to comment
Share on other sites

It might be one character, but it is quite literally the difference between black and white. ;)

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.