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