Skip to content

Commit

Permalink
Fixed PacketAutoRecipe
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 24, 2024
1 parent 2ed1f2b commit afcbcfa
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package com.willfp.eco.internal.spigot.proxy.common.packet.display
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.packet.PacketEvent
import com.willfp.eco.core.packet.PacketListener
import com.willfp.eco.internal.spigot.proxy.common.toResourceLocation
import com.willfp.eco.util.namespacedKeyOf
import net.minecraft.network.protocol.game.ClientboundPlaceGhostRecipePacket
import net.minecraft.resources.ResourceLocation

class PacketAutoRecipe(
private val plugin: EcoPlugin
) : PacketListener {
private val fKey = ClientboundPlaceGhostRecipePacket::class.java
.declaredFields
.first { it.type == ResourceLocation::class.java }
.apply { isAccessible = true }

override fun onSend(event: PacketEvent) {
val packet = event.packet.handle as? ClientboundPlaceGhostRecipePacket ?: return

Expand All @@ -24,9 +31,7 @@ class PacketAutoRecipe(
return
}

val fKey = packet.javaClass.getDeclaredField("b")
fKey.isAccessible = true
val key = fKey[packet] as ResourceLocation
fKey[packet] = ResourceLocation(key.namespace, key.path + "_displayed")
fKey[packet] = namespacedKeyOf(key.namespace, key.path + "_displayed").toResourceLocation()
}
}

0 comments on commit afcbcfa

Please sign in to comment.