Merge remote-tracking branch 'origin/main' into eval/cc

This commit is contained in:
Alwinfy 2022-11-16 00:48:06 -05:00
commit cc3691d9c9
No known key found for this signature in database
GPG key ID: 2CCB99445F0C949E
28 changed files with 1408 additions and 156 deletions

View file

@ -115,9 +115,9 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
}
public void applyScryingLensOverlay(List<Pair<ItemStack, Component>> lines,
BlockState state, BlockPos pos,
Player observer, Level world,
Direction hitFace) {
BlockState state, BlockPos pos,
Player observer, Level world,
Direction hitFace) {
if (world.getBlockEntity(pos) instanceof BlockEntityAbstractImpetus beai) {
if (beai.getMedia() < 0) {
lines.add(new Pair<>(new ItemStack(HexItems.AMETHYST_DUST), ItemCreativeUnlocker.infiniteMedia(world)));
@ -286,7 +286,6 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
new SpellCircleContext(this.getBlockPos(), bounds, this.activatorAlwaysInRange()));
var harness = new CastingHarness(ctx);
var makeSound = false;
BlockPos erroredPos = null;
for (var tracked : this.trackedBlocks) {
var bs = this.level.getBlockState(tracked);
@ -294,9 +293,6 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
var newPattern = cc.getPattern(tracked, bs, this.level);
if (newPattern != null) {
var info = harness.executeIota(new PatternIota(newPattern), splayer.getLevel());
if (info.getMakesCastSound()) {
makeSound = true;
}
if (!info.getResolutionType().getSuccess()) {
erroredPos = tracked;
break;
@ -305,11 +301,6 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
}
}
if (makeSound) {
this.level.playSound(null, this.getBlockPos(), HexSounds.SPELL_CIRCLE_CAST, SoundSource.BLOCKS,
2f, 1f);
}
if (erroredPos != null) {
this.sfx(erroredPos, false);
} else {
@ -541,19 +532,22 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
@Override
public boolean canPlaceItem(int index, ItemStack stack) {
if (remainingMediaCapacity() == 0)
if (remainingMediaCapacity() == 0) {
return false;
}
if (stack.is(HexItems.CREATIVE_UNLOCKER))
if (stack.is(HexItems.CREATIVE_UNLOCKER)) {
return true;
}
var mediamount = extractMediaFromItem(stack, true);
return mediamount > 0;
}
public int extractMediaFromItem(ItemStack stack, boolean simulate) {
if (this.media < 0)
if (this.media < 0) {
return 0;
}
return MediaHelper.extractMedia(stack, remainingMediaCapacity(), true, simulate);
}
@ -576,8 +570,9 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
}
public int remainingMediaCapacity() {
if (this.media < 0)
if (this.media < 0) {
return 0;
}
return Math.max(0, MAX_CAPACITY - this.media);
}
}

View file

@ -28,9 +28,18 @@ import kotlin.math.min
data class CastingContext(
val caster: ServerPlayer,
val castingHand: InteractionHand,
val source: CastSource,
val spellCircle: SpellCircleContext? = null
) {
constructor(caster: ServerPlayer, castingHand: InteractionHand) : this(caster, castingHand, null)
constructor(caster: ServerPlayer, castingHand: InteractionHand, source: CastSource) : this(
caster,
castingHand,
source,
null
)
constructor(caster: ServerPlayer, castingHand: InteractionHand, spellCircleContext: SpellCircleContext) :
this(caster, castingHand, CastSource.SPELL_CIRCLE, spellCircleContext)
private var depth: Int = 0
@ -223,7 +232,8 @@ data class CastingContext(
DiscoveryHandlers.addOperativeSlotDiscoverer {
val slots = mutableListOf<ItemStack>()
val anchorSlot = if (it.castingHand == InteractionHand.MAIN_HAND) (it.caster.inventory.selected + 1) % 9 else 0
val anchorSlot =
if (it.castingHand == InteractionHand.MAIN_HAND) (it.caster.inventory.selected + 1) % 9 else 0
slots.add(it.caster.getItemInHand(it.otherHand))
for (delta in 0 until 9) {
@ -234,4 +244,10 @@ data class CastingContext(
}
}
}
enum class CastSource {
STAFF,
PACKAGED_HEX,
SPELL_CIRCLE,
}
}

View file

@ -28,6 +28,8 @@ import net.minecraft.nbt.Tag
import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerLevel
import net.minecraft.sounds.SoundSource
import net.minecraft.world.level.gameevent.GameEvent
import net.minecraft.world.phys.Vec3
import kotlin.math.min
@ -92,7 +94,7 @@ class CastingHarness private constructor(
// Initialize the continuation stack to a single top-level eval for all iotas.
var continuation = SpellContinuation.Done.pushFrame(ContinuationFrame.Evaluate(SpellList.LList(0, iotas)))
// Begin aggregating info
val info = TempControllerInfo(playSound = false, earlyExit = false)
val info = TempControllerInfo(earlyExit = false)
var lastResolutionType = ResolvedPatternType.UNRESOLVED
while (continuation is SpellContinuation.NotDone && !info.earlyExit) {
// Take the top of the continuation stack...
@ -112,7 +114,8 @@ class CastingHarness private constructor(
mishap,
Mishap.Context(pattern ?: HexPattern(HexDir.WEST), operator)
)
)
),
EvalSound.MISHAP,
)
}
// Then write all pertinent data back to the harness for the next iteration.
@ -121,7 +124,7 @@ class CastingHarness private constructor(
}
continuation = result.continuation
lastResolutionType = result.resolutionType
performSideEffects(info, result.sideEffects)
performSideEffects(info, result.sideEffects, result.sound)
info.earlyExit = info.earlyExit || !lastResolutionType.success
}
@ -133,7 +136,6 @@ class CastingHarness private constructor(
val (stackDescs, parenDescs, ravenmind) = generateDescs()
return ControllerInfo(
info.playSound,
this.stack.isEmpty() && this.parenCount == 0 && !this.escapeNext,
lastResolutionType,
stackDescs,
@ -146,7 +148,7 @@ class CastingHarness private constructor(
fun getUpdate(iota: Iota, world: ServerLevel, continuation: SpellContinuation): CastResult {
try {
this.handleParentheses(iota)?.let { (data, resolutionType) ->
return@getUpdate CastResult(continuation, data, resolutionType, listOf())
return@getUpdate CastResult(continuation, data, resolutionType, listOf(), EvalSound.GENERIC)
}
return if (iota is PatternIota) {
@ -169,6 +171,7 @@ class CastingHarness private constructor(
Mishap.Context(HexPattern(HexDir.WEST), null)
)
),
EvalSound.MISHAP
)
}
} catch (mishap: Mishap) {
@ -179,11 +182,16 @@ class CastingHarness private constructor(
listOf(
OperatorSideEffect.DoMishap(
mishap,
Mishap.Context((iota as? PatternIota)?.pattern ?: HexPattern(HexDir.WEST), getOperatorForPattern(iota, world))
Mishap.Context(
(iota as? PatternIota)?.pattern ?: HexPattern(HexDir.WEST),
getOperatorForPattern(iota, world)
)
)
),
EvalSound.MISHAP
)
} catch (exception: Exception) {
// This means something very bad has happened
exception.printStackTrace()
return CastResult(
continuation,
@ -192,9 +200,13 @@ class CastingHarness private constructor(
listOf(
OperatorSideEffect.DoMishap(
MishapError(exception),
Mishap.Context((iota as? PatternIota)?.pattern ?: HexPattern(HexDir.WEST), getOperatorForPattern(iota, world))
Mishap.Context(
(iota as? PatternIota)?.pattern ?: HexPattern(HexDir.WEST),
getOperatorForPattern(iota, world)
)
)
)
),
EvalSound.MISHAP
)
}
}
@ -268,11 +280,28 @@ class CastingHarness private constructor(
hereFd
}
var soundType =
if (this.ctx.source == CastingContext.CastSource.STAFF) EvalSound.GENERIC else EvalSound.NONE;
for (se in sideEffects) {
if (se is OperatorSideEffect.AttemptSpell) {
if (se.hasCastingSound) {
soundType = soundType.greaterOf(EvalSound.SPELL_BOINK)
} else {
// WITH CATLIKE TREAD
// UPON OUR PREY WE STEAL
soundType = EvalSound.NONE
break
}
} else if (se is OperatorSideEffect.DoMishap) {
soundType = EvalSound.MISHAP
}
}
return CastResult(
cont2,
fd,
ResolvedPatternType.EVALUATED,
sideEffects,
soundType,
)
} catch (mishap: Mishap) {
@ -281,19 +310,7 @@ class CastingHarness private constructor(
null,
mishap.resolutionType(ctx),
listOf(OperatorSideEffect.DoMishap(mishap, Mishap.Context(newPat, actionIdPair?.first))),
)
} catch (exception: Exception) {
exception.printStackTrace()
return CastResult(
continuation,
null,
ResolvedPatternType.ERRORED,
listOf(
OperatorSideEffect.DoMishap(
MishapError(exception),
Mishap.Context(newPat, actionIdPair?.first)
)
)
EvalSound.MISHAP
)
}
}
@ -301,19 +318,21 @@ class CastingHarness private constructor(
/**
* Execute the side effects of a pattern, updating our aggregated info.
*/
fun performSideEffects(info: TempControllerInfo, sideEffects: List<OperatorSideEffect>) {
fun performSideEffects(info: TempControllerInfo, sideEffects: List<OperatorSideEffect>, sound: EvalSound) {
for (haskellProgrammersShakingandCryingRN in sideEffects) {
val mustStop = haskellProgrammersShakingandCryingRN.performEffect(this)
if (mustStop) {
info.earlyExit = true
break
}
if (haskellProgrammersShakingandCryingRN is OperatorSideEffect.AttemptSpell &&
haskellProgrammersShakingandCryingRN.hasCastingSound
) {
info.playSound = true
}
}
sound.soundEvent()?.let {
this.ctx.world.playSound(
null, this.ctx.position.x, this.ctx.position.y, this.ctx.position.z, it,
SoundSource.PLAYERS, 1f, 1f
)
// TODO: is it worth mixing in to the immut map and making our own game event with blackjack and hookers
this.ctx.world.gameEvent(this.ctx.caster, GameEvent.ITEM_INTERACT_FINISH, this.ctx.position)
}
}
@ -626,7 +645,6 @@ class CastingHarness private constructor(
}
data class TempControllerInfo(
var playSound: Boolean,
var earlyExit: Boolean,
)
@ -635,5 +653,6 @@ class CastingHarness private constructor(
val newData: FunctionalData?,
val resolutionType: ResolvedPatternType,
val sideEffects: List<OperatorSideEffect>,
val sound: EvalSound,
)
}

View file

@ -61,16 +61,16 @@ sealed interface ContinuationFrame {
harness: CastingHarness
): CastResult {
// If there are patterns left...
if (list.nonEmpty) {
return if (list.nonEmpty) {
val newCont = if (list.cdr.nonEmpty) { // yay TCO
// ...enqueue the evaluation of the rest of the patterns...
continuation.pushFrame(Evaluate(list.cdr))
} else continuation
// ...before evaluating the first one in the list.
return harness.getUpdate(list.car, level, newCont)
harness.getUpdate(list.car, level, newCont)
} else {
// If there are no patterns (e.g. empty Hermes), just return OK.
return CastResult(continuation, null, ResolvedPatternType.EVALUATED, listOf())
CastResult(continuation, null, ResolvedPatternType.EVALUATED, listOf(), EvalSound.NONE)
}
}
@ -98,7 +98,8 @@ sealed interface ContinuationFrame {
continuation,
FunctionalData(harness.stack.toList(), 0, listOf(), false, harness.ravenmind),
ResolvedPatternType.EVALUATED,
listOf()
listOf(),
EvalSound.NONE,
)
}
@ -163,11 +164,13 @@ sealed interface ContinuationFrame {
}
val tStack = stack.toMutableList()
tStack.add(stackTop)
// TODO: this means we could have Thoth casting do a different sound
return CastResult(
newCont,
FunctionalData(tStack, 0, listOf(), false, harness.ravenmind),
ResolvedPatternType.EVALUATED,
listOf()
listOf(),
EvalSound.NONE,
)
}

