Jump to content

[1.7.10] Cant pick up/move items in custom gui


JayWolves

Recommended Posts

So here I am again, stuck with a problem I can't figure out myself. I searched for this topic and found some older post with the same/similar issue, but with a different (older) forge version. The bugfix they found was adding @NetworkMod to the main mod file, but this is not needed anymore for 1.7 as far as I know.

 

I can place my block, click on it and it will open the gui properly. All player items show up just fine. I can put items in my block with a hopper and they will pop out when I destroy the block, but they wont show up.

When I click an item, it seems to pick it up to the mouse and place it back in the slot in a split second. Shift-Clicking items wont work either. They get duplicated and when I close the gui and open it back up, they are still there, but when I destroy the block, they wont spit out.

 

I bet I just missing something very obvious here, but I have no clue where to look anymore. Hope someone can point me to the right direction =)

 

My mod file

[spoiler=Main]

@Mod(modid = SolarCraft.MODID, version = SolarCraft.VERSION)
public class SolarCraft {
public static final String MODID = "solarcraft";
public static final String VERSION = "0.1";

public static Block crystallizerBlock;
(...)

@Instance(SolarCraft.MODID)
public static SolarCraft instance;

@SidedProxy(clientSide = "solarcraft.proxy.ClientProxy", serverSide = "solarcraft.proxy.CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {

}

@EventHandler
public void init(FMLInitializationEvent event) {
	crystallizerBlock = registerBlock(new BlockCrystallizer("crystallizerBlock"));
	(...)

	TileTechCrystallizer.init();
	(...)

	NetworkRegistry.INSTANCE.registerGuiHandler(SolarCraft.instance, new GuiHandler());
	proxy.registerRenderers();
}


private Block registerBlock(Block regBlock) {
	GameRegistry.registerBlock(regBlock, regBlock.getUnlocalizedName());

	return regBlock;
}

(...)
}

 

The gui handler

[spoiler=GuiHandler]

public class GuiHandler implements IGuiHandler {

(...)
public static final int crystallizerGui = 4;

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity te;

	switch (ID) {
	(...)
	case crystallizerGui:
		te = world.getTileEntity(x, y, z);

		if (te != null && te instanceof TileTechCrystallizer)
			return new ContainerCrystallizer(player.inventory, (TileTechCrystallizer) te);
		break;
	}

	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity te = world.getTileEntity(x, y, z);

	switch (ID) {
	(...)
	case crystallizerGui:
		if (te != null && te instanceof TileTechCrystallizer)
			return new GuiCrystallizer(player.inventory, (TileTechCrystallizer) te);
		break;
	}

	return null;
}
}

 

The Gui

[spoiler=GuiCrystallizer]

public class GuiCrystallizer extends GuiContainer {

public GuiCrystallizer(IInventory playerInv, TileTechCrystallizer te) {
	super(new ContainerCrystallizer(playerInv, te));

	this.xSize = 176;
	this.ySize = 166;
}

@Override
protected void drawGuiContainerBackgroundLayer(float gameTicks, int mouseX, int mouseY) {
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture(new ResourceLocation("solarcraft:textures/gui/crystallizer.png"));
	int x = (width - xSize) / 2;
	int y = (height - ySize) / 2;
	this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

 

The container

[spoiler=ContainerMachine]

public abstract class ContainerMachine extends Container {

protected TileTechMachine tem;
protected int invSize = 1;

public ContainerMachine(TileTechMachine tem) {
	this.tem = tem;
	this.invSize = tem.getSizeInventory();
}

@Override
public boolean canInteractWith(EntityPlayer playerIn) {
	return this.tem.isUseableByPlayer(playerIn);
}

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

	// null checks and checks if the item can be stacked (maxStackSize > 1)
	if (slotObject != null && slotObject.getHasStack()) {
		ItemStack stackInSlot = slotObject.getStack();
		stack = stackInSlot.copy();

		// merges the item into player inventory since its in the tileEntity
		if (slot < tem.getSizeInventory()) {
			if (!this.mergeItemStack(stackInSlot, tem.getSizeInventory(), 36 + tem.getSizeInventory(), true)) {
				return null;
			}
		}
		// places it into the tileEntity is possible since its in the player inventory
		else if (!this.mergeItemStack(stackInSlot, 0, tem.getSizeInventory(), false)) {
			return null;
		}

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

		if (stackInSlot.stackSize == stack.stackSize) {
			return null;
		}
		slotObject.onPickupFromSlot(player, stackInSlot);
	}
	return stack;
}
}

 

[spoiler=ContainerCrystallizer]

public class ContainerCrystallizer extends ContainerMachine {

public ContainerCrystallizer(IInventory playerInv, TileTechMachine tem) {
	super(tem);

	// My Tile Entity
	addSlotToContainer(new Slot(tem, 0, 44, 11));
	addSlotToContainer(new Slot(tem, 1, 62, 11));
	addSlotToContainer(new Slot(tem, 2, 44, 29));
	addSlotToContainer(new Slot(tem, 3, 62, 29));
	addSlotToContainer(new Slot(tem, 4, 89, 59));
	addSlotToContainer(new Slot(tem, 5, 116, 20));

	// Player Inventory
	for (int y = 0; y < 3; ++y) {
		for (int x = 0; x < 9; ++x) {
			int i = x + y * 9 + 9;
			Slot slot = addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
		}
	}

	// Player Hotbar
	for (int x = 0; x < 9; ++x) {
		Slot slot = addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 142));
	}
}
}

 

