Jump to content

Recommended Posts

Posted

Hi everyone,

 

I have created a gui where I have the players inventory and a custom inventory. I have run into the problem where If I click on an item which is inside a player inventory slot I cant seem to move it to my other inventory slots (not even from one player inventory slot to the next) and Im not sure what the issue is? here is my code:

 

Gui class

 

  Reveal hidden contents

 

 

Container Class

 

  Reveal hidden contents

 

 

Inventory Class

 

  Reveal hidden contents

 

 

gui Handler class (I removed the other guis cause I have alot of them in there this is just the stuff pertaining to my custom one with the mouse issues)

 

  Reveal hidden contents
Posted

Key is pressed

public class KeyMiney extends KeyBinding
{
private static int index= 1;	

public KeyMiney()
{
	super("key.keyMoney", Keyboard.KEY_M, "key.categories.custommod");
}

@SubscribeEvent
public void keyDown(InputEvent.KeyInputEvent event)
{
	if (isPressed())  {
		PacketOverlord.sendToServer(new PacketC2SMineyKeyPressed());
		}
}
}

 

that key press sends a packet to server which then sends a packet back to client that opens the gui

public class PacketC2SMineyKeyPressed extends AbstractMessageToServer<PacketC2SMineyKeyPressed> {
public PacketC2SMineyKeyPressed() {}

@Override
protected void read(PacketBuffer buffer) throws IOException {
}

@Override
protected void write(PacketBuffer buffer) throws IOException {
}

@Override
public void process(EntityPlayer player, Side side) {
		PacketOverlord.sendTo(new PacketS2COpenMineyGui((EntityPlayer) player, (int)player.posX, (int)player.posY, (int)player.posZ),(EntityPlayerMP) player);
}

}

 

packet that actually opens the gui client side

public class PacketS2COpenMineyGui extends AbstractMessageToClient<PacketS2COpenMineyGui> {
int xPos;
int yPos;
int zPos;

public PacketS2COpenMineyGui() {}
public PacketS2COpenMineyGui(EntityPlayer player, int xPos, int yPos, int zPos) {

	this.xPos = xPos;
	this.yPos = yPos;
	this.zPos = zPos;

}

@Override
protected void read(PacketBuffer buffer) throws IOException {
xPos = buffer.readInt();
yPos = buffer.readInt();
zPos = buffer.readInt();

}

@Override
protected void write(PacketBuffer buffer) throws IOException {
	buffer.writeInt(xPos);
	buffer.writeInt(yPos);
	buffer.writeInt(zPos);
}

@Override
public void process(EntityPlayer player, Side side) {

   if(player.worldObj.isRemote){ //player is only the client side player here using if(!player.worldObj.isRemote) does not work nothing is called

    player.openGui(CustomMod.instance, 9, player.worldObj, xPos, yPos, zPos);
   }
   }
   }

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.