Replaced totem nbt target_cost with target_deaths. Added method for checking if totem is full and if totem can afford a target. Added more text in item tooltip for different config settings.
This commit is contained in:
@ -10,9 +10,11 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Rarity;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
@ -32,7 +34,7 @@ public abstract class TotemItem extends Item {
|
||||
private static final String TAG_TARGET_INDEX = "target_index";
|
||||
private static final String TAG_TARGET_UUID = "target_uuid";
|
||||
private static final String TAG_TARGET_NAME = "target_name";
|
||||
private static final String TAG_TARGET_COST = "target_cost";
|
||||
private static final String TAG_TARGET_DEATHS = "target_deaths";
|
||||
private static final String TAG_CHARGE = "charge";
|
||||
|
||||
public TotemItem(int durability) {
|
||||
@ -71,23 +73,42 @@ public abstract class TotemItem extends Item {
|
||||
if (!isTotem(stack)) { return null; }
|
||||
return stack.getOrCreateTag().getString(TAG_TARGET_NAME);
|
||||
}
|
||||
public static void setTagTargetName(ItemStack stack, String targetName) {
|
||||
public static void setTargetName(ItemStack stack, String targetName) {
|
||||
if (!isTotem(stack)) { return; }
|
||||
stack.getOrCreateTag().putString(TAG_TARGET_NAME, targetName);
|
||||
}
|
||||
|
||||
public static int getTargetCost(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return -1; }
|
||||
return !isCostDynamic(stack) ? getRawTargetCost(stack) :
|
||||
(int)(getRawTargetCost(stack) * getConfig(stack).getChargeCostMultiplier());
|
||||
return !isCostDynamic(stack) ? getConfig(stack).getChargeCost() :
|
||||
(int)(getTargetDeaths(stack) * getConfig(stack).getChargeCostMultiplier());
|
||||
}
|
||||
private static int getRawTargetCost(ItemStack stack) {
|
||||
|
||||
public static int getTargetDeaths(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return -1; }
|
||||
return stack.getOrCreateTag().getInt(TAG_TARGET_COST);
|
||||
return stack.getOrCreateTag().getInt(TAG_TARGET_DEATHS);
|
||||
}
|
||||
public static void setTargetCost(ItemStack stack, int targetCost) {
|
||||
public static void setTargetDeaths(ItemStack stack, ServerPlayerEntity target) {
|
||||
if (!isTotem(stack)) { return; }
|
||||
stack.getOrCreateTag().putInt(TAG_TARGET_COST, targetCost);
|
||||
stack.getOrCreateTag().putInt(TAG_TARGET_DEATHS, target.getStats().getValue(Stats.CUSTOM.get(Stats.DEATHS)));
|
||||
}
|
||||
|
||||
public static boolean isTotemFull(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return false; }
|
||||
return getCharge(stack) == getMaxCharge(stack);
|
||||
}
|
||||
|
||||
public static boolean canTotemAffordTarget(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return false; }
|
||||
if (getCharge(stack) < getTargetCost(stack)) {
|
||||
if (!isTotemFull(stack)) {
|
||||
return false;
|
||||
}
|
||||
if (isTotemFull(stack) && canReviveMoreExpensiveTargets(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int getCharge(ItemStack stack) {
|
||||
@ -135,15 +156,6 @@ public abstract class TotemItem extends Item {
|
||||
return getConfig(stack).getIsEnabled();
|
||||
}
|
||||
|
||||
public static void validateTargetCost(ItemStack stack, int targetDeaths) {
|
||||
if (!isTotem(stack)) { return; }
|
||||
if (isCostDynamic(stack) && getRawTargetCost(stack) != targetDeaths) {
|
||||
setTargetCost(stack, targetDeaths);
|
||||
} else if (!isCostDynamic(stack) && getRawTargetCost(stack) != getMaxCharge(stack)) {
|
||||
setTargetCost(stack, getMaxCharge(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@ParametersAreNonnullByDefault
|
||||
@ -163,13 +175,19 @@ public abstract class TotemItem extends Item {
|
||||
tooltip.add(new StringTextComponent(TextFormatting.WHITE + "Target: " + TextFormatting.GRAY + targetName));
|
||||
}
|
||||
tooltip.add(new StringTextComponent(""));
|
||||
if (charge < targetCost && !canReviveMoreExpensiveTargets(stack)) {
|
||||
if (!canTotemAffordTarget(stack)) {
|
||||
tooltip.add(new StringTextComponent(TextFormatting.RED + "Charges: " + TextFormatting.DARK_RED + "(" + charge + "/" + targetCost + ") " +
|
||||
TextFormatting.RED + "[Max: " + TextFormatting.DARK_RED + maxCharge + TextFormatting.RED + "]"));
|
||||
} else {
|
||||
tooltip.add(new StringTextComponent(TextFormatting.WHITE + "Charges: " + TextFormatting.GRAY + "(" + charge + "/" + targetCost + ") " +
|
||||
TextFormatting.WHITE + "[Max: " + TextFormatting.GRAY + maxCharge + TextFormatting.WHITE + "]"));
|
||||
}
|
||||
if (canReviveMoreExpensiveTargets(stack)) {
|
||||
tooltip.add(new StringTextComponent(TextFormatting.WHITE + "Can revive more expensive targets."));
|
||||
}
|
||||
if (canReviveAcrossDimensions(stack)) {
|
||||
tooltip.add(new StringTextComponent(TextFormatting.WHITE + "Can revive targets across dimensions."));
|
||||
}
|
||||
tooltip.add(new StringTextComponent(""));
|
||||
if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_SHIFT)) {
|
||||
tooltip.add(new StringTextComponent(TextFormatting.GRAY + "Showing advanced tooltip."));
|
||||
|
Reference in New Issue
Block a user