Some more cleanup

This commit is contained in:
DerFrZocker 2023-11-03 18:47:57 +01:00
parent 807e4bc249
commit bef033b58d
No known key found for this signature in database
GPG key ID: 713F71FFFE1DDF91
6 changed files with 58 additions and 24 deletions

View file

@ -106,7 +106,20 @@ public abstract class Art extends OldEnum<Art> implements Keyed {
@Deprecated @Deprecated
@Nullable @Nullable
public static Art getById(int id) { public static Art getById(int id) {
return BY_ID.get(id); Art art = BY_ID.get(id);
if (art != null) {
return art;
}
for (Art other : Registry.ART) {
if (other.getId() == id) {
BY_ID.put(id, other);
return other;
}
}
return null;
} }
/** /**

View file

@ -88,15 +88,19 @@ public abstract class PatternType extends OldEnum<PatternType> implements Keyed
return null; return null;
} }
return byString.computeIfAbsent(identifier, id -> { PatternType patternType = byString.get(identifier);
for (PatternType patternType : Registry.BANNER_PATTERN) { if (patternType != null) {
if (identifier.equals(patternType.getIdentifier())) { return patternType;
return patternType; }
}
}
return null; for (PatternType type : Registry.BANNER_PATTERN) {
}); if (identifier.equals(type.getIdentifier())) {
byString.put(identifier, type);
return type;
}
}
return null;
} }
/** /**

View file

@ -337,6 +337,14 @@ public abstract class EntityType<E extends Entity> extends OldEnum<EntityType<E>
@Nullable @Nullable
public abstract Class<E> getEntityClass(); public abstract Class<E> getEntityClass();
/**
* Gets if this EntityType is enabled by feature in a world.
*
* @param world the world to check
* @return true if this EntityType can be used to spawn an Entity for this World.
*/
public abstract boolean isEnabledByFeature(@NotNull World world);
/** /**
* Gets the entity type name. * Gets the entity type name.
* *
@ -478,14 +486,4 @@ public abstract class EntityType<E extends Entity> extends OldEnum<EntityType<E>
return from; return from;
} }
/**
* Gets if this EntityType is enabled by feature in a world.
*
* @param world the world to check
* @return true if this EntityType can be used to spawn an Entity for this World.
*/
public boolean isEnabledByFeature(@NotNull World world) {
return Bukkit.getDataPackManager().isEnabledByFeature(this, world);
}
} }

View file

@ -208,9 +208,7 @@ public abstract class PotionEffectType implements Keyed {
* @see PotionBrewer#createEffect(PotionEffectType, int, int) * @see PotionBrewer#createEffect(PotionEffectType, int, int)
*/ */
@NotNull @NotNull
public PotionEffect createEffect(int duration, int amplifier) { public abstract PotionEffect createEffect(int duration, int amplifier);
return new PotionEffect(this, isInstant() ? 1 : (int) (duration * getDurationModifier()), amplifier);
}
/** /**
* Returns whether the effect of this type happens once, immediately. * Returns whether the effect of this type happens once, immediately.
@ -260,9 +258,11 @@ public abstract class PotionEffectType implements Keyed {
* *
* @param key key to fetch * @param key key to fetch
* @return Resulting PotionEffectType, or null if not found * @return Resulting PotionEffectType, or null if not found
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
*/ */
@Contract("null -> null") @Contract("null -> null")
@Nullable @Nullable
@Deprecated
public static PotionEffectType getByKey(@Nullable NamespacedKey key) { public static PotionEffectType getByKey(@Nullable NamespacedKey key) {
return Registry.POTION_EFFECT_TYPE.get(key); return Registry.POTION_EFFECT_TYPE.get(key);
} }
@ -277,7 +277,20 @@ public abstract class PotionEffectType implements Keyed {
@Deprecated @Deprecated
@Nullable @Nullable
public static PotionEffectType getById(int id) { public static PotionEffectType getById(int id) {
return ID_MAP.get(id); PotionEffectType type = ID_MAP.get(id);
if (type != null) {
return type;
}
for (PotionEffectType other : Registry.POTION_EFFECT_TYPE) {
if (other.getId() == id) {
ID_MAP.put(id, other);
return other;
}
}
return null;
} }
/** /**

View file

@ -37,6 +37,12 @@ public class PotionEffectTypeWrapper extends PotionEffectType {
return PotionEffectType.getByKey(getKey()); return PotionEffectType.getByKey(getKey());
} }
@NotNull
@Override
public PotionEffect createEffect(int duration, int amplifier) {
return getType().createEffect(duration, amplifier);
}
@Override @Override
public boolean isInstant() { public boolean isInstant() {
return getType().isInstant(); return getType().isInstant();

View file

@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** /**
* This enum reflects and matches each potion state that can be obtained from * This class reflects and matches each potion state that can be obtained from
* the Creative mode inventory * the Creative mode inventory
*/ */
public abstract class PotionType extends OldEnum<PotionType> implements Keyed { public abstract class PotionType extends OldEnum<PotionType> implements Keyed {