Skip to content

Commit

Permalink
feat: support 1.21.3 (partially)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Dec 1, 2024
1 parent df82fc6 commit a42a5a2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package city.norain.slimefun4.compatibillty;

import city.norain.slimefun4.SlimefunExtended;
import lombok.experimental.UtilityClass;
import org.bukkit.attribute.Attribute;

@UtilityClass
public class VersionedAttribute {
public static Attribute getMaxHealth() {
if (SlimefunExtended.getMinecraftVersion().isAtLeast(1, 21, 3)) {
return Attribute.valueOf("MAX_HEALTH");
} else {
return Attribute.valueOf("GENERIC_MAX_HEALTH");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.medical;

import city.norain.slimefun4.compatibillty.VersionedAttribute;
import io.github.bakedlibs.dough.items.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -48,7 +49,7 @@ public ItemUseHandler getItemHandler() {
// Player is neither burning nor injured
if (p.getFireTicks() <= 0
&& p.getHealth()
>= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
>= p.getAttribute(VersionedAttribute.getMaxHealth()).getValue()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.medical;

import city.norain.slimefun4.compatibillty.VersionedAttribute;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.ItemHandler;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void clearNegativeEffects(@Nonnull LivingEntity n) {
*/
public void heal(@Nonnull LivingEntity n) {
double health = n.getHealth() + healAmount;
double maxHealth = n.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double maxHealth = n.getAttribute(VersionedAttribute.getMaxHealth()).getValue();
n.setHealth(Math.min(health, maxHealth));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.medical;

import city.norain.slimefun4.compatibillty.VersionedAttribute;
import io.github.bakedlibs.dough.items.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -36,7 +37,7 @@ public Splint(
// Player is neither burning nor injured
if (p.getFireTicks() <= 0
&& p.getHealth()
>= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
>= p.getAttribute(VersionedAttribute.getMaxHealth()).getValue()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.weapons;

import city.norain.slimefun4.compatibillty.VersionedAttribute;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -42,7 +43,7 @@ public VampireBlade(ItemGroup itemGroup, SlimefunItemStack item, RecipeType reci
if (ThreadLocalRandom.current().nextInt(100) < getChance()) {
SoundEffect.VAMPIRE_BLADE_HEALING_SOUND.playFor(p);
double health = p.getHealth() + HEALING_AMOUNT;
double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double maxHealth = p.getAttribute(VersionedAttribute.getMaxHealth()).getValue();
p.setHealth(Math.min(health, maxHealth));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class BiomeMap<T> implements Keyed {
/**
* Our internal {@link EnumMap} holding all the data.
*/
private final Map<Biome, T> dataMap = new EnumMap<>(Biome.class);
private final Map<Biome, T> dataMap = new HashMap<>();

/**
* The {@link NamespacedKey} to identify this {@link BiomeMap}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand All @@ -36,7 +38,7 @@ public class BiomeMapParser<T> {

private final NamespacedKey key;
private final BiomeDataConverter<T> valueConverter;
private final Map<Biome, T> map = new EnumMap<>(Biome.class);
private final Map<Biome, T> map = new HashMap<>();

/**
* This flag specifies whether the parsing is "lenient" or not.
Expand Down Expand Up @@ -158,7 +160,7 @@ private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException {

private @Nonnull Set<Biome> readBiomes(@Nonnull JsonArray array) throws BiomeMapException {
Validate.notNull(array, "The JSON array should not be null!");
Set<Biome> biomes = EnumSet.noneOf(Biome.class);
Set<Biome> biomes = new HashSet<>();

for (JsonElement element : array) {
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) {
Expand Down

0 comments on commit a42a5a2

Please sign in to comment.