Skip to content

Commit

Permalink
Progress snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Mar 11, 2024
1 parent 3de1feb commit 8f91c3e
Show file tree
Hide file tree
Showing 28 changed files with 222 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package miyucomics.hexical.casting.mishaps

import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.Mishap
import miyucomics.hexical.Hexical
import net.minecraft.text.Text
import net.minecraft.util.DyeColor
import net.minecraft.util.Hand

class GrimoireAccessDeniedMishap : Mishap() {
override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer = dyeColor(DyeColor.BLUE)
override fun particleSpray(ctx: CastingContext) = ParticleSpray.burst(ctx.caster.pos, 1.0)
override fun errorMessage(ctx: CastingContext, errorCtx: Context): Text = error(Hexical.MOD_ID + ":grimoire_access_denied")

override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList<Iota>) {
yeetHeldItem(ctx, Hand.OFF_HAND)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators
package miyucomics.hexical.casting.operators

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -8,7 +8,6 @@ import at.petrak.hexcasting.api.spell.iota.Iota

class OpGetEntityBurning : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf(BooleanIota(args.getEntity(0, argc).isOnFire))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators
package miyucomics.hexical.casting.operators

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -8,7 +8,6 @@ import at.petrak.hexcasting.api.spell.iota.Iota

class OpGetEntityBurningTime : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf(DoubleIota(args.getEntity(0, argc).fireTicks.toDouble()))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators
package miyucomics.hexical.casting.operators

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -8,7 +8,6 @@ import at.petrak.hexcasting.api.spell.iota.Iota

class OpGetEntityWet : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf(BooleanIota(args.getEntity(0, argc).isWet))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators
package miyucomics.hexical.casting.operators

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -8,7 +8,6 @@ import at.petrak.hexcasting.api.spell.iota.Iota

class OpGetPlayerSprinting : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf(BooleanIota(args.getPlayer(0, argc).isSprinting()))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators.eval
package miyucomics.hexical.casting.operators.eval

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells.grimoire
package miyucomics.hexical.casting.operators.grimoire

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package miyucomics.hexical.casting.operators.grimoire

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.ListIota
import miyucomics.hexical.items.GrimoireItem

class OpGrimoireIndex : ConstMediaAction {
override val argc = 0
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val (stack, _) = ctx.getHeldItemToOperateOn { it.item is GrimoireItem }
return listOf(ListIota(GrimoireItem.getPatternsInGrimoire(stack)))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package miyucomics.hexical.casting.operators.grimoire

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.DoubleIota
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.ListIota
import at.petrak.hexcasting.api.spell.iota.NullIota
import miyucomics.hexical.items.GrimoireItem

class OpGrimoireQuery : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val (stack, _) = ctx.getHeldItemToOperateOn { it.item is GrimoireItem }
val uses = GrimoireItem.getUses(stack, args.getPattern(0, argc)) ?: return listOf(NullIota())
return listOf(DoubleIota(uses.toDouble()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package miyucomics.hexical.casting.operators.grimoire

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.math.HexPattern
import miyucomics.hexical.casting.mishaps.GrimoireAccessDeniedMishap
import miyucomics.hexical.items.GrimoireItem
import net.minecraft.item.ItemStack

class OpGrimoireRestrict : SpellAction {
override val argc = 2

override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pattern = args.getPattern(0, argc)
val uses = args.getPositiveInt(1, argc)
val (stack, _) = ctx.getHeldItemToOperateOn { it.item is GrimoireItem }
val currentUses = GrimoireItem.getUses(stack, pattern) ?: return Triple(Spell(pattern, stack, uses), 0, listOf())
if (uses > currentUses)
throw GrimoireAccessDeniedMishap()
return Triple(Spell(pattern, stack, uses), 0, listOf())
}

private data class Spell(val pattern: HexPattern, val stack: ItemStack, val uses: Int) : RenderedSpell {
override fun cast(ctx: CastingContext) {
GrimoireItem.restrict(stack, pattern, uses)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells.grimoire
package miyucomics.hexical.casting.operators.grimoire

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators.lamp
package miyucomics.hexical.casting.operators.lamp

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -13,7 +13,6 @@ import miyucomics.hexical.utils.CastingUtils

class OpGetArchLampData(private val mode: Int) : ConstMediaAction {
override val argc = 0

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
if (!CastingUtils.doesPlayerHaveActiveArchLamp(ctx.caster))
throw NeedsActiveArchLampMishap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators.lamp
package miyucomics.hexical.casting.operators.lamp

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -12,7 +12,6 @@ import miyucomics.hexical.registry.HexicalItems

class OpGetLampData(private val mode: Int) : ConstMediaAction {
override val argc = 0

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
if (!(ctx.caster.activeItem.item == HexicalItems.LAMP_ITEM && ctx.source == CastingContext.CastSource.PACKAGED_HEX))
throw NeedsLampMishap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.operators.lamp
package miyucomics.hexical.casting.operators.lamp

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand All @@ -9,7 +9,6 @@ import miyucomics.hexical.utils.CastingUtils

class OpIsUsingArchLamp : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf(BooleanIota(CastingUtils.doesPlayerHaveActiveArchLamp(args.getPlayer(0, argc))))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells

import at.petrak.hexcasting.api.misc.DiscoveryHandlers
import at.petrak.hexcasting.api.misc.MediaConstants
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.ParticleSpray
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells

import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells.lamp

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells.lamp

import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.spells
package miyucomics.hexical.casting.spells.lamp

import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.spell.math.HexDir
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.utils.putCompound
import at.petrak.hexcasting.client.getCenteredPattern
import net.minecraft.block.Block
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityType
import net.minecraft.entity.data.DataTracker
Expand All @@ -14,7 +12,6 @@ import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.nbt.NbtCompound
import net.minecraft.network.Packet
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket
import net.minecraft.util.math.Vec2f
import net.minecraft.world.World

val patternDataTracker: TrackedData<NbtCompound> = DataTracker.registerData(SpeckEntity::class.java, TrackedDataHandlerRegistry.NBT_COMPOUND)
Expand All @@ -33,7 +30,7 @@ class SpeckEntity(entityType: EntityType<SpeckEntity?>?, world: World?) : Entity
pattern = HexPattern.fromNBT(nbt.getCompound("pattern"))
pigment = FrozenColorizer.fromNBT(nbt.getCompound("pigment"))
dataTracker.set(patternDataTracker, nbt.getCompound("pattern"))
dataTracker.set(pigmentDataTracker, nbt.getCompound("pattern"))
dataTracker.set(pigmentDataTracker, nbt.getCompound("pigment"))
}

override fun writeCustomDataToNbt(nbt: NbtCompound) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
package miyucomics.hexical.entities

import at.petrak.hexcasting.client.*
import at.petrak.hexcasting.client.drawLineSeq
import at.petrak.hexcasting.client.findDupIndices
import at.petrak.hexcasting.client.makeZappy
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.render.*
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.render.entity.EntityRenderer
import net.minecraft.client.render.entity.EntityRendererFactory
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.Identifier
import net.minecraft.util.math.Quaternion
import net.minecraft.util.math.Vec2f
import net.minecraft.util.math.Vec3d
import net.minecraft.util.math.Vec3f
import kotlin.math.asin
import kotlin.math.atan2


class SpeckEntityRenderer(ctx: EntityRendererFactory.Context?) : EntityRenderer<SpeckEntity?>(ctx) {
override fun render(entity: SpeckEntity?, yaw: Float, tickDelta: Float, matrices: MatrixStack?, vertexConsumers: VertexConsumerProvider?, light: Int) {
val oldShader = RenderSystem.getShader()
RenderSystem.setShader(GameRenderer::getPositionColorShader)
RenderSystem.enableDepthTest()
matrices!!.push()

val size = 0.25f
val pattern = entity!!.getPattern()
val lines = pattern.toLines(size, pattern.getCenter(size).negate()).toMutableList()
for (i in lines.indices)
lines[i] = Vec2f(lines[i].x, -lines[i].y)
val zappy = makeZappy(lines, findDupIndices(pattern.positions()), 10, 1.5f, 0.1f, 0.2f, 0f, 1f, hashCode().toDouble())
val outer = -0x9b3701
val outer = entity.getPigment().getColor(entity.age.toFloat(), entity.pos)

val mat = matrices.peek()
drawLineSeq(mat.positionMatrix, zappy, 0.05f, 0.01f, outer, outer)
val rotation = Vec3f.NEGATIVE_Y.getRadialQuaternion(entity.yaw)
rotation.hamiltonProduct(Vec3f.POSITIVE_X.getRadialQuaternion((entity.pitch - Math.PI / 2).toFloat()))
matrices.multiply(rotation)
drawLineSeq(matrices.peek().positionMatrix, zappy, 0.05f, 0.01f, outer, outer)
matrices.pop()
RenderSystem.setShader { oldShader }
}

fun getQuaternion(direction: Vec3d, forward: Boolean): Quaternion {
var copiedVector = direction
copiedVector = copiedVector.normalize()
val pitch = asin(-copiedVector.y).toFloat()
val yaw = (-atan2(copiedVector.x, copiedVector.z)).toFloat()
val rotation = Vec3f.NEGATIVE_Y.getRadialQuaternion(yaw)
if (forward) {
rotation.hamiltonProduct(Vec3f.POSITIVE_X.getRadialQuaternion((pitch + Math.PI / 2).toFloat()))
} else {
rotation.hamiltonProduct(Vec3f.POSITIVE_X.getRadialQuaternion((pitch - Math.PI / 2).toFloat()))
}
return rotation
}

override fun getTexture(entity: SpeckEntity?): Identifier? { return null }
}
Loading

0 comments on commit 8f91c3e

Please sign in to comment.