-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ok, added
inavid_operator_args
and associated stuff
- Loading branch information
1 parent
e73025f
commit a2db04c
Showing
4 changed files
with
60 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapInvalidIotas.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
Common/src/main/java/at/petrak/hexcasting/api/casting/mishaps/MishapInvalidOperatorArgs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package at.petrak.hexcasting.api.casting.mishaps | ||
|
||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment | ||
import at.petrak.hexcasting.api.casting.iota.GarbageIota | ||
import at.petrak.hexcasting.api.casting.iota.Iota | ||
import at.petrak.hexcasting.api.pigment.FrozenPigment | ||
import net.minecraft.network.chat.Component | ||
import net.minecraft.network.chat.ComponentContents | ||
import net.minecraft.network.chat.MutableComponent | ||
import net.minecraft.world.item.DyeColor | ||
|
||
/** | ||
* The value failed some kind of predicate. | ||
*/ | ||
class MishapInvalidOperatorArgs( | ||
private val perpetrators: List<Iota> | ||
) : Mishap() { | ||
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment = | ||
dyeColor(DyeColor.GRAY) | ||
|
||
override fun execute(env: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { | ||
for (i in perpetrators.indices) { | ||
stack[stack.size - 1 - i] = GarbageIota() | ||
} | ||
} | ||
|
||
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context): Component { | ||
return if (perpetrators.size == 1) { | ||
error( | ||
"invalid_operator_args.single", | ||
0, | ||
perpetrators[0].display() | ||
) | ||
} else { | ||
error( | ||
"invalid_operator_args.plural", | ||
perpetrators.size, | ||
0, | ||
perpetrators.lastIndex, | ||
collateIotas(perpetrators) | ||
) | ||
} | ||
} | ||
private fun collateIotas(iotas: List<Iota>): MutableComponent { | ||
val out = MutableComponent.create(ComponentContents.EMPTY) | ||
for (i in iotas.indices) { | ||
out.append(iotas[i].display()) | ||
if (i < iotas.size-1) { | ||
out.append(", ") | ||
} | ||
} | ||
return out | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters