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 @@ -4,6 +4,7 @@ package at.petrak.hexcasting.api.casting

import at.petrak.hexcasting.api.casting.iota.*
import at.petrak.hexcasting.api.casting.math.HexPattern
import at.petrak.hexcasting.api.casting.mishaps.MishapEntityNotFound
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs
import at.petrak.hexcasting.api.utils.asTranslatedComponent
Expand Down Expand Up @@ -37,7 +38,7 @@ fun List<Iota>.getDouble(idx: Int, argc: Int = 0): Double {
fun List<Iota>.getEntity(level: ServerLevel, idx: Int, argc: Int = 0): Entity {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
return x.getEntity(level)
return x.getEntity(level) ?: throw MishapEntityNotFound(x.entityId, x.entityName)
} else {
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "entity")
}
Expand Down Expand Up @@ -84,7 +85,7 @@ fun List<Iota>.getBool(idx: Int, argc: Int = 0): Boolean {
fun List<Iota>.getItemEntity(level: ServerLevel, idx: Int, argc: Int = 0): ItemEntity {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.getEntity(level)
val e = x.getEntity(level) ?: throw MishapEntityNotFound(x.entityId, x.entityName)
if (e is ItemEntity)
return e
}
Expand All @@ -94,7 +95,7 @@ fun List<Iota>.getItemEntity(level: ServerLevel, idx: Int, argc: Int = 0): ItemE
fun List<Iota>.getPlayer(level: ServerLevel, idx: Int, argc: Int = 0): ServerPlayer {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.getEntity(level)
val e = x.getEntity(level) ?: throw MishapEntityNotFound(x.entityId, x.entityName)
if (e is ServerPlayer)
return e
}
Expand All @@ -104,7 +105,7 @@ fun List<Iota>.getPlayer(level: ServerLevel, idx: Int, argc: Int = 0): ServerPla
fun List<Iota>.getMob(level: ServerLevel, idx: Int, argc: Int = 0): Mob {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.getEntity(level)
val e = x.getEntity(level) ?: throw MishapEntityNotFound(x.entityId, x.entityName)
if (e is Mob)
return e
}
Expand All @@ -114,7 +115,7 @@ fun List<Iota>.getMob(level: ServerLevel, idx: Int, argc: Int = 0): Mob {
fun List<Iota>.getLivingEntityButNotArmorStand(level: ServerLevel, idx: Int, argc: Int = 0): LivingEntity {
val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) }
if (x is EntityIota) {
val e = x.getEntity(level)
val e = x.getEntity(level) ?: throw MishapEntityNotFound(x.entityId, x.entityName)
if (e is LivingEntity && e !is ArmorStand)
return e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -44,7 +43,7 @@ public UUID getEntityId() {
return entityId;
}

public Entity getEntity(ServerLevel level) {
public @Nullable Entity getEntity(ServerLevel level) {
return level.getEntity(entityId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class MishapInternalException(val exception: Exception) : Mishap() {
}

override fun errorMessage(ctx: CastingEnvironment, errorCtx: Context) =
error("unknown", exception)
error("unknown", exception.toString())
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.api.utils.validateIota
import at.petrak.hexcasting.xplat.IXplatAbstractions

object OpRead : ConstMediaAction {
Expand All @@ -28,6 +29,6 @@ object OpRead : ConstMediaAction {
?: datumHolder.emptyIota()
?: throw MishapBadOffhandItem.of(handStack, "iota.read")

return listOf(datum)
return listOf(validateIota(datum, env.world))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getEntity
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapBadEntity
import at.petrak.hexcasting.api.utils.validateIota
import at.petrak.hexcasting.xplat.IXplatAbstractions

object OpTheCoolerRead : ConstMediaAction {
Expand All @@ -24,6 +25,6 @@ object OpTheCoolerRead : ConstMediaAction {
val datum = datumHolder.readIota()
?: datumHolder.emptyIota()
?: throw MishapBadEntity.of(target, "iota.read")
return listOf(datum)
return listOf(validateIota(datum, env.world))
}
}