Looting for Bows

Discussion in 'Plugin Development' started by Demyxa, Jan 25, 2020.

Thread Status:
Not open for further replies.
  1. I've been thinking about adding a looting enchantment for Bows, seeing as the good old "Shoot'n Swap" doesn't work anymore.
    Would there be any way to create an Enchantment that increases the drops when shot with a bow enchanted with "Huntsman" or some other name.
     
  2. I'm not sure if you can get the information about the bow enchantments directly from the ProjectileHitEvent but you could save them in the metadata or customname of the arrow in ProjectileLaunchEvent and check for that later

    EDIT: And yeah ProjectlieHitEvent doesn't make sense in that case
     
    Last edited: Jan 26, 2020
  3. For the actual functionality of the enchantment (I've been struggling with the setup a bit) I have this so far:

    PHP:
    public void onEntityDeathEvent(EntityDeathEvent K) {
                if (
    K.getEntity().getKiller() instanceof Player) {
                    
    Player p = (PlayerK.getEntity().getKiller();
                  
                    
    ItemStack Hand p.getInventory().getItemInMainHand();
                  
                    if (
    Hand.containsEnchantment(this)) {
                      
        }
    Anyone see anything wrong with it?

    EDIT: Changed it to EntityDeathEvent to better reflect it being similar to looting.
     
    Last edited: Jan 25, 2020
  4. @Demyxa Well, does it work?

    The problem with your code is that the shooter could switch the slot before the arrow hits.
    I would go with EntityDamageByEntityEvent. That way you can get the Arrow instance and check for the enchantments
     
  5. Well, it doesn't. Not because the Enchant doesn't work, but because I can't even initialize the plugin.
    I've followed a Tutorial by The Source Code, and I've followed it step by step so far.

    However, I struggle at this bit here:


    PHP:
    public class Huntsman extends Enchantment implements Listener{
       

       
        public 
    Huntsman(int Id) {
            
    super(Id);
    I know, it's very simple but I can't wrap my head around the "super(Id)". It requests a NamespacedKey, but in my main class here, it wants "Id" to be an int here:

    PHP:
        public Huntsman ench = new Huntsman(101);
    In the tutorial, everything worked fine just the way this is. However it IS from two years ago and things might have changed.
     
  6. You should give the constructor what he wants ^^
    Syntax is
    Code:
    new NameapacedKey(Plugin, String)
    IDs are not used anymore
    Tip: you can also write the namespace directly into the super() and leave the huntsman constructor blank (or pass the main in your case)
     
Thread Status:
Not open for further replies.

Share This Page