Skip to content

Commit

Permalink
More spike rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 8, 2024
1 parent 689bdbf commit bd653f7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/java/miyucomics/hexical/entities/SpeckEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SpeckEntity(entityType: EntityType<SpeckEntity?>?, world: World?) : Entity
super.tick()
}

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

override fun initDataTracker() {
dataTracker.startTracking(displayDataTracker, NbtCompound())
Expand Down
26 changes: 10 additions & 16 deletions src/main/java/miyucomics/hexical/entities/SpikeEntity.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
package miyucomics.hexical.entities

import net.minecraft.entity.Entity
import net.minecraft.entity.EntityDimensions
import net.minecraft.entity.EntityPose
import net.minecraft.entity.EntityType
import net.minecraft.nbt.NbtCompound
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket
import net.minecraft.util.math.Direction
import net.minecraft.world.World

class SpikeEntity(entityType: EntityType<SpikeEntity?>?, world: World?) : Entity(entityType, world) {
private var direction: Direction = Direction.UP
companion object {
}
override fun getEyeHeight(pose: EntityPose, dimensions: EntityDimensions) = 0.5f

fun setDirection() {
if (this.direction.axis.isHorizontal) {
fun setDirection(direction: Direction) {
if (direction.axis.isHorizontal) {
this.pitch = 0.0f
this.yaw = (this.direction.horizontal * 90).toFloat()
this.yaw = (direction.horizontal * 90).toFloat()
} else {
this.pitch = (-90 * this.direction.direction.offset()).toFloat()
this.pitch = (-90 * direction.direction.offset()).toFloat()
this.yaw = 0.0f
}
}

override fun initDataTracker() {
}

override fun readCustomDataFromNbt(nbt: NbtCompound) {
}

override fun writeCustomDataToNbt(nbt: NbtCompound) {
}

override fun initDataTracker() {}
override fun readCustomDataFromNbt(nbt: NbtCompound) {}
override fun writeCustomDataToNbt(nbt: NbtCompound) {}
override fun createSpawnPacket() = EntitySpawnS2CPacket(this)
}
24 changes: 16 additions & 8 deletions src/main/java/miyucomics/hexical/entities/SpikeRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,32 @@ import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.Identifier
import net.minecraft.util.math.Matrix3f
import net.minecraft.util.math.Matrix4f
import net.minecraft.util.math.Vec3f

class SpikeRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<SpikeEntity>(ctx) {
override fun getTexture(spike: SpikeEntity?) = Identifier("textures/block/amethyst_cluster.png")
override fun render(spike: SpikeEntity?, yaw: Float, deltaTick: Float, matrices: MatrixStack, vertexConsumers: VertexConsumerProvider, light: Int) {
matrices.push()
val buffer = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCull(getTexture(spike)))

matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-spike!!.yaw))
matrices.translate(-0.5, 0.0, -0.5)
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(spike.pitch))

val form = ((spike.world.time.toInt() % 100) + deltaTick) / 100

val mat = matrices.peek().positionMatrix
val norm = matrices.peek().normalMatrix

vertex(mat, light, buffer, norm, 0.5f, 0f, -0.5f, 0f, 0f)
vertex(mat, light, buffer, norm, 0.5f, -1f, -0.5f, 0f, 1f)
vertex(mat, light, buffer, norm, -0.5f, -1f, 0.5f, 1f, 1f)
vertex(mat, light, buffer, norm, -0.5f, 0f, 0.5f, 1f, 0f)
vertex(mat, light, buffer, norm, 1f, 1f, 0f, 0f, 0f)
vertex(mat, light, buffer, norm, 1f, 0f, 0f, 0f, form)
vertex(mat, light, buffer, norm, 0f, 0f, 1f, 1f, form)
vertex(mat, light, buffer, norm, 0f, 1f, 1f, 1f, 0f)

vertex(mat, light, buffer, norm, -0.5f, 0f, -0.5f, 0f, 0f)
vertex(mat, light, buffer, norm, -0.5f, -1f, -0.5f, 0f, 1f)
vertex(mat, light, buffer, norm, 0.5f, -1f, 0.5f, 1f, 1f)
vertex(mat, light, buffer, norm, 0.5f, 0f, 0.5f, 1f, 0f)
vertex(mat, light, buffer, norm, 0f, 1f, 0f, 0f, 0f)
vertex(mat, light, buffer, norm, 0f, 0f, 0f, 0f, form)
vertex(mat, light, buffer, norm, 1f, 0f, 1f, 1f, form)
vertex(mat, light, buffer, norm, 1f, 1f, 1f, 1f, 0f)

matrices.pop()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object HexicalEntities {
val LIVING_SCROLL_ENTITY: EntityType<LivingScrollEntity?> = EntityType.Builder.create(::LivingScrollEntity, SpawnGroup.MISC).setDimensions(0.5f, 0.5f).maxTrackingRange(10).trackingTickInterval(1).build(HexicalMain.MOD_ID + ":living_scroll")
val MESH_ENTITY: EntityType<MeshEntity?> = EntityType.Builder.create(::MeshEntity, SpawnGroup.MISC).setDimensions(0.5f, 0.5f).maxTrackingRange(10).trackingTickInterval(1).build(HexicalMain.MOD_ID + ":mesh")
val SPECK_ENTITY: EntityType<SpeckEntity?> = EntityType.Builder.create(::SpeckEntity, SpawnGroup.MISC).setDimensions(0.5f, 0.5f).maxTrackingRange(10).trackingTickInterval(1).build(HexicalMain.MOD_ID + ":speck")
val SPIKE_ENTITY: EntityType<SpikeEntity?> = EntityType.Builder.create(::SpikeEntity, SpawnGroup.MISC).setDimensions(0.5f, 0.5f).maxTrackingRange(10).trackingTickInterval(1).build(HexicalMain.MOD_ID + ":spike")
val SPIKE_ENTITY: EntityType<SpikeEntity?> = EntityType.Builder.create(::SpikeEntity, SpawnGroup.MISC).setDimensions(1f, 1f).maxTrackingRange(10).trackingTickInterval(1).build(HexicalMain.MOD_ID + ":spike")

@JvmStatic
fun init() {
Expand Down

0 comments on commit bd653f7

Please sign in to comment.