Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun List<Iota>.getVec3(idx: Int, argc: Int = 0): Vec3 {
if (x is Vec3Iota) {
return x.vec3
} else {
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "vector")
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "vec3")
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ fun List<Iota>.getBlockPos(idx: Int, argc: Int = 0): BlockPos {
return BlockPos.containing(x.vec3)
}

throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "vector")
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "vec3")
}

fun List<Iota>.getNumOrVec(idx: Int, argc: Int = 0): Either<Double, Vec3> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean toleratesOther(Iota that) {
castedName = special.handler::getName;
action = special.handler.act();
} else if (lookup instanceof PatternShapeMatch.Nothing) {
throw new MishapInvalidPattern();
throw new MishapInvalidPattern(this.getPattern());
} else throw new IllegalStateException();

// do the actual calculation!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor

Expand All @@ -23,11 +24,14 @@ class MishapInvalidIota(
stack[stack.size - 1 - reverseIdx] = GarbageIota();
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
error(
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component? {
val typeStr = HexIotaTypes.REGISTRY.getKey(perpetrator.getType())?.getPath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of this; what if two mods add iota types with the same path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently set up this way because the hexcasting.mishap.invalid_value.class.<type> lang keys already exist (for use in the old version of MishapInvalidIota) with exactly the string that's needed for this part of the message, and are already used by basically every addon. The alternative would be to make a completely new set of lang keys for this based on the full ResourceLocation, but that would A) require writing out effectively the exact same strings twice for every iota type and B) require every addon to update their lang to do so as well in order to support this version of the base mod.

I agree that it's not a perfect solution, but I can't really think of a better one that doesn't introduce other issues as described above. If you have one in mind though, please let me know!

On another note, two addons that use the same path will likely run into issues regardless of this change, since using the MishapInvalidIota.ofType() method requires defining a hexcasting.mishap.invalid_value.class.<type> lang key for your iota type, and those will conflict with each other anyway unless one of them uses a type name in the lang that isn't the same as the identifier path.

val typeComp = Component.translatable("hexcasting.mishap.invalid_value.class.${typeStr}")
return error(
"invalid_value", expected, reverseIdx,
perpetrator.display()
typeComp, perpetrator.display()
)
}

companion object {
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.PatternIota
import at.petrak.hexcasting.api.casting.math.HexPattern
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor

class MishapInvalidPattern : Mishap() {
class MishapInvalidPattern(val pattern: HexPattern) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.YELLOW)

Expand All @@ -18,5 +20,5 @@ class MishapInvalidPattern : Mishap() {
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
error("invalid_pattern")
error("invalid_pattern", PatternIota.display(pattern))
}
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@
mishap: {
"": "%s: %s",

invalid_pattern: "That pattern isn't associated with any action",
invalid_pattern: "The pattern %s isn't associated with any action",
unescaped: "Expected to evaluate a pattern, but evaluated %s instead",

not_enough_args: "expected %s or more arguments but the stack was only %s tall",
Expand Down Expand Up @@ -1025,15 +1025,17 @@
bad_caster: "Tried to execute a pattern that requires a greater mind",

invalid_value: {
"": "expected %s at index %s of the stack, but got %s",
"": "expected %s at index %s of the stack, but got %s: %s",

class: {
double: "a number",
boolean: "a boolean",
vector: "a vector",
vec3: "a vector",
list: "a list",
widget: "an influence",
pattern: "a pattern",
continuation: "a jump iota",
garbage: "garbage",
null: "null",

entity: {
"": "an entity",
Expand Down
Loading