mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Add method to retrieve FishHook (#12310)
This commit is contained in:
parent
3e3b42cdf5
commit
f8fa4f6f5e
@ -1,5 +1,6 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -323,7 +324,6 @@ public interface FishHook extends Projectile {
|
||||
BOBBING;
|
||||
}
|
||||
|
||||
// Paper start - More FishHook API
|
||||
/**
|
||||
* Get the number of ticks the hook needs to wait for a fish to bite.
|
||||
*
|
||||
@ -367,5 +367,18 @@ public interface FishHook extends Projectile {
|
||||
* enchantment.
|
||||
*/
|
||||
void resetFishingState();
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
* Retrieve this fishhook back to the casting player.
|
||||
* <p>
|
||||
* This method will trigger and respect API events, which may be subject to cancellation.
|
||||
* Plugins listening to {@link org.bukkit.event.player.PlayerFishEvent} might for example cancel this action.
|
||||
*
|
||||
* @param slot Slot holding the fishing rod (must be HAND/OFF_HAND)
|
||||
* @return The amount of damage which would be applied to the itemstack
|
||||
* @throws IllegalStateException if the fish hook does not have a player casting it.
|
||||
* @throws IllegalStateException if the player casting it is not holding a
|
||||
* {@link org.bukkit.inventory.ItemType#FISHING_ROD} in the specified equipment slot.
|
||||
*/
|
||||
int retrieve(@NotNull EquipmentSlot slot);
|
||||
}
|
||||
|
@ -2,10 +2,16 @@ package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.FishingHook;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
private double biteChance = -1;
|
||||
@ -233,4 +239,18 @@ public class CraftFishHook extends CraftProjectile implements FishHook {
|
||||
hook.resetTimeUntilLured();
|
||||
hook.timeUntilHooked = 0; // Reset time until hooked, will be repopulated once lured time is ticked down.
|
||||
}
|
||||
|
||||
@Override
|
||||
public int retrieve(EquipmentSlot slot) {
|
||||
Preconditions.checkArgument(slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND, "Equipment slot must be HAND or OFF_HAND");
|
||||
final FishingHook fishingHook = getHandle();
|
||||
final Player playerOwner = fishingHook.getPlayerOwner();
|
||||
Preconditions.checkState(playerOwner != null, "Player owner cannot be null");
|
||||
|
||||
final InteractionHand hand = CraftEquipmentSlot.getHand(slot);
|
||||
final ItemStack itemInHand = playerOwner.getItemInHand(hand);
|
||||
Preconditions.checkState(itemInHand.is(Items.FISHING_ROD), "Item in slot is not a FISHING_ROD");
|
||||
|
||||
return fishingHook.retrieve(itemInHand, hand);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user