2023-01-20 20:27:35 +01:00
|
|
|
package at.petrak.hexcasting.api.casting.mishaps
|
2022-03-26 19:46:50 +01:00
|
|
|
|
2023-01-22 03:29:09 +01:00
|
|
|
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
|
2023-01-20 20:27:35 +01:00
|
|
|
import at.petrak.hexcasting.api.casting.iota.Iota
|
2023-04-27 21:26:15 +02:00
|
|
|
import at.petrak.hexcasting.api.pigment.FrozenPigment
|
2022-05-29 21:59:48 +02:00
|
|
|
import at.petrak.hexcasting.api.utils.asTranslatedComponent
|
2022-03-26 19:46:50 +01:00
|
|
|
import net.minecraft.network.chat.Component
|
2022-04-16 06:08:16 +02:00
|
|
|
import net.minecraft.world.entity.item.ItemEntity
|
2022-03-26 19:46:50 +01:00
|
|
|
import net.minecraft.world.item.DyeColor
|
|
|
|
|
2022-04-16 06:08:16 +02:00
|
|
|
class MishapBadItem(val item: ItemEntity, val wanted: Component) : Mishap() {
|
2023-04-27 21:26:15 +02:00
|
|
|
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
|
2022-03-26 19:46:50 +01:00
|
|
|
dyeColor(DyeColor.BROWN)
|
|
|
|
|
2023-01-22 03:29:09 +01:00
|
|
|
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {
|
2022-04-27 04:15:24 +02:00
|
|
|
item.deltaMovement = item.deltaMovement.add((Math.random() - 0.5) * 0.05, 0.75, (Math.random() - 0.5) * 0.05)
|
2022-03-26 19:46:50 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 03:29:09 +01:00
|
|
|
override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) = if (item.item.isEmpty)
|
2023-01-20 20:27:35 +01:00
|
|
|
error("no_item", wanted)
|
2022-05-29 21:59:48 +02:00
|
|
|
else
|
2023-01-20 20:27:35 +01:00
|
|
|
error("bad_item", wanted, item.item.count, item.item.displayName)
|
2022-03-26 19:46:50 +01:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
@JvmStatic
|
2022-04-16 06:08:16 +02:00
|
|
|
fun of(item: ItemEntity, stub: String): MishapBadItem {
|
2022-05-29 21:59:48 +02:00
|
|
|
return MishapBadItem(item, "hexcasting.mishap.bad_item.$stub".asTranslatedComponent)
|
2022-03-26 19:46:50 +01:00
|
|
|
}
|
|
|
|
}
|
2022-04-09 18:42:38 +02:00
|
|
|
}
|