#block data

1 messages · Page 1 of 1 (latest)

mortal basin
#

How do I do this exactly? I tried it

        Block b = e.getBlock();
        if(b.getType() == Material.JACK_O_LANTERN) {
            Location l = b.getLocation();
            ItemStack i = new ItemStack(Material.TORCH);
            BlockData bData = b.getBlockData().clone();

            e.setCancelled(true);
            b.setBlockData(bData);
            b.setType(Material.CARVED_PUMPKIN);
            e.setDropItems(false);
            b.getWorld().dropItemNaturally(l,i);
trim meadow
#

You need to set the block data after setting the type

#

Also, block data also contains the material

mortal basin
#

then how do i copy the face of the original block?

trim meadow
#

You'd probably want something like

Orientable orientation = (Orientable) block.getBlockData();
block.setType(Material.MAT);
Orientable newData = (Orientable) block.getBlockData();
newData.setAxis(orientation.getAxis());
block.setBlockData(newData);
mortal basin
#

oh ok

#

what exactly is the (Orientable) cast for?

trim meadow
#

just omit and you'll see

mortal basin
#

i get this error

#

ava.lang.ClassCastException: class org.bukkit.craftbukkit.v1_18_R1.block.impl.CraftPumpkinCarved cannot be cast to class org.bukkit.block.data.Orientable (org.bukkit.craftbukkit.v1_18_R1.block.impl.CraftPumpkinCarved and org.bukkit.block.data.Orientable are in unnamed module of loader java.net.URLClassLoader @ba8a1dc)

trim meadow
#

smh

#

why does everything need to be complicated there days

#

It's

Directional orientation = (Directional) block.getBlockData();
block.setType(Material.MAT);
Directional newData = (Directional) block.getBlockData();
newData.setFacing(orientation.getFacing());
block.setBlockData(newData);

then

mortal basin
#

thank you so much it worked