Skip to content

fix: made book work when right clicking thin air. #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -107,6 +108,18 @@ public int modeValue(ItemMode mode) {
return this.getItemModes().indexOf(mode) ;
}

@Override
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
ItemStack itemStack = pPlayer.getItemInHand(pUsedHand);
if(!pPlayer.isShiftKeyDown() && pLevel.isClientSide) {
ItemMode curr = this.getCurrentItemMode(itemStack);
WorkAreaSize workAreaSize = ItemNBTUtil.getWorkAreaSize(itemStack);
GuiHelper.openBookOfCallingGui(curr, workAreaSize);
}
return super.use(pLevel, pPlayer, pUsedHand);

}

@Override
public InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
Expand Down Expand Up @@ -178,13 +191,14 @@ public InteractionResult useOn(UseOnContext context) {
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity target,
InteractionHand hand) {
if (target.level().isClientSide)
return InteractionResult.PASS;

//Ignore anything that is not a spirit
if (!(target instanceof SpiritEntity targetSpirit))
return InteractionResult.PASS;

if (target.level().isClientSide)
return InteractionResult.SUCCESS;

//books can only control the spirit that is bound to them.
if (!targetSpirit.getUUID().equals(ItemNBTUtil.getSpiritEntityUUID(stack))) {
//re-link book
Expand Down