Created
July 28, 2021 10:07
-
-
Save LukeOnuke/348f2b4d2ca23c522131290eb41173a2 to your computer and use it in GitHub Desktop.
Spi.gt go brrrrt LeafDecay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EventHandler(priority = EventPriority.MONITOR) | |
public void onBlockBreak(BlockBreakEvent event) { | |
final Block block = event.getBlock(); | |
int delay; | |
if (Tag.LEAVES.isTagged(block.getType())){ | |
delay = 2; | |
}else{ | |
return; | |
} | |
if(Tag.LOGS.isTagged(block.getType())){ | |
delay = 5; | |
}else{ | |
return; | |
} | |
FastLeafDecay.onBreak(block, delay); | |
} | |
public static boolean decayLeaf(Block block){ | |
/* | |
* Before casting to specific types you gotta use block#getBlockData(), and then clone it because sometimes | |
* It will return CraftBlockData witch will mess up the cast but CraftBlockData#clone still returns BlockData. | |
* Totally didn't waste two hours trying to figure that out. Never (╯°□°)╯︵ ┻━┻ | |
* //TODO : Fix it deciding to commit die | |
* Still doesnt work -Luke | |
* */ | |
Leaves leaves = (Leaves) block.getBlockData(); | |
if (leaves.isPersistent()) { | |
return false; | |
} | |
if(leaves.getDistance() > 6){ | |
block.breakNaturally(); | |
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 0.05f, 1.2f); | |
block.getWorld().spawnParticle(Particle.BLOCK_DUST, block.getLocation().add(0.5, 0.5, 0.5), 8, 0.2, 0.2, 0.2, 0, block.getType().createBlockData()); | |
//To make this recursive like we will call the LeafDecayEvent wich already exists on every leaf decay. | |
LeavesDecayEvent event = new LeavesDecayEvent(block); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment