Skip to content

Commit

Permalink
Bedrock Anvil Item Coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
f-raZ0R committed Nov 22, 2024
1 parent a31d49c commit 5c02afc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void appendTooltip(ItemStack stack, @Nullable BlockView world, List<Text>
super.appendTooltip(stack, world, tooltip, options);
tooltip.add(Text.translatable("container.spectrum.bedrock_anvil.tooltip").formatted(Formatting.GRAY));
tooltip.add(Text.translatable("container.spectrum.bedrock_anvil.tooltip2").formatted(Formatting.GRAY));
tooltip.add(Text.translatable("container.spectrum.bedrock_anvil.tooltip3").formatted(Formatting.GRAY));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.items.*;
import de.dafuqs.spectrum.networking.*;
import net.fabricmc.api.*;
import net.fabricmc.fabric.api.client.networking.v1.*;
Expand Down Expand Up @@ -187,6 +188,24 @@ protected void drawInvalidRecipeArrow(DrawContext context, int x, int y) {
public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
if (slotId == 0) {
this.nameField.setText(stack.isEmpty() ? "" : stack.getName().getString());
if(!(this.handler.getSlot(1).getStack().getItem() instanceof PigmentItem))
{
if(stack.getName() instanceof MutableText mutableText)
{
if(mutableText.getStyle().getColor() == null)
{
this.nameField.setEditableColor(-1);
}
else
{
this.nameField.setEditableColor(mutableText.getStyle().getColor().getRgb());
}
}
else{
this.nameField.setEditableColor(-1);
}
}

this.nameField.setEditable(!stack.isEmpty());

String loreString = LoreHelper.getStringFromLoreTextArray(LoreHelper.getLoreList(stack));
Expand All @@ -195,6 +214,29 @@ public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {

this.setFocused(this.nameField);
}
if (slotId == 1)
{
if(stack.getItem() instanceof PigmentItem)
{
this.nameField.setEditableColor(ColorHelper.getInt(((PigmentItem)stack.getItem()).getColor()));
}
else
{
if(this.handler.getSlot(0).getStack().getName() instanceof MutableText mutableText)
{
if(mutableText.getStyle().getColor() == null)
{
this.nameField.setEditableColor(-1);
}
else
{
this.nameField.setEditableColor(mutableText.getStyle().getColor().getRgb());
}
}
else{
this.nameField.setEditableColor(-1);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.items.*;
import net.minecraft.*;
import net.minecraft.block.*;
import net.minecraft.enchantment.*;
Expand Down Expand Up @@ -135,11 +136,17 @@ public void updateResult() {
Map<Enchantment, Integer> enchantmentLevelMap = EnchantmentHelper.get(outputStack);
repairLevelCost += inputStack.getRepairCost() + (repairSlotStack.isEmpty() ? 0 : repairSlotStack.getRepairCost());
this.repairItemCount = 0;
boolean pigmentInRepairSlot = repairSlotStack.getItem() instanceof PigmentItem;
if(pigmentInRepairSlot)
{
repairItemCount = 1;
}
if (!repairSlotStack.isEmpty()) {
combined = true;

boolean enchantedBookInInputSlot = inputStack.isOf(Items.ENCHANTED_BOOK) && !EnchantedBookItem.getEnchantmentNbt(inputStack).isEmpty();
boolean enchantedBookInRepairSlot = repairSlotStack.isOf(Items.ENCHANTED_BOOK) && !EnchantedBookItem.getEnchantmentNbt(repairSlotStack).isEmpty();


int o;
int repairItemCount;
Expand All @@ -161,13 +168,13 @@ public void updateResult() {

this.repairItemCount = repairItemCount;
} else {
if (!enchantedBookInRepairSlot && (!outputStack.isOf(repairSlotStack.getItem()) || !outputStack.isDamageable())) {
if (!pigmentInRepairSlot && !enchantedBookInRepairSlot && (!outputStack.isOf(repairSlotStack.getItem()) || !outputStack.isDamageable())) {
this.output.setStack(0, ItemStack.EMPTY);
this.levelCost.set(0);
return;
}

if (outputStack.isDamageable() && !enchantedBookInRepairSlot) {
if (outputStack.isDamageable() && !enchantedBookInRepairSlot && !pigmentInRepairSlot) {
o = inputStack.getMaxDamage() - inputStack.getDamage();
repairItemCount = repairSlotStack.getMaxDamage() - repairSlotStack.getDamage();
newOutputStackDamage = repairItemCount + outputStack.getMaxDamage() * 12 / 100;
Expand Down Expand Up @@ -250,11 +257,27 @@ public void updateResult() {

if (this.newItemName != null && !Util.isBlank(this.newItemName)) {
if (!this.newItemName.equals(inputStack.getName().getString())) {
outputStack.setCustomName(Text.literal(this.newItemName));
if(inputStack.getName() instanceof MutableText inputText && inputText.getStyle().getColor()!= null)
{
outputStack.setCustomName(Text.literal(this.newItemName).setStyle(Style.EMPTY.withColor(inputText.getStyle().getColor())));
}
else{
outputStack.setCustomName(Text.literal(this.newItemName));
}
}
} else if (inputStack.hasCustomName()) {
outputStack.removeCustomName();
}
Text text = outputStack.getName();
if(pigmentInRepairSlot && text instanceof MutableText mutableText)
{
TextColor newColor = TextColor.fromRgb(ColorHelper.getInt(((PigmentItem)repairSlotStack.getItem()).getColor()));
Text newName = mutableText.setStyle(mutableText.getStyle().withColor(newColor));
if(!newName.equals(inputStack.getName()))
{
outputStack.setCustomName(newName);
}
}

if (this.newLoreString != null && !Util.isBlank(this.newLoreString)) {
List<Text> lore = LoreHelper.getLoreTextArrayFromString(this.newLoreString);
Expand All @@ -270,7 +293,7 @@ public void updateResult() {
outputStack = ItemStack.EMPTY;
}

if (!combined) {
if (!combined || pigmentInRepairSlot) {
// renaming and lore is free
this.levelCost.set(0);
} else if (!outputStack.isEmpty()) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/assets/spectrum/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@
"book.spectrum.guidebook.base_trinkets.name": "Base Trinkets",
"book.spectrum.guidebook.base_trinkets.page0.text": "These basic accessories will serve me well as a starting point for more advanced Trinkets.\\\nAll final Trinkets are created in the [Fusion Shrine](entry://general/fusion_shrine).",
"book.spectrum.guidebook.bedrock_anvil.page0.text": "I've used my Anvil plenty (a lot of Anvils, actually). [Item Crushing](entry://general/item_crushing), repairing and enchanting are burning a hole in my iron supply.\\\nTo make the Anvil last longer - indestructible, in fact - Bedrock seems like the perfect choice.\\\n\\\nIt allows me to rename items for free and has no maximum repair limit.",
"book.spectrum.guidebook.bedrock_anvil.page1.text": "It also allows me to add descriptions to my items.\\\n\\\n*Pro tip: \"\\n\" will split the text into multiple lines.*",
"book.spectrum.guidebook.bedrock_anvil.page1.text": "It also allows me to add descriptions to my items, as well as a spark of color with some pigment.\\\n\\\n*Pro tip: \"\\n\" will split the text into multiple lines.*\\\n*Also, leaving the name field blank will reset the name.*",
"book.spectrum.guidebook.bedrock_armor.page0.text": "The strongest material I could find so far was Netherite. However, repairing [#](bb00bb)Netherite Armor[#]() was more expensive than making the armor itself. Also, the protection decreased with each scratch. All this is less of a problem if the armor simply *cannot* be damaged in the first place.\\\n\\\n*Never wilt, stone blossom.*",
"book.spectrum.guidebook.bedrock_armor.page1.text": "The Bedrock Helmet comes with **Projectile Protection V**.",
"book.spectrum.guidebook.bedrock_armor.page2.text": "The Bedrock Chestplate comes with **Protection V**.",
Expand Down Expand Up @@ -4013,11 +4013,12 @@
"commands.spectrum.progression_sanity.success": "Printed the sanity checks findings to the servers console",
"commands.spectrum.spawn_shooting_star.success": "Spawned %d shooting stars for each player",

"container.spectrum.bedrock_anvil": "Repair & write Lore",
"container.spectrum.bedrock_anvil": "Repair & Customize",
"container.spectrum.bedrock_anvil.lore": "Lore:",
"container.spectrum.bedrock_anvil.tooltip": "Indestructible. Free renaming, unlimited",
"container.spectrum.bedrock_anvil.tooltip2": "repair cap & able to add Lore to Items",
"container.spectrum.modonomicon.crystallarieum.catalyst": "Catalyst:\nAccel:\nInk Cons:\nUsed Up:",
"container.spectrum.bedrock_anvil.tooltip3": "Add pigment to items to color their name",
"container.spectrum.modonomicon.crystallarieum.catalyst": "Catalyst:\nAccel:\nInk Cons:\nUsed Up:",

"container.spectrum.rei.anvil_crushing.high_force_required": "High force required",
"container.spectrum.rei.anvil_crushing.low_force_required": "Low force required",
Expand Down

0 comments on commit 5c02afc

Please sign in to comment.