[code snippet] Recommending a server texture pack

Discussion in 'Resources' started by jtjj222, Aug 25, 2012.

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

    jtjj222

    EDIT: Bukkit now has an api for this. Player.setTexturePack("url");

    I know others have done it, but in lack of many resources on the subject, I thought I would explain how to change a client's texture pack.
    Code:java
    1.  
    2. public Packet250CustomPayload getTexturePackChangePacket(String url) {
    3.  
    4. Packet250CustomPayload packet = new Packet250CustomPayload();
    5.  
    6. int size = 16;
    7. String message = url + "\u0000" + size; //build the data
    8.  
    9. byte[] data= message.getBytes();
    10.  
    11. packet.data = data;
    12. packet.length = data.length;
    13. packet.lowPriority = false;
    14. packet.tag = "MC|TPack"; //set the channel
    15.  
    16. return packet;
    17.  
    18. }
    19.  

    This just uses the custom payload packet to recommend a texture pack to a client. There are other uses to the custom payload packet (if I find a really cool use for it, I will write another tutorial). This packet takes a channel, and some data. In this case, the channel must be MC|TPack, and the data the link to the texture pack. To use this, link craftbukkit.jar to your project, and sue the following to send the packet:
    Code:java
    1.  
    2. EntityPlayer victim = ((CraftPlayer) p).getHandle();
    3. victim.netServerHandler.sendPacket(getTexturePackChangePacket(url + p.getWorld().getName() + ".zip"));
    4.  

    You can keep changing the pack too. iZone allows custom texture packs based on regions, as an example. Anyway, I hope somebody can make use of this. :D
     
    LazyLemons and ZachBora like this.
  2. You need a client mod, correct?
     
  3. Offline

    Giant

    Incorrect, this is part of vanilla minecraft 1.3
     
Thread Status:
Not open for further replies.

Share This Page