public static void playerInteract(PlayerInteractEvent event){
Player player = event.getPlayer();
if(event.getHand() == EquipmentSlot.HAND && cmdClass.stripToggle.get(player.getName())){
Material clickedBlock = event.getClickedBlock().getType();
if (clickedBlock == Material.SPRUCE_LOG) {
Location loc = event.getClickedBlock().getLocation();
Block block = loc.getBlock();
block.setType(Material.STRIPPED_SPRUCE_LOG);
player.playSound(player.getLocation(), Sound.ITEM_AXE_STRIP, 2, 1);
}
}
}```
In this code, a player can strip a log just by right/left clicking, except it doesn't keep the orientation of the log, and the new block is always facing up. How do I get the "axis" property of a block and then set it to the new block? Thanks!
#Getting direction of a block and then setting it (getAxis();)
1 messages · Page 1 of 1 (latest)
getBlockData and cast appropriately
so I get the block data and then set it with .setData()?
You’ll have to copy the property you want
Actually I think you can just setType in the block data, not sure
sorry, I'm new to spigot & java in general, what do you mean & how do I do that
NewData.setWhatever(OldData.getWhatever())
In my case that would be setAxis and getAxis, but it's giving me a compiler error when I try to use them
https://docs.improbable-game.fr/spigot-api/1.14.2/org/bukkit/block/data/Orientable.html#getAxis--
Cannot resolve method 'setAxis' in 'BlockData'
public static void playerInteract(PlayerInteractEvent event){
Player player = event.getPlayer();
if(event.getHand() == EquipmentSlot.HAND && cmdClass.stripToggle.get(player.getName())){
Material clickedBlock = event.getClickedBlock().getType();
if (clickedBlock == Material.SPRUCE_LOG) {
Location loc = event.getClickedBlock().getLocation();
Block block = loc.getBlock();
BlockData oldData = block.getBlockData();
block.setType(Material.STRIPPED_SPRUCE_LOG);
BlockData newData = loc.getBlock().getBlockData();
newData.setAxis();
player.playSound(player.getLocation(), Sound.ITEM_AXE_STRIP, 2, 1);
}
}
}```
You gotta cast
cast?
Yes
what's that
Okay, what do I cast it to? Orientable?
Yes
Block block = loc.getBlock();
BlockData oldData = block.getBlockData();
block.setType(Material.STRIPPED_SPRUCE_LOG);
BlockData newData = loc.getBlock().getBlockData();
(Orientable) newData.setAxis();
player.playSound(player.getLocation(), Sound.ITEM_AXE_STRIP, 2, 1);```
Gives same error. Did I do something wrong?