Skip to content
Merged
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
@@ -0,0 +1,17 @@
package ram.talia.hexal.api.casting.iota;

import at.petrak.hexcasting.api.casting.iota.Iota;

import java.util.function.UnaryOperator;

/**
* An Interface to facilitate replacing illegal Iotas.
*/
public interface IMappableIota {
/**
* Returns a new iota consisting of the result of applying the given function to the contents of this iota.
* <br />
* Implementations should apply {@code mapper} to every sub-iota ({@link Iota#subIotas()}), then return a copy of itself containing the mapped iotas.
*/
Iota mapSubIotas(UnaryOperator<Iota> mapper);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import at.petrak.hexcasting.api.utils.isOfTag
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor
import ram.talia.hexal.api.casting.iota.IMappableIota
import ram.talia.hexal.common.lib.HexalTags

class MishapIllegalInterworldIota(val iota: Iota) : Mishap() {
Expand All @@ -36,8 +37,7 @@ class MishapIllegalInterworldIota(val iota: Iota) : Mishap() {
val iotaToCheck = poolToSearch.removeFirst()
if (iotaTypeIsIllegal(iotaToCheck))
return iotaToCheck
if (iotaToCheck is ListIota)
poolToSearch.addAll(iotaToCheck.list)
iotaToCheck.subIotas()?.let { poolToSearch.addAll(it) }
}

return null
Expand All @@ -46,9 +46,10 @@ class MishapIllegalInterworldIota(val iota: Iota) : Mishap() {
fun replaceInNestedIota(iota: Iota): Iota {
return when {
iotaTypeIsIllegal(iota) -> GarbageIota()
iota is IMappableIota -> iota.mapSubIotas(::replaceInNestedIota)
iota is ListIota -> iota.list.map { replaceInNestedIota(it) }.asActionResult[0]
else -> iota
}
}
}
}
}
Loading