fix empty null datum for realsies
This commit is contained in:
parent
17644ab40f
commit
81fa34841f
6 changed files with 28 additions and 10 deletions
|
@ -30,6 +30,11 @@ public interface DataHolder {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
default SpellDatum<?> emptyDatum(ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean canWrite(ItemStack stack, @Nullable SpellDatum<?> datum);
|
||||
|
||||
void writeDatum(ItemStack stack, @Nullable SpellDatum<?> datum);
|
||||
|
|
|
@ -12,11 +12,13 @@ object OpRead : ConstManaOperator {
|
|||
override fun execute(args: List<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
|
||||
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
||||
val item = it.item
|
||||
item is DataHolder && item.readDatum(it, ctx.world) != null
|
||||
item is DataHolder && (item.readDatum(it, ctx.world) != null || item.emptyDatum(it) != null)
|
||||
}
|
||||
|
||||
val handItem = handStack.item
|
||||
val datum = (handItem as? DataHolder)?.readDatum(handStack, ctx.world) ?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read")
|
||||
val datum = (handItem as? DataHolder)?.readDatum(handStack, ctx.world)
|
||||
?: (handItem as? DataHolder)?.emptyDatum(handStack)
|
||||
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read")
|
||||
|
||||
return listOf(datum)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@ object OpTheCoolerRead : ConstManaOperator {
|
|||
ctx.assertEntityInRange(target)
|
||||
|
||||
|
||||
val datum = item.readDatum(stack, ctx.world) ?: throw MishapBadItem.of(stack, "iota.read")
|
||||
val datum = item.readDatum(stack, ctx.world)
|
||||
?: item.emptyDatum(stack)
|
||||
?: throw MishapBadItem.of(stack, "iota.read")
|
||||
return listOf(datum)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,16 +28,21 @@ public class ItemFocus extends Item implements DataHolder {
|
|||
@Override
|
||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
||||
if (!stack.hasTag()) {
|
||||
return SpellDatum.make(Widget.NULL).serializeToNBT();
|
||||
return null;
|
||||
}
|
||||
var tag = stack.getTag();
|
||||
if (!tag.contains(TAG_DATA, Tag.TAG_COMPOUND)) {
|
||||
return SpellDatum.make(Widget.NULL).serializeToNBT();
|
||||
return null;
|
||||
}
|
||||
|
||||
return tag.getCompound(TAG_DATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable SpellDatum<?> emptyDatum(ItemStack stack) {
|
||||
return SpellDatum.make(Widget.NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(ItemStack stack, SpellDatum<?> datum) {
|
||||
return !stack.hasTag() || !stack.getTag().getBoolean(TAG_SEALED);
|
||||
|
|
|
@ -43,7 +43,6 @@ public class ItemSpellbook extends Item implements DataHolder {
|
|||
var tag = stack.getOrCreateTag();
|
||||
if (tag.contains(TAG_SELECTED_PAGE, Tag.TAG_ANY_NUMERIC)) {
|
||||
var pageIdx = tag.getInt(TAG_SELECTED_PAGE);
|
||||
var pages = tag.getCompound(ItemSpellbook.TAG_PAGES);
|
||||
int highest = HighestPage(stack);
|
||||
if (highest != 0) {
|
||||
tooltip.add(new TranslatableComponent("hexcasting.tooltip.spellbook.page",
|
||||
|
@ -98,7 +97,7 @@ public class ItemSpellbook extends Item implements DataHolder {
|
|||
@Override
|
||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
||||
if (!stack.hasTag()) {
|
||||
return SpellDatum.make(Widget.NULL).serializeToNBT();
|
||||
return null;
|
||||
}
|
||||
var tag = stack.getTag();
|
||||
|
||||
|
@ -114,13 +113,18 @@ public class ItemSpellbook extends Item implements DataHolder {
|
|||
if (pagesTag.contains(key)) {
|
||||
return pagesTag.getCompound(key);
|
||||
} else {
|
||||
return SpellDatum.make(Widget.NULL).serializeToNBT();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return SpellDatum.make(Widget.NULL).serializeToNBT();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable SpellDatum<?> emptyDatum(ItemStack stack) {
|
||||
return SpellDatum.make(Widget.NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(ItemStack stack, SpellDatum<?> datum) {
|
||||
return true;
|
||||
|
|
|
@ -85,7 +85,7 @@ public abstract class ItemManaHolder extends Item implements ManaHolder {
|
|||
@Override
|
||||
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
||||
TooltipFlag pIsAdvanced) {
|
||||
if (pIsAdvanced.isAdvanced()) {
|
||||
if (pIsAdvanced.isAdvanced() && getMaxMana(pStack) > 0) {
|
||||
pTooltipComponents.add(
|
||||
new TranslatableComponent("item.hexcasting.manaholder.amount",
|
||||
String.format("%,d", getMana(pStack)),
|
||||
|
|
Loading…
Reference in a new issue