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
@@ -1,12 +1,13 @@
package at.petrak.hexcasting.api.addldata;

import at.petrak.hexcasting.api.casting.iota.Iota;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.Nullable;

public interface ADIotaHolder {

@Nullable
Iota readIota();
Iota readIota(ServerLevel world);

@Nullable
default Iota emptyIota() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.common.entities.EntityWallScroll;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -39,9 +40,9 @@ public boolean writeIota(@Nullable Iota datum, boolean simulate) {
}

@Override
public @Nullable Iota readIota() {
public @Nullable Iota readIota(ServerLevel world) {
var delegate = IXplatAbstractions.INSTANCE.findDataHolder(this.stackSupplier.get());
return delegate == null ? null : delegate.readIota();
return delegate == null ? null : delegate.readIota(world);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
sound = HexEvalSounds.MISHAP,
)
} else {
result
result.copy(
newData = result.newData?.copy(
stack = validateIotaList(result.newData.stack, world)
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ fun <T : Iota> validateIota(iota: T, serverLevel: ServerLevel): Iota {
}
}

fun <T: Iota> validateIotaNullable(iota: T?, serverLevel: ServerLevel): Iota? {
return iota?.let { validateIota(iota, serverLevel) }
}

fun <T : Iota> validateIotaList(iotaList: List<T>, serverLevel: ServerLevel): List<Iota> {
return iotaList.map { validateIota(it, serverLevel) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
} else {
var datumContainer = IXplatAbstractions.INSTANCE.findDataHolder(usedStack);
if (datumContainer != null) {
var stored = datumContainer.readIota();
var stored = datumContainer.readIota(sLevel);
if (stored instanceof EntityIota eieio) {
var entity = eieio.getEntity(sLevel);
if (entity instanceof Player iotaPlayer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object OpRead : ConstMediaAction {
override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val (handStack) = env.getHeldItemToOperateOn {
val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
dataHolder != null && (dataHolder.readIota() != null || dataHolder.emptyIota() != null)
dataHolder != null && (dataHolder.readIota(env.world) != null || dataHolder.emptyIota() != null)
}
// If there are no data holders that are readable, find a data holder that isn't readable
// so that the error message is more helpful.
Expand All @@ -24,7 +24,7 @@ object OpRead : ConstMediaAction {
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
?: throw MishapBadOffhandItem.of(handStack, "iota.read")

val datum = datumHolder.readIota()
val datum = datumHolder.readIota(env.world)
?: datumHolder.emptyIota()
?: throw MishapBadOffhandItem.of(handStack, "iota.read")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object OpReadable : ConstMediaAction {
?: return false.asActionResult

// If the datum contains no iota, return whether it has a default empty iota.
datumHolder.readIota()
datumHolder.readIota(env.world)
?: return (datumHolder.emptyIota() != null).asActionResult

return true.asActionResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object OpTheCoolerRead : ConstMediaAction {
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(target)
?: throw MishapBadEntity.of(target, "iota.read")

val datum = datumHolder.readIota()
val datum = datumHolder.readIota(env.world)
?: datumHolder.emptyIota()
?: throw MishapBadEntity.of(target, "iota.read")
return listOf(datum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object OpTheCoolerReadable : ConstMediaAction {
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(target)
?: return false.asActionResult

datumHolder.readIota()
datumHolder.readIota(env.world)
?: datumHolder.emptyIota()
?: return false.asActionResult

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import at.petrak.hexcasting.api.casting.iota.Iota;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -27,8 +28,8 @@ public Wrapper(ItemDelegatingEntityIotaHolder inner) {


@Override
public @Nullable Iota readIota() {
return inner.readIota();
public @Nullable Iota readIota(ServerLevel world) {
return inner.readIota(world);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import at.petrak.hexcasting.api.item.IotaHolderItem;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.cca.api.v3.component.Component;

import java.util.function.Function;

import static at.petrak.hexcasting.api.utils.HexUtils.validateIotaNullable;

public abstract class CCItemIotaHolder implements CCIotaHolder, Component {
final ItemStack stack;
public CCItemIotaHolder(ItemStack stack) {
Expand All @@ -28,8 +31,8 @@ public ItemBased(ItemStack stack) {
}

@Override
public @Nullable Iota readIota() {
return this.iotaHolder.readIota(this.stack);
public @Nullable Iota readIota(ServerLevel world) {
return validateIotaNullable(this.iotaHolder.readIota(this.stack), world);
}

@Override
Expand Down Expand Up @@ -69,7 +72,7 @@ public Static(ItemStack stack, Function<ItemStack, Iota> provider) {
}

@Override
public @Nullable Iota readIota() {
public @Nullable Iota readIota(ServerLevel world) {
return this.provider.apply(this.stack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.addldata.ItemDelegatingEntityIotaHolder;
import at.petrak.hexcasting.api.casting.iota.Iota;
import net.minecraft.server.level.ServerLevel;
import org.jetbrains.annotations.Nullable;

public abstract class CapEntityIotaHolder implements ADIotaHolder {
Expand All @@ -24,8 +25,8 @@ public boolean writeIota(@Nullable Iota iota, boolean simulate) {
}

@Override
public @Nullable Iota readIota() {
return inner.readIota();
public @Nullable Iota readIota(ServerLevel world) {
return inner.readIota(world);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.item.IotaHolderItem;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import static at.petrak.hexcasting.api.utils.HexUtils.validateIotaNullable;

public record CapItemIotaHolder(IotaHolderItem holder, ItemStack stack) implements ADIotaHolder {

@Override
public @Nullable
Iota readIota() {
return holder.readIota(stack);
Iota readIota(ServerLevel world) {
return validateIotaNullable(holder.readIota(stack), world);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.casting.iota.Iota;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

Expand All @@ -12,7 +13,7 @@ public record CapStaticIotaHolder(Function<ItemStack, Iota> provider,

@Override
public @Nullable
Iota readIota() {
Iota readIota(ServerLevel world) {
return provider.apply(stack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.casting.iota.NullIota;
import at.petrak.hexcasting.api.item.IotaHolderItem;
import at.petrak.hexcasting.common.lib.HexDataComponents;
import at.petrak.hexcasting.forge.lib.ForgeHexIngredientTypes;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
Expand Down Expand Up @@ -56,8 +57,8 @@ public boolean test(@Nullable ItemStack input) {
}
if (this.stack.getItem() == input.getItem() && this.stack.getDamageValue() == input.getDamageValue()) {
ADIotaHolder holder = IXplatAbstractions.INSTANCE.findDataHolder(this.stack);
if (holder != null) {
return holder.readIota() != null && holder.writeIota(new NullIota(), true);
if (holder != null && this.stack.getItem() instanceof IotaHolderItem holderItem) {
return holderItem.readIota(this.stack) != null && holder.writeIota(new NullIota(), true);
}
}

Expand Down
Loading