-
-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lexicon can be placed in bookshelf and on lectern (fixes #4488)
- Loading branch information
1 parent
27f4a80
commit c0f31c7
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
Xplat/src/generated/resources/.cache/5e449fe289648869bd1f4d4d99715c8b4e0c057d
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
Xplat/src/generated/resources/data/minecraft/tags/items/bookshelf_books.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
Xplat/src/generated/resources/data/minecraft/tags/items/lectern_books.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Xplat/src/main/java/vazkii/botania/mixin/LecternEventHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters