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

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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