Skip to content

Commit

Permalink
Optimized networking channels, akashic utils
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 8, 2024
1 parent bd653f7 commit 4af8ae0
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package miyucomics.hexical.casting.patterns.akashic

import at.petrak.hexcasting.api.spell.ConstMediaAction
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.iota.NullIota
import at.petrak.hexcasting.api.spell.mishaps.MishapBadBlock
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicBookshelf
import at.petrak.hexcasting.common.lib.HexBlocks
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes

class OpReadAkashicShelf : 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)
if (!block.isOf(HexBlocks.AKASHIC_BOOKSHELF))
throw MishapBadBlock.of(position, "akashic_bookshelf")
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
@@ -0,0 +1,37 @@
package miyucomics.hexical.casting.patterns.akashic

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 at.petrak.hexcasting.api.spell.mishaps.MishapBadBlock
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicBookshelf
import at.petrak.hexcasting.common.lib.HexBlocks
import net.minecraft.util.math.BlockPos

class OpWriteAkashicShelf : SpellAction {
override val argc = 3
override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val position = args.getBlockPos(0, argc)
ctx.assertVecInRange(position)
val block = ctx.world.getBlockState(position)
if (!block.isOf(HexBlocks.AKASHIC_BOOKSHELF))
throw MishapBadBlock.of(position, "akashic_bookshelf")
val pattern = args.getPattern(1, argc)
val iota = args[2]
val trueName = MishapOthersName.getTrueNameFromDatum(iota, ctx.caster)
if (trueName != null)
throw MishapOthersName(trueName)
return Triple(Spell(position, pattern, iota), 0, listOf())
}

private data class Spell(val position: BlockPos, val pattern: HexPattern, val iota: Iota) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val shelf = ctx.world.getBlockEntity(position)!! as BlockEntityAkashicBookshelf
shelf.clearIota()
shelf.setNewMapping(pattern, iota)
shelf.markDirty()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import at.petrak.hexcasting.api.spell.iota.Iota
import miyucomics.hexical.casting.mishaps.NeedsActiveArchLampMishap
import miyucomics.hexical.items.hasActiveArchLamp
import miyucomics.hexical.registry.HexicalItems
import miyucomics.hexical.registry.HexicalSounds

