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



  • Create New...

Important Information

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