Skip to content

Commit

Permalink
Cleaned up by IntelliJ
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 9, 2024
1 parent 4af8ae0 commit ab1a31b
Show file tree
Hide file tree
Showing 113 changed files with 921 additions and 783 deletions.
2 changes: 1 addition & 1 deletion src/main/java/miyucomics/hexical/blocks/MageBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MageBlock : BlockConjured(
}

override fun getCollisionShape(state: BlockState?, world: BlockView?, pos: BlockPos?, context: ShapeContext): VoxelShape {
if (((world!!.getBlockEntity(pos)?: return super.getCollisionShape(state, world, pos, context)) as MageBlockEntity).properties["semipermeable"] == true) {
if (((world!!.getBlockEntity(pos) ?: return super.getCollisionShape(state, world, pos, context)) as MageBlockEntity).properties["semipermeable"] == true) {
if (context is EntityShapeContext && context.entity != null) {
val entity = context.entity!!
if (entity is FallingBlockEntity || entity.isSprinting && context.isAbove(VoxelShapes.fullCube(), pos, false) && !context.isDescending()) {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/miyucomics/hexical/casting/patterns/OpReweave.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package miyucomics.hexical.casting.patterns

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d

class OpReweave : SpellAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val headOffset = args.getVec3(0, argc)
val xAxis = ctx.caster.rotationVector
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()
val yAxis = Vec3d(MathHelper.sin(yaw).toDouble() * j, MathHelper.sin(upPitch).toDouble(), h * j)
val zAxis = xAxis.crossProduct(yAxis).normalize()
val offset = Vec3d.ZERO
.add(xAxis.multiply(headOffset.x))
.add(yAxis.multiply(headOffset.y))
.add(zAxis.multiply(headOffset.z))
if (offset.length() > 128)
throw MishapLocationTooFarAway(ctx.caster.eyePos.add(offset))
return Triple(Spell(ctx.caster.eyePos.add(offset)), MediaConstants.SHARD_UNIT * 2, listOf())
}

private data class Spell(val position: Vec3d) : RenderedSpell {
override fun cast(ctx: CastingContext) {
ctx.caster.teleport(position.x, position.y, position.z)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OpReadAkashicShelf : ConstMediaAction {
val block = ctx.world.getBlockState(position)
if (!block.isOf(HexBlocks.AKASHIC_BOOKSHELF))
throw MishapBadBlock.of(position, "akashic_bookshelf")
val nbt = (ctx.world.getBlockEntity(position) as BlockEntityAkashicBookshelf).iotaTag?: return listOf(NullIota())
val nbt = (ctx.world.getBlockEntity(position) as BlockEntityAkashicBookshelf).iotaTag ?: return listOf(NullIota())
return listOf(HexIotaTypes.deserialize(nbt, ctx.world))
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.Action
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.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.util.hit.HitResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package miyucomics.hexical.casting.patterns.basic

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.Action
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.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.iota.NullIota
import net.minecraft.util.hit.HitResult
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/miyucomics/hexical/casting/patterns/dye/OpGetDye.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ import net.minecraft.util.math.BlockPos
class OpGetDye : ConstMediaAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingContext): List<Iota> {
return listOf(when (args[0]) {
is EntityIota -> {
val entity = args.getEntity(0, argc)
ctx.assertEntityInRange(entity)
processEntity(entity)
}
is Vec3Iota -> {
val position = args.getBlockPos(0, argc)
ctx.assertVecInRange(position)
processVec3d(position, ctx.world)
return listOf(
when (args[0]) {
is EntityIota -> {
val entity = args.getEntity(0, argc)
ctx.assertEntityInRange(entity)
processEntity(entity)
}
is Vec3Iota -> {
val position = args.getBlockPos(0, argc)
ctx.assertVecInRange(position)
processVec3d(position, ctx.world)
}
else -> NullIota()
}
else -> NullIota()
})
)
}

private fun processEntity(entity: Entity): Iota {
Expand Down Expand Up @@ -66,12 +68,14 @@ class OpGetDye : ConstMediaAction {
else -> NullIota()
}
}

private fun processVec3d(position: BlockPos, world: ServerWorld): Iota {
val state = world.getBlockState(position)
if (state.block is SignBlock)
return DyeIota((world.getBlockEntity(position) as SignBlockEntity).textColor.getName())
return getDyeFromBlock(world.getBlockState(position).block)
}

private fun getDyeFromBlock(block: Block): Iota {
val dye = DyeData.getDye(block) ?: return NullIota()
return DyeIota(dye)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OpGetFoodTypeData(private val mode: Int) : ConstMediaAction {
val id = args.getIdentifier(0, argc)
if (!Registry.ITEM.containsId(id))
throw MishapInvalidIota.of(args[0], 0, "food_id")
val food = Registry.ITEM.get(id).foodComponent?: 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
Expand Up @@ -53,7 +53,7 @@ class OpReloadLamp : SpellAction {
val newLamp = ctx.caster.getStackInHand(ctx.otherHand)
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(newLamp)!!
val mediaHolder = IXplatAbstractions.INSTANCE.findMediaHolder(lamp)!!
hexHolder.writeHex(hexHolder.getHex(ctx.world)?: listOf(), mediaHolder.media + battery)
hexHolder.writeHex(hexHolder.getHex(ctx.world) ?: listOf(), mediaHolder.media + battery)
HexicalAdvancements.RELOAD_LAMP.trigger(ctx.caster)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OpMageHand : SpellAction {

private data class EntitySpell(val entity: Entity) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val stack = PersistentStateHandler.wristpocketItem(ctx.caster)
val stack = PersistentStateHandler.wristpocketItem(ctx.caster)
val originalItem = ctx.caster.getStackInHand(ctx.castingHand)
ctx.caster.setStackInHand(ctx.castingHand, stack)
entity.interact(ctx.caster, Hand.MAIN_HAND)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/miyucomics/hexical/data/DyeData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object DyeData {
}
return block.defaultState
}

fun getNewItem(item: Item, dye: String): Item {
itemFamilies.forEach { (_, family) ->
if (family.containsValue(Registry.ITEM.getId(item).toString()) && family.containsKey(dye))
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/miyucomics/hexical/entities/LivingScrollEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import net.minecraft.util.math.Direction
import net.minecraft.util.math.Vec3d
import net.minecraft.world.GameRules
import net.minecraft.world.World
import java.lang.IllegalStateException

class LivingScrollEntity(entityType: EntityType<LivingScrollEntity?>?, world: World?) : AbstractDecorationEntity(entityType, world) {
var patterns: MutableList<NbtCompound> = mutableListOf()
var cachedPattern = HexPattern.fromAngles("", HexDir.EAST) // client-only

companion object {
private val agedDataTracker: TrackedData<Boolean> = DataTracker.registerData(LivingScrollEntity::class.java, TrackedDataHandlerRegistry.BOOLEAN)
private val sizeDataTracker: TrackedData<Int> = DataTracker.registerData(LivingScrollEntity::class.java, TrackedDataHandlerRegistry.INTEGER)
Expand Down Expand Up @@ -140,12 +140,14 @@ class LivingScrollEntity(entityType: EntityType<LivingScrollEntity?>?, world: Wo
if (this.world.gameRules.getBoolean(GameRules.DO_ENTITY_DROPS)) {
if (entity is PlayerEntity && entity.abilities.creativeMode)
return
val stack = ItemStack(when (this.dataTracker.get(sizeDataTracker)) {
1 -> HexicalItems.SMALL_LIVING_SCROLL_ITEM
2 -> HexicalItems.MEDIUM_LIVING_SCROLL_ITEM
3 -> HexicalItems.LARGE_LIVING_SCROLL_ITEM
else -> throw IllegalStateException()
})
val stack = ItemStack(
when (this.dataTracker.get(sizeDataTracker)) {
1 -> HexicalItems.SMALL_LIVING_SCROLL_ITEM
2 -> HexicalItems.MEDIUM_LIVING_SCROLL_ITEM
3 -> HexicalItems.LARGE_LIVING_SCROLL_ITEM
else -> throw IllegalStateException()
}
)
val constructed = mutableListOf<PatternIota>()
for (pattern in this.patterns)
constructed.add(PatternIota(HexPattern.fromNBT(pattern)))
Expand All @@ -155,12 +157,14 @@ class LivingScrollEntity(entityType: EntityType<LivingScrollEntity?>?, world: Wo
}
}

override fun getPickBlockStack() = ItemStack(when (this.dataTracker.get(sizeDataTracker)) {
1 -> HexicalItems.SMALL_LIVING_SCROLL_ITEM
2 -> HexicalItems.MEDIUM_LIVING_SCROLL_ITEM
3 -> HexicalItems.LARGE_LIVING_SCROLL_ITEM
else -> throw IllegalStateException("Invalid size")
})
override fun getPickBlockStack() = ItemStack(
when (this.dataTracker.get(sizeDataTracker)) {
1 -> HexicalItems.SMALL_LIVING_SCROLL_ITEM
2 -> HexicalItems.MEDIUM_LIVING_SCROLL_ITEM
3 -> HexicalItems.LARGE_LIVING_SCROLL_ITEM
else -> throw IllegalStateException("Invalid size")
}
)

fun toggleAged() = this.dataTracker.set(agedDataTracker, !this.dataTracker.get(agedDataTracker))
fun getAged(): Boolean = this.dataTracker.get(agedDataTracker)
Expand All @@ -173,7 +177,7 @@ class LivingScrollEntity(entityType: EntityType<LivingScrollEntity?>?, world: Wo
override fun refreshPositionAndAngles(x: Double, y: Double, z: Double, yaw: Float, pitch: Float) = this.setPosition(x, y, z)
override fun updateTrackedPositionAndAngles(x: Double, y: Double, z: Double, yaw: Float, pitch: Float, interpolationSteps: Int, interpolate: Boolean) = this.setPosition(x, y, z)

override fun createSpawnPacket() = EntitySpawnS2CPacket(this, facing.id, this.decorationBlockPos)
override fun createSpawnPacket() = EntitySpawnS2CPacket(this, facing.id, this.decorationBlockPos)
override fun onSpawnPacket(packet: EntitySpawnS2CPacket) {
super.onSpawnPacket(packet)
this.setFacing(Direction.byId(packet.entityData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class LivingScrollRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<

matrices.pop()
}

private fun drawPattern(matrices: MatrixStack, vertexConsumers: VertexConsumerProvider, pattern: HexPattern, size: Int, light: Int) {
matrices.push()
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180f))
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/miyucomics/hexical/entities/MeshEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ 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.nbt.NbtCompound
import net.minecraft.nbt.NbtElement
import net.minecraft.nbt.NbtFloat
import net.minecraft.nbt.NbtList
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket
import net.minecraft.util.math.Vec3d
import net.minecraft.world.World
Expand All @@ -24,6 +27,7 @@ class MeshEntity(entityType: EntityType<MeshEntity?>?, world: World?) : Entity(e
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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/miyucomics/hexical/entities/SpeckEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SpeckEntity(entityType: EntityType<SpeckEntity?>?, world: World?) : Entity
private val thicknessDataTracker: TrackedData<Float> = DataTracker.registerData(SpeckEntity::class.java, TrackedDataHandlerRegistry.FLOAT)
private val rollDataTracker: TrackedData<Float> = DataTracker.registerData(SpeckEntity::class.java, TrackedDataHandlerRegistry.FLOAT)
}

private var lifespan = -1

// client-only
Expand Down
1 change: 1 addition & 0 deletions src/main/java/miyucomics/hexical/entities/SpikeRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SpikeRenderer(ctx: EntityRendererFactory.Context) : EntityRenderer<SpikeEn

matrices.pop()
}

private fun vertex(mat: Matrix4f, light: Int, verts: VertexConsumer, normalMatrix: Matrix3f, x: Float, y: Float, z: Float, u: Float, v: Float) = verts.vertex(mat, x, y, z)
.color(255, 255, 255, 255)
.texture(u, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AbstractClientPlayerEntityMixin implements PlayerAnimations {

@Inject(method = "<init>", at = @At(value = "RETURN"))
private void init(ClientWorld world, GameProfile profile, PlayerPublicKey publicKey, CallbackInfo ci) {
PlayerAnimationAccess.getPlayerAnimLayer((AbstractClientPlayerEntity) (Object)this).addAnimLayer(50, modAnimationContainer);
PlayerAnimationAccess.getPlayerAnimLayer((AbstractClientPlayerEntity) (Object) this).addAnimLayer(50, modAnimationContainer);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
public abstract class FrameForEachMixin implements FrameForEachMinterface {
@Unique
private InjectedGambit hexical$injectedGambit = InjectedGambit.NONE;

@Shadow
public abstract SpellList getData();

@Shadow
public abstract SpellList getCode();

@Shadow
public abstract List<Iota> getBaseStack();

@Shadow
public abstract List<Iota> getAcc();

Expand All @@ -54,7 +58,8 @@ void hijackEvaluate(SpellContinuation continuation, ServerWorld level, CastingHa
cir.setReturnValue(OpThemis.INSTANCE.evaluate(continuation, harness, getData(), getCode(), getBaseStack(), getAcc()));
}

@Override public void overwrite(@NotNull InjectedGambit gambit) {
@Override
public void overwrite(@NotNull InjectedGambit gambit) {
hexical$injectedGambit = gambit;
}
}
4 changes: 2 additions & 2 deletions src/main/java/miyucomics/hexical/mixin/OpReadMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

@Mixin(value = OpRead.class, remap = false)
public class OpReadMixin {
@Inject(method ="execute(Ljava/util/List;Lat/petrak/hexcasting/api/spell/casting/CastingContext;)Ljava/util/List;", at = @At("HEAD"), cancellable = true)
@Inject(method = "execute(Ljava/util/List;Lat/petrak/hexcasting/api/spell/casting/CastingContext;)Ljava/util/List;", at = @At("HEAD"), cancellable = true)
private void readCompass(List<? extends Iota> args, CastingContext ctx, CallbackInfoReturnable<List<Iota>> cir) {
ItemStack stack = ctx.getHeldItemToOperateOn(item -> item.isOf(HexicalItems.INSTANCE.getCONJURED_COMPASS_ITEM())).getFirst();
if (stack.isOf(HexicalItems.INSTANCE.getCONJURED_COMPASS_ITEM())){
if (stack.isOf(HexicalItems.INSTANCE.getCONJURED_COMPASS_ITEM())) {
if (!stack.getOrCreateNbt().contains("location")) {
cir.setReturnValue(List.of(new NullIota()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class BooleanPropertyEffect(private val property: BooleanProperty) : Prestidigit
val state = caster.world.getBlockState(position)
caster.world.setBlockState(position, state.with(property, !state.get(property)), Block.NOTIFY_ALL or Block.REDRAW_ON_MAIN_THREAD)
}

override fun effectEntity(caster: ServerPlayerEntity, entity: Entity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RingBellEffect : PrestidigitationEffect {
override fun effectBlock(caster: ServerPlayerEntity, position: BlockPos) {
val state = caster.world.getBlockState(position)
if (state.block is BellBlock) {
val bell = (caster.world.getBlockEntity(position)?: return) as BellBlockEntity
val bell = (caster.world.getBlockEntity(position) ?: return) as BellBlockEntity
val facing = state.get(BellBlock.FACING)
val ringDirection = when (state.get(BellBlock.ATTACHMENT)) {
Attachment.SINGLE_WALL -> facing.rotateYClockwise()
Expand All @@ -29,5 +29,6 @@ class RingBellEffect : PrestidigitationEffect {
caster.world.emitGameEvent(caster, GameEvent.BLOCK_CHANGE, position)
}
}

override fun effectEntity(caster: ServerPlayerEntity, entity: Entity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class TransformBlockEffect(val state: BlockState) : PrestidigitationEffect {
override fun effectBlock(caster: ServerPlayerEntity, position: BlockPos) {
caster.world.setBlockState(position, state)
}

override fun effectEntity(caster: ServerPlayerEntity, entity: Entity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class TriggerImpetusEffect : PrestidigitationEffect {
override fun effectBlock(caster: ServerPlayerEntity, position: BlockPos) {
val state = caster.world.getBlockState(position)
if (state.block is BlockAbstractImpetus) {
val impetus: BlockEntityAbstractImpetus = (caster.world.getBlockEntity(position)?: return) as BlockEntityAbstractImpetus
val impetus: BlockEntityAbstractImpetus = (caster.world.getBlockEntity(position) ?: return) as BlockEntityAbstractImpetus
impetus.activateSpellCircle(caster)
}
}

override fun effectEntity(caster: ServerPlayerEntity, entity: Entity) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UseItemOnEffect(val stack: ItemStack) : PrestidigitationEffect {
caster.mainHandStack.useOnBlock(ItemUsageContext(caster, Hand.MAIN_HAND, BlockHitResult(Vec3d.ofCenter(position), Direction.UP, position, true)))
caster.setStackInHand(Hand.MAIN_HAND, oldStack)
}

override fun effectEntity(caster: ServerPlayerEntity, entity: Entity) {
val oldStack = caster.mainHandStack
caster.setStackInHand(Hand.MAIN_HAND, stack)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/miyucomics/hexical/registry/HexicalEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object HexicalEvents {
@JvmStatic
fun clientInit() {
ShaderEffectRenderCallback.EVENT.register(ShaderEffectRenderCallback { tickDelta: Float ->
val player = MinecraftClient.getInstance().player?: return@ShaderEffectRenderCallback
val player = MinecraftClient.getInstance().player ?: return@ShaderEffectRenderCallback
if (player.hasStatusEffect(HexicalStatusEffects.MEDIA_VISION_STATUS_EFFECT))
MEDIA_SICKNESS_SHADER.render(tickDelta)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object HexicalNetworking {
fun clientInit() {
ClientPlayNetworking.registerGlobalReceiver(START_EVOKE_CHANNEL) { client, _, packet, _ ->
val uuid = packet.readUuid()
val player = client.world!!.getPlayerByUuid(uuid)?: return@registerGlobalReceiver
val player = client.world!!.getPlayerByUuid(uuid) ?: return@registerGlobalReceiver
val container = (player as PlayerAnimations).hexicalModAnimations()
val frame = PlayerAnimationRegistry.getAnimation(HexicalMain.id("cast_loop"))!!
container.setAnimation(KeyframeAnimationPlayer(frame))
Expand Down
Loading

0 comments on commit ab1a31b

Please sign in to comment.