Skip to content

Commit

Permalink
Lexicon can be placed in bookshelf and on lectern (fixes #4488)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealWormbo committed Nov 27, 2023
1 parent 27f4a80 commit c0f31c7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Xplat/src/main/java/vazkii/botania/data/ItemTagProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ protected void addTags(HolderLookup.Provider provider) {
BotaniaBlocks.hourglass.asItem(), BotaniaBlocks.manaPylon.asItem(), monocle);
this.tag(ItemTags.MUSIC_DISCS).add(recordGaia1, recordGaia2);
this.tag(ItemTags.CLUSTER_MAX_HARVESTABLES).add(manasteelPick, elementiumPick, terraPick, glassPick);
this.tag(ItemTags.LECTERN_BOOKS).add(lexicon);
this.tag(ItemTags.BOOKSHELF_BOOKS).add(lexicon);

this.tag(BotaniaTags.Items.DUSTS_MANA).add(manaPowder);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package vazkii.botania.mixin;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.phys.BlockHitResult;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import vazkii.botania.common.advancements.UseItemSuccessTrigger;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.patchouli.common.handler.LecternEventHandler;

@Mixin(LecternEventHandler.class)
public class LecternEventHandlerMixin {
/**
* Hooks into the Patchouli lectern event handler, right before the call to {@code openBookGUI}, to properly award
* the lexicon reading advancement if read via a lectern instead of via the book item directly.
*/
@Inject(
method = "rightClick(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;",
at = @At(value = "INVOKE", target = "Lvazkii/patchouli/api/PatchouliAPI$IPatchouliAPI;openBookGUI(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/resources/ResourceLocation;)V")
)
private static void checkUseLexicon(Player player, Level world, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> cir) {
if (!(player instanceof ServerPlayer serverPlayer)) {
return;
}
final var blockEntity = world.getBlockEntity(hit.getBlockPos(), BlockEntityType.LECTERN);
blockEntity.ifPresent(lecternBlockEntity -> {
final var itemStack = lecternBlockEntity.getBook();
if (itemStack.is(BotaniaItems.lexicon)) {
UseItemSuccessTrigger.INSTANCE.trigger(serverPlayer, itemStack, serverPlayer.serverLevel(),
player.getX(), player.getY(), player.getZ());
}
});
}
}
1 change: 1 addition & 0 deletions Xplat/src/main/resources/botania_xplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ItemEntityAccessor",
"ItemEntityMixin",
"ItemMixin",
"LecternEventHandlerMixin",
"LevelAccessor",
"LivingEntityAccessor",
"LoomMenuMixin",
Expand Down

0 comments on commit c0f31c7

Please sign in to comment.