Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error Messages to the Downgrade Ritual #1990

Open
wants to merge 3 commits into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/generated/resources/assets/bloodmagic/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
"chat.bloodmagic.ritual.notValid": "You feel that these runes are not configured correctly...",
"chat.bloodmagic.ritual.prevent": "The ritual is actively resisting you!",
"chat.bloodmagic.ritual.weak": "You feel a push, but are too weak to perform this ritual.",
"chat.bloodmagic.ritualLivingDowngrade.missingInventory": "No inventory found at %d, %d, %d.",
"chat.bloodmagic.ritualLivingDowngrade.notEnoughKeyItems": "You sense you need more %s to apply a stronger Downgrade.",
"chat.bloodmagic.ritualLivingDowngrade.notEnoughPoints": "You sense you will need more Upgrade Points to apply these Downgrades.",
"chat.bloodmagic.ritualLivingDowngrade.trainingBraceletBlock": "Your Training Bracelet vibrates as it prevents the downgrade from being applied.",
"chat.bloodmagic.routing.distance": "Invalid - link distance greater than 16 blocks!",
"chat.bloodmagic.routing.link": "Linked nodes together.",
"chat.bloodmagic.routing.link.master": "Linked node to master!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ protected void addTranslations()
add("chat.bloodmagic.ritual.activate", "A rush of energy flows through the ritual!");
add("chat.bloodmagic.ritual.notValid", "You feel that these runes are not configured correctly...");
add("chat.bloodmagic.diviner.blockedBuild", "Unable to replace block at %d, %d, %d.");
add("chat.bloodmagic.ritualLivingDowngrade.trainingBraceletBlock", "Your Training Bracelet vibrates as it prevents the downgrade from being applied.");
add("chat.bloodmagic.ritualLivingDowngrade.notEnoughKeyItems", "You sense you need more %s to apply a stronger Downgrade.");
add("chat.bloodmagic.ritualLivingDowngrade.notEnoughPoints", "You sense you will need more Upgrade Points to apply these Downgrades.");
add("chat.bloodmagic.ritualLivingDowngrade.missingInventory", "No inventory found at %d, %d, %d.");

// GUI
add("gui.bloodmagic.empty", "Empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Container;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LightningBolt;
Expand Down Expand Up @@ -72,7 +73,6 @@ public void performRitual(IMasterRitualStone masterRitualStone)

if (selectedPlayer == null)
{

return;
}

Expand All @@ -89,6 +89,7 @@ public void performRitual(IMasterRitualStone masterRitualStone)

if (tile == null)
{
selectedPlayer.displayClientMessage(Component.translatable("chat.bloodmagic.ritualLivingDowngrade.missingInventory", chestPos.getX(), chestPos.getY(), chestPos.getZ()), true);
return;
}

Expand All @@ -100,6 +101,8 @@ public void performRitual(IMasterRitualStone masterRitualStone)
Direction accessDir = Direction.DOWN;

Map<Integer, List<Integer>> priorityMap = new HashMap<>();
// Contains the ItemStack used for each downgrade. Used for the insufficient level message.
Map<LivingUpgrade, ItemStack> downgradeItemStacksMap= new HashMap<>();

LazyOptional<IItemHandler> capability = tile.getCapability(ForgeCapabilities.ITEM_HANDLER, accessDir);
if (capability.isPresent())
Expand All @@ -115,6 +118,7 @@ public void performRitual(IMasterRitualStone masterRitualStone)
{
int wantedLevel = getLevelFromStack(invStack);
downgradeMap.put(downgrade, downgradeMap.getOrDefault(downgrade, 0) + wantedLevel);
downgradeItemStacksMap.put(downgrade, invStack);
}

int priority = getPriorityFromStack(invStack);
Expand Down Expand Up @@ -142,6 +146,7 @@ public void performRitual(IMasterRitualStone masterRitualStone)
{
int wantedLevel = getLevelFromStack(invStack);
downgradeMap.put(downgrade, downgradeMap.getOrDefault(downgrade, 0) + wantedLevel);
downgradeItemStacksMap.put(downgrade, invStack);
}

int priority = getPriorityFromStack(invStack);
Expand Down Expand Up @@ -171,18 +176,21 @@ public void performRitual(IMasterRitualStone masterRitualStone)
// downgrade. 0 means nothing is added.
Map<LivingUpgrade, Integer> pointDifferentialMap = new HashMap<LivingUpgrade, Integer>();
int totalDifferentialPoints = 0;
LivingUpgrade lastSkippedDowngrade = null;
for (Entry<LivingUpgrade, Integer> entry : downgradeMap.entrySet())
{
LivingUpgrade downgrade = entry.getKey();
int playerDowngradeLevel = playerStats.getLevel(downgrade.getKey());
int wantedLevel = Math.min(entry.getValue(), downgrade.getLevel(Integer.MAX_VALUE));
if (playerDowngradeLevel >= wantedLevel)
{
lastSkippedDowngrade = downgrade;
continue;
}

if (!LivingUtil.canTrain(selectedPlayer, downgrade, playerDowngradeLevel, wantedLevel))
{
selectedPlayer.displayClientMessage(Component.translatable("chat.bloodmagic.ritualLivingDowngrade.trainingBraceletBlock"), true);
return;
}

Expand All @@ -201,11 +209,23 @@ public void performRitual(IMasterRitualStone masterRitualStone)
}
}

if (availablePoints < totalDifferentialPoints || priorityMap.isEmpty() || pointDifferentialMap.isEmpty())
if (availablePoints < totalDifferentialPoints)
{
// Can't upgrade! Not enough points
// TODO: Add smoke particles to indicate this?

selectedPlayer.displayClientMessage(Component.translatable("chat.bloodmagic.ritualLivingDowngrade.notEnoughPoints"), true);
return;
}
if (priorityMap.isEmpty() || pointDifferentialMap.isEmpty())
{
if (lastSkippedDowngrade != null)
{
String itemName = downgradeItemStacksMap.get(lastSkippedDowngrade).getItem().getDefaultInstance().getDisplayName().getString();
int lastCharIndex = itemName.length() - 1;
if (itemName.charAt(0) == '[' && itemName.charAt(lastCharIndex) == ']')
{
itemName = itemName.substring(1, lastCharIndex); // remove the brackets around the item name.
}
selectedPlayer.displayClientMessage(Component.translatable("chat.bloodmagic.ritualLivingDowngrade.notEnoughKeyItems", itemName), true);
}
return;
}

Expand Down