mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-20 15:39:21 +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) {
|
public void onBlockChange(BlockFadeEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (block.getType() == Material.FARMLAND) {
|
if (block.getType() == Material.FARMLAND) {
|
||||||
Pos3 above = Pos3.from(block.getLocation()).add(0,1,0);
|
Pos3 pos3 = Pos3.from(block.getLocation());
|
||||||
BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(block.getWorld())
|
Pos3 above = pos3.add(0,1,0);
|
||||||
.flatMap(world -> world.getBlockState(above)).ifPresent(blockState -> {
|
Optional<CustomCropsWorld<?>> optionalWorld = BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(block.getWorld());
|
||||||
if (blockState.type() instanceof CropBlock) {
|
if (optionalWorld.isPresent()) {
|
||||||
|
CustomCropsWorld<?> world = optionalWorld.get();
|
||||||
|
Optional<CustomCropsBlockState> optionalState = world.getBlockState(above);
|
||||||
|
if (optionalState.isPresent() && optionalState.get().type() instanceof CropBlock) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.itemManager.handlePhysicsBreak(block.getLocation(), "FARMLAND", event);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ public abstract class AbstractItemManager implements ItemManager {
|
|||||||
Cancellable event
|
Cancellable event
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public abstract void handlePhysicsBreak(
|
||||||
|
Location location,
|
||||||
|
String brokenID,
|
||||||
|
Cancellable event
|
||||||
|
);
|
||||||
|
|
||||||
public abstract void handleEntityTrample(
|
public abstract void handleEntityTrample(
|
||||||
Entity entity,
|
Entity entity,
|
||||||
Location location,
|
Location location,
|
||||||
|
|||||||
@@ -21,5 +21,6 @@ public enum BreakReason {
|
|||||||
BREAK,
|
BREAK,
|
||||||
TRAMPLE,
|
TRAMPLE,
|
||||||
EXPLODE,
|
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
|
@Override
|
||||||
public void handleEntityTrample(Entity entity, Location location, String brokenID, Cancellable event) {
|
public void handleEntityTrample(Entity entity, Location location, String brokenID, Cancellable event) {
|
||||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(entity.getWorld());
|
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(entity.getWorld());
|
||||||
|
|||||||
Reference in New Issue
Block a user