i've been patching up the harness, all the live-long day

This commit is contained in:
petrak@ 2023-02-18 17:53:27 -06:00
parent ca5ccf60f6
commit a501f774c3
13 changed files with 39 additions and 32 deletions

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.casting.eval package at.petrak.hexcasting.api.casting.eval
import net.minecraft.network.chat.Component import net.minecraft.nbt.CompoundTag
/** /**
* Information sent back to the client * Information sent back to the client
@ -9,7 +9,9 @@ data class ExecutionClientView(
val isStackClear: Boolean, val isStackClear: Boolean,
val resolutionType: ResolvedPatternType, val resolutionType: ResolvedPatternType,
val stackDescs: List<Component>, // These must be tags so the wrapping of the text can happen on the client
val ravenmind: Component?, // otherwise we don't know when to stop rendering
val stackDescs: List<CompoundTag>,
val ravenmind: CompoundTag?,
) )

View file

@ -27,7 +27,6 @@ import net.minecraft.server.level.ServerLevel
* [CastingEnvironment] to affect the world. * [CastingEnvironment] to affect the world.
*/ */
class CastingVM(var image: CastingImage, val env: CastingEnvironment) { class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
/** /**
* Execute a single iota. * Execute a single iota.
*/ */
@ -229,11 +228,10 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
} }
} }
fun generateDescs(): Pair<List<Component>, Component?> { fun generateDescs(): Pair<List<CompoundTag>, CompoundTag?> {
val stackDescs = this.image.stack.map { it.display() } val stackDescs = this.image.stack.map { IotaType.serialize(it) }
val ravenmind = if (this.image.userData.contains(HexAPI.RAVENMIND_USERDATA)) { val ravenmind = if (this.image.userData.contains(HexAPI.RAVENMIND_USERDATA)) {
val tag = this.image.userData.getCompound(HexAPI.RAVENMIND_USERDATA) this.image.userData.getCompound(HexAPI.RAVENMIND_USERDATA)
IotaType.getDisplay(tag)
} else null } else null
return Pair(stackDescs, ravenmind) return Pair(stackDescs, ravenmind)
} }
@ -357,4 +355,11 @@ class CastingVM(var image: CastingImage, val env: CastingEnvironment) {
data class TempControllerInfo( data class TempControllerInfo(
var earlyExit: Boolean, var earlyExit: Boolean,
) )
companion object {
@JvmStatic
fun empty(env: CastingEnvironment): CastingVM {
return CastingVM(CastingImage(), env)
}
}
} }

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.client; package at.petrak.hexcasting.client;
import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.item.IotaHolderItem; import at.petrak.hexcasting.api.item.IotaHolderItem;
import at.petrak.hexcasting.api.item.MediaHolderItem; import at.petrak.hexcasting.api.item.MediaHolderItem;
import at.petrak.hexcasting.api.misc.MediaConstants; import at.petrak.hexcasting.api.misc.MediaConstants;

View file

@ -40,7 +40,6 @@ class GuiSpellcasting constructor(
private val handOpenedWith: InteractionHand, private val handOpenedWith: InteractionHand,
private var patterns: MutableList<ResolvedPattern>, private var patterns: MutableList<ResolvedPattern>,
private var cachedStack: List<CompoundTag>, private var cachedStack: List<CompoundTag>,
private var cachedParens: List<CompoundTag>,
private var cachedRavenmind: CompoundTag?, private var cachedRavenmind: CompoundTag?,
private var parenCount: Int, private var parenCount: Int,
) : Screen("gui.hexcasting.spellcasting".asTranslatedComponent) { ) : Screen("gui.hexcasting.spellcasting".asTranslatedComponent) {
@ -67,10 +66,8 @@ class GuiSpellcasting constructor(
it.type = info.resolutionType it.type = info.resolutionType
} }
this.cachedStack = info.stack this.cachedStack = info.stackDescs
this.cachedParens = info.parenthesized
this.cachedRavenmind = info.ravenmind this.cachedRavenmind = info.ravenmind
this.parenCount = info.parenCount
this.calculateIotaDisplays() this.calculateIotaDisplays()
} }

View file

