Skip to content

Commit

Permalink
fix: old patchouli books not working when right clicking tables
Browse files Browse the repository at this point in the history
  • Loading branch information
williambl committed Oct 11, 2022
1 parent 45f441e commit cd33e77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/com/williambl/haema/core/BookOfBloodItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> {
Expand All @@ -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
}
}
}
8 changes: 7 additions & 1 deletion src/main/kotlin/com/williambl/haema/ritual/RitualModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit cd33e77

Please sign in to comment.