diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java index f95fa84f0..81eead9e6 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java @@ -37,25 +37,27 @@ public class CircleExecutionState { TAG_ENTERED_FROM = "entered_from", TAG_IMAGE = "image", TAG_CASTER = "caster", - TAG_PIGMENT = "pigment"; + TAG_PIGMENT = "pigment", + TAG_REACHED_NUMBER = "reached_slate"; public final BlockPos impetusPos; public final Direction impetusDir; // Does contain the starting impetus public final Set knownPositions; - public final List reachedPositions; + public final HashSet reachedPositions; public BlockPos currentPos; public Direction enteredFrom; public CastingImage currentImage; public @Nullable UUID caster; public @Nullable FrozenPigment casterPigment; + public Integer reachedNumber; public final AABB bounds; protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set knownPositions, - List reachedPositions, BlockPos currentPos, Direction enteredFrom, - CastingImage currentImage, @Nullable UUID caster, @Nullable FrozenPigment casterPigment) { + HashSet reachedPositions, BlockPos currentPos, Direction enteredFrom, + CastingImage currentImage, @Nullable UUID caster, @Nullable FrozenPigment casterPigment, Integer reachedSlate) { this.impetusPos = impetusPos; this.impetusDir = impetusDir; this.knownPositions = knownPositions; @@ -65,6 +67,7 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set(this.knownPositions)); } @@ -83,7 +86,7 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set createNew(BlockEntityAbstractImpetus impetus, - @Nullable ServerPlayer caster) { + @Nullable ServerPlayer caster) { var level = (ServerLevel) impetus.getLevel(); if (level == null) @@ -129,7 +132,7 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set(seenGoodPositions); - var reachedPositions = new ArrayList(); + var reachedPositions = new HashSet(); reachedPositions.add(impetus.getBlockPos()); var start = seenGoodPositions.get(0); @@ -143,7 +146,7 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set( new CircleExecutionState(impetus.getBlockPos(), impetus.getStartDirection(), knownPositions, - reachedPositions, start, impetus.getStartDirection(), new CastingImage(), casterUUID, colorizer)); + reachedPositions, start, impetus.getStartDirection(), new CastingImage(), casterUUID, colorizer, 0)); } public CompoundTag save() { @@ -173,7 +176,7 @@ public CompoundTag save() { if (this.casterPigment != null) out.put(TAG_PIGMENT, this.casterPigment.serializeToNBT()); - + out.putInt(TAG_REACHED_NUMBER, this.reachedNumber); return out; } @@ -186,7 +189,7 @@ public static CircleExecutionState load(CompoundTag nbt, ServerLevel world) { for (var tag : knownTag) { knownPositions.add(NbtUtils.readBlockPos(HexUtils.downcast(tag, CompoundTag.TYPE))); } - var reachedPositions = new ArrayList(); + var reachedPositions = new HashSet(); var reachedTag = nbt.getList(TAG_REACHED_POSITIONS, Tag.TAG_COMPOUND); for (var tag : reachedTag) { reachedPositions.add(NbtUtils.readBlockPos(HexUtils.downcast(tag, CompoundTag.TYPE))); @@ -204,8 +207,13 @@ public static CircleExecutionState load(CompoundTag nbt, ServerLevel world) { if (nbt.contains(TAG_PIGMENT, Tag.TAG_COMPOUND)) pigment = FrozenPigment.fromNBT(nbt.getCompound(TAG_PIGMENT)); + int reachedNumber = 0; + if (nbt.contains(TAG_REACHED_NUMBER, Tag.TAG_INT)) { + reachedNumber = nbt.getInt(TAG_REACHED_NUMBER); + } + return new CircleExecutionState(startPos, startDir, knownPositions, reachedPositions, currentPos, - enteredFrom, image, caster, pigment); + enteredFrom, image, caster, pigment, reachedNumber); } /** @@ -231,6 +239,7 @@ public boolean tick(BlockEntityAbstractImpetus impetus) { executorBlockState = executor.startEnergized(this.currentPos, executorBlockState, world); this.reachedPositions.add(this.currentPos); + this.reachedNumber = this.reachedNumber +1; // Do the execution! boolean halt = false; @@ -257,7 +266,7 @@ public boolean tick(BlockEntityAbstractImpetus impetus) { Component.literal(this.currentPos.toShortString()).withStyle(ChatFormatting.RED)), new ItemStack(Items.COMPASS)); ICircleComponent.sfx(this.currentPos, executorBlockState, world, - Objects.requireNonNull(env.getImpetus()), false); + Objects.requireNonNull(env.getImpetus()), false); halt = true; break; } else { @@ -289,7 +298,7 @@ public boolean tick(BlockEntityAbstractImpetus impetus) { * How many ticks should pass between activations, given the number of blocks encountered so far. */ protected int getTickSpeed() { - return Math.max(2, 10 - (this.reachedPositions.size() - 1) / 3); + return Math.max(2, 10 - (this.reachedNumber - 1) / 3); } public void endExecution(BlockEntityAbstractImpetus impetus) {