Skip to content

Commit

Permalink
Port InteractionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
opekope2 committed Oct 25, 2024
1 parent f165d80 commit 29ceb41
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ import net.fabricmc.fabric.api.event.player.UseItemCallback
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen
import net.minecraft.client.gui.screen.ingame.BookEditScreen
import net.minecraft.client.gui.screen.ingame.BookScreen
import net.minecraft.client.gui.screen.ingame.HangingSignEditScreen
import net.minecraft.client.gui.screen.ingame.*
import net.minecraft.entity.Entity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.Identifier
import net.minecraft.util.TypedActionResult
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.EntityHitResult
import net.minecraft.world.World
Expand Down Expand Up @@ -74,17 +69,15 @@ internal object InteractionHandler : ClientModInitializer, UseBlockCallback, Use
return ActionResult.PASS
}

override fun interact(player: PlayerEntity, world: World, hand: Hand): TypedActionResult<ItemStack> {
val stack = player.getStackInHand(hand)
val result = TypedActionResult.pass(stack)

if (!world.isClient) return result
override fun interact(player: PlayerEntity, world: World, hand: Hand): ActionResult {
if (!world.isClient) return ActionResult.PASS

val stack = player.getStackInHand(hand)
if (stack.isOf(Items.WRITABLE_BOOK) || stack.isOf(Items.WRITTEN_BOOK)) {
Interaction.prepare(stack.item.identifier, player, world, Hand.MAIN_HAND, null, BookExtraProperties(0, 0))
// BookExtraProperties will be updated later
}
return result
return ActionResult.PASS
}

override fun onBeforeBegin(screen: Screen) {
Expand All @@ -110,7 +103,8 @@ internal object InteractionHandler : ClientModInitializer, UseBlockCallback, Use
@JvmStatic
fun interact(player: PlayerEntity, world: World, currentScreen: Screen) {
val container = when (currentScreen) {
is AbstractInventoryScreen<*> -> Identifier.ofVanilla("player")
is InventoryScreen -> Identifier.ofVanilla("player")
is CreativeInventoryScreen -> Identifier.ofVanilla("player")
is HangingSignEditScreen -> world.getBlockState(currentScreen.blockEntity.pos).block.identifier
else -> return
}
Expand Down

0 comments on commit 29ceb41

Please sign in to comment.