Skip to content

Commit

Permalink
fix: remove needing GearyContext for furniture API methods as locatio…
Browse files Browse the repository at this point in the history
…n is provided
  • Loading branch information
Boy0000 committed Oct 31, 2024
1 parent 2fd5e3d commit 91a4dfd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
gearyPaper = "0.31.0-dev.2"
gearyPaper = "0.31.0"
guiy="0.12.4"

[libraries]
Expand Down
12 changes: 5 additions & 7 deletions src/main/kotlin/com/mineinabyss/blocky/api/BlockyFurnitures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import com.mineinabyss.geary.modules.Geary
import com.mineinabyss.geary.papermc.toEntityOrNull
import com.mineinabyss.geary.papermc.toGeary
import com.mineinabyss.geary.papermc.tracking.blocks.helpers.toGearyOrNull
import com.mineinabyss.geary.papermc.tracking.entities.helpers.withGeary
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.papermc.tracking.items.ItemTracking
import com.mineinabyss.geary.papermc.withGeary
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.idofront.events.call
import io.th0rgal.protectionlib.ProtectionLib
Expand Down Expand Up @@ -50,8 +52,7 @@ object BlockyFurnitures {
context(Geary) val ItemStack.blockyFurniture get() = this.decode<BlockyFurniture>()
context(Geary) val PrefabKey.blockyFurniture get() = this.toEntityOrNull()?.get<BlockyFurniture>()

//TODO toGearyOrNull wouldnt work here as furniture isnt in geary
context(Geary) val Block.blockyFurniture get() = this.toGearyOrNull()?.get<BlockyFurniture>()
val Block.blockyFurniture get() = this.baseFurniture?.withGeary { it.toGearyOrNull()?.get<BlockyFurniture>() }

val Block.baseFurniture: ItemDisplay?
get() = FurniturePacketHelpers.baseFurnitureFromCollisionHitbox(this.toBlockPos())
Expand All @@ -67,13 +68,10 @@ object BlockyFurnitures {
val ItemDisplay.blockySeat
get() = this.seats.minByOrNull { it.location.distanceSquared(this.location) }

context(Geary)
fun placeFurniture(prefabKey: PrefabKey, location: Location) =
placeFurniture(prefabKey, location, 0f)
fun placeFurniture(prefabKey: PrefabKey, location: Location) = placeFurniture(prefabKey, location, 0f)

context(Geary)
fun placeFurniture(prefabKey: PrefabKey, location: Location, yaw: Float) =
getAddon(ItemTracking).createItem(prefabKey)?.let { FurnitureHelpers.placeBlockyFurniture(prefabKey, location, yaw, it) }
location.withGeary { getAddon(ItemTracking).createItem(prefabKey) }?.let { FurnitureHelpers.placeBlockyFurniture(prefabKey, location, yaw, it) }

fun placeFurniture(prefabKey: PrefabKey, location: Location, yaw: Float, itemStack: ItemStack) =
FurnitureHelpers.placeBlockyFurniture(prefabKey, location, yaw, itemStack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object CopperHelpers {

fun isFakeWaxedCopper(block: Block) = (block.type in VANILLA_COPPER) && block.container { has<WaxedCopperBlock>() }
context(Geary) fun isFakeWaxedCopper(itemStack: ItemStack) =
itemStack.type.name.contains("WAXED") && itemStack.type.isBlock && !isBlockyCopper(itemStack)
"WAXED" in itemStack.type.name && itemStack.type.isBlock && !isBlockyCopper(itemStack)

fun setFakeWaxedCopper(block: Block, value: Boolean) = when {
!value -> block.container { remove<WaxedCopperBlock>() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fun placeBlockyBlock(
against: Block,
face: BlockFace,
newData: BlockData
) = with(player.world.toGeary()) {
) = player.withGeary {
val targetBlock = if (against.isReplaceable) against else against.getRelative(face)
if (!targetBlock.type.isAir && !targetBlock.isLiquid && targetBlock.type != Material.LIGHT) return
if (!against.isBlockyBlock && !newData.isBlockyBlock && !CopperHelpers.isBlockyCopper(against) && !CopperHelpers.isBlockyCopper(newData)) return
Expand Down

0 comments on commit 91a4dfd

Please sign in to comment.