Skip to content

Commit

Permalink
Spike spell progress
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 8, 2024
1 parent a3ef463 commit 689bdbf
Show file tree
Hide file tree
Showing 24 changed files with 332 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
- changed Identify pattern to have ambit limitation
- changed speed and variance of living scroll patterns
- changed specks to be one block big by default, can be scaled
- changed some item scrying patterns to take item type identifiers instead
- changed all the food scrying patterns to take item type identifiers instead
- changed Miner's and Demoman's Purification to take block type identifiers instead
- moved them into separate blocks category
- dropped support for Forge in order to prioritize development speed and features
- fixed specks being slightly off-center
- fixed advancements occasionally breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getEntity
import at.petrak.hexcasting.api.spell.iota.Iota
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d

class OpGetEntityData(private val mode: Int) : ConstMediaAction {
override val argc = 1
Expand All @@ -14,6 +16,17 @@ class OpGetEntityData(private val mode: Int) : ConstMediaAction {
0 -> entity.isOnFire.asActionResult
1 -> (entity.fireTicks.toDouble() / 20).asActionResult
2 -> entity.isWet.asActionResult
3 -> {
val upPitch = (-ctx.caster.pitch + 90) * (Math.PI.toFloat() / 180)
val yaw = -ctx.caster.headYaw * (Math.PI.toFloat() / 180)
val h = MathHelper.cos(yaw).toDouble()
val j = MathHelper.cos(upPitch).toDouble()
Vec3d(
MathHelper.sin(yaw).toDouble() * j,
MathHelper.sin(upPitch).toDouble(),
h * j
).asActionResult
}
else -> throw IllegalStateException()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ class OpGetItemStackData(private val mode: Int) : ConstMediaAction {
val stack = args.getItemStack(0, argc)
return when (mode) {
0 -> stack.count.asActionResult
1 -> stack.maxCount.asActionResult
2 -> stack.damage.asActionResult
3 -> stack.maxDamage.asActionResult
4 -> stack.isFood.asActionResult
5 -> {
1 -> stack.damage.asActionResult
2 -> {
var data = stack.enchantments
if (stack.isOf(Items.ENCHANTED_BOOK))
data = EnchantedBookItem.getEnchantmentNbt(stack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OpGetStatusEffectInstanceData(private val mode: Int) : ConstMediaAction {
val instance = entity.getStatusEffect(Registry.STATUS_EFFECT.get(effect)) ?: return listOf(NullIota())
return when (mode) {
0 -> instance.amplifier.asActionResult
1 -> (instance.duration / 20).asActionResult
1 -> (instance.duration.toDouble() / 20.0).asActionResult
else -> throw IllegalStateException()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package miyucomics.hexical.casting.patterns.getters
package miyucomics.hexical.casting.patterns.getters.misc

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import miyucomics.hexical.casting.iota.getIdentifier
import miyucomics.hexical.casting.patterns.getters.getItemStack
import net.minecraft.enchantment.EnchantmentHelper
import net.minecraft.util.registry.Registry

Expand All @@ -15,7 +16,7 @@ class OpGetEnchantmentStrength : ConstMediaAction {
val stack = args.getItemStack(0, argc)
val id = args.getIdentifier(1, argc)
if (!Registry.ENCHANTMENT.containsId(id))
throw MishapInvalidIota.of(args[1], 1, "enchantment")
throw MishapInvalidIota.of(args[1], 1, "enchantment_id")
val data = EnchantmentHelper.get(stack)
val enchantment = Registry.ENCHANTMENT.get(id)
if (!data.containsKey(enchantment))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.getters
package miyucomics.hexical.casting.patterns.getters.misc

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
Expand All @@ -14,7 +14,7 @@ class OpGetStatusEffectCategory : ConstMediaAction {
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val effect = args.getIdentifier(0, argc)
if (!Registry.STATUS_EFFECT.containsId(effect))
throw MishapInvalidIota.of(args[0], 0, "status_effect")
throw MishapInvalidIota.of(args[0], 0, "status_effect_id")
return when (Registry.STATUS_EFFECT.get(effect)!!.category) {
StatusEffectCategory.BENEFICIAL -> (1).asActionResult
StatusEffectCategory.NEUTRAL -> (0).asActionResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package miyucomics.hexical.casting.patterns.getters
package miyucomics.hexical.casting.patterns.getters.types

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getBlockPos
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import miyucomics.hexical.casting.iota.getIdentifier
import net.minecraft.util.registry.Registry

class OpGetBlockData(private val mode: Int) : ConstMediaAction {
class OpGetBlockTypeData(private val mode: Int) : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val position = args.getBlockPos(0, argc)
ctx.assertVecInRange(position)
val block = ctx.world.getBlockState(position).block
val id = args.getIdentifier(0, argc)
if (!Registry.BLOCK.containsId(id))
throw MishapInvalidIota.of(args[0], 0, "block_id")
val block = Registry.BLOCK.get(id)
return when (mode) {
0 -> block.hardness.asActionResult
1 -> block.blastResistance.asActionResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package miyucomics.hexical.casting.patterns.getters
package miyucomics.hexical.casting.patterns.getters.types

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
Expand All @@ -8,13 +8,13 @@ import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import miyucomics.hexical.casting.iota.getIdentifier
import net.minecraft.util.registry.Registry

class OpGetFoodData(private val mode: Int) : ConstMediaAction {
class OpGetFoodTypeData(private val mode: Int) : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val id = args.getIdentifier(0, argc)
if (!Registry.ITEM.containsId(id))
throw MishapInvalidIota.of(args[0], 0, "food")
val food = Registry.ITEM.get(id).foodComponent?: throw MishapInvalidIota.of(args[0], 0, "food")
throw MishapInvalidIota.of(args[0], 0, "food_id")
val food = Registry.ITEM.get(id).foodComponent?: throw MishapInvalidIota.of(args[0], 0, "food_id")
return when (mode) {
0 -> food.hunger.asActionResult
1 -> food.saturationModifier.asActionResult
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package miyucomics.hexical.casting.patterns.getters.types

import at.petrak.hexcasting.api.spell.ConstMediaAction
import at.petrak.hexcasting.api.spell.asActionResult
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import miyucomics.hexical.casting.iota.getIdentifier
import net.minecraft.util.registry.Registry

class OpGetItemTypeData(private val mode: Int) : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
val id = args.getIdentifier(0, argc)
if (!Registry.ITEM.containsId(id))
throw MishapInvalidIota.of(args[0], 0, "item_id")
val item = Registry.ITEM.get(id)
return when (mode) {
0 -> item.maxCount.asActionResult
1 -> item.maxDamage.asActionResult
2 -> item.isFood.asActionResult
else -> throw IllegalStateException()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.ceil

class LivingScrollRenderer(ctx: EntityRendererFactory.Context?) : EntityRenderer<LivingScrollEntity?>(ctx) {
class LivingScrollRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<LivingScrollEntity>(ctx) {
override fun render(scroll: LivingScrollEntity?, yaw: Float, deltaTick: Float, matrices: MatrixStack, vertexConsumers: VertexConsumerProvider, light: Int) {
RenderSystem.setShader { GameRenderer.getPositionTexShader() }
matrices.push()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.minecraft.client.render.entity.ProjectileEntityRenderer
import net.minecraft.util.Identifier

@Environment(value = EnvType.CLIENT)
class MagicMissileRenderer(context: EntityRendererFactory.Context?) : ProjectileEntityRenderer<MagicMissileEntity?>(context) {
class MagicMissileRenderer(context: EntityRendererFactory.Context) : ProjectileEntityRenderer<MagicMissileEntity>(context) {
override fun getTexture(entity: MagicMissileEntity?): Identifier {
return TEXTURE
}
Expand Down
109 changes: 109 additions & 0 deletions src/main/java/miyucomics/hexical/entities/MeshEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package miyucomics.hexical.entities

import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.utils.putCompound
import at.petrak.hexcasting.api.utils.putList
import miyucomics.hexical.interfaces.Specklike
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityDimensions
import net.minecraft.entity.EntityPose
import net.minecraft.entity.EntityType
import net.minecraft.entity.data.DataTracker
import net.minecraft.entity.data.TrackedData
import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.nbt.*
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket
import net.minecraft.util.math.Vec3d
import net.minecraft.world.World

class MeshEntity(entityType: EntityType<MeshEntity?>?, world: World?) : Entity(entityType, world), Specklike {
companion object {
private val shapeDataTracker: TrackedData<NbtCompound> = DataTracker.registerData(MeshEntity::class.java, TrackedDataHandlerRegistry.NBT_COMPOUND)
private val pigmentDataTracker: TrackedData<NbtCompound> = DataTracker.registerData(MeshEntity::class.java, TrackedDataHandlerRegistry.NBT_COMPOUND)
private val sizeDataTracker: TrackedData<Float> = DataTracker.registerData(MeshEntity::class.java, TrackedDataHandlerRegistry.FLOAT)
private val thicknessDataTracker: TrackedData<Float> = DataTracker.registerData(MeshEntity::class.java, TrackedDataHandlerRegistry.FLOAT)
private val rollDataTracker: TrackedData<Float> = DataTracker.registerData(MeshEntity::class.java, TrackedDataHandlerRegistry.FLOAT)
}
private var lifespan = -1

// client-only
var clientVertices: MutableList<Vec3d> = mutableListOf()
var clientPigment: FrozenColorizer = FrozenColorizer.DEFAULT.get()
var clientSize = 1f
var clientThickness = 1f
var clientRoll = 0f

override fun tick() {
if (lifespan != -1)
lifespan--
if (lifespan == 0)
discard()
super.tick()
}

override fun getEyeHeight(pose: EntityPose?, dimensions: EntityDimensions?) = 0f

override fun initDataTracker() {
dataTracker.startTracking(shapeDataTracker, NbtCompound())
dataTracker.startTracking(pigmentDataTracker, NbtCompound())
dataTracker.startTracking(rollDataTracker, 0f)
dataTracker.startTracking(sizeDataTracker, 1f)
dataTracker.startTracking(thicknessDataTracker, 1f)
}

override fun onTrackedDataSet(data: TrackedData<*>) {
when (data) {
shapeDataTracker -> {
val list = this.dataTracker.get(shapeDataTracker).getList("shape", NbtElement.FLOAT_TYPE.toInt())
this.clientVertices = mutableListOf()
for (i in 0..(list.size / 3))
clientVertices.add(Vec3d(list.getFloat(i).toDouble(), list.getFloat(i + 1).toDouble(), list.getFloat(i + 2).toDouble()))
}
pigmentDataTracker -> this.clientPigment = FrozenColorizer.fromNBT(dataTracker.get(pigmentDataTracker))
sizeDataTracker -> this.clientSize = dataTracker.get(sizeDataTracker)
rollDataTracker -> this.clientRoll = dataTracker.get(rollDataTracker)
thicknessDataTracker -> this.clientThickness = dataTracker.get(thicknessDataTracker)
else -> {}
}
}

fun setShape(shape: List<Vec3d>) {
val compound = NbtCompound()
val list = NbtList()
for (vertex in shape) {
list.add(NbtFloat.of(vertex.x.toFloat()))
list.add(NbtFloat.of(vertex.y.toFloat()))
list.add(NbtFloat.of(vertex.z.toFloat()))
}
compound.putList("shape", list)
this.dataTracker.set(shapeDataTracker, compound)
}

override fun readCustomDataFromNbt(nbt: NbtCompound) {
dataTracker.set(shapeDataTracker, nbt.getCompound("shape"))
dataTracker.set(pigmentDataTracker, nbt.getCompound("pigment"))
dataTracker.set(rollDataTracker, nbt.getFloat("roll"))
dataTracker.set(sizeDataTracker, nbt.getFloat("size"))
dataTracker.set(thicknessDataTracker, nbt.getFloat("thickness"))
this.lifespan = nbt.getInt("lifespan")
}

override fun writeCustomDataToNbt(nbt: NbtCompound) {
nbt.putCompound("shape", dataTracker.get(shapeDataTracker))
nbt.putCompound("pigment", dataTracker.get(pigmentDataTracker))
nbt.putFloat("roll", dataTracker.get(rollDataTracker))
nbt.putFloat("size", dataTracker.get(sizeDataTracker))
nbt.putFloat("thickness", dataTracker.get(thicknessDataTracker))
nbt.putInt("lifespan", lifespan)
}

override fun setLifespan(lifespan: Int) {
this.lifespan = lifespan
}

override fun setSize(size: Float) = dataTracker.set(sizeDataTracker, size)
override fun setRoll(rotation: Float) = dataTracker.set(rollDataTracker, rotation)
override fun setThickness(thickness: Float) = dataTracker.set(thicknessDataTracker, thickness)
override fun setPigment(pigment: FrozenColorizer) = dataTracker.set(pigmentDataTracker, pigment.serializeToNBT())
override fun createSpawnPacket() = EntitySpawnS2CPacket(this)
}
38 changes: 38 additions & 0 deletions src/main/java/miyucomics/hexical/entities/MeshRenderer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package miyucomics.hexical.entities

import com.mojang.blaze3d.systems.RenderSystem
import miyucomics.hexical.utils.RenderUtils
import net.minecraft.client.render.Frustum
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.Vec3f

class MeshRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<MeshEntity>(ctx) {
override fun getTexture(entity: MeshEntity?): Identifier? = null
override fun shouldRender(entity: MeshEntity?, frustum: Frustum?, x: Double, y: Double, z: Double) = true
override fun render(entity: MeshEntity?, yaw: Float, tickDelta: Float, matrices: MatrixStack, vertexConsumers: VertexConsumerProvider, light: Int) {
val oldShader = RenderSystem.getShader()
RenderSystem.setShader(GameRenderer::getPositionColorShader)
RenderSystem.enableDepthTest()
matrices.push()

if (entity!!.yaw != 0.0f)
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-entity.yaw))
if (entity.pitch != 0.0f)
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(entity.pitch))
if (entity.clientRoll != 0.0f)
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(entity.clientRoll))
matrices.scale(entity.clientSize, entity.clientSize, entity.clientSize)

RenderSystem.disableCull()
RenderUtils.sentinelLike(matrices, entity.clientVertices, entity.clientThickness * 0.05f, entity.clientPigment)
RenderSystem.enableCull()

matrices.pop()
RenderSystem.setShader { oldShader }
}
}
2 changes: 1 addition & 1 deletion src/main/java/miyucomics/hexical/entities/SpeckRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.Identifier
import net.minecraft.util.math.Vec3f

class SpeckRenderer(ctx: EntityRendererFactory.Context?) : EntityRenderer<SpeckEntity?>(ctx) {
class SpeckRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<SpeckEntity>(ctx) {
override fun getTexture(entity: SpeckEntity?): Identifier? = null
override fun shouldRender(entity: SpeckEntity?, frustum: Frustum?, x: Double, y: Double, z: Double) = true
override fun render(entity: SpeckEntity?, yaw: Float, tickDelta: Float, matrices: MatrixStack, vertexConsumers: VertexConsumerProvider, light: Int) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/miyucomics/hexical/entities/SpikeEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package miyucomics.hexical.entities

import net.minecraft.entity.Entity
import net.minecraft.entity.EntityType
import net.minecraft.entity.data.DataTracker
import net.minecraft.entity.data.TrackedData
import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.nbt.NbtCompound
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket
import net.minecraft.util.math.Direction
Expand Down
Loading

0 comments on commit 689bdbf

Please sign in to comment.