Skip to content

Commit 5c02afc

Browse files
committed
Bedrock Anvil Item Coloring
1 parent a31d49c commit 5c02afc

4 files changed

Lines changed: 75 additions & 8 deletions

File tree

src/main/java/de/dafuqs/spectrum/blocks/BedrockAnvilBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void appendTooltip(ItemStack stack, @Nullable BlockView world, List<Text>
3939
super.appendTooltip(stack, world, tooltip, options);
4040
tooltip.add(Text.translatable("container.spectrum.bedrock_anvil.tooltip").formatted(Formatting.GRAY));
4141
tooltip.add(Text.translatable("container.spectrum.bedrock_anvil.tooltip2").formatted(Formatting.GRAY));
42+
tooltip.add(Text.translatable("container.spectrum.bedrock_anvil.tooltip3").formatted(Formatting.GRAY));
4243
}
4344

4445
}

src/main/java/de/dafuqs/spectrum/inventories/BedrockAnvilScreen.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.dafuqs.spectrum.*;
44
import de.dafuqs.spectrum.helpers.*;
5+
import de.dafuqs.spectrum.items.*;
56
import de.dafuqs.spectrum.networking.*;
67
import net.fabricmc.api.*;
78
import net.fabricmc.fabric.api.client.networking.v1.*;
@@ -187,6 +188,24 @@ protected void drawInvalidRecipeArrow(DrawContext context, int x, int y) {
187188
public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
188189
if (slotId == 0) {
189190
this.nameField.setText(stack.isEmpty() ? "" : stack.getName().getString());
191+
if(!(this.handler.getSlot(1).getStack().getItem() instanceof PigmentItem))
192+
{
193+
if(stack.getName() instanceof MutableText mutableText)
194+
{
195+
if(mutableText.getStyle().getColor() == null)
196+
{
197+
this.nameField.setEditableColor(-1);
198+
}
199+
else
200+
{
201+
this.nameField.setEditableColor(mutableText.getStyle().getColor().getRgb());
202+
}
203+
}
204+
else{
205+
this.nameField.setEditableColor(-1);
206+
}
207+
}
208+
190209
this.nameField.setEditable(!stack.isEmpty());
191210

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

196215
this.setFocused(this.nameField);
197216
}
217+
if (slotId == 1)
218+
{
219+
if(stack.getItem() instanceof PigmentItem)
220+
{
221+
this.nameField.setEditableColor(ColorHelper.getInt(((PigmentItem)stack.getItem()).getColor()));
222+
}
223+
else
224+
{
225+
if(this.handler.getSlot(0).getStack().getName() instanceof MutableText mutableText)
226+
{
227+
if(mutableText.getStyle().getColor() == null)
228+
{
229+
this.nameField.setEditableColor(-1);
230+
}
231+
else
232+
{
233+
this.nameField.setEditableColor(mutableText.getStyle().getColor().getRgb());
234+
}
235+
}
236+
else{
237+
this.nameField.setEditableColor(-1);
238+
}
239+
}
240+
}
198241
}
199-
200242
}

