Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Send itemstack to server


Samistine
 Share

Recommended Posts

How would i get the code below, to work on vanilla minecraft servers? It seems to only work in singleplayer mode. Basically what i am asking, is how do I send an itemstack to a server

 

@SubscribeEvent

public void onClick(PlayerInteractEvent e) {

if (e.action == Action.RIGHT_CLICK_AIR && e.entity instanceof EntityPlayer) {

EntityPlayer player = (EntityPlayer) e.entity;

ItemStack item = player.getHeldItem();

item.setTagCompound(new NBTTagCompound());

NBTTagCompound tag = item.getTagCompound();

 

tag.setTag("BlockEntityTag", tag.copy());

tag.setTag("display", tag.copy());

 

NBTTagCompound tag3 = tag.getCompoundTag("display");

tag3.setString("Name", "HELLO");

Link to comment
Share on other sites

"Works only on singleplayer" makes no sense. If that is the case, you are doing something fundamentally wrong. Singleplayer is the same as multiplayer, except with one player only. It runs a server, too.

You need to check that you are only doing this on the server (world.isRemote is false). Your mod will need to be installed on servers, too.

Link to comment
Share on other sites

Okay thank you for that, but it still does not seem to work, fully, on a vanilla server:

 

  public void event(PlayerInteractEvent e) {

        System.out.println("test");

        ItemStack item = new ItemStack(Items.sign);

        item.setTagCompound(new NBTTagCompound());

        NBTTagCompound tag = item.getTagCompound();

 

        tag.setTag("BlockEntityTag", tag.copy());

        NBTTagCompound blockEntityTag = tag.getCompoundTag("BlockEntityTag");

       

       

        blockEntityTag.setString("id", "Sign");

        blockEntityTag.setString("Text1", "Line 1");

        blockEntityTag.setString("Text2", "Line 2");

        blockEntityTag.setString("Text3", "Line 3");

       

        cl.mc.playerController.sendSlotPacket(item, 0 *woops I changed it to 20*);

 

Issue is, the console in Eclipse, never spits out "test" with the code above ^. However when I just spawn in, a plain old, itemstack it spits out "test".

 

  (Plain old Itemstack  :))

  public void event(PlayerInteractEvent e) {

        System.out.println("test");

        ItemStack item = new ItemStack(Items.sign);

        cl.mc.playerController.sendSlotPacket(item, 20);

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
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.

 Share



×
×
  • Create New...

Important Information

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