From 1709dd1420b706edb8804467b2dece46501d03f6 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 8 Oct 2024 13:04:55 +0100 Subject: [PATCH] Support Datapack Biomes --- build.gradle | 4 ++- .../oribuin/fishing/api/task/SyncTicker.java | 2 +- .../java/xyz/oribuin/fishing/fish/Fish.java | 2 +- .../fishing/fish/condition/Condition.java | 6 ++--- .../fish/condition/impl/BiomeCondition.java | 26 ++++++++++++++++--- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 7cfb072..a1c9e70 100644 --- a/build.gradle +++ b/build.gradle @@ -46,8 +46,9 @@ dependencies { compileOnly "com.mojang:authlib:${authLibVersion}" compileOnly "com.github.MilkBowl:VaultAPI:${vaultVersion}" - implementation"net.objecthunter:exp4j:${exp4jVersion}" + implementation "net.objecthunter:exp4j:${exp4jVersion}" implementation "com.jeff-media:MorePersistentDataTypes:${persistentDataTypeVersion}" + implementation "xyz.oribuin:biome-adapter:1.0.1" } shadowJar { @@ -57,6 +58,7 @@ shadowJar { relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.persistentdatatypes") relocate("net.objecthunter.exp4j", "${project.group}.fishing.libs.exp4j") relocate("dev.triumphteam.gui", "${project.group}.fishing.libs.triumphgui") + relocate("xyz.oribuin.biomeadapter", "${project.group}.fishing.libs.biomeadapter") } // Include version replacement diff --git a/src/main/java/xyz/oribuin/fishing/api/task/SyncTicker.java b/src/main/java/xyz/oribuin/fishing/api/task/SyncTicker.java index 7981f78..028cbfa 100644 --- a/src/main/java/xyz/oribuin/fishing/api/task/SyncTicker.java +++ b/src/main/java/xyz/oribuin/fishing/api/task/SyncTicker.java @@ -8,7 +8,7 @@ public interface SyncTicker { * The method that should run everytime the task is ticked, * this method will be ran synchronously */ - void tickAsync(); + void tickSync(); /** * The delay between each tick, Set to Duration#ZERO for no delay diff --git a/src/main/java/xyz/oribuin/fishing/fish/Fish.java b/src/main/java/xyz/oribuin/fishing/fish/Fish.java index cde5dbc..095e35c 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/Fish.java +++ b/src/main/java/xyz/oribuin/fishing/fish/Fish.java @@ -69,7 +69,7 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { // Catch Conditions Condition condition = new Condition(); - condition.biomes(FishUtils.getEnumList(Biome.class, config.getStringList("biomes"))); + condition.biomes(config.getStringList("biomes")); condition.weather(FishUtils.getEnum(Weather.class, config.getString("weather"))); condition.time(FishUtils.getEnum(Time.class, config.getString("time"))); condition.worlds(config.getStringList("worlds")); diff --git a/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java b/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java index 242dbe6..d17316e 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java +++ b/src/main/java/xyz/oribuin/fishing/fish/condition/Condition.java @@ -13,7 +13,7 @@ */ public class Condition { - private List biomes = new ArrayList<>(); + private List biomes = new ArrayList<>(); private Weather weather = null; private Time time = Time.ALL_DAY; private List worlds = new ArrayList<>(); @@ -24,11 +24,11 @@ public class Condition { private Integer lightLevel = null; private boolean boatFishing = false; - public List biomes() { + public List biomes() { return biomes; } - public Condition biomes(List biomes) { + public Condition biomes(List biomes) { this.biomes = biomes; return this; } diff --git a/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BiomeCondition.java b/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BiomeCondition.java index 4df4f14..31ce992 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BiomeCondition.java +++ b/src/main/java/xyz/oribuin/fishing/fish/condition/impl/BiomeCondition.java @@ -1,12 +1,16 @@ package xyz.oribuin.fishing.fish.condition.impl; -import org.bukkit.block.Biome; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import xyz.oribuin.biomeadapter.BiomeAdapter; +import xyz.oribuin.biomeadapter.api.BiomeHandler; +import xyz.oribuin.biomeadapter.api.BiomeWrapper; import xyz.oribuin.fishing.api.condition.CatchCondition; import xyz.oribuin.fishing.fish.Fish; +import java.util.List; + public class BiomeCondition implements CatchCondition { /** @@ -33,8 +37,24 @@ public boolean shouldRun(Fish fish) { */ @Override public boolean check(Fish fish, Player player, ItemStack rod, FishHook hook) { - Biome biome = hook.getLocation().getBlock().getBiome(); - return fish.condition().biomes().contains(biome); + BiomeHandler handler = BiomeAdapter.get(); + List biomes = fish.condition().biomes(); + boolean datapackSupported = handler != null && handler.getNoiseBiome(hook.getLocation()) != null; + + // If the NMS Version is not supported, use bukkit's default biome check + if (!datapackSupported) { + return biomes.contains(hook.getLocation().getBlock().getBiome().name()); + } + + BiomeWrapper biomeWrapper = handler.getNoiseBiome(hook.getLocation()); + if (biomeWrapper == null) return false; + + // If the biome is null, return false + String[] split = biomeWrapper.getKey().getNamespace().split(":"); + if (split.length != 2) return false; // If the namespace is not valid, return false + + // Support for "plains" or "minecraft:plains" + return biomes.contains(split[0]) || biomes.contains(biomeWrapper.getKey().namespace()); } }