src/main/java/de/dafuqs/spectrum/inventories/BedrockAnvilScreenHandler.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.dafuqs.spectrum.*;
44
import de.dafuqs.spectrum.helpers.*;
5+
import de.dafuqs.spectrum.items.*;
56
import net.minecraft.*;
67
import net.minecraft.block.*;
78
import net.minecraft.enchantment.*;
@@ -135,11 +136,17 @@ public void updateResult() {
135136
Map<Enchantment, Integer> enchantmentLevelMap = EnchantmentHelper.get(outputStack);
136137
repairLevelCost += inputStack.getRepairCost() + (repairSlotStack.isEmpty() ? 0 : repairSlotStack.getRepairCost());
137138
this.repairItemCount = 0;
139+
boolean pigmentInRepairSlot = repairSlotStack.getItem() instanceof PigmentItem;
140+
if(pigmentInRepairSlot)
141+
{
142+
repairItemCount = 1;
143+
}
138144
if (!repairSlotStack.isEmpty()) {
139145
combined = true;
140146

141147
boolean enchantedBookInInputSlot = inputStack.isOf(Items.ENCHANTED_BOOK) && !EnchantedBookItem.getEnchantmentNbt(inputStack).isEmpty();
142148
boolean enchantedBookInRepairSlot = repairSlotStack.isOf(Items.ENCHANTED_BOOK) && !EnchantedBookItem.getEnchantmentNbt(repairSlotStack).isEmpty();
149+
143150

144151
int o;
145152
int repairItemCount;
@@ -161,13 +168,13 @@ public void updateResult() {
161168

162169
this.repairItemCount = repairItemCount;
163170
} else {
164-
if (!enchantedBookInRepairSlot && (!outputStack.isOf(repairSlotStack.getItem()) || !outputStack.isDamageable())) {
171+
if (!pigmentInRepairSlot && !enchantedBookInRepairSlot && (!outputStack.isOf(repairSlotStack.getItem()) || !outputStack.isDamageable())) {
165172
this.output.setStack(0, ItemStack.EMPTY);
166173
this.levelCost.set(0);
167174
return;
168175
}
169176

170-
if (outputStack.isDamageable() && !enchantedBookInRepairSlot) {
177+
if (outputStack.isDamageable() && !enchantedBookInRepairSlot && !pigmentInRepairSlot) {
171178
o = inputStack.getMaxDamage() - inputStack.getDamage();
172179
repairItemCount = repairSlotStack.getMaxDamage() - repairSlotStack.getDamage();
173180
newOutputStackDamage = repairItemCount + outputStack.getMaxDamage() * 12 / 100;
@@ -250,11 +257,27 @@ public void updateResult() {
250257

251258
if (this.newItemName != null && !Util.isBlank(this.newItemName)) {
252259
if (!this.newItemName.equals(inputStack.getName().getString())) {
253-
outputStack.setCustomName(Text.literal(this.newItemName));
260+
if(inputStack.getName() instanceof MutableText inputText && inputText.getStyle().getColor()!= null)
261+
{
262+
outputStack.setCustomName(Text.literal(this.newItemName).setStyle(Style.EMPTY.withColor(inputText.getStyle().getColor())));
263+
}
264+
else{
265+
outputStack.setCustomName(Text.literal(this.newItemName));
266+
}
254267
}
255268
} else if (inputStack.hasCustomName()) {
256269
outputStack.removeCustomName();
257270
}
271+
Text text = outputStack.getName();
272+
if(pigmentInRepairSlot && text instanceof MutableText mutableText)
273+
{
274+
TextColor newColor = TextColor.fromRgb(ColorHelper.getInt(((PigmentItem)repairSlotStack.getItem()).getColor()));
275+
Text newName = mutableText.setStyle(mutableText.getStyle().withColor(newColor));
276+
if(!newName.equals(inputStack.getName()))
277+
{
278+
outputStack.setCustomName(newName);
279+
}
280+
}
258281

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

273-
if (!combined) {
296+
if (!combined || pigmentInRepairSlot) {
274297
// renaming and lore is free
275298
this.levelCost.set(0);
276299
} else if (!outputStack.isEmpty()) {

src/main/resources/assets/spectrum/lang/en_us.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@
21902190
"book.spectrum.guidebook.base_trinkets.name": "Base Trinkets",
21912191
"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).",
21922192
"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.",
2193-
"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.*",
2193+
"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.*",
21942194
"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.*",
21952195
"book.spectrum.guidebook.bedrock_armor.page1.text": "The Bedrock Helmet comes with **Projectile Protection V**.",
21962196
"book.spectrum.guidebook.bedrock_armor.page2.text": "The Bedrock Chestplate comes with **Protection V**.",
@@ -4013,11 +4013,12 @@
40134013
"commands.spectrum.progression_sanity.success": "Printed the sanity checks findings to the servers console",
40144014
"commands.spectrum.spawn_shooting_star.success": "Spawned %d shooting stars for each player",
40154015

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

40224023
"container.spectrum.rei.anvil_crushing.high_force_required": "High force required",
40234024
"container.spectrum.rei.anvil_crushing.low_force_required": "Low force required",

0 commit comments

Comments
 (0)