-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3ef463
commit 689bdbf
Showing
24 changed files
with
332 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
...asting/patterns/getters/OpGetBlockData.kt → ...terns/getters/types/OpGetBlockTypeData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/miyucomics/hexical/casting/patterns/getters/types/OpGetItemTypeData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/main/java/miyucomics/hexical/entities/MeshEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.