The block

[spoiler=BlockCrystallizer]

public class BlockCrystallizer extends BlockMachine {

public BlockCrystallizer(String unlocalizedName) {
	super(unlocalizedName);
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {
	return new TileTechCrystallizer();
}

@Override
public void registerBlockIcons(IIconRegister iconRegister) {
	super.registerBlockIcons(iconRegister);
	icons[3] = iconRegister.registerIcon(SolarCraft.MODID + ":" + "crystallizer");
}

@Override
public int getGuiId() {
	return GuiHandler.crystallizerGui;
}
}

 

The tile

[spoiler=TileTechMachine]

public abstract class TileTechMachine extends TileTech implements IEnergyReceiver, IInventory {

private int energyRate = 0;
private Set<ForgeDirection> inputDirections = new HashSet<ForgeDirection>();

public ItemStack[] inventory;
private int inventorySize;
private String customName;

public TileTechMachine(int invSize) {
	inventorySize = invSize;
	this.inventory = new ItemStack[invSize];
}

@Override
public boolean canConnectEnergy(ForgeDirection arg0) {
	return inputDirections.contains(arg0);
}

@Override
public int getEnergyStored(ForgeDirection from) {
	return getStorage().getEnergyStored();
}

@Override
public int getMaxEnergyStored(ForgeDirection from) {
	return getStorage().getMaxEnergyStored();
}

@Override
public int receiveEnergy(ForgeDirection side, int maxReceive, boolean simulate) {
	return getStorage().receiveEnergy(maxReceive, simulate);
}

@Override
public void updateEntity() {
	super.updateEntity();

	process();
}

protected abstract void process();

@Override
public ItemStack getStackInSlot(int index) {
	return this.inventory[index];
}

@Override
public ItemStack decrStackSize(int slot, int num) {
	if (this.inventory[slot] != null) {
		ItemStack stack;
		if (this.inventory[slot].stackSize <= num) {
			stack = this.inventory[slot];
			this.inventory[slot] = null;
			return stack;
		} else {
			stack = this.inventory[slot].splitStack(num);
			if (this.inventory[slot].stackSize == 0) {
				this.inventory[slot] = null;
			}
			return stack;
		}
	} else
		return null;
}

@Override
public ItemStack getStackInSlotOnClosing(int index) {
	if (this.inventory[index] != null) {
		ItemStack var2 = this.inventory[index];
		this.inventory[index] = null;
		return var2;
	} else
		return null;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	this.inventory[index] = stack;
	if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
		stack.stackSize = this.getInventoryStackLimit();
	}
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
		return false;
	}
	return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64D;
}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	return true;
}

@Override
public String getInventoryName() {
	return this.hasCustomInventoryName() ? this.customName : "container.tiletechmachine";
}

@Override
public boolean hasCustomInventoryName() {
	return this.customName != null && !this.customName.equals("");
}

@Override
public int getSizeInventory() {
	return inventorySize;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

public String getCustomName() {
	return this.customName;
}

public void setCustomName(String customName) {
	this.customName = customName;
}

@Override
public void openInventory() {
}

@Override
public void closeInventory() {
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
	super.readFromNBT(tagCompound);

	NBTTagList tagList = tagCompound.getTagList("Inventory", 10);
	for (int i = 0; i < tagList.tagCount(); i++) {
		NBTTagCompound tag = tagList.getCompoundTagAt(i);
		byte slot = tag.getByte("Slot");
		if (slot >= 0 && slot < inventory.length) {
			inventory[slot] = ItemStack.loadItemStackFromNBT(tag);
		}
	}
}

@Override
public void writeToNBT(NBTTagCompound tagCompound) {
	super.writeToNBT(tagCompound);

	NBTTagList itemList = new NBTTagList();
	for (int i = 0; i < inventory.length; i++) {
		ItemStack stack = inventory[i];
		if (stack != null) {
			NBTTagCompound tag = new NBTTagCompound();
			tag.setByte("Slot", (byte) i);
			stack.writeToNBT(tag);
			itemList.appendTag(tag);
		}
	}
	tagCompound.setTag("Inventory", itemList);
}
}

 

[spoiler=TileTechCrystallizer]

public class TileTechCrystallizer extends TileTechMachine {

public TileTechCrystallizer() {
	super(6);
}

public static void init() {
	GameRegistry.registerTileEntity(TileTechCrystallizer.class, "crystallizerTile");
}

@Override
protected void process() {
	// TODO Auto-generated method stub

}
}

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • BD303 merupakan salah satu situs slot mudah scatter paling populer dan digemari oleh kalangan slot online di tahun 2024 mainkan sekarang dengan kesempatan yang mudah menang jackpot jutaan rupiah.
  • Topics

×
×
  • Create New...

Important Information

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