use of com.easterlyn.util.BlockUpdateManager in project Easterlyn by Easterlyn.
the class EffectTunnelBore method applyEffect.
@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
if (!(event instanceof BlockBreakEvent) || event instanceof IndirectBreakEvent) {
return;
}
BlockBreakEvent breakEvent = (BlockBreakEvent) event;
Player player = breakEvent.getPlayer();
if (player.isSneaking()) {
// Sneak to mine single blocks
return;
}
Block block = breakEvent.getBlock();
if (!BlockUtil.isCorrectTool(player.getInventory().getItemInMainHand(), breakEvent.getBlock().getType())) {
// Require correct tool used
return;
}
RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
/*
* Forgiveness of .25 hardness allows indirect breaking of most common related materials
* while not excessively increasing risk of accidents inside builds. Allows for mining gravel
* via sand and dirt, etc.
*/
float hardness = block.getType().getHardness() + 0.25F;
for (BlockFace yLevel : levels) {
if (block.getY() == 0 && yLevel == BlockFace.DOWN) {
continue;
}
Block relativeCenter = block.getRelative(yLevel);
if (yLevel != BlockFace.SELF) {
if (handleBlock(hardness, relativeCenter, player, budManager)) {
return;
}
}
for (BlockFace face : faces) {
if (handleBlock(hardness, relativeCenter.getRelative(face), player, budManager)) {
return;
}
}
}
player.updateInventory();
}
use of com.easterlyn.util.BlockUpdateManager in project Easterlyn by Easterlyn.
the class EffectAdjacentBlockModifier method applyEffect.
@Override
public void applyEffect(@NotNull LivingEntity entity, int level, @Nullable Event event) {
if (!(event instanceof BlockBreakEvent)) {
return;
}
RegisteredServiceProvider<EasterlynCore> registration = getPlugin().getServer().getServicesManager().getRegistration(EasterlynCore.class);
if (registration == null) {
return;
}
BlockUpdateManager budManager = registration.getProvider().getBlockUpdateManager();
BlockBreakEvent breakEvent = (BlockBreakEvent) event;
Player player = breakEvent.getPlayer();
int currentCount = 0;
for (BlockFace face : faces) {
Block relative = breakEvent.getBlock().getRelative(face);
if (handleAdjacentBlock(player, relative, currentCount)) {
budManager.queueBlock(relative);
}
}
}
Aggregations