1. powns

    powns Well-Known Member

    powns
    MVP++
    Infamy INFAMY
    Member
    Messages:
    3,415
    Okay so as far as I have investigated Hypixel has custom implementations for thrown entities (snowballs, potions, eggs etc.) but I still need to know who threw the entity... Is there any way to figure this out? If you call EntityThrowable#getThrower it always returns null..

    Thanks in advance :)
     
    #1
  2. powns

    powns Well-Known Member

    powns
    MVP++
    Infamy INFAMY
    Member
    Messages:
    3,415
    Even though this forums section is basically dead and I doubt anyone will read this; what I ended up doing is the following:

    Code:
    private static HashMap<Integer, ProjectileSpawnInfo> throwableEntitySpawnPoints = new HashMap<Integer, ProjectileSpawnInfo>();
    
    @SubscribeEvent
        public void onProjectileEntitySpawn(EntityJoinWorldEvent e){
            if(mc.theWorld == null){
                return;
            }
    
            if(e.entity instanceof EntityThrowable && !(e.entity instanceof EntityPotion || e.entity instanceof EntityEnderPearl)){
    
                double smallestDistance = -1;
                EntityPlayer closestPlayer = null;
    
                for(EntityPlayer player : mc.theWorld.playerEntities){
                  
                       double currentDistance = e.entity.getDistanceSqToEntity(player);
    
                       if(currentDistance <= 30 && (smallestDistance == -1 || currentDistance < smallestDistance)){
                                smallestDistance = e.entity.getDistanceSqToEntity(player);
                                closestPlayer = player;
                         }
                }
    
                EntityThrowable throwableEntity = (EntityThrowable) e.entity;
                throwableEntitySpawnPoints.put(throwableEntity.getEntityId(), new ProjectileSpawnInfo(throwableEntity.posX, throwableEntity.posY, throwableEntity.posZ, closestPlayer));
            }
        }
    Notice that the HashMap is static because I need to access its info through an ASM hook. I will clean up this code later on, and if you have any questions feel free to pm me on the forums or on twitter :)

    EDIT: Also, be sure to check for a max distance between the players and the snowball otherwise you will end up having a thrower from f.e. 50 blocks bc it was "spawned in" by a snow golem.
     
    #2
    Last edited: Feb 9, 2020
    • Like Like x 2

Share This Page