Jump to content

[Solved!] Item disappears when grabbing it in custom gui.


Recommended Posts

Posted

http://cdn.makeagif.com/media/9-08-2014/5wGA2P.gif

 

The gif above illustrates my conundrum:

When I click Done! An item should appear in the bottom slot, which works. But, when I grab it, it disappears an instant after being in my hand and the above stacksize increases until I pick that up and then goes back down. The item in the bottom slot is called "reel_written" and the item above is "reel_blank" (They are not the same items and so I do not place the item in the top slot as is the illusion)

 

I suspect it is a syncing problem, but I really don't enjoy the thought of getting into packet handling (besides, people have said that this is already taken care of with guis, maybe I'm/they're wrong, idk)

 

TileEntityMusicDesk

 

  Reveal hidden contents

 

 

ContainerMusicDesk

 

  Reveal hidden contents

 

 

CommonProxy

 

  Reveal hidden contents

 

 

GuiMusicBox

 

  Reveal hidden contents

 

 

And in my main mod class, I register the proxy as the guihandler in the initialisation method since it implements IGuiHandler.

 

If anyone knows what is going on, please help me to understand how to fix this issue.

 

I have been googling this problem 3 days and all the relevant links are purple'd out and not one helped. :(

 

I am new on these forums, so if I have done anything incorrectly, I'd prefer you not to be harsh, just tell me calmly, thanks.

Posted

Ok, thank you. So, this is what I have for my packet. (I followed the forge netty packet example).

 

 

  Reveal hidden contents

 

 

If I remove the "this.createSOngReel();" in the GuiMusicDesk.class, this will do it for me since I set it to do that on the client side above AND the server side?

 

Here is the modified code:

 

  Reveal hidden contents

 

 

I've never used packets before. :P So I expect to be completely wrong.

Posted
  On 9/8/2014 at 12:47 PM, diesieben07 said:

@Whov: What? markDirty is something completely different.

 

Oops, derp.. It actually is completely different.

I thought your tile wasn't updating because I didn't consider (as diesieben07 said) that you are using a button (that is client side only, so server overrides client). Sorry my bad.

To create buttons for my guis I use CodeChickenCore API: if you think it might help give it a try. This is my code using CCC (extending GuiScreenWidget):

	@Override
public void actionPerformed(String ident, Object... params) {
	if (ident=="dismantle") {
		((Fabricator)tile.getWorldObj().getBlock(tile.xCoord, tile.yCoord, tile.zCoord)).breakMultiBlock(tile.getWorldObj(), tile);
		this.mc.thePlayer.closeScreen();
	}
}

@Override
public void addWidgets() {
	GuiCCButton widget = new GuiCCButton(30, (height-ySize)/2, 199, 20, "Dismantle multiblock");
	widget.setActionCommand("dismantle");
	this.add(widget);
}

 

EDIT: how did you solve out of curiosity?

Check out my blog!

http://www.whov.altervista.org

Posted

In my GUI actionPerformed method:

 

MusicboxCore.network.sendToServer(new MusicBoxMessage(this.tileEntity.xCoord,this.tileEntity.yCoord,this.tileEntity.zCoord, this.nameField.getText(), this.tileEntity.unsavedSong[0], this.tileEntity.unsavedSong[1], this.tileEntity.unsavedSong[2], this.tileEntity.unsavedSong[3]));

Here is the packet to be sent:

 

package neuro.musicbox.main;

