simplify Flock's Gambit, use formatting for display components, add first-party type names

This commit is contained in:
yrsegal@gmail.com 2022-11-11 19:48:59 -05:00
parent 0193da311d
commit 2e152f9b08
7 changed files with 34 additions and 12 deletions

View file

@ -62,7 +62,7 @@ public class BooleanIota extends Iota {
} }
public static Component display(boolean b) { public static Component display(boolean b) {
return Component.literal(b ? "True" : "False") return Component.literal(b ? "hexcasting.tooltip.boolean_true" : "hexcasting.tooltip.boolean_false")
.withStyle(b ? ChatFormatting.DARK_GREEN : ChatFormatting.DARK_RED); .withStyle(b ? ChatFormatting.DARK_GREEN : ChatFormatting.DARK_RED);
} }
} }

View file

@ -1,8 +1,10 @@
package at.petrak.hexcasting.api.spell.iota; package at.petrak.hexcasting.api.spell.iota;
import at.petrak.hexcasting.common.lib.HexIotaTypes;
import net.minecraft.client.gui.Font; import net.minecraft.client.gui.Font;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextColor;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.FormattedCharSequence;
@ -42,4 +44,13 @@ public abstract class IotaType<T extends Iota> {
* Get the color associated with this datum type. * Get the color associated with this datum type.
*/ */
public abstract int color(); public abstract int color();
/**
* Get a display component that's the name of this iota type.
*/
public Component typeName() {
var key = HexIotaTypes.REGISTRY.getKey(this);
return Component.translatable("hexcasting.iota." + key)
.withStyle(style -> style.withColor(TextColor.fromRgb(color())));
}
} }

View file

@ -97,7 +97,7 @@ public class ListIota extends Iota {
@Override @Override
public Component display(Tag tag) { public Component display(Tag tag) {
var out = Component.literal("[").withStyle(ChatFormatting.DARK_PURPLE); var out = Component.empty();
var list = HexUtils.downcast(tag, ListTag.TYPE); var list = HexUtils.downcast(tag, ListTag.TYPE);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Tag sub = list.get(i); Tag sub = list.get(i);
@ -109,8 +109,7 @@ public class ListIota extends Iota {
out.append(", "); out.append(", ");
} }
} }
out.append(Component.literal("]").withStyle(ChatFormatting.DARK_PURPLE)); return Component.translatable("hexcasting.tooltip.list_contents", out).withStyle(ChatFormatting.DARK_PURPLE);
return out;
} }
@Override @Override

View file

@ -15,8 +15,7 @@ import org.jetbrains.annotations.Nullable;
public class NullIota extends Iota { public class NullIota extends Iota {
private static final Object NULL_SUBSTITUTE = new Object(); private static final Object NULL_SUBSTITUTE = new Object();
public static final Component DISPLAY = Component.literal("NULL") public static final Component DISPLAY = Component.translatable("hexcasting.tooltip.null_iota").withStyle(ChatFormatting.GRAY);
.withStyle(ChatFormatting.GRAY);
public NullIota() { public NullIota() {
// We have to pass *something* here, but there's nothing that actually needs to go there, // We have to pass *something* here, but there's nothing that actually needs to go there,

View file

@ -67,7 +67,6 @@ public class PatternIota extends Iota {
} }
public static Component display(HexPattern pat) { public static Component display(HexPattern pat) {
var component = Component.literal("HexPattern(").withStyle(ChatFormatting.GOLD);
var bob = new StringBuilder(); var bob = new StringBuilder();
bob.append(pat.getStartDir()); bob.append(pat.getStartDir());
@ -76,8 +75,8 @@ public class PatternIota extends Iota {
bob.append(" "); bob.append(" ");
bob.append(sig); bob.append(sig);
} }
component.append(Component.literal(bob.toString()).withStyle(ChatFormatting.WHITE)); return Component.translatable("hexcasting.tooltip.pattern_iota",
component.append(Component.literal(")").withStyle(ChatFormatting.GOLD)); Component.literal(bob.toString()).withStyle(ChatFormatting.WHITE))
return component; .withStyle(ChatFormatting.GOLD);
} }
} }

View file

@ -22,8 +22,7 @@ object OpLastNToList : Action {
stack.removeLast() stack.removeLast()
val output = mutableListOf<Iota>() val output = mutableListOf<Iota>()
output.addAll(stack.takeLast(yoinkCount)) output.addAll(stack.takeLast(yoinkCount))
val endSize = stack.size - output.toList().size for (i in 0 until yoinkCount) {
while (stack.size != endSize) {
stack.removeLast() stack.removeLast()
} }
stack.addAll(output.asActionResult) stack.addAll(output.asActionResult)

View file

@ -146,6 +146,21 @@
"hexcasting.tooltip.media_amount": "Contains: %s (%s)", "hexcasting.tooltip.media_amount": "Contains: %s (%s)",
"hexcasting.tooltip.media_amount.advanced": "Contains: %s/%s (%s)", "hexcasting.tooltip.media_amount.advanced": "Contains: %s/%s (%s)",
"hexcasting.tooltip.list_contents": "[%s]",
"hexcasting.tooltip.pattern_iota": "HexPattern(%s)",
"hexcasting.tooltip.null_iota": "NULL",
"hexcasting.tooltip.boolean_true": "True",
"hexcasting.tooltip.boolean_false": "False",
"hexcasting.iota.hexcasting:null": "Null",
"hexcasting.iota.hexcasting:double": "Number",
"hexcasting.iota.hexcasting:boolean": "Boolean",
"hexcasting.iota.hexcasting:entity": "Entity",
"hexcasting.iota.hexcasting:list": "List",
"hexcasting.iota.hexcasting:pattern": "Pattern",
"hexcasting.iota.hexcasting:garbage": "Garbage",
"hexcasting.iota.hexcasting:vec3": "Vector",
"gui.hexcasting.spellcasting": "Hex Grid", "gui.hexcasting.spellcasting": "Hex Grid",
"tag.hexcasting.staves": "Hex Staves", "tag.hexcasting.staves": "Hex Staves",
"tag.hexcasting.edified_logs": "Edified Logs", "tag.hexcasting.edified_logs": "Edified Logs",