Ported totem tooltip. Implemented helpers for getting target UUID from totem data.
This commit is contained in:
@ -7,12 +7,14 @@ import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TotemData {
|
||||
public static final Codec<TotemData> CODEC = RecordCodecBuilder.create(instance ->
|
||||
instance.group(
|
||||
Codec.INT.fieldOf("targetIndex").forGetter(TotemData::getTargetIndex),
|
||||
Codec.STRING.fieldOf("targetUUID").forGetter(TotemData::getTargetUUID),
|
||||
Codec.STRING.fieldOf("targetUUID").forGetter(TotemData::getTargetStringUUID),
|
||||
Codec.STRING.fieldOf("targetName").forGetter(TotemData::getTargetName),
|
||||
Codec.INT.fieldOf("targetDeaths").forGetter(TotemData::getTargetDeaths),
|
||||
Codec.INT.fieldOf("charge").forGetter(TotemData::getCharge)
|
||||
@ -20,7 +22,7 @@ public class TotemData {
|
||||
);
|
||||
public static final StreamCodec<ByteBuf, TotemData> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.INT, TotemData::getTargetIndex,
|
||||
ByteBufCodecs.STRING_UTF8, TotemData::getTargetUUID,
|
||||
ByteBufCodecs.STRING_UTF8, TotemData::getTargetStringUUID,
|
||||
ByteBufCodecs.STRING_UTF8, TotemData::getTargetName,
|
||||
ByteBufCodecs.INT, TotemData::getTargetDeaths,
|
||||
ByteBufCodecs.INT, TotemData::getCharge,
|
||||
@ -48,13 +50,24 @@ public class TotemData {
|
||||
this.targetIndex = targetIndex;
|
||||
}
|
||||
|
||||
public String getTargetUUID() {
|
||||
public String getTargetStringUUID() {
|
||||
return targetUUID;
|
||||
}
|
||||
public void setTargetUUID(String targetUUID) {
|
||||
public void setTargetStringUUID(String targetUUID) {
|
||||
this.targetUUID = targetUUID;
|
||||
}
|
||||
|
||||
public Optional<UUID> getTargetUUID() {
|
||||
Optional<UUID> targetUUID = Optional.empty();
|
||||
try {
|
||||
targetUUID = Optional.of(UUID.fromString(this.targetUUID));
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
return targetUUID;
|
||||
}
|
||||
public void setTargetUUID(UUID targetUUID) {
|
||||
this.targetUUID = targetUUID.toString();
|
||||
}
|
||||
|
||||
public String getTargetName() {
|
||||
return targetName;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ public abstract class TotemItem extends Item {
|
||||
ServerPlayer target = playerList.getPlayers().get(targetIndex);
|
||||
|
||||
totemData.setTargetIndex(targetIndex);
|
||||
totemData.setTargetUUID(target.getStringUUID());
|
||||
totemData.setTargetUUID(target.getUUID());
|
||||
totemData.setTargetName(target.getScoreboardName());
|
||||
totemData.setTargetDeaths(target.getStats().getValue(Stats.CUSTOM.get(Stats.DEATHS)));
|
||||
|
||||
@ -124,7 +124,12 @@ public abstract class TotemItem extends Item {
|
||||
TotemItem totemItem = ((TotemItem) itemStack.getItem());
|
||||
Config.TotemConfig config = totemItem.getConfig();
|
||||
|
||||
ServerPlayer target = playerList.getPlayer(UUID.fromString(totemData.getTargetUUID()));
|
||||
Optional<UUID> targetUUID = totemData.getTargetUUID();
|
||||
if (targetUUID.isEmpty()) {
|
||||
return Component.literal(ChatFormatting.WHITE + "Unable to find player!");
|
||||
}
|
||||
|
||||
ServerPlayer target = playerList.getPlayer(targetUUID.get());
|
||||
if (target == null) {
|
||||
return Component.literal(ChatFormatting.WHITE + "Unable to find player!");
|
||||
}
|
||||
@ -164,50 +169,50 @@ public abstract class TotemItem extends Item {
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@ParametersAreNonnullByDefault
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag tooltipFlag) {
|
||||
if (world == null) { return; }
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
TotemData totemData = getTotemData(stack);
|
||||
|
||||
UUID targetUUID = getTargetUUID(stack);
|
||||
String targetName = getTargetName(stack);
|
||||
int targetCost = getTargetCost(stack);
|
||||
int charge = getCharge(stack);
|
||||
int maxCharge = getMaxCharge(stack);
|
||||
double multiplier = getConfig(stack).getChargeCostMultiplier();
|
||||
Optional<UUID> targetUUID = totemData.getTargetUUID();
|
||||
if (targetUUID.isEmpty()) {
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.RED + "Target: " + ChatFormatting.DARK_RED + "N/A"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "Target: " + ChatFormatting.GRAY + totemData.getTargetName()));
|
||||
}
|
||||
|
||||
if (targetUUID == null) {
|
||||
tooltip.add(Component.literal(ChatFormatting.RED + "Target: " + ChatFormatting.DARK_RED + "NONE"));
|
||||
tooltipComponents.add(Component.empty());
|
||||
|
||||
if (!canAffordTarget(totemData)) {
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.RED + "Charges: " + ChatFormatting.DARK_RED + "(" + totemData.getCharge() + "/" + getTargetCost(totemData) + ") " +
|
||||
ChatFormatting.RED + "[Max: " + ChatFormatting.DARK_RED + getMaxCharge() + ChatFormatting.RED + "] [Multi: " + ChatFormatting.DARK_RED + getConfig().getChargeCostMultiplier() + ChatFormatting.RED + "]"));
|
||||
} else {
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "Target: " + ChatFormatting.GRAY + targetName));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "Charges: " + ChatFormatting.GRAY + "(" + totemData.getCharge() + "/" + getTargetCost(totemData) + ") " +
|
||||
ChatFormatting.WHITE + "[Max: " + ChatFormatting.GRAY + getMaxCharge() + ChatFormatting.WHITE + "] [Multi: " + ChatFormatting.GRAY + getConfig().getChargeCostMultiplier() + ChatFormatting.WHITE + "]"));
|
||||
}
|
||||
tooltip.add(Component.literal(""));
|
||||
if (!canTotemAffordTarget(stack)) {
|
||||
tooltip.add(Component.literal(ChatFormatting.RED + "Charges: " + ChatFormatting.DARK_RED + "(" + charge + "/" + targetCost + ") " +
|
||||
ChatFormatting.RED + "[Max: " + ChatFormatting.DARK_RED + maxCharge + ChatFormatting.RED + "] [Multi: " + ChatFormatting.DARK_RED + multiplier + ChatFormatting.RED + "]"));
|
||||
} else {
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "Charges: " + ChatFormatting.GRAY + "(" + charge + "/" + targetCost + ") " +
|
||||
ChatFormatting.WHITE + "[Max: " + ChatFormatting.GRAY + maxCharge + ChatFormatting.WHITE + "] [Multi: " + ChatFormatting.GRAY + multiplier + ChatFormatting.WHITE + "]"));
|
||||
|
||||
if (getConfig().getCanReviveMoreExpensiveTargets()) {
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "Can revive more expensive targets."));
|
||||
}
|
||||
if (canReviveMoreExpensiveTargets(stack)) {
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "Can revive more expensive targets."));
|
||||
|
||||
if (getConfig().getCanReviveAcrossDimensions()) {
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "Can revive targets across dimensions."));
|
||||
}
|
||||
if (canReviveAcrossDimensions(stack)) {
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "Can revive targets across dimensions."));
|
||||
}
|
||||
tooltip.add(Component.literal(""));
|
||||
|
||||
tooltipComponents.add(Component.empty());
|
||||
|
||||
if (ModKeyMappings.ADVANCED_TOOLTIP.isDown()) {
|
||||
tooltip.add(Component.literal(ChatFormatting.GRAY + "Showing advanced tooltip."));
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "[" + ChatFormatting.GRAY + "R-CLICK" + ChatFormatting.WHITE + "]"));
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "When second hand is empty: revive target."));
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "When second hand is holding a reviving charge: charge totem."));
|
||||
tooltip.add(Component.literal(""));
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "[" + ChatFormatting.GRAY + "L-SHIFT + R-CLICK" + ChatFormatting.WHITE + "]"));
|
||||
tooltip.add(Component.literal(ChatFormatting.WHITE + "Change target."));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.GRAY + "Showing advanced tooltip."));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "[" + ChatFormatting.GRAY + "R-CLICK" + ChatFormatting.WHITE + "]"));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "When second hand is empty: revive target."));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "When second hand is holding a reviving charge: charge totem."));
|
||||
tooltipComponents.add(Component.literal(""));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "[" + ChatFormatting.GRAY + "L-SHIFT + R-CLICK" + ChatFormatting.WHITE + "]"));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.WHITE + "Change target."));
|
||||
} else {
|
||||
tooltip.add(Component.literal(ChatFormatting.GRAY + "Hold [" + ChatFormatting.DARK_GRAY + "L-SHIFT" + ChatFormatting.GRAY + "] for advanced tooltip."));
|
||||
tooltipComponents.add(Component.literal(ChatFormatting.GRAY + "Hold [" + ChatFormatting.DARK_GRAY + "L-SHIFT" + ChatFormatting.GRAY + "] for advanced tooltip."));
|
||||
}
|
||||
super.appendHoverText(stack, world, tooltip, tooltipFlag);
|
||||
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user