@ -53,6 +53,11 @@ public class PackagedItemCastEnv extends PlayerBasedCastEnv {
return costLeft; return costLeft;
} }
@Override
public InteractionHand castingHand() {
return this.castingHand;
}
@Override @Override
public FrozenColorizer getColorizer() { public FrozenColorizer getColorizer() {
return null; return null;

View file

@ -77,10 +77,10 @@ public class StaffCastEnv extends PlayerBasedCastEnv {
ExecutionClientView clientInfo = harness.queueAndExecuteIota(new PatternIota(msg.pattern()), sender.getLevel()); ExecutionClientView clientInfo = harness.queueAndExecuteIota(new PatternIota(msg.pattern()), sender.getLevel());
if (clientInfo.isStackClear()) { if (clientInfo.isStackClear()) {
IXplatAbstractions.INSTANCE.setHarness(sender, null); IXplatAbstractions.INSTANCE.setStaffcastImage(sender, null);
IXplatAbstractions.INSTANCE.setPatterns(sender, List.of()); IXplatAbstractions.INSTANCE.setPatterns(sender, List.of());
} else { } else {
IXplatAbstractions.INSTANCE.setHarness(sender, harness); IXplatAbstractions.INSTANCE.setStaffcastImage(sender, harness);
if (!resolvedPatterns.isEmpty()) { if (!resolvedPatterns.isEmpty()) {
resolvedPatterns.get(resolvedPatterns.size() - 1).setType(clientInfo.getResolutionType()); resolvedPatterns.get(resolvedPatterns.size() - 1).setType(clientInfo.getResolutionType());
} }

View file

@ -1,11 +1,11 @@
package at.petrak.hexcasting.common.items.magic; package at.petrak.hexcasting.common.items.magic;
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.Iota; import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.casting.iota.IotaType; import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.item.HexHolderItem; import at.petrak.hexcasting.api.item.HexHolderItem;
import at.petrak.hexcasting.api.utils.NBTHelper; import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.common.casting.env.PackagedItemCastEnv;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
@ -108,9 +108,9 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold
return InteractionResultHolder.fail(stack); return InteractionResultHolder.fail(stack);
} }
var sPlayer = (ServerPlayer) player; var sPlayer = (ServerPlayer) player;
var ctx = new CastingEnvironment(sPlayer, usedHand, CastingEnvironment.CastSource.PACKAGED_HEX); var ctx = new PackagedItemCastEnv(sPlayer, usedHand);
var harness = new CastingVM(ctx); var harness = CastingVM.empty(ctx);
var info = harness.queueAndExecuteIotas(instrs, sPlayer.getLevel()); harness.queueAndExecuteIotas(instrs, sPlayer.getLevel());
boolean broken = breakAfterDepletion() && getMedia(stack) == 0; boolean broken = breakAfterDepletion() && getMedia(stack) == 0;
@ -133,11 +133,6 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold
} }
} }
@Override
public int getUseDuration(ItemStack pStack) {
return 16;
}
@Override @Override
public UseAnim getUseAnimation(ItemStack pStack) { public UseAnim getUseAnimation(ItemStack pStack) {
return UseAnim.BLOCK; return UseAnim.BLOCK;

View file

@ -8,6 +8,7 @@ import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler; import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.casting.eval.ResolvedPattern; import at.petrak.hexcasting.api.casting.eval.ResolvedPattern;
import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound; import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.IotaType; import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.misc.FrozenColorizer;
@ -82,7 +83,7 @@ public interface IXplatAbstractions {
void setAltiora(Player target, @Nullable AltioraAbility altiora); void setAltiora(Player target, @Nullable AltioraAbility altiora);
void setHarness(ServerPlayer target, @Nullable CastingVM harness); void setStaffcastImage(ServerPlayer target, @Nullable CastingImage image);
void setPatterns(ServerPlayer target, List<ResolvedPattern> patterns); void setPatterns(ServerPlayer target, List<ResolvedPattern> patterns);

View file

@ -8,13 +8,13 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class CCHarness implements Component { public class CCStaffcastImage implements Component {
public static final String TAG_HARNESS = "harness"; public static final String TAG_HARNESS = "harness";
private final ServerPlayer owner; private final ServerPlayer owner;
private CompoundTag lazyLoadedTag = new CompoundTag(); private CompoundTag lazyLoadedTag = new CompoundTag();
public CCHarness(ServerPlayer owner) { public CCStaffcastImage(ServerPlayer owner) {
this.owner = owner; this.owner = owner;
} }

View file

@ -45,8 +45,8 @@ public class HexCardinalComponents implements EntityComponentInitializer, ItemCo
public static final ComponentKey<CCAltiora> ALTIORA = ComponentRegistry.getOrCreate(modLoc("altiora"), public static final ComponentKey<CCAltiora> ALTIORA = ComponentRegistry.getOrCreate(modLoc("altiora"),
CCAltiora.class); CCAltiora.class);
public static final ComponentKey<CCHarness> HARNESS = ComponentRegistry.getOrCreate(modLoc("harness"), public static final ComponentKey<CCStaffcastImage> HARNESS = ComponentRegistry.getOrCreate(modLoc("harness"),
CCHarness.class); CCStaffcastImage.class);
public static final ComponentKey<CCPatterns> PATTERNS = ComponentRegistry.getOrCreate(modLoc("patterns"), public static final ComponentKey<CCPatterns> PATTERNS = ComponentRegistry.getOrCreate(modLoc("patterns"),
CCPatterns.class); CCPatterns.class);
@ -67,7 +67,7 @@ public class HexCardinalComponents implements EntityComponentInitializer, ItemCo
registry.registerForPlayers(ALTIORA, CCAltiora::new, RespawnCopyStrategy.LOSSLESS_ONLY); registry.registerForPlayers(ALTIORA, CCAltiora::new, RespawnCopyStrategy.LOSSLESS_ONLY);
// Fortunately these are all both only needed on the server and don't want to be copied across death // Fortunately these are all both only needed on the server and don't want to be copied across death
registry.registerFor(ServerPlayer.class, FLIGHT, CCFlight::new); registry.registerFor(ServerPlayer.class, FLIGHT, CCFlight::new);
registry.registerFor(ServerPlayer.class, HARNESS, CCHarness::new); registry.registerFor(ServerPlayer.class, HARNESS, CCStaffcastImage::new);
registry.registerFor(ServerPlayer.class, PATTERNS, CCPatterns::new); registry.registerFor(ServerPlayer.class, PATTERNS, CCPatterns::new);

View file

@ -8,6 +8,7 @@ import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler; import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.casting.eval.ResolvedPattern; import at.petrak.hexcasting.api.casting.eval.ResolvedPattern;
import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound; import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.IotaType; import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.misc.FrozenColorizer;
@ -170,7 +171,7 @@ public class FabricXplatImpl implements IXplatAbstractions {
cc.setAltiora(altiora); cc.setAltiora(altiora);
} }
public void setHarness(ServerPlayer target, CastingHarness harness) { public void setHarness(ServerPlayer target, CastingImage image) {
var cc = HexCardinalComponents.HARNESS.get(target); var cc = HexCardinalComponents.HARNESS.get(target);
cc.setHarness(harness); cc.setHarness(harness);
} }

View file

@ -29,7 +29,7 @@ public class CapSyncers {
x.setAltiora(player, x.getAltiora(proto)); x.setAltiora(player, x.getAltiora(proto));
x.setSentinel(player, x.getSentinel(proto)); x.setSentinel(player, x.getSentinel(proto));
x.setColorizer(player, x.getColorizer(proto)); x.setColorizer(player, x.getColorizer(proto));
x.setHarness(player, x.getStaffHarness(proto, InteractionHand.MAIN_HAND)); x.setStaffcastImage(player, x.getStaffHarness(proto, InteractionHand.MAIN_HAND));
x.setPatterns(player, x.getPatternsSavedInUi(proto)); x.setPatterns(player, x.getPatternsSavedInUi(proto));
} }

View file

@ -214,7 +214,7 @@ public class ForgeXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public void setHarness(ServerPlayer player, CastingVM harness) { public void setStaffcastImage(ServerPlayer player, CastingVM harness) {
player.getPersistentData().put(TAG_HARNESS, harness == null ? new CompoundTag() : harness.serializeToNBT()); player.getPersistentData().put(TAG_HARNESS, harness == null ? new CompoundTag() : harness.serializeToNBT());
} }