Solved All BlockData

Discussion in 'Spigot Plugin Development' started by Gerolmed, Nov 14, 2017.

  1. What blockdata would be important to save:
    I need to save blocks like:
    • normal ex. Stone
    • blocks with rotational data like logs
    • skulls
    I alread have Material, x, y, z. But how do i save and get Rotation and skull data?
     
    #1 Gerolmed, Nov 14, 2017
    Last edited: Nov 14, 2017
  2. Code (Text):
        public static ItemStack getSkull(String url) {
            ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            if(url.isEmpty())return head;
           
           
            SkullMeta headMeta = (SkullMeta) head.getItemMeta();
            GameProfile profile = new GameProfile(UUID.randomUUID(), null);
            byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
            profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
            Field profileField = null;
            try {
                profileField = headMeta.getClass().getDeclaredField("profile");
                profileField.setAccessible(true);
                profileField.set(headMeta, profile);
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
                e1.printStackTrace();
            }
            head.setItemMeta(headMeta);
            return head;
        }
    This is a small piece of code to create a skull from an image online. All skull images are stored online, so to be able to replicate a skull you'll have to save the url of the image.

    The url is Base64 encoded in a Property object placed under the key "textures" in the GameProfile object. The GameProfile can be accessed trough reflection just as I did in the code above.
     
    • Like Like x 1
  3. You have to cast the block state to a Skull in order to get the owner (after making sure the BlockState is an instance of Sign).
    Code (Text):
    Skull skull = (Skull) block.getState();
    // skull.getOwner();
    For the orientation, this topic should help you:
    https://www.spigotmc.org/threads/determine-if-block-data-is-for-colour-or-rotation.138075/
     
    • Like Like x 1
  4. Kinda wrong. The skull skin is same as the player skin handled using the texture and thus you just need to store the encoded texture. The url method is used to fetch said texture from the mojang server but once the texture is fetched the skin can be removed from the mojang server and can still be applied to skulls or players using the encoded and signed texture.
     
    • Agree Agree x 1
  5. You're indeed correct about that, it is just easier to store a single string than an entire encoded image and I was trying to not make the process over complex because it seemed a little above his skill already
     
  6. But it creates traffic to always fetch the skin and maybe the owner changes his skin and he wants to keep the skin as it is. Depends on his intention. However traffic is always slow and might result in a time out of his servers' ip address.
     
  7. Are you kidding me... ive developed 5 Gamemodes, lobbysystems, and nicksystems as well as a bungee sys. I just didnt have to randomly gen dungeons before... so I didn't need to store more than simple block data...
     
  8. Why do you need to store the generated dungeon like this?
     
  9. I'm saving different parts to reconnect them randomly. This is just a small part of a system similar to schematics.
     

Share This Page