Solved Projectile with CustomModelData

Discussion in 'Spigot Plugin Development' started by SirPsp, Oct 21, 2019.

  1. If I set a custom texture for a snowball (using CustomModelData), when thrown the projectile will also show the custom texture.
    But if I use player.launchProjectile(Snowball.class) it doesn't use the custom texture.

    My goal is to create infinite snowballs that have a custom texture. So I'm cancelling the interact event and launching the projectile myself.

    I've also tried allowing the interact to go through and then setting the item in the hand during the ProjectileLaunchEvent but that doesn't work, I guess the item is removed afterwards. I thought about setting the item 1 tick later but I'd rather a better solution.

    Is there a way to do this?
     
  2. Sadly not possible.
    You'll have to create an instance of the Item entity class and launch that instead. (You'll need to write the a lot of the code yourself)
     
  3. This is possible with protocollib coupled with NMS and PersistentData API of spigot which applies to entities and itemstacks
    Already made a disguise library using this method
    Note that you will have to do reflection to change data values
     
  4. I figured it out, pretty simple.

    Code (Java):
    Snowball snowball = p.launchProjectile(Snowball.class);
    net.minecraft.server.v1_14_R1.EntitySnowball entitysnowball = ((CraftSnowball)snowball).getHandle();
    net.minecraft.server.v1_14_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    entitysnowball.setItem(stack);
    (item is the ItemStack with CustomModelData)
     
  5. Seems like a good candidate for a Spigot PR