Skip to content

Commit

Permalink
Support Datapack Biomes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Oct 8, 2024
1 parent 8911e46 commit 1709dd1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/oribuin/fishing/api/task/SyncTicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/oribuin/fishing/fish/Fish.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class Condition {

private List<Biome> biomes = new ArrayList<>();
private List<String> biomes = new ArrayList<>();
private Weather weather = null;
private Time time = Time.ALL_DAY;
private List<String> worlds = new ArrayList<>();
Expand All @@ -24,11 +24,11 @@ public class Condition {
private Integer lightLevel = null;
private boolean boatFishing = false;

public List<Biome> biomes() {
public List<String> biomes() {
return biomes;
}

public Condition biomes(List<Biome> biomes) {
public Condition biomes(List<String> biomes) {
this.biomes = biomes;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

/**
Expand All @@ -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<String> 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());
}

}

0 comments on commit 1709dd1

Please sign in to comment.