mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 14:16:45 +01:00
add saturation support
This commit is contained in:
parent
d185c7538c
commit
adc480fd03
@ -51,6 +51,8 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EntityListener implements Listener {
|
||||
private final mcMMO pluginRef;
|
||||
private final @NotNull AbstractPersistentDataLayer persistentDataLayer;
|
||||
@ -893,6 +895,9 @@ public class EntityListener implements Listener {
|
||||
int newFoodLevel = event.getFoodLevel();
|
||||
int foodChange = newFoodLevel - currentFoodLevel;
|
||||
|
||||
float currentSaturationLevel = player.getSaturation();
|
||||
float newSaturationLevel = 0.0F; //No support in spigot API, use saturation table
|
||||
|
||||
if (foodChange <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -909,6 +914,12 @@ public class EntityListener implements Listener {
|
||||
return; //Not Food
|
||||
}
|
||||
|
||||
Float foodSaturation = ItemUtils.getFoodSaturation(foodInHand);
|
||||
|
||||
if (foodSaturation != null) {
|
||||
newSaturationLevel = currentSaturationLevel + foodSaturation;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some foods have 3 ranks Some foods have 5 ranks The number of ranks
|
||||
* is based on how 'common' the item is We can adjust this quite easily
|
||||
@ -917,64 +928,32 @@ public class EntityListener implements Listener {
|
||||
|
||||
//Hacky 1.17 support
|
||||
if(foodInHand.getKey().getKey().equalsIgnoreCase("glow_berries")) {
|
||||
newSaturationLevel = currentSaturationLevel + 0.4F;
|
||||
if (Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_FARMERS_DIET)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(newFoodLevel));
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDietHunger(newFoodLevel));
|
||||
player.setSaturation(UserManager.getPlayer(player).getHerbalismManager().farmersDietSaturation(newSaturationLevel));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (foodInHand) {
|
||||
case BAKED_POTATO: /*
|
||||
* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @
|
||||
* 1000
|
||||
*/
|
||||
case BEETROOT:
|
||||
case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
case CARROT: /*
|
||||
* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @
|
||||
* 1000
|
||||
*/
|
||||
case GOLDEN_CARROT: /*
|
||||
* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @
|
||||
* 1000
|
||||
*/
|
||||
case MUSHROOM_STEW: /*
|
||||
* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @
|
||||
* 1000
|
||||
*/
|
||||
case PUMPKIN_PIE: /*
|
||||
* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @
|
||||
* 1000
|
||||
*/
|
||||
case BAKED_POTATO, BEETROOT, BREAD, CARROT, GOLDEN_CARROT, MUSHROOM_STEW, PUMPKIN_PIE, COOKIE, MELON_SLICE, POISONOUS_POTATO, POTATO -> {
|
||||
if (Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_FARMERS_DIET)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(newFoodLevel));
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDietHunger(newFoodLevel));
|
||||
player.setSaturation(UserManager.getPlayer(player).getHerbalismManager().farmersDietSaturation(newSaturationLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
case MELON_SLICE: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POISONOUS_POTATO: /*
|
||||
* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER
|
||||
* @ 1000
|
||||
*/
|
||||
case POTATO: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
if (Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_FARMERS_DIET)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(newFoodLevel));
|
||||
}
|
||||
return;
|
||||
case COD:
|
||||
case SALMON:
|
||||
case TROPICAL_FISH:
|
||||
case COOKED_COD:
|
||||
case COOKED_SALMON:
|
||||
|
||||
}
|
||||
case COD, SALMON, TROPICAL_FISH, COOKED_COD, COOKED_SALMON -> {
|
||||
if (Permissions.isSubSkillEnabled(player, SubSkillType.FISHING_FISHERMANS_DIET)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(newFoodLevel));
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDietHunger(newFoodLevel));
|
||||
player.setSaturation(UserManager.getPlayer(player).getFishingManager().handleFishermanDietSaturation(newSaturationLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,14 +213,25 @@ public class FishingManager extends SkillManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Fisherman's Diet ability
|
||||
* Handle the Fisherman's Diet ability about hunger
|
||||
*
|
||||
* @param eventFoodLevel The initial change in hunger from the event
|
||||
*
|
||||
* @return the modified change in hunger for the event
|
||||
*/
|
||||
public int handleFishermanDiet(int eventFoodLevel) {
|
||||
return SkillUtils.handleFoodSkills(getPlayer(), eventFoodLevel, SubSkillType.FISHING_FISHERMANS_DIET);
|
||||
public int handleFishermanDietHunger(int eventFoodLevel) {
|
||||
return SkillUtils.handleFoodSkillsHunger(getPlayer(), eventFoodLevel, SubSkillType.FISHING_FISHERMANS_DIET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Fisherman's Diet ability about saturation
|
||||
*
|
||||
* @param eventSaturationLevel The initial change in saturation from the event
|
||||
*
|
||||
* @return the modified change in saturation for the event
|
||||
*/
|
||||
public float handleFishermanDietSaturation(float eventSaturationLevel) {
|
||||
return SkillUtils.handleFoodSkillsSaturation(getPlayer(), eventSaturationLevel, SubSkillType.FISHING_FISHERMANS_DIET);
|
||||
}
|
||||
|
||||
public void iceFishing(FishHook hook, Block block) {
|
||||
|
@ -166,13 +166,23 @@ public class HerbalismManager extends SkillManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Farmer's Diet ability
|
||||
* Handle the Farmer's Diet ability about hunger
|
||||
*
|
||||
* @param eventFoodLevel The initial change in hunger from the event
|
||||
* @return the modified change in hunger for the event
|
||||
*/
|
||||
public int farmersDiet(int eventFoodLevel) {
|
||||
return SkillUtils.handleFoodSkills(getPlayer(), eventFoodLevel, SubSkillType.HERBALISM_FARMERS_DIET);
|
||||
public int farmersDietHunger(int eventFoodLevel) {
|
||||
return SkillUtils.handleFoodSkillsHunger(getPlayer(), eventFoodLevel, SubSkillType.HERBALISM_FARMERS_DIET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Farmer's Diet ability about saturation
|
||||
*
|
||||
* @param eventSaturationLevel The initial change in saturation from the event
|
||||
* @return the modified change in saturation for the event
|
||||
*/
|
||||
public float farmersDietSaturation(float eventSaturationLevel) {
|
||||
return SkillUtils.handleFoodSkillsSaturation(getPlayer(), eventSaturationLevel, SubSkillType.HERBALISM_FARMERS_DIET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public final class ItemUtils {
|
||||
@ -30,6 +31,51 @@ public final class ItemUtils {
|
||||
*/
|
||||
private ItemUtils() {}
|
||||
|
||||
private static final HashMap<Material, Float> foodSaturation = new HashMap<>();
|
||||
|
||||
static {
|
||||
foodSaturation.put(Material.APPLE, 2.4F);
|
||||
foodSaturation.put(Material.BAKED_POTATO, 6.0F);
|
||||
foodSaturation.put(Material.BEETROOT, 1.2F);
|
||||
foodSaturation.put(Material.BEETROOT_SOUP, 7.2F);
|
||||
foodSaturation.put(Material.BREAD, 6.0F);
|
||||
foodSaturation.put(Material.CAKE, 0.4F);
|
||||
foodSaturation.put(Material.CARROT, 3.6F);
|
||||
foodSaturation.put(Material.CHORUS_FRUIT, 2.4F);
|
||||
foodSaturation.put(Material.COOKED_BEEF, 12.8F);
|
||||
foodSaturation.put(Material.COOKED_CHICKEN, 7.2F);
|
||||
foodSaturation.put(Material.COOKED_COD, 6.0F);
|
||||
foodSaturation.put(Material.COOKED_MUTTON, 9.6F);
|
||||
foodSaturation.put(Material.COOKED_PORKCHOP, 12.8F);
|
||||
foodSaturation.put(Material.COOKED_RABBIT, 6.0F);
|
||||
foodSaturation.put(Material.COOKED_SALMON, 9.6F);
|
||||
foodSaturation.put(Material.COOKIE, 0.4F);
|
||||
foodSaturation.put(Material.DRIED_KELP, 0.6F);
|
||||
foodSaturation.put(Material.ENCHANTED_GOLDEN_APPLE, 9.6F);
|
||||
foodSaturation.put(Material.HONEY_BOTTLE, 1.2F);
|
||||
foodSaturation.put(Material.GOLDEN_APPLE, 9.6F);
|
||||
foodSaturation.put(Material.GOLDEN_CARROT, 14.4F);
|
||||
foodSaturation.put(Material.MELON_SLICE, 1.2F);
|
||||
foodSaturation.put(Material.MUSHROOM_STEW, 7.2F);
|
||||
foodSaturation.put(Material.POISONOUS_POTATO, 1.2F);
|
||||
foodSaturation.put(Material.POTATO, 0.6F);
|
||||
foodSaturation.put(Material.PUFFERFISH, 0.2F);
|
||||
foodSaturation.put(Material.PUMPKIN_PIE, 4.8F);
|
||||
foodSaturation.put(Material.RABBIT_STEW, 12.0F);
|
||||
foodSaturation.put(Material.BEEF, 1.8F);
|
||||
foodSaturation.put(Material.CHICKEN, 1.2F);
|
||||
foodSaturation.put(Material.COD, 0.4F);
|
||||
foodSaturation.put(Material.MUTTON, 1.2F);
|
||||
foodSaturation.put(Material.PORKCHOP, 1.8F);
|
||||
foodSaturation.put(Material.RABBIT, 1.8F);
|
||||
foodSaturation.put(Material.SALMON, 0.4F);
|
||||
foodSaturation.put(Material.ROTTEN_FLESH, 0.8F);
|
||||
foodSaturation.put(Material.SPIDER_EYE, 3.2F);
|
||||
foodSaturation.put(Material.SUSPICIOUS_STEW, 7.2F);
|
||||
foodSaturation.put(Material.SWEET_BERRIES, 0.4F);
|
||||
foodSaturation.put(Material.TROPICAL_FISH, 0.2F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the item is a bow.
|
||||
*
|
||||
@ -650,4 +696,8 @@ public final class ItemUtils {
|
||||
int randomIndex = Misc.getRandom().nextInt(enchantmentWrappers.size());
|
||||
return enchantmentWrappers.get(randomIndex);
|
||||
}
|
||||
|
||||
public static @Nullable Float getFoodSaturation(@NotNull Material food) {
|
||||
return foodSaturation.get(food);
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public final class SkillUtils {
|
||||
* Others
|
||||
*/
|
||||
|
||||
public static int handleFoodSkills(Player player, int eventFoodLevel, SubSkillType subSkillType) {
|
||||
public static int handleFoodSkillsHunger(Player player, int eventFoodLevel, SubSkillType subSkillType) {
|
||||
int curRank = RankUtils.getRank(player, subSkillType);
|
||||
|
||||
int currentFoodLevel = player.getFoodLevel();
|
||||
@ -90,6 +90,17 @@ public final class SkillUtils {
|
||||
return currentFoodLevel + foodChange;
|
||||
}
|
||||
|
||||
public static float handleFoodSkillsSaturation(Player player, float eventSaturationLevel, SubSkillType subSkillType) {
|
||||
int curRank = RankUtils.getRank(player, subSkillType);
|
||||
|
||||
float currentSaturationLevel = player.getSaturation();
|
||||
float saturationChange = eventSaturationLevel - currentSaturationLevel;
|
||||
|
||||
saturationChange += curRank;
|
||||
|
||||
return currentSaturationLevel + saturationChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time remaining until the cooldown expires.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user