Jump to content

Recommended Posts

Posted

The problem is solved now.

Thanks to Briman0094 for the help in the IRC Chat :)

 

[spoiler=Old post]My problem..

So.. a quick explanation what should happen is: Whenever you put a item in slot 1, the exact same item creates in slot 2 but with an enchantment and when you take the item from slot 2 the item from slot 1 disappears.

 

Seems simple to do.. but I'm having some trouble with it.

What happens now is when I take the item from slot 2, I take it up for about 1 second and also the item in slot 1 disappears but after a second i loose the item from slot 2 and the item from slot 1 pops back.

 

I hope this makes sense to some of you guys, because I really need help.

 

Some useful information

Forge build: v6.4.1.426

Minecraft version: 1.4.5

 

Container

public class CustomContainer extends Container{
private int inventorySize;
private InventoryBasic input;
private InventoryBasic output;

    public CustomContainer(InventoryPlayer inventoryPlayer){
    	input = new CustomInventory(this, "Input", 1);
    	output = new InventoryBasic("Output", 1);
    	
    	addSlotToContainer(new Slot(input, 0, 49, 47));
    	addSlotToContainer(new CustomSlot(output, 0, 107, 47));

	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 9; j++){
			addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

        for(int i = 0; i < 9; i++){
        	addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
        }
        
        inventorySize = input.getSizeInventory();
    }
    
    @Override
    public void onCraftMatrixChanged(IInventory par1iInventory){
    	super.onCraftMatrixChanged(par1iInventory);
    	if(par1iInventory == this.inventorySlots){
    		checkItem();
    	}
    }
    
    public void checkItem(){
    	ItemStack itemstack = getSlot(0).getStack();
    	if(itemstack == null){
    		output.setInventorySlotContents(0, null);
    		return;
    	}
    	itemstack = itemstack.copy();
    	ItemStack resultStack = null;
    	
    	itemstack.addEnchantment(Enchantment.protection, 5);
    	resultStack = itemstack;
    	
    	output.setInventorySlotContents(0, resultStack);
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer player){
    	return true;
    }
    
    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int slot){
    	ItemStack stack = null;
    	Slot slotObject = (Slot)inventorySlots.get(slot);

	if(slotObject != null && slotObject.getHasStack()){
		ItemStack stackInSlot = slotObject.getStack();
		stack = stackInSlot.copy();

		if(slot <= inventorySize){
			if(!mergeItemStack(stackInSlot, inventorySize + 1, inventorySlots.size(), true)){
				return null;
			}
		} else if(!mergeItemStack(stackInSlot, 0, inventorySize, false)){
			return null;
		}

		if(stackInSlot.stackSize == 0){
			slotObject.putStack(null);
		} else {
			slotObject.onSlotChanged();
		}
	}
	return stack;
    }
}

 

CustomSlot:

public class CustomSlot extends Slot{

public CustomSlot(IInventory par1iInventory, int par2, int par3, int par4){
	super(par1iInventory, par2, par3, par4);
}

@Override
public boolean isItemValid(ItemStack par1ItemStack){
	return false;
}

}

 

CustomInventory:

public class CustomInventory extends InventoryBasic{
    final Container container;

    public CustomInventory(Container container, String name, int size){
        super(name, size);
        this.container = container;
    }
    
    public void onInventoryChanged(){
        super.onInventoryChanged();
        container.onCraftMatrixChanged(this);
    }
}

 

 

I really hope someone knows what I'm doing wrong.

My Guess is that It's some kind of problem with the Server / Client (Client gets updated but not server). But i'm not sure what's the problem.

 

Posted

not sure if this will help you or not as I am still learning all this myself but a couple things that stick out

In your container

 

Before:

slotObject.putStack(null);

 

After:

slotObject.putStack((ItemStack)null);

 

Before:

		} else {
			slotObject.onSlotChanged();
		}

	}
	return stack;
}

 

After:

		} else {
			slotObject.onSlotChanged();
		}

		slotObject.onPickupFromSlot(par1EntityPlayer, stackInSlot);

	}
	return stack;
}

Posted

Before:

addSlotToContainer(new Slot(input, 0, 49, 47));
addSlotToContainer(new CustomSlot(output, 0, 107, 47));

 

After:

addSlotToContainer(new CustomSlot(output, 0, 107, 47));
addSlotToContainer(new Slot(input, 1, 49, 47));

 

also below should be something like this being a crafting table 2 slots one input one output

 

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
    ItemStack stack = null;
        Slot slotObject = (Slot)this.inventorySlots.get(slot);

        if (slotObject != null && slotObject.getHasStack())
        {
            ItemStack stackInSlot = slotObject.getStack();
            stack = stackInSlot.copy();

            if (slot == 0)
            {
                if (!this.mergeItemStack(stackInSlot, 2, 38, true))
                {
                    return null;
                }

                slotObject.onSlotChange(stackInSlot, stack);
            }
            else if (slot >= 2 && slot < 29)
            {
                if (!this.mergeItemStack(stackInSlot, 29, 38, false))
                {
                    return null;
                }
            }
            else if (slot >= 29 && slot < 38)
            {
                if (!this.mergeItemStack(stackInSlot, 2, 29, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(stackInSlot, 2, 38, false))
            {
                return null;
            }
            
            if (stackInSlot.stackSize == 0)
            {
                slotObject.putStack((ItemStack)null);
            }
            else
            {
                slotObject.onSlotChanged();
            }
            
            if (stackInSlot.stackSize == stack.stackSize)
            {
                return null;
            }

            slotObject.onPickupFromSlot(par1EntityPlayer, stackInSlot);
        }

        return stack;
}

 

just trying to be helpful  :)

Posted

No no no, that's not the problem. Shift clicking is working fine.

My problem is that I try to add a new itemstack to slot 2, which works perfectly but it's only visibly the itemstack is not really there, because when i try to pick it up everything resets back.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

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