View file

@ -6,7 +6,6 @@ import net.minecraft.nbt.CompoundTag
* Information for the sake of the GUI.
*/
data class ControllerInfo(
val makesCastSound: Boolean,
val isStackClear: Boolean,
val resolutionType: ResolvedPatternType,
val stack: List<CompoundTag>,
@ -14,3 +13,4 @@ data class ControllerInfo(
val ravenmind: CompoundTag?,
val parenCount: Int,
)

View file

@ -0,0 +1,34 @@
package at.petrak.hexcasting.api.spell.casting
import at.petrak.hexcasting.common.lib.HexSounds
import net.minecraft.sounds.SoundEvent
/**
* Sound that plays as a side-effect-adjacent when casting
*/
enum class EvalSound {
/** Silence */
NONE,
/** The generic "bvwonh" sound for non-spell ops */
GENERIC,
/** The "bwoink!" for spell ops */
SPELL_BOINK,
/** The "gvwoh" for mishaps */
MISHAP;
/**
* Which sound type has the greater priority?
*/
fun greaterOf(that: EvalSound): EvalSound =
EvalSound.values()[maxOf(this.ordinal, that.ordinal)]
fun soundEvent(): SoundEvent? = when (this) {
NONE -> null
GENERIC -> HexSounds.ADD_PATTERN
SPELL_BOINK -> HexSounds.ACTUALLY_CAST
MISHAP -> HexSounds.FAIL_PATTERN
}
}

View file

@ -9,9 +9,7 @@ import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.mishaps.Mishap
import at.petrak.hexcasting.api.utils.asTranslatedComponent
import at.petrak.hexcasting.common.lib.HexItems
import at.petrak.hexcasting.common.lib.HexSounds
import net.minecraft.Util
import net.minecraft.sounds.SoundSource
import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack
@ -44,6 +42,7 @@ sealed class OperatorSideEffect {
this.spell.cast(harness.ctx)
if (awardStat)
harness.ctx.caster.awardStat(HexStatistics.SPELLS_CAST)
return false
}
}
@ -92,11 +91,6 @@ sealed class OperatorSideEffect {
)
)
harness.ctx.world.playSound(
null, harness.ctx.position.x, harness.ctx.position.y, harness.ctx.position.z,
HexSounds.FAIL_PATTERN, SoundSource.PLAYERS, 1f, 1f
)
mishap.execute(harness.ctx, errorCtx, harness.stack)
return true

