.setChestPlate() and other armor methods cause invisible armor?

Discussion in 'Plugin Development' started by orange451, Nov 6, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    orange451

    For my plugin Squadbot, I used to use .setChestplate() and all the other armor setting methods to set the players armor (keep in mind that squadbot is a NPC player plugin). All the way up to 1.4.2 it worked perfectly. Now, however, when I try to set the armor of a NPC, the armor wont update for all the clients (unless you relog).
    So, if the NPC is wearing leather armor and I set the armor to gold, I will still see leather. If the NPC is wearing nothing and I set it to leather, I see nothing.

    Any ideas on what causes this, and any ideas on perhaps how to fix it?
     
  2. Offline

    mollekake

    well 1.4.2 is unstable and still in the beta, so there might be some bugs like this one.
     
  3. Offline

    fireblast709

  4. Offline

    orange451

    That actually worked really well :)
    Code:
        public void updateArmor() {
            for (int i = 1; i <= 4; i++)
                this.npc.updateArmor(i, getPlayer().getInventory().getArmorContents()[i-1]);
        }
    Code:
    public void updateArmor(int slot, ItemStack itm) {
    net.minecraft.server.ItemStack i = new CraftItemStack(itm).getHandle();
    Packet p = new Packet5EntityEquipment(getEntity().id, slot, i);
    sendPacket(getEntity(), p);
    }
     
    public void sendPacket(EntityLiving to, Packet p) {
    ((WorldServer) getEntity().world).tracker.a(to, p);
    }
    

    However, player.setItemInHand() doesn't update when an item is set with it.
    Any suggestions about that?
     
  5. Offline

    orange451

    Bump. Anyone?
     
  6. Offline

    md_5

    Judging by all these errors, your NPC is not implementing some crucial parts of the server.
    SetItemInhand is a Packet16 with the slot id (0-10) of the held item.
     
  7. Offline

    orange451

    There must be :p! Once I figure out what I've done (or rather, what I haven't changed in my plugin to make it compatable with MC 1.4.2), I won't need these little patches :)

    Anyways, I tried what you said:
    Code:
        public void blockItemSwitch(int slot) {
            try {
                Packet p = new Packet16BlockItemSwitch();
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                DataOutputStream dat = new DataOutputStream(bos);
                dat.write(slot);
                p.a(dat);
                sendPacket(getEntity(), p);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
     
        public void sendPacket(EntityLiving to, Packet p) {
            ((WorldServer) getEntity().world).tracker.a(to, p);
        }
    However, I get kicked for "Java.io.IOException: Bad packet id 16"

    Any ideas? (I also tried it without all that output stream stuff, same error)
     
  8. Offline

    md_5

    That code looks so incredibly wrong....
    Take a look at alta189 's NPC library
     
  9. Offline

    orange451

    In what way does it look wrong?
    It can't be the way I send the packets; that method works for every other packet I send. The only thing that is off, is the output stream I'm using (which I said I just tried because it also wasn't working without it).
     
  10. Offline

    md_5

    I can't figure out why an NPC library would need to send packets.
     
  11. Offline

    orange451

    So I can put armor on the NPC's, and put items in their inventories.
    Like I said, I need to do this until "...I figure out what I've done (or rather, what I haven't changed in my plugin to make it compatible with MC 1.4.2)".
     
  12. Offline

    md_5

    Can't you do that like all other libraries and make an npc entity and modify that....
     
  13. Offline

    orange451

    Because I want to make my own npc library :)
     
  14. Offline

    md_5

    Well use those as a base, making it deal with packets doesn't make sense....
    Look at creating your own HumanEntity and wrapping that.
     
Thread Status:
Not open for further replies.

Share This Page