9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-28 03:19:15 +00:00

further improve farmlands

This commit is contained in:
XiaoMoMi
2024-09-04 23:14:46 +08:00
parent 375c9c5938
commit 956d2863b3
4 changed files with 33 additions and 6 deletions

View File

@@ -205,13 +205,18 @@ public abstract class AbstractCustomEventListener implements Listener {
public void onBlockChange(BlockFadeEvent event) {
Block block = event.getBlock();
if (block.getType() == Material.FARMLAND) {
Pos3 above = Pos3.from(block.getLocation()).add(0,1,0);
BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(block.getWorld())
.flatMap(world -> world.getBlockState(above)).ifPresent(blockState -> {
if (blockState.type() instanceof CropBlock) {
Pos3 pos3 = Pos3.from(block.getLocation());
Pos3 above = pos3.add(0,1,0);
Optional<CustomCropsWorld<?>> optionalWorld = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(block.getWorld());
if (optionalWorld.isPresent()) {
CustomCropsWorld<?> world = optionalWorld.get();
Optional<CustomCropsBlockState> optionalState = world.getBlockState(above);
if (optionalState.isPresent() && optionalState.get().type() instanceof CropBlock) {
event.setCancelled(true);
return;
}
});
this.itemManager.handlePhysicsBreak(block.getLocation(), "FARMLAND", event);
}
}
}

View File

@@ -62,6 +62,12 @@ public abstract class AbstractItemManager implements ItemManager {
Cancellable event
);
public abstract void handlePhysicsBreak(
Location location,
String brokenID,
Cancellable event
);
public abstract void handleEntityTrample(
Entity entity,
Location location,

View File

@@ -21,5 +21,6 @@ public enum BreakReason {
BREAK,
TRAMPLE,
EXPLODE,
ACTION
ACTION,
PHYSICS,
}