View file

@ -65,22 +65,6 @@ class GuiSpellcasting constructor(
it.type = info.resolutionType
}
val mc = Minecraft.getInstance()
if (info.resolutionType.success) {
mc.soundManager.play(
SimpleSoundInstance(
HexSounds.ADD_PATTERN,
SoundSource.PLAYERS,
0.5f,
1f + (Math.random().toFloat() - 0.5f) * 0.1f,
randSrc,
this.ambianceSoundInstance!!.x,
this.ambianceSoundInstance!!.y,
this.ambianceSoundInstance!!.z,
)
)
}
this.cachedStack = info.stack
this.cachedParens = info.parenthesized
this.cachedRavenmind = info.ravenmind

View file

@ -91,19 +91,29 @@ public class RegisterPatterns {
// == Modify Stack ==
PatternRegistry.mapPattern(HexPattern.fromAngles("aawdd", HexDir.EAST), modLoc("swap"), OpSwap.INSTANCE);
PatternRegistry.mapPattern(HexPattern.fromAngles("aawdd", HexDir.EAST), modLoc("swap"),
new OpTwiddling(2, new int[]{1, 0}));
PatternRegistry.mapPattern(HexPattern.fromAngles("aaeaa", HexDir.EAST), modLoc("rotate"),
OpRotate.INSTANCE);
new OpTwiddling(3, new int[]{1, 2, 0}));
PatternRegistry.mapPattern(HexPattern.fromAngles("ddqdd", HexDir.NORTH_EAST), modLoc("rotate-reverse"),
new OpTwiddling(3, new int[]{2, 0, 1}));
PatternRegistry.mapPattern(HexPattern.fromAngles("aadaa", HexDir.EAST), modLoc("duplicate"),
OpDuplicate.INSTANCE);
PatternRegistry.mapPattern(HexPattern.fromAngles("aadaadaa", HexDir.EAST), modLoc("duplicate_n"),
OpDuplicateN.INSTANCE);
new OpTwiddling(1, new int[]{0, 0}));
PatternRegistry.mapPattern(HexPattern.fromAngles("aaedd", HexDir.EAST), modLoc("over"),
OpOver.INSTANCE);
new OpTwiddling(2, new int[]{0, 1, 0}));
PatternRegistry.mapPattern(HexPattern.fromAngles("ddqaa", HexDir.EAST), modLoc("tuck"),
new OpTwiddling(2, new int[]{1, 0, 1}));
PatternRegistry.mapPattern(HexPattern.fromAngles("aadadaaw", HexDir.EAST), modLoc("2dup"),
new OpTwiddling(2, new int[]{0, 1, 0, 1}));
PatternRegistry.mapPattern(HexPattern.fromAngles("qwaeawqaeaqa", HexDir.NORTH_WEST), modLoc("stack_len"),
OpStackSize.INSTANCE);
PatternRegistry.mapPattern(HexPattern.fromAngles("aadaadaa", HexDir.EAST), modLoc("duplicate_n"),
OpDuplicateN.INSTANCE);
PatternRegistry.mapPattern(HexPattern.fromAngles("ddad", HexDir.WEST), modLoc("fisherman"),
OpFisherman.INSTANCE);
PatternRegistry.mapPattern(HexPattern.fromAngles("aada", HexDir.EAST), modLoc("fisherman/copy"),
OpFishermanButItCopies.INSTANCE);
PatternRegistry.mapPattern(HexPattern.fromAngles("qaawdde", HexDir.SOUTH_EAST), modLoc("swizzle"),
OpAlwinfyHasAscendedToABeingOfPureMath.INSTANCE);

