Solved Preventing custom zombie catch fire from daylight

Discussion in 'Plugin Development' started by ski23, May 17, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    ski23

    I would like to prevent a zombie from catching fire due to the sunlight. I do not want to do this with EntityCombustEvent. I would like to prevent the zombie from catching fire in the method where it happens. I have searched through the EntityZombie class and have determined that the combust event happens in the m() method. The problem is that I cannot simply override this method as the super method needs to be called otherwise the zombie will not move. I cannot simply override the method and call the super method as if I call super in the custom zombie, it will call the entity zombie's m method causing the zombie to catch fire anyway. I did some researching and it does not appear to be possible to call the super method of a grandparent in Java. This leaves me rather stumped and how to fix this seemingly simple issue.
     
  2. Offline

    Lolmewn

    You could wrap the parent in your class, and use that variable to call the "grandparent" functions maybe?
     
  3. Offline

    ski23

    @Lolmewn How would I store the parent? The only way I have previously referenced a parent is by calling its methods or constructors using super.
     
  4. Offline

    Lolmewn

    @ski23 When constructing your object, pass the parent along. You're basically creating a wrapper for it. Not sure if this would work for you though, but it's worth a try.
     
  5. Offline

    ski23

    @Lolmewn I'm not sure exactly how to get an instance of the parent even when instantiating the mob initially. I'm not actually storing an instance of the mob directly. I'm storing it by referencing it as an interface. Here is some code to show what I mean:
    Code:
    public class CustomMobManager
    {
        public static List<CustomMob> Team1Mobs;
        public static List<CustomMob> Team2Mobs;
        public static Game currentGame;
        protected static final Logger MyLogger = Logger.getLogger("Minecraft");
        public CustomMobManager(Game game)
        {
            Team1Mobs = new ArrayList<CustomMob>();
            Team2Mobs = new ArrayList<CustomMob>();
            currentGame = game;
        }
        public static void spawnEntity(MobTypes type,TdTeam team)
        {
            CustomMob mob;
            Location[] path;
            if (team.equals(TdTeam.Team1))
            {
                //MyLogger.info("team1path " + currentGame.map.pathTeam1);
                path = currentGame.map.pathTeam1;
            }
            else if (team.equals(TdTeam.Team2))
            {
                //MyLogger.info("team2path " + currentGame.map.pathTeam2);
                path = currentGame.map.pathTeam2;
            }
            else
            {
                path = null;
                return;
            }
            MyLogger.info("path " + path);
            for (int i = 0; i < path.length; i++)
            {
                path[i].setWorld(Bukkit.getServer().getWorld(currentGame.map.worldName + "Copy"));
            }
            switch (type)
            {
                case Zombie:
                {
                 
                    CustomZombie zombie = new CustomZombie(path[0].getWorld(), path ,1);
                    EntityTypes.spawnEntity(zombie, path[0]);
                    mob = (CustomMob) zombie;
                    zombie.team = team;
                    break;
                }
                case Skeleton:
                {
                    CustomSkeleton skeleton = new CustomSkeleton(path[0].getWorld(), path, 1);
                    EntityTypes.spawnEntity(skeleton, path[0]);
                    mob = (CustomMob) skeleton;
                    skeleton.team = team;
                    break;
                }
                case Spider:
                {
                    CustomSpider spider = new CustomSpider(path[0].getWorld(), path, 1);
                    EntityTypes.spawnEntity(spider, path[0]);
                    mob = (CustomMob) spider;
                    spider.team = team;
                    break;
                }
                default:
                {
                    mob = null;
                }
            }
            if (mob != null)
            {
                if (team.equals(TdTeam.Team1))
                {
                    Team1Mobs.add(mob);
                }
                else if (team.equals(TdTeam.Team2))
                {
                    Team2Mobs.add(mob);
                }
                mob.setPath();
            }
            //MyLogger.info("Team1Mobs " + Team1Mobs);
            //MyLogger.info("Team2Mobs " + Team2Mobs);
         
        }
    }
    
    Note that CustomMob is an interface

    Never found a clean way to do it. I just change the fireproof boolean to be off. If I ever need to allow the zombie to catch fire by unnatural means, I will turn it back on temporarily.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
Thread Status:
Not open for further replies.

Share This Page