mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 15:09:25 +00:00
further improve farmlands
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -21,5 +21,6 @@ public enum BreakReason {
|
||||
BREAK,
|
||||
TRAMPLE,
|
||||
EXPLODE,
|
||||
ACTION
|
||||
ACTION,
|
||||
PHYSICS,
|
||||
}
|
||||
|
||||
@@ -474,6 +474,21 @@ public class BukkitItemManager extends AbstractItemManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePhysicsBreak(Location location, String brokenID, Cancellable event) {
|
||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(location.getWorld());
|
||||
if (optionalWorld.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomCropsWorld<?> world = optionalWorld.get();
|
||||
WrappedBreakEvent wrapped = new WrappedBreakEvent(null, null, world, location, brokenID, null, null, BreakReason.PHYSICS, event);
|
||||
CustomCropsBlock customCropsBlock = Registries.BLOCKS.get(brokenID);
|
||||
if (customCropsBlock != null) {
|
||||
customCropsBlock.onBreak(wrapped);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityTrample(Entity entity, Location location, String brokenID, Cancellable event) {
|
||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(entity.getWorld());
|
||||
|
||||
Reference in New Issue
Block a user