Type mismatch: cannot convert from element type Object to EntityPlayer | Java

Discussion in 'Programming' started by Constipate, Jul 30, 2020.

  1. I'm trying to do a java statement I'm using the Minecraft Coderpack.
    I'm getting this error in eclipse when I try to do the following statement.

    Code (Text):
        for (EntityPlayer player : mc.theWorld.playerEntities) {
            if (player.getHealth() != Float.NaN && player != mc.thePlayer) mc.theWorld.removeEntity(player);
        }
    The error is:

    > Type mismatch: cannot convert from element type Object to EntityPlayer
     
  2. through what exactly are you iterating there?
    where do you get "mc.theWorld.playerEntities"?
     
  3. I still need help. The code works perfectly for someone else who is on 1.8.8 I'm on 1.8
     
  4. The full class is down below. I don't know what you mean.
    Code (Text):
    package kyle.modules.combat;

    import org.lwjgl.input.Keyboard;

    import kyle.events.Event;
    import kyle.events.listeners.EventTarget;
    import kyle.events.listeners.EventUpdate;
    import kyle.modules.Module;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;

    public class AntiBot extends Module{

        public AntiBot() {
            super("AntiBot", Keyboard.KEY_NONE, Category.COMBAT);
        }
       
        public void onEvent(Event e) {
           
            for (EntityPlayer player : mc.theWorld.loadedEntityList) {
                if (player.getHealth() != Float.NaN && player != mc.thePlayer) mc.theWorld.removeEntity(player);
        }
               
            }
       
        public void onDisable() {

        }
                       
    }
     
  5. Sent above.
     
  6. i couldn't think of any reason why this would work for anyone else. the whole thing makes entirely no sense.
    you have no @EventHandler Annotation, you haven't declared what Event you want, you don't have anywhere where you would get "mc.theWorld.loadedEntityList" from
     
  7. I'm using version 1.8 and It's saying mc.theWorld.playerEntities is error
    but with 1.8.8 it works fine

    Would you know what would replace mc.theWorld.playerEntities in 1.8 to get all player entities ?

    I'm coding with Minecraft Coder Pack for version minecraft 1.8
    I'm not coding a forge mod.