Placing a skull in 1.12 and 1.13

Discussion in 'Spigot Plugin Development' started by Hex_27, Jul 23, 2018.

  1. Code (Text):
    public void placeSkullBlock(Block turretBlock, String owner){
            Skull skull = (Skull) turretBlock.getState();
            //Rotatable r = (Rotatable) turretBlock.getBlockData();\
    This code places a skull facing north on the floor for 1.13, but will place a wall skull in 1.12. However, setData for 1.12 is removed in 1.13, and Rotatable in 1.13 doesn't exist in 1.12. It's a mess of deprecation and different methods, and the javadocs don't shed much light on this. What's the proper way to set a ground skull with a skin that works across versions?
  2. In 1.13, the material of a skeleton skull placed on the ground is a SKELETON_SKULL, whilst the material of a skeleton skull placed on a "wall" is a SKELETON_WALL_SKULL.

    If you want a player head however, it's PLAYER_HEAD and PLAYER_WALL_HEAD.

    As for it working across versions... if you use NMS at all, then you should have separate classes for each version. For 1.12.2 classes and below, use the following method to get the old material:

    Code (Text):
    Material.getMaterial("SKULL_ITEM"); // In case it doesn't let you use Material.SKULL_ITEM
    Whereas for 1.13, just use the materials mentioned before.

    If I've misunderstood anything just say so. I'm still trying to wake up - again.
  3. Yeah, I ended up going with different classes for different sets of versions. I was wondering if there was a set way that directly works for both versions.
  4. Code (Java):
    try {
                Block.class.getMethod("setData", byte.class).invoke(turretBlock, (byte) 1);
            } catch (IllegalAccessException | IllegalArgumentException
                    | InvocationTargetException | NoSuchMethodException
                    | SecurityException e) {
    This current reflection code doesn't do anything, and I can't seem to have both spigot jars as external jars, so I can't call setData at all either
  5. Found the issue, I was calling setData after getting the skull's state