View file

@ -7,6 +7,7 @@ import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.common.network.MsgBeepAck
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument
import net.minecraft.world.level.gameevent.GameEvent
import net.minecraft.world.phys.Vec3
object OpBeep : SpellAction {
@ -33,6 +34,7 @@ object OpBeep : SpellAction {
private data class Spell(val target: Vec3, val note: Int, val instrument: NoteBlockInstrument) : RenderedSpell {
override fun cast(ctx: CastingContext) {
IXplatAbstractions.INSTANCE.sendPacketNear(target, 128.0, ctx.world, MsgBeepAck(target, note, instrument))
ctx.world.gameEvent(null, GameEvent.NOTE_BLOCK_PLAY, target)
}
}
}

View file

@ -0,0 +1,28 @@
package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.Action
import at.petrak.hexcasting.api.spell.OperationResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.SpellContinuation
import at.petrak.hexcasting.api.spell.getPositiveIntUnderInclusive
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapNotEnoughArgs
object OpFishermanButItCopies : Action {
override fun operate(
continuation: SpellContinuation,
stack: MutableList<Iota>,
ravenmind: Iota?,
ctx: CastingContext
): OperationResult {
if (stack.size < 2)
throw MishapNotEnoughArgs(2, stack.size)
val depth = stack.getPositiveIntUnderInclusive(stack.lastIndex, stack.size - 1)
stack.removeLast()
val fish = stack.get(stack.size - 1 - depth)
stack.add(fish)
return OperationResult(continuation, stack, ravenmind, listOf())
}
}

View file

@ -1,15 +0,0 @@
package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
// Had never heard of this operation before i heard it from uxn, but turns out it's from forth
// see also http://www.forth.org/Ting/Forth-for-the-Complete-Idiot/Forth-79-Handy-Reference.pdf
// "fisherman's" is called "roll," apparently
object OpOver : ConstMediaAction {
override val argc: Int
get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[0], args[1], args[0])
}

