Skip to content

Commit

Permalink
fix: made book work when right clicking thin air. (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaeaKat authored Mar 16, 2024
1 parent 4725758 commit ee46fc8
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit ee46fc8

Please sign in to comment.