spell circle error handling is a bit sus

This commit is contained in:
petrak@ 2023-05-15 12:19:53 -05:00
parent ac2a938119
commit 35e6b3f766
4 changed files with 48 additions and 19 deletions

View file

@ -79,16 +79,17 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
public void clearError() { public void clearError() {
this.errorMsg = null; this.errorMsg = null;
this.errorDisplay = null; this.errorDisplay = null;
this.sync();
} }
public void postError(Component error, ItemStack display) { public void postError(Component error, ItemStack display) {
this.errorMsg = error; this.errorMsg = error;
this.errorDisplay = display; this.errorDisplay = display;
this.sync();
} }
public void postMishap(Component mishapDisplay) { public void postMishap(Component mishapDisplay) {
this.errorMsg = mishapDisplay; this.postError(mishapDisplay, new ItemStack(Items.MUSIC_DISC_11));
this.errorDisplay = new ItemStack(Items.MUSIC_DISC_11);
} }
//region execution //region execution
@ -98,7 +99,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
return; return;
this.setChanged(); this.setChanged();
var state = this.getExecutionState(); var state = this.getExecutionState();
if (state == null) { if (state == null) {
return; return;
@ -109,15 +110,14 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
if (!shouldContinue) { if (!shouldContinue) {
this.endExecution(); this.endExecution();
this.executionState = null; this.executionState = null;
} } else
else
this.level.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), state.getTickSpeed()); this.level.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), state.getTickSpeed());
} }
public void endExecution() { public void endExecution() {
if (this.executionState == null) if (this.executionState == null)
return; return;
this.executionState.endExecution(this); this.executionState.endExecution(this);
} }
@ -143,7 +143,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
return; // TODO: error here? return; // TODO: error here?
if (this.level.isClientSide) if (this.level.isClientSide)
return; // TODO: error here? return; // TODO: error here?
if (this.executionState != null) { if (this.executionState != null) {
return; return;
} }
@ -151,12 +151,14 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
if (this.executionState == null) if (this.executionState == null)
return; return;
var serverLevel = (ServerLevel) this.level; var serverLevel = (ServerLevel) this.level;
serverLevel.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), this.executionState.getTickSpeed()); serverLevel.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(),
this.executionState.getTickSpeed());
serverLevel.setBlockAndUpdate(this.getBlockPos(), this.getBlockState().setValue(BlockCircleComponent.ENERGIZED, true));
serverLevel.setBlockAndUpdate(this.getBlockPos(),
this.getBlockState().setValue(BlockCircleComponent.ENERGIZED, true));
} }
@Contract(pure = true) @Contract(pure = true)
@ -263,11 +265,19 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
this.lazyExecutionState = null; this.lazyExecutionState = null;
} }
if (tag.contains(TAG_MEDIA, Tag.TAG_INT)) { if (tag.contains(TAG_MEDIA, Tag.TAG_LONG)) {
this.media = tag.getInt(TAG_MEDIA);
} else if (tag.contains(TAG_MEDIA, Tag.TAG_LONG)) {
this.media = tag.getLong(TAG_MEDIA); this.media = tag.getLong(TAG_MEDIA);
} }
if (tag.contains(TAG_ERROR_MSG, Tag.TAG_STRING) && tag.contains(TAG_ERROR_DISPLAY, Tag.TAG_COMPOUND)) {
var msg = Component.Serializer.fromJson(tag.getString(TAG_ERROR_MSG));
var display = ItemStack.of(tag.getCompound(TAG_ERROR_DISPLAY));
this.errorMsg = msg;
this.errorDisplay = display;
} else {
this.errorMsg = null;
this.errorDisplay = null;
}
} }
public void applyScryingLensOverlay(List<Pair<ItemStack, Component>> lines, public void applyScryingLensOverlay(List<Pair<ItemStack, Component>> lines,

View file

@ -7,6 +7,7 @@ import at.petrak.hexcasting.api.casting.circles.CircleExecutionState;
import at.petrak.hexcasting.api.casting.eval.CastResult; import at.petrak.hexcasting.api.casting.eval.CastResult;
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment; import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
import at.petrak.hexcasting.api.casting.eval.MishapEnvironment; import at.petrak.hexcasting.api.casting.eval.MishapEnvironment;
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect;
import at.petrak.hexcasting.api.pigment.FrozenPigment; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexItems;
import net.minecraft.Util; import net.minecraft.Util;
@ -63,6 +64,20 @@ public class CircleCastEnv extends CastingEnvironment {
var soundPos = this.execState.currentPos; var soundPos = this.execState.currentPos;
this.world.playSound(null, soundPos, sound, SoundSource.PLAYERS, 1f, 1f); this.world.playSound(null, soundPos, sound, SoundSource.PLAYERS, 1f, 1f);
} }
// TODO: this is gonna bite us in the bum someday
// we check whether we should cut the execution in BlockSlate, but post the mishap here;
// although everything should be pretty immutable here it's something to keep in mind
// classic time-of-check/time-of-use
var imp = this.getImpetus();
if (imp != null) {
for (var sideEffect : result.getSideEffects()) {
if (sideEffect instanceof OperatorSideEffect.DoMishap doMishap) {
var msg = doMishap.getMishap().errorMessageWithName(this, doMishap.getErrorCtx());
imp.postMishap(msg);
}
}
}
} }
@Override @Override

View file

@ -94,9 +94,11 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim
var vm = new CastingVM(imageIn, env); var vm = new CastingVM(imageIn, env);
var result = vm.queueExecuteAndWrapIota(new PatternIota(pattern), world); var result = vm.queueExecuteAndWrapIota(new PatternIota(pattern), world);
// TODO: make mishaps actually halt execution if (result.getResolutionType().getSuccess()) {
return new ControlFlow.Continue(vm.getImage(), exitDirs.toList());
return new ControlFlow.Continue(vm.getImage(), exitDirs.toList()); } else {
return new ControlFlow.Stop();
}
} }
@Override @Override

View file

@ -286,6 +286,8 @@
"brainsweep.min_level": "Level %s or higher", "brainsweep.min_level": "Level %s or higher",
"brainsweep.level": "Level %s", "brainsweep.level": "Level %s",
"brainsweep.product": "Mindless Body", "brainsweep.product": "Mindless Body",
"media": "%d dust"
}, },
// ^ tooltip // ^ tooltip
spelldata: { spelldata: {