View file

@ -1,13 +0,0 @@
package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
// more Forth
object OpRotate : ConstMediaAction {
override val argc: Int
get() = 3
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[1], args[2], args[0])
}

View file

@ -1,14 +0,0 @@
package at.petrak.hexcasting.common.casting.operators.stack
import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpSwap : ConstMediaAction {
override val argc: Int
get() = 2
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return args.asReversed()
}
}

View file

@ -4,9 +4,10 @@ import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
object OpDuplicate : ConstMediaAction {
class OpTwiddling(val argumentCount: Int, val lookup: IntArray) : ConstMediaAction {
override val argc: Int
get() = 1
get() = this.argumentCount
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> = listOf(args[0], args[0])
}
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> =
this.lookup.map(args::get)
}

View file

@ -43,6 +43,7 @@ public class ItemStaff extends Item {
}
player.awardStat(Stats.ITEM_USED.get(this));
// player.gameEvent(GameEvent.ITEM_INTERACT_START);
return InteractionResultHolder.success(player.getItemInHand(hand));
}

View file

@ -6,14 +6,12 @@ import at.petrak.hexcasting.api.spell.casting.CastingHarness;
import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.common.lib.HexIotaTypes;
import at.petrak.hexcasting.common.lib.HexSounds;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
@ -108,7 +106,7 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold
return InteractionResultHolder.fail(stack);
}
var sPlayer = (ServerPlayer) player;
var ctx = new CastingContext(sPlayer, usedHand);
var ctx = new CastingContext(sPlayer, usedHand, CastingContext.CastSource.PACKAGED_HEX);
var harness = new CastingHarness(ctx);
var info = harness.executeIotas(instrs, sPlayer.getLevel());
@ -123,11 +121,6 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold
player.awardStat(stat);
sPlayer.getCooldowns().addCooldown(this, 5);
if (info.getMakesCastSound()) {
sPlayer.level.playSound(null, sPlayer.getX(), sPlayer.getY(), sPlayer.getZ(),
HexSounds.ACTUALLY_CAST, SoundSource.PLAYERS, 1f,
1f + ((float) Math.random() - 0.5f) * 0.2f);
}
if (broken) {
stack.shrink(1);

View file

@ -27,7 +27,6 @@ public record MsgNewSpellPatternAck(ControllerInfo info, int index) implements I
public static MsgNewSpellPatternAck deserialize(ByteBuf buffer) {
var buf = new FriendlyByteBuf(buffer);
var wasSpellCast = buf.readBoolean();
var isStackEmpty = buf.readBoolean();
var resolutionType = buf.readEnum(ResolvedPatternType.class);
var index = buf.readInt();
@ -39,13 +38,12 @@ public record MsgNewSpellPatternAck(ControllerInfo info, int index) implements I
var parenCount = buf.readVarInt();
return new MsgNewSpellPatternAck(
new ControllerInfo(wasSpellCast, isStackEmpty, resolutionType, stack, parens, raven, parenCount), index
new ControllerInfo(isStackEmpty, resolutionType, stack, parens, raven, parenCount), index
);
}
@Override
public void serialize(FriendlyByteBuf buf) {
buf.writeBoolean(this.info.getMakesCastSound());
buf.writeBoolean(this.info.isStackClear());
buf.writeEnum(this.info.getResolutionType());
buf.writeInt(this.index);

View file

@ -8,14 +8,12 @@ import at.petrak.hexcasting.api.spell.casting.ResolvedPatternType;
import at.petrak.hexcasting.api.spell.iota.PatternIota;
import at.petrak.hexcasting.api.spell.math.HexCoord;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.common.lib.HexSounds;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import java.util.ArrayList;
@ -62,6 +60,7 @@ public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern
public void handle(MinecraftServer server, ServerPlayer sender) {
server.execute(() -> {
// TODO: should we maybe not put tons of logic in a packet class
var held = sender.getItemInHand(this.handUsed);
if (held.is(HexItemTags.STAVES)) {
boolean autoFail = false;
@ -87,16 +86,10 @@ public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern
ControllerInfo clientInfo;
if (autoFail) {
var descs = harness.generateDescs();
clientInfo = new ControllerInfo(false, harness.getStack().isEmpty(), ResolvedPatternType.INVALID,
clientInfo = new ControllerInfo(harness.getStack().isEmpty(), ResolvedPatternType.INVALID,
descs.getFirst(), descs.getSecond(), descs.getThird(), harness.getParenCount());
} else {
clientInfo = harness.executeIota(new PatternIota(this.pattern), sender.getLevel());
if (clientInfo.getMakesCastSound()) {
sender.level.playSound(null, sender.getX(), sender.getY(), sender.getZ(),
HexSounds.ACTUALLY_CAST, SoundSource.PLAYERS, 1f,
1f + ((float) Math.random() - 0.5f) * 0.2f);
}
}
if (clientInfo.isStackClear()) {
@ -110,7 +103,8 @@ public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern
IXplatAbstractions.INSTANCE.setPatterns(sender, resolvedPatterns);
}
IXplatAbstractions.INSTANCE.sendPacketToPlayer(sender, new MsgNewSpellPatternAck(clientInfo, resolvedPatterns.size() - 1));
IXplatAbstractions.INSTANCE.sendPacketToPlayer(sender,
new MsgNewSpellPatternAck(clientInfo, resolvedPatterns.size() - 1));
}
});
}

View file

@ -650,7 +650,7 @@
"hexcasting.page.mishaps.disabled.title": "Disallowed Action",
"hexcasting.page.mishaps.disabled": "I tried to cast an action that has been disallowed by a server administrator.$(br2)Causes black sparks.",
"hexcasting.page.mishaps.other.title": "Catastrophic Failure",
"hexcasting.page.mishaps.other": "A bug in the mod caused an iota of an invalid type or otherwise caused the spell to crash. $(l:https://https://github.com/gamma-delta/HexMod/issues)Please open a bug report!/$$(br2)Causes black sparks.",
"hexcasting.page.mishaps.other": "A bug in the mod caused an iota of an invalid type or otherwise caused the spell to crash. $(l:https://github.com/gamma-delta/HexMod/issues)Please open a bug report!/$$(br2)Causes black sparks.",
"hexcasting.entry.stack": "Stacks",
"hexcasting.page.stack.1": "A $(thing)Stack/$, also known as a \"LIFO\", is a concept borrowed from computer science. In short, it's a collection of things designed so that you can only interact with the most recently used thing.$(br2)Think of a stack of plates, where new plates are added to the top: if you want to interact with a plate halfway down the stack, you have to remove the plates above it in order to get ahold of it.",
@ -1171,9 +1171,9 @@
"hexcasting.entry.lore.experiment1": "Wooleye Instance Notes",
"hexcasting.page.lore.experiment1.1": "$(italic)I only managed to find these five entries from this log./$$(br2)Detonation #26$(li)Location: Carpenter's North$(li)Population: 174$(li)Nodes Formed: 3$(li)Node Distance from Epicenter: 55-80m vertical, 85-156m horizontal$(li)Media Generation: 1320 uθ/min",
"hexcasting.page.lore.experiment1.2": "Detonation #27$(li)Location: Brackenfalls$(li)Population: 79$(li)Nodes Formed: 1$(li)Node Distance from Epicenter: 95m vertical, 67m horizontal$(li)Media Generation: 412 uθ/min",
"hexcasting.page.lore.experiment1.3": "Detonation #28$(li)Location: Greyston(li)Population: approx. 1000$(li)Nodes Formed: 18$(li)Node Distance from Epicenter: 47-110m vertical, 59-289m horizontal$(li)Media Generation: 8478 uθ/min",
"hexcasting.page.lore.experiment1.3": "Detonation #28$(li)Location: Greyston$(li)Population: approx. 1000$(li)Nodes Formed: 18$(li)Node Distance from Epicenter: 47-110m vertical, 59-289m horizontal$(li)Media Generation: 8478 uθ/min",
"hexcasting.page.lore.experiment1.4": "Detonation #29$(li)Location: Unnamed; village two days west of Greyston$(li)Population: 35$(li)Nodes Formed: 0$(li)Node Distance from Epicenter: N/A$(li)Media Generation: N/A$(br2)Note: inhabitants still affected in the normal way",
"hexcasting.page.lore.experiment1.5": "Detonation #30$(li)Location: Boiling Brook(li)Population: 231$(li)Nodes Formed: 4$(li)Node Distance from Epicenter: 61-89m vertical, 78-191m horizontal$(li)Media Generation: 1862 uθ/min",
"hexcasting.page.lore.experiment1.5": "Detonation #30$(li)Location: Boiling Brook$(li)Population: 231$(li)Nodes Formed: 4$(li)Node Distance from Epicenter: 61-89m vertical, 78-191m horizontal$(li)Media Generation: 1862 uθ/min",
"hexcasting.page.lore.experiment1.6": "Conclusion: approx 60 needed for one node. Too few consumes them but does not provide enough energy for node formation. Little correlation between input count and breadth/depth.$(br2)Effects on inhabitants still consistently more severe than with single-target testing, especially the physical effects.",
"hexcasting.entry.lore.experiment2": "Wooleye Interview Logs",

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,8 @@
"macros": {
"$(thing)": "$(#8d6acc)",
"$(action)": "$(#fc77be)",
"$(media)": "$(#74b3f2)",
"$(hex)": "$(#b38ef3)",
"_Media": "$(#74b3f2)Media/$",
"_media": "$(#74b3f2)media/$",
"_Hexcasters": "$(#b38ef3)Hexcasters/$",

View file

@ -47,6 +47,17 @@ repositories {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/releases/"
}
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}
dependencies {
@ -97,6 +108,12 @@ dependencies {
// We can't figure out what it is
// so i'm just including a fresher version
modImplementation("com.terraformersmc:modmenu:4.1.0")
// i am speed
// sodium is causing frustum mixin errors so don't use it
// modImplementation "maven.modrinth:sodium:${sodiumVersion}"
modImplementation "maven.modrinth:lithium:${lithiumVersion}"
modImplementation "maven.modrinth:phosphor:${phosphorVersion}"
}
tasks.withType(JavaCompile) {

View file

@ -11,3 +11,8 @@ emiVersion=0.4.0+1.19
gravityApiVersion=0.7.12+fabric
clothConfigVersion=8.2.88
trinketsVersion=3.4.0
# Optimizations
sodiumVersion=mc1.19.2-0.4.4
lithiumVersion=mc1.19.2-0.10.2
phosphorVersion=mc1.19.x-0.8.1

View file

@ -19,7 +19,7 @@ public class CCHarness implements Component {
}
public CastingHarness getHarness(InteractionHand hand) {
var ctx = new CastingContext(this.owner, hand);
var ctx = new CastingContext(this.owner, hand, CastingContext.CastSource.STAFF);
if (this.lazyLoadedTag.isEmpty()) {
return new CastingHarness(ctx);
} else {

View file

@ -424,7 +424,8 @@ public class FabricXplatImpl implements IXplatAbstractions {
@Override
public boolean isBreakingAllowed(Level world, BlockPos pos, BlockState state, Player player) {
return PlayerBlockBreakEvents.BEFORE.invoker().beforeBlockBreak(world, player, pos, state, world.getBlockEntity(pos));
return PlayerBlockBreakEvents.BEFORE.invoker()
.beforeBlockBreak(world, player, pos, state, world.getBlockEntity(pos));
}
@Override

View file

@ -232,7 +232,8 @@ public class ForgeXplatImpl implements IXplatAbstractions {
@Override
public CastingHarness getHarness(ServerPlayer player, InteractionHand hand) {
var ctx = new CastingContext(player, hand);
// This is always from a staff because we don't need to load the harness when casting from item
var ctx = new CastingContext(player, hand, CastingContext.CastSource.STAFF);
return CastingHarness.fromNBT(player.getPersistentData().getCompound(TAG_HARNESS), ctx);
}

View file

@ -10,7 +10,7 @@ jetbrainsAnnotationsVersion=23.0.0
minecraftVersion=1.19.2
kotlinVersion=1.7.20
modVersion=1.0
modVersion=0.10.0
paucalVersion=0.5.0
patchouliVersion=77