WIP: Converting methods to utilize Optionals.
This commit is contained in:
@ -40,9 +40,8 @@ public abstract class TotemItem extends Item {
|
||||
|
||||
public abstract boolean isCharge(ItemStack stack);
|
||||
|
||||
@Nullable
|
||||
public static Integer getTargetIndex(ItemStack stack) {
|
||||
return getTotemData(stack).map(TotemData::getTargetIndex).orElse(null);
|
||||
public static Optional<Integer> getTargetIndex(ItemStack stack) {
|
||||
return getTotemData(stack).flatMap(totemData -> Optional.of(totemData.getTargetIndex()));
|
||||
}
|
||||
public static void setTargetIndex(ItemStack stack, int targetIndex) {
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
@ -52,9 +51,8 @@ public abstract class TotemItem extends Item {
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static UUID getTargetUUID(ItemStack stack) {
|
||||
return getTotemData(stack).map(totemData -> UUID.fromString(totemData.getTargetUUID())).orElse(null);
|
||||
public static Optional<UUID> getTargetUUID(ItemStack stack) {
|
||||
return getTotemData(stack).flatMap(totemData -> Optional.of(UUID.fromString(totemData.getTargetUUID())));
|
||||
}
|
||||
public static void setTargetUUID(ItemStack stack, UUID targetUUID) {
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
@ -64,9 +62,8 @@ public abstract class TotemItem extends Item {
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getTargetName(ItemStack stack) {
|
||||
return getTotemData(stack).map(TotemData::getTargetName).orElse(null);
|
||||
public static Optional<String> getTargetName(ItemStack stack) {
|
||||
return getTotemData(stack).flatMap(totemData -> Optional.of(totemData.getTargetName()));
|
||||
}
|
||||
public static void setTargetName(ItemStack stack, String targetName) {
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
@ -76,15 +73,8 @@ public abstract class TotemItem extends Item {
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
public static int getTargetCost(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return -1; }
|
||||
return !isCostDynamic(stack) ? getConfig(stack).getChargeCost() :
|
||||
(int)(getTargetDeaths(stack) * getConfig(stack).getChargeCostMultiplier());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Integer getTargetDeaths(ItemStack stack) {
|
||||
return getTotemData(stack).map(TotemData::getTargetDeaths).orElse(null);
|
||||
public static Optional<Integer> getTargetDeaths(ItemStack stack) {
|
||||
return getTotemData(stack).flatMap(totemData -> Optional.of(totemData.getTargetDeaths()));
|
||||
}
|
||||
public static void setTargetDeaths(ItemStack stack, ServerPlayer target) {
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
@ -94,6 +84,23 @@ public abstract class TotemItem extends Item {
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
public static Optional<Integer> getCharge(ItemStack stack) {
|
||||
return getTotemData(stack).flatMap(totemData -> Optional.of(totemData.getCharge()));
|
||||
}
|
||||
public static void setCharge(ItemStack stack, int charge) {
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
if (data.isEmpty()) { return; }
|
||||
|
||||
data.get().setCharge(charge);
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
public static int getTargetCost(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return -1; }
|
||||
return !isCostDynamic(stack) ? getConfig(stack).getChargeCost() :
|
||||
(int)(getTargetDeaths(stack) * getConfig(stack).getChargeCostMultiplier());
|
||||
}
|
||||
|
||||
public static boolean isTotemFull(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return false; }
|
||||
return getCharge(stack) == getMaxCharge(stack);
|
||||
@ -110,18 +117,6 @@ public abstract class TotemItem extends Item {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Integer getCharge(ItemStack stack) {
|
||||
return getTotemData(stack).map(TotemData::getCharge).orElse(null);
|
||||
}
|
||||
public static void setCharge(ItemStack stack, int charge) {
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
if (data.isEmpty()) { return; }
|
||||
|
||||
data.get().setCharge(charge);
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
public static int getMaxCharge(ItemStack stack) {
|
||||
Config.TotemConfig config = getConfig(stack);
|
||||
if (config == null) { return -1; }
|
||||
|
||||
Reference in New Issue
Block a user