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