From cd33e77c42203b211a5a083baa59fade2618618f Mon Sep 17 00:00:00 2001 From: williambl Date: Tue, 11 Oct 2022 15:46:35 +0100 Subject: [PATCH] fix: old patchouli books not working when right clicking tables --- .../com/williambl/haema/compat/emi/HaemaEmiPlugin.kt | 3 ++- .../com/williambl/haema/compat/rei/HaemaREIPlugin.kt | 3 ++- .../kotlin/com/williambl/haema/core/BookOfBloodItem.kt | 7 +++++++ .../kotlin/com/williambl/haema/ritual/RitualModule.kt | 8 +++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/williambl/haema/compat/emi/HaemaEmiPlugin.kt b/src/main/kotlin/com/williambl/haema/compat/emi/HaemaEmiPlugin.kt index 96b952af..64fa6f3d 100644 --- a/src/main/kotlin/com/williambl/haema/compat/emi/HaemaEmiPlugin.kt +++ b/src/main/kotlin/com/williambl/haema/compat/emi/HaemaEmiPlugin.kt @@ -2,6 +2,7 @@ package com.williambl.haema.compat.emi import com.williambl.haema.Haema import com.williambl.haema.api.RitualTableUseEvent +import com.williambl.haema.core.BookOfBloodItem import com.williambl.haema.craft.BookOfBloodRecipe import com.williambl.haema.ritual.RitualModule import dev.emi.emi.api.EmiApi @@ -41,7 +42,7 @@ class HaemaEmiPlugin: EmiPlugin{ init { RitualTableUseEvent.EVENT.register(RitualTableUseEvent { _, world, _, player, hand, _ -> - if (player.getStackInHand(hand).item == Haema.BOOK_OF_BLOOD && world.isClient) { + if (BookOfBloodItem.isBook(player.getStackInHand(hand)) && world.isClient) { EmiApi.displayRecipeCategory(RitualCategory) } }) diff --git a/src/main/kotlin/com/williambl/haema/compat/rei/HaemaREIPlugin.kt b/src/main/kotlin/com/williambl/haema/compat/rei/HaemaREIPlugin.kt index 52f32941..ea1b53ce 100644 --- a/src/main/kotlin/com/williambl/haema/compat/rei/HaemaREIPlugin.kt +++ b/src/main/kotlin/com/williambl/haema/compat/rei/HaemaREIPlugin.kt @@ -2,6 +2,7 @@ package com.williambl.haema.compat.rei import com.williambl.haema.Haema import com.williambl.haema.api.RitualTableUseEvent +import com.williambl.haema.core.BookOfBloodItem import com.williambl.haema.craft.BookOfBloodRecipe import com.williambl.haema.ritual.craft.RitualRecipe import com.williambl.haema.util.SelfClosingScreen @@ -29,7 +30,7 @@ class HaemaREIPlugin : REIClientPlugin { init { RitualTableUseEvent.EVENT.register(RitualTableUseEvent { _, world, _, player, hand, _ -> - if (player.getStackInHand(hand).item == Haema.BOOK_OF_BLOOD && world.isClient) { + if (BookOfBloodItem.isBook(player.getStackInHand(hand)) && world.isClient) { ViewSearchBuilder.builder().addCategory(ritualId).open() REIRuntimeImpl.getInstance().previousScreen = SelfClosingScreen() } diff --git a/src/main/kotlin/com/williambl/haema/core/BookOfBloodItem.kt b/src/main/kotlin/com/williambl/haema/core/BookOfBloodItem.kt index 2a7506fd..81d9a7e7 100644 --- a/src/main/kotlin/com/williambl/haema/core/BookOfBloodItem.kt +++ b/src/main/kotlin/com/williambl/haema/core/BookOfBloodItem.kt @@ -12,6 +12,7 @@ import net.minecraft.world.World import vazkii.patchouli.api.PatchouliAPI import vazkii.patchouli.common.base.PatchouliSounds import vazkii.patchouli.common.book.BookRegistry +import vazkii.patchouli.common.item.PatchouliItems class BookOfBloodItem(settings: Settings?) : Item(settings) { override fun use(world: World, player: PlayerEntity, hand: Hand): TypedActionResult { @@ -25,4 +26,10 @@ class BookOfBloodItem(settings: Settings?) : Item(settings) { } return TypedActionResult(ActionResult.SUCCESS, stack) } + + companion object { + fun isBook(stack: ItemStack): Boolean { + return stack.item is BookOfBloodItem || stack.item == PatchouliItems.BOOK + } + } } diff --git a/src/main/kotlin/com/williambl/haema/ritual/RitualModule.kt b/src/main/kotlin/com/williambl/haema/ritual/RitualModule.kt index ddb50f33..f410770e 100644 --- a/src/main/kotlin/com/williambl/haema/ritual/RitualModule.kt +++ b/src/main/kotlin/com/williambl/haema/ritual/RitualModule.kt @@ -2,6 +2,7 @@ package com.williambl.haema.ritual import com.williambl.haema.Haema import com.williambl.haema.api.RitualTableUseEvent +import com.williambl.haema.core.BookOfBloodItem import com.williambl.haema.id import com.williambl.haema.ritual.craft.AddLevelsRitualAction import com.williambl.haema.ritual.craft.ChangeAbilitiesRitualAction @@ -27,6 +28,7 @@ import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos import net.minecraft.util.registry.Registry import net.minecraft.world.World +import vazkii.patchouli.common.item.PatchouliItems import vazkii.patchouli.common.multiblock.DenseMultiblock import vazkii.patchouli.common.multiblock.MultiblockRegistry import vazkii.patchouli.common.multiblock.StateMatcher @@ -62,7 +64,11 @@ object RitualModule: ModInitializer { override fun onInitialize() { RitualTableUseEvent.EVENT.register { _: BlockState, world: World, _: BlockPos, player: PlayerEntity, hand: Hand, _: BlockHitResult -> - if (player.getStackInHand(hand).item == Haema.BOOK_OF_BLOOD && world.isClient && !FabricLoader.getInstance().isModLoaded("roughlyenoughitems") && !FabricLoader.getInstance().isModLoaded("emi")) { + if (world.isClient + && BookOfBloodItem.isBook(player.getStackInHand(hand)) + && !FabricLoader.getInstance().isModLoaded("roughlyenoughitems") + && !FabricLoader.getInstance().isModLoaded("emi") + ) { player.sendMessage(Text.translatable("gui.haema.message.no_recipe_viewer"), true); } }