Skip to content

Commit

Permalink
Fix block can use
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Aug 17, 2024
1 parent c5540c4 commit 4d001a5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import net.minecraft.block.*
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventories
import net.minecraft.inventory.Inventory
import net.minecraft.inventory.SidedInventory
import net.minecraft.item.HoeItem
import net.minecraft.item.ItemStack
Expand Down Expand Up @@ -167,9 +168,7 @@ class HarvestBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite
}

override fun canPlayerUse(player: PlayerEntity): Boolean {
return if (world!!.getBlockEntity(pos) !== this) {
false
} else player.squaredDistanceTo(pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5) <= 64.0
return Inventory.canPlayerUse(this, player)
}

override fun getAvailableSlots(side: Direction): IntArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ class TestGuiBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite
}

override fun canPlayerUse(player: PlayerEntity): Boolean {
return if (world!!.getBlockEntity(pos) !== this) {
false
} else player.squaredDistanceTo(pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5) <= 64.0
return Inventory.canPlayerUse(this, player)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class TrashcanBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: It

override fun setStack(slot: Int, stack: ItemStack?) {}

override fun canPlayerUse(player: PlayerEntity): Boolean = false
override fun canPlayerUse(player: PlayerEntity): Boolean {
return Inventory.canPlayerUse(this, player)
}

override fun onClick(player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult {
if (player.isSpectator) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/one/oktw/galaxy/gui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GUI private constructor(
override fun getDisplayName() = title

override fun createMenu(syncId: Int, playerInventory: PlayerInventory, player: PlayerEntity): ScreenHandler? {
if (blockEntity?.isRemoved == true) return null
if ((blockEntity as? Inventory)?.canPlayerUse(player) == false) return null
return GuiContainer(syncId, playerInventory)
}

Expand Down

0 comments on commit 4d001a5

Please sign in to comment.