Solved Get MONSTER_EGG Entity Name

Discussion in 'Plugin Development' started by EnZiGuRi, Aug 12, 2016.

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

    EnZiGuRi

    Hello, Iam trying to get a MONSTER_EGG creature type with java. With some searches, i thing Eggs have now a NBT tag. Iam novice to java and i can't find a way of getting the creature type to store it on a MySQL database to get it later on a different server.

    Here is the code.

    Thanks.

    Code:
    if (itemStack.getType() == Material.MONSTER_EGG) {
                    String EggType = String.valueOf(itemStack.getItemMeta());
                    serializedItemStack = serializedItemStack + ":d@"
                            + EggType;
                    //Debug
                    player.sendMessage(ChatColor.GREEN
                            + serializedItemStack.toString());
                }
    
     
    Last edited: Aug 13, 2016
  2. Offline

    HeartandSoul

    Why would you store it like that? Just curious.

    Just asking, why are you putting in the variable twice?
    It should be
    And: Where does "itemStack" come from?
    Aside. If you're making a plugin to serialize the NBT value of monster eggs, I don't even know if there are NBT values. Iv'e never tried.

    And storing in an SQL server? You have one set up, right? Just asking.
     
  3. Offline

    Zombie_Striker

    @EnZiGuRi
    I currently cannot understand what you are doing in your code, as a lot of it should not work/ should produce results I that can't image you would want. For what you want, get the ItemMeta, check if the meta is an instance of SpawnEgg, and then use (SpawnEgg).getType() to get the EntityType of the egg.
     
  4. Offline

    EnZiGuRi

    @HeardandSoul
    Code:
    serializedItemStack = serializedItemStack + ":d@" + EggType;
    will output "Item@383:d@<eggtype>". This will fill a single database row named item.

    @Zombie_Striker

    Can you explain me how to do it? iam currently learning java and i can't figure out how to do it.

    About the .getType(), i get this output: UNSPECIFIC_META:{meta-type=UNSPECIFIC, internal=H4sIAAAAAAAAAONiYOBi4HTNK8ksqQxJTOdgYMpMYWB3LkpNLUgtYmAAAGXHBBMfAAAA}

    How can i know from here that this is a creeper spawn egg?

    Thanks.

    EDIT:

    I got it. Here is my output: "Item@383:d@Creeper".

    Iam sharing the code for who want something like this.

    Thanks for the help anyways.

    Code:
    if (itemStack.getType() == Material.MONSTER_EGG) {
                  
                    net.minecraft.server.v1_10_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
    
                    if (nmsStack.hasTag()) {
                      NBTTagCompound tag = nmsStack.getTag();
                      NBTTagCompound entityTag = tag.getCompound("EntityTag");
                      if (entityTag.hasKey("id")) {
                        String EggEntity = entityTag.getString("id");
                        serializedItemStack = serializedItemStack + ":d@"
                                    + EggEntity;
                            //Debug
                            player.sendMessage(ChatColor.GREEN
                                    + EggEntity.toString());
                      }
                    }
                  }
    
     
    Last edited: Aug 13, 2016
Thread Status:
Not open for further replies.

Share This Page