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

fix item detection

This commit is contained in:
XiaoMoMi
2024-03-29 13:09:20 +08:00
parent 3e7633a4b0
commit c82244188e
12 changed files with 53 additions and 34 deletions

View File

@@ -17,6 +17,7 @@
package net.momirealms.customcrops.api.mechanic.requirement;
import net.momirealms.customcrops.api.util.LocationUtils;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -35,7 +36,7 @@ public class State {
public State(Player player, ItemStack itemInHand, @NotNull Location location) {
this.player = player;
this.itemInHand = itemInHand;
this.location = location.toBlockLocation();
this.location = LocationUtils.toBlockLocation(location);
this.args = new HashMap<>();
if (player != null) {
setArg("{player}", player.getName());

View File

@@ -19,6 +19,7 @@ package net.momirealms.customcrops.api.util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
public class LocationUtils {
@@ -41,4 +42,22 @@ public class LocationUtils {
public static Location getAnyLocationInstance() {
return new Location(Bukkit.getWorlds().get(0), 0, 64, 0);
}
@NotNull
public static Location toBlockLocation(Location location) {
Location blockLoc = location.clone();
blockLoc.setX(location.getBlockX());
blockLoc.setY(location.getBlockY());
blockLoc.setZ(location.getBlockZ());
return blockLoc;
}
@NotNull
public static Location toCenterLocation(Location location) {
Location centerLoc = location.clone();
centerLoc.setX(location.getBlockX() + 0.5);
centerLoc.setY(location.getBlockY() + 0.5);
centerLoc.setZ(location.getBlockZ() + 0.5);
return centerLoc;
}
}