import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import neuro.musicbox.gui.TileEntityMusicDesk;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class MusicBoxMessage implements IMessage {

int x, y, z;
public String song1,song2,song3,song4;
public String name;

public MusicBoxMessage(int i, int j, int k, String name, String... song)
{
	x = i;
	y = j;
	z = k;

	song1 = song[0];
	song2 = song[1];
	song3 = song[2];
	song4 = song[3];

	this.name = name;
}

@Override
public void fromBytes(ByteBuf buf)
{
	//Reads the data in the same order it was written. x, y, z, song1-4, then name
	x = buf.readInt();
	y = buf.readInt();
	z = buf.readInt();
	song1 = ByteBufUtils.readUTF8String(buf);
	song2 = ByteBufUtils.readUTF8String(buf);
	song3 = ByteBufUtils.readUTF8String(buf);
	song4 = ByteBufUtils.readUTF8String(buf);
	name = ByteBufUtils.readUTF8String(buf);
}

@Override
public void toBytes(ByteBuf buf) {

	buf.writeInt(x);
	buf.writeInt(y);
	buf.writeInt(z);
	ByteBufUtils.writeUTF8String(buf, song1);
	ByteBufUtils.writeUTF8String(buf, song2);
	ByteBufUtils.writeUTF8String(buf, song3);
	ByteBufUtils.writeUTF8String(buf, song4);
	ByteBufUtils.writeUTF8String(buf, name);
}

public static class Handler implements IMessageHandler<MusicBoxMessage, IMessage> {

	@Override
	public IMessage onMessage(MusicBoxMessage message, MessageContext ctx) {

		//Get the tileentity at the correct coordinates server-side:
		TileEntityMusicDesk te = ((TileEntityMusicDesk)ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z));
		//Call the method server-side:
		te.createSongReel(ctx.getServerHandler().playerEntity, new String[] {message.song1,message.song2,message.song3,message.song4,message.song2,message.song3,message.song4}, message.name);
	}
}
}

Posted

Thanks for the help again, however I have yet another minor issue. It seems to still be adding the items on the client as well, possibly more than it needs to. When I pick up an item, it will re-add the items to the inventory. For illustration:

 

Slot 1: Has 6 items.

Slot 2: Has 3 item.

 

I take one item from slot 2 so it has 2 left.

Now:

 

Slot 1: Has 12 items.

Slot 2: Has 4 items.

 

However, the extra items are just fake duplicates which disappear once I grab 'em.

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

    • And without soulsweapons?
    • In France, we deeply value financial security and independence. After my divorce, my life took a chaotic turn, and amidst all the turmoil, I misplaced the backup phrase for my Bitcoin wallet, which held a significant amount, $220,000. I was already grappling with emotional challenges, and the thought of losing my Bitcoin felt like the final blow. In moments like these, I couldn't help but think of the French saying, “Il ne faut jamais dire jamais,” which means “Never say never.” Little did I know that this would become a mantra for my recovery journey. I spent days searching for that elusive phrase, going through old documents and turning my apartment upside down, but it was as if the universe had conspired against me—the backup was simply gone. Feeling desperate and overwhelmed, I confided in a friend who works in the cryptocurrency space. He recommended Hack Buster Recovery, mentioning that they had helped many French investors in similar situations. Skeptical but out of options, I decided to reach out. From the moment I contacted Hack Buster Recovery, I was struck by their understanding of my situation. They were professional and compassionate, reassuring me that I wasn’t alone in this struggle. Their team quickly got to work, explaining the recovery process in a way that put my mind at ease. It was clear they had dealt with cases like mine before, WEBSITE: hackbusters.online
    • (LEEULTIMATEHACKER @ A O L . C O M)  telegram: LEEULTIMATE With LEE ULTIMATE HACKER, a team which specializes in recovering a wide range of digital assets including, Bitcoin, Etherium, stablecoins, non -fungible tokens (NFTs), and other various cryptocurrencies, In the ever evolving crypto world the need for effective recovery solutions is very critical. Their services are specifically tailored to assist clients dealing with fraud, LEE ULTIMATE HACKER's strength lies in its team of industry pioneers who have contributed to shaping the legal and regulatory frameworks around crypto assets, They also work closely with trusted insolvency practitioners, crypto custodians leading exchanges, and Insurance providers, LEE ULTIMATE HACKER and team works with a robust network allows them to delivery seamless end-to-end recovery service capable of handling even the most complex cases, services that are specifically tailored to assist clients dealing with fraud, Bitcoin scams and digital assets that are deliberately concealed or Misappropriated. LEE ULTIMATE HACKER strength lies in its team of industry pioneers who have contributed to shaping the legal and regulatory framework around crypto assets, from the moment assets go missing LEE ULTIMATE HACKER is dedicated to guiding clients through every step of the recovery process, they understand the urgency and emotional weight of such situations and leverage their expertise to maximize the chances of successful outcome, whether facing fraud, scams, or other crypto -related challenges, LEE ULTIMATE HACKER stands ready to help clients reclaim what is rightfully theirs.
    • I deleted wildbackport and now i get this https://mclo.gs/1Q7mHD1
    • Add the full crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here
  • Topics

×
×
  • Create New...

Important Information

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