class OpTerminateArchLamp : SpellAction {
override val argc = 0
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/miyucomics/hexical/entities/SpikeRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package miyucomics.hexical.entities

import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.render.*
import net.minecraft.client.render.OverlayTexture
import net.minecraft.client.render.RenderLayer
import net.minecraft.client.render.VertexConsumer
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void tick(CallbackInfo info) {
buf.writeInt(rank);
for (int i = 0; i < rank; i++)
buf.writeBoolean(hexical$clicks.get(i));
ClientPlayNetworking.send(HexicalNetworking.INSTANCE.getCAST_CONJURED_STAFF_PACKET(), buf);
ClientPlayNetworking.send(HexicalNetworking.INSTANCE.getCONJURED_STAFF_CHANNEL(), buf);
hexical$clicks.clear();
}
}
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 @@ -22,7 +22,7 @@ object HexicalEvents {
for (otherPlayer in server.playerManager.playerList) {
val packet = PacketByteBufs.create()
packet.writeUuid(player)
ServerPlayNetworking.send(otherPlayer, HexicalNetworking.CONFIRM_START_EVOKING_PACKET, packet)
ServerPlayNetworking.send(otherPlayer, HexicalNetworking.START_EVOKE_CHANNEL, packet)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/miyucomics/hexical/registry/HexicalItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder
import net.minecraft.client.item.CompassAnglePredicateProvider
import net.minecraft.client.item.CompassAnglePredicateProvider.CompassTarget
import net.minecraft.client.item.ModelPredicateProviderRegistry
import net.minecraft.client.item.UnclampedModelPredicateProvider
import net.minecraft.client.world.ClientWorld
import net.minecraft.entity.Entity
import net.minecraft.entity.LivingEntity
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/miyucomics/hexical/registry/HexicalKeybinds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ object HexicalKeybinds {

if (states.keys.contains(EVOKE_KEYBIND.translationKey)) {
if (states[EVOKE_KEYBIND.translationKey] == true && !EVOKE_KEYBIND.isPressed) {
ClientPlayNetworking.send(HexicalNetworking.REQUEST_END_EVOKING_PACKET, PacketByteBufs.empty())
ClientPlayNetworking.send(HexicalNetworking.END_EVOKING_CHANNEL, PacketByteBufs.empty())
} else if (states[EVOKE_KEYBIND.translationKey] == false && EVOKE_KEYBIND.isPressed) {
ClientPlayNetworking.send(HexicalNetworking.REQUEST_START_EVOKING_PACKET, PacketByteBufs.empty())
ClientPlayNetworking.send(HexicalNetworking.START_EVOKE_CHANNEL, PacketByteBufs.empty())
}
}
states[EVOKE_KEYBIND.translationKey] = EVOKE_KEYBIND.isPressed
Expand All @@ -36,11 +36,11 @@ object HexicalKeybinds {
if (states[key.translationKey] == true && !key.isPressed) {
val buf = PacketByteBufs.create()
buf.writeString(key.translationKey)
ClientPlayNetworking.send(HexicalNetworking.RELEASED_KEY_PACKET, buf)
ClientPlayNetworking.send(HexicalNetworking.RELEASED_KEY_CHANNEL, buf)
} else if (states[key.translationKey] == false && key.isPressed) {
val buf = PacketByteBufs.create()
buf.writeString(key.translationKey)
ClientPlayNetworking.send(HexicalNetworking.PRESSED_KEY_PACKET, buf)
ClientPlayNetworking.send(HexicalNetworking.PRESSED_KEY_CHANNEL, buf)
}
}
states[key.translationKey] = key.isPressed
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/miyucomics/hexical/registry/HexicalNetworking.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ import net.minecraft.sound.SoundEvents
import net.minecraft.util.Identifier

object HexicalNetworking {
val CAST_CONJURED_STAFF_PACKET: Identifier = HexicalMain.id("cast_conjured_staff")
val PRESSED_KEY_PACKET: Identifier = HexicalMain.id("press_key")
val RELEASED_KEY_PACKET: Identifier = HexicalMain.id("release_key")
val CONJURED_STAFF_CHANNEL: Identifier = HexicalMain.id("conjured_staff")
val PRESSED_KEY_CHANNEL: Identifier = HexicalMain.id("press_key")
val RELEASED_KEY_CHANNEL: Identifier = HexicalMain.id("release_key")

val REQUEST_START_EVOKING_PACKET: Identifier = HexicalMain.id("request_start_evoking")
val REQUEST_END_EVOKING_PACKET: Identifier = HexicalMain.id("request_end_evoking")
val CONFIRM_START_EVOKING_PACKET: Identifier = HexicalMain.id("confirm_start_evoking")
private val CONFIRM_END_EVOKING_PACKET: Identifier = HexicalMain.id("confirm_end_evoking")
val START_EVOKE_CHANNEL: Identifier = HexicalMain.id("start_evoking")
val END_EVOKING_CHANNEL: Identifier = HexicalMain.id("end_evoking")

@JvmStatic
fun serverInit() {
ServerPlayNetworking.registerGlobalReceiver(CAST_CONJURED_STAFF_PACKET) { server, player, _, buf, _ ->
ServerPlayNetworking.registerGlobalReceiver(CONJURED_STAFF_CHANNEL) { server, player, _, buf, _ ->
val hand = getConjuredStaff(player) ?: return@registerGlobalReceiver
val constructedStack: MutableList<Iota> = ArrayList()
val staffRank = buf.readInt()
Expand All @@ -41,7 +39,7 @@ object HexicalNetworking {
}
}

ServerPlayNetworking.registerGlobalReceiver(PRESSED_KEY_PACKET) { _, player, _, buf, _ ->
ServerPlayNetworking.registerGlobalReceiver(PRESSED_KEY_CHANNEL) { _, player, _, buf, _ ->
if (!KeybindData.active.containsKey(player.uuid)) {
KeybindData.active[player.uuid] = HashMap()
KeybindData.duration[player.uuid] = HashMap()
Expand All @@ -50,13 +48,13 @@ object HexicalNetworking {
KeybindData.active[player.uuid]!![key] = true
KeybindData.duration[player.uuid]!![key] = 0
}
ServerPlayNetworking.registerGlobalReceiver(RELEASED_KEY_PACKET) { _, player, _, buf, _ ->
ServerPlayNetworking.registerGlobalReceiver(RELEASED_KEY_CHANNEL) { _, player, _, buf, _ ->
val key = buf.readString()
KeybindData.active[player.uuid]!![key] = false
KeybindData.duration[player.uuid]!![key] = 0
}

ServerPlayNetworking.registerGlobalReceiver(REQUEST_START_EVOKING_PACKET) { server, player, _, _, _ ->
ServerPlayNetworking.registerGlobalReceiver(START_EVOKE_CHANNEL) { server, player, _, _, _ ->
if (!CastingUtils.isEnlightened(player))
return@registerGlobalReceiver
EvokeState.active[player.uuid] = true
Expand All @@ -65,33 +63,33 @@ object HexicalNetworking {
for (otherPlayer in server.playerManager.playerList) {
val packet = PacketByteBufs.create()
packet.writeUuid(player.uuid)
ServerPlayNetworking.send(otherPlayer, CONFIRM_START_EVOKING_PACKET, packet)
ServerPlayNetworking.send(otherPlayer, START_EVOKE_CHANNEL, packet)
}
}
ServerPlayNetworking.registerGlobalReceiver(REQUEST_END_EVOKING_PACKET) { server, player, _, _, _ ->
ServerPlayNetworking.registerGlobalReceiver(END_EVOKING_CHANNEL) { server, player, _, _, _ ->
if (!CastingUtils.isEnlightened(player))
return@registerGlobalReceiver
EvokeState.active[player.uuid] = false
EvokeState.duration[player.uuid] = -1
for (otherPlayer in server.playerManager.playerList) {
val packet = PacketByteBufs.create()
packet.writeUuid(player.uuid)
ServerPlayNetworking.send(otherPlayer, CONFIRM_END_EVOKING_PACKET, packet)
ServerPlayNetworking.send(otherPlayer, END_EVOKING_CHANNEL, packet)
}
}
}

@JvmStatic
fun clientInit() {
ClientPlayNetworking.registerGlobalReceiver(CONFIRM_START_EVOKING_PACKET) { client, _, packet, _ ->
ClientPlayNetworking.registerGlobalReceiver(START_EVOKE_CHANNEL) { client, _, packet, _ ->
val uuid = packet.readUuid()
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))
EvokeState.active[uuid] = true
}
ClientPlayNetworking.registerGlobalReceiver(CONFIRM_END_EVOKING_PACKET) { client, _, packet, _ ->
ClientPlayNetworking.registerGlobalReceiver(END_EVOKING_CHANNEL) { client, _, packet, _ ->
val uuid = packet.readUuid()
val container = (client.world!!.getPlayerByUuid(uuid) as PlayerAnimations).hexicalModAnimations()
val frame = PlayerAnimationRegistry.getAnimation(HexicalMain.id("cast_end"))!!
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/miyucomics/hexical/registry/HexicalPatterns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.common.casting.operators.selectors.OpGetEntitiesBy
import miyucomics.hexical.HexicalMain
import miyucomics.hexical.casting.patterns.*
import miyucomics.hexical.casting.patterns.akashic.OpReadAkashicShelf
import miyucomics.hexical.casting.patterns.akashic.OpWriteAkashicShelf
import miyucomics.hexical.casting.patterns.basic.*
import miyucomics.hexical.casting.patterns.circle.OpDisplace
import miyucomics.hexical.casting.patterns.conjured_staff.OpConjureStaff
Expand Down Expand Up @@ -63,6 +65,9 @@ object HexicalPatterns {
register("perlin", "qawedqdq", HexDir.WEST, OpPerlin())
register("theodolite", "wqaa", HexDir.EAST, OpGetEntityData(3))

register("read_shelf", "qaqqqada", HexDir.EAST, OpReadAkashicShelf())
register("write_shelf", "edeeedad", HexDir.SOUTH_WEST, OpWriteAkashicShelf())

register("age_scroll", "wewaawewaddwwewwdwwew", HexDir.SOUTH_EAST, OpAgeScroll())

register("conjure_firework", "dedwaqwwawwqa", HexDir.SOUTH_WEST, OpConjureFirework())
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/miyucomics/hexical/utils/PerlinNoise.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ class PerlinNoise(seed: Int) {
return a + b + c + d
}

fun noise(x: Double, y: Double, z: Double, w: Double): Double {
val X = floor(x).toInt() and 255
val Y = floor(y).toInt() and 255
val Z = floor(z).toInt() and 255
val W = floor(w).toInt() and 255
fun noise(sampleX: Double, sampleY: Double, sampleZ: Double, time: Double): Double {
val X = floor(sampleX).toInt() and 255
val Y = floor(sampleY).toInt() and 255
val Z = floor(sampleZ).toInt() and 255
val W = floor(time).toInt() and 255

val x = x - floor(x)
val y = y - floor(y)
val z = z - floor(z)
val w = w - floor(w)
val x = sampleX - floor(sampleX)
val y = sampleY - floor(sampleY)
val z = sampleZ - floor(sampleZ)
val w = time - floor(time)

val u = fade(x)
val v = fade(y)
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/hexical/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"subtitles.hexical.lamp_deactivate": "Lamp deactivates",
"particle.minecraft.soul_7": "",

"hexcasting.mishap.bad_block.akashic_bookshelf": "an akashic bookshelf",
"hexcasting.mishap.bad_block.mage_block": "a mage block",
"hexcasting.mishap.bad_block.prestidigitation": "a prestidigitation-sensitive block",
"hexcasting.mishap.bad_item.grimoire": "a grimoire",
Expand Down Expand Up @@ -332,6 +333,13 @@
"hexcasting.spell.hexical:write_staff": "Staff Gambit",
"hexical.page.write_staff.summary": "Writes an iota to the conjured staff's inner storage. Does not allow player references.",

"hexical.page.akashic_utils.title": "Akashic Utilities",
"hexical.page.akashic_utils.0": "I have discovered some conveniences with akashic libraries! I can right-click a filled akashic bookshelf to copy the iota from it into my player stack. I can also right-click with a scroll to copy the pattern of the bookshelf onto the scroll. Finally, I have discovered two patterns that can read and write directly to a bookshelf without need of a record. While I sacrifice being able to access them universally, I can perform these actions for free.",
"hexcasting.spell.hexical:read_shelf": "Librarian's Purification",
"hexical.page.read_shelf.summary": "Reads the iota from an akashic bookshelf within ambit. Free.",
"hexcasting.spell.hexical:write_shelf": "Librarian's Gambit",
"hexical.page.write_shelf.summary": "Writes an iota under a pattern to an akashic bookshelf within ambit. Free.",

"hexical.page.circle_spells.title": "Circle Spells",
"hexical.page.circle_spells.0": "When the media courses through the boundaries of a circle, it saturates the domain inside the circle with _media, allowing me to manipulate the environment inside far more flexibly than I am used to. The following are some spells I've come across or developed, which are to only be cast by a $(l:greatwork/spellcircles)spell circle$().",
"hexcasting.spell.hexical:displace": "Displace",
Expand Down
Binary file modified src/main/resources/assets/hexical/textures/block/hex_candle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/hexical/textures/item/hex_candle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "hexical.page.akashic_utils.title",
"icon": "hexcasting:akashic_bookshelf",
"category": "hexcasting:greatwork",
"advancement": "hexcasting:enlightenment",
"sortnum": 5,
"pages": [
{
"type": "patchouli:text",
"text": "hexical.page.akashic_utils.0"
},
{
"type": "hexcasting:pattern",
"op_id": "hexical:read_shelf",
"anchor": "hexical:read_shelf",
"input": "vector",
"output": "any",
"text": "hexical.page.read_shelf.summary"
},
{
"type": "hexcasting:pattern",
"op_id": "hexical:write_shelf",
"anchor": "hexical:write_shelf",
"input": "vector, pattern, any",
"output": "",
"text": "hexical.page.write_shelf.summary"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"type": "hexcasting:pattern",
"op_id": "hexical:block_hardness",
"anchor": "hexical:block_hardness",
"input": "vector",
"input": "identifier",
"output": "number",
"text": "hexical.page.block_hardness.summary"
},
{
"type": "hexcasting:pattern",
"op_id": "hexical:block_blast_resistance",
"anchor": "hexical:block_blast_resistance",
"input": "vector",
"input": "identifier",
"output": "number",
"text": "hexical.page.block_blast_resistance.summary"
}
]
}
}

0 comments on commit 4af8ae0

Please sign in to comment.