#BlameMojang

Discussion in 'Mod Development' started by Strikingwolf, Jan 29, 2015.

  1. OreCruncher

    OreCruncher Well-Known Member Mod Developer

    Haiku :)
     
    Type1Ninja and Lethosos like this.
  2. RavynousHunter

    RavynousHunter New Member

    Wow, didn't even intend to do that, lol.
     
    Type1Ninja and goldenapple like this.
  3. Type1Ninja

    Type1Ninja New Member

    The real question is what the background image will be. Captions are easy. :p
     
  4. RavynousHunter

    RavynousHunter New Member

    Headdesk, maybe?
     
  5. Firebats

    Firebats New Member

    Background would be /cast slash wrists, re roll NE hunter scream Mojang still sucks then /Facedesk.
     
  6. lucariomaster2

    lucariomaster2 New Member

    At risk of necroposting, I found this gem in 1.9:

    Code:
        
        private Packet<?> createSpawnPacket()
        {
            if (this.trackedEntity.isDead)
            {
                LOGGER.warn("Fetching addPacket for removed entity");
            }
    
            Packet pkt = net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.getEntitySpawningPacket(this.trackedEntity);
            if (pkt != null) return pkt;
    
            if (this.trackedEntity instanceof EntityItem)
            {
                return new SPacketSpawnObject(this.trackedEntity, 2, 1);
            }
            else if (this.trackedEntity instanceof EntityPlayerMP)
            {
                return new SPacketSpawnPlayer((EntityPlayer)this.trackedEntity);
            }
            else if (this.trackedEntity instanceof EntityMinecart)
            {
                EntityMinecart entityminecart = (EntityMinecart)this.trackedEntity;
                return new SPacketSpawnObject(this.trackedEntity, 10, entityminecart.getType().getId());
            }
            else if (this.trackedEntity instanceof EntityBoat)
            {
                return new SPacketSpawnObject(this.trackedEntity, 1);
            }
            else if (this.trackedEntity instanceof IAnimals)
            {
                this.lastHeadMotion = MathHelper.floor_float(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F);
                return new SPacketSpawnMob((EntityLivingBase)this.trackedEntity);
            }
            else if (this.trackedEntity instanceof EntityFishHook)
            {
                Entity entity2 = ((EntityFishHook)this.trackedEntity).angler;
                return new SPacketSpawnObject(this.trackedEntity, 90, entity2 != null ? entity2.getEntityId() : this.trackedEntity.getEntityId());
            }
            else if (this.trackedEntity instanceof EntitySpectralArrow)
            {
                Entity entity1 = ((EntitySpectralArrow)this.trackedEntity).shootingEntity;
                return new SPacketSpawnObject(this.trackedEntity, 91, 1 + (entity1 != null ? entity1.getEntityId() : this.trackedEntity.getEntityId()));
            }
            else if (this.trackedEntity instanceof EntityTippedArrow)
            {
                Entity entity = ((EntityArrow)this.trackedEntity).shootingEntity;
                return new SPacketSpawnObject(this.trackedEntity, 60, 1 + (entity != null ? entity.getEntityId() : this.trackedEntity.getEntityId()));
            }
            else if (this.trackedEntity instanceof EntitySnowball)
            {
                return new SPacketSpawnObject(this.trackedEntity, 61);
            }
            else if (this.trackedEntity instanceof EntityPotion)
            {
                return new SPacketSpawnObject(this.trackedEntity, 73);
            }
            else if (this.trackedEntity instanceof EntityExpBottle)
            {
                return new SPacketSpawnObject(this.trackedEntity, 75);
            }
            else if (this.trackedEntity instanceof EntityEnderPearl)
            {
                return new SPacketSpawnObject(this.trackedEntity, 65);
            }
            else if (this.trackedEntity instanceof EntityEnderEye)
            {
                return new SPacketSpawnObject(this.trackedEntity, 72);
            }
            else if (this.trackedEntity instanceof EntityFireworkRocket)
            {
                return new SPacketSpawnObject(this.trackedEntity, 76);
            }
            else if (this.trackedEntity instanceof EntityFireball)
            {
                EntityFireball entityfireball = (EntityFireball)this.trackedEntity;
                SPacketSpawnObject spacketspawnobject = null;
                int i = 63;
    
                if (this.trackedEntity instanceof EntitySmallFireball)
                {
                    i = 64;
                }
                else if (this.trackedEntity instanceof EntityDragonFireball)
                {
                    i = 93;
                }
                else if (this.trackedEntity instanceof EntityWitherSkull)
                {
                    i = 66;
                }
    
                if (entityfireball.shootingEntity != null)
                {
                    spacketspawnobject = new SPacketSpawnObject(this.trackedEntity, i, ((EntityFireball)this.trackedEntity).shootingEntity.getEntityId());
                }
                else
                {
                    spacketspawnobject = new SPacketSpawnObject(this.trackedEntity, i, 0);
                }
    
                spacketspawnobject.setSpeedX((int)(entityfireball.accelerationX * 8000.0D));
                spacketspawnobject.setSpeedY((int)(entityfireball.accelerationY * 8000.0D));
                spacketspawnobject.setSpeedZ((int)(entityfireball.accelerationZ * 8000.0D));
                return spacketspawnobject;
            }
            else if (this.trackedEntity instanceof EntityShulkerBullet)
            {
                SPacketSpawnObject spacketspawnobject1 = new SPacketSpawnObject(this.trackedEntity, 67, 0);
                spacketspawnobject1.setSpeedX((int)(this.trackedEntity.motionX * 8000.0D));
                spacketspawnobject1.setSpeedY((int)(this.trackedEntity.motionY * 8000.0D));
                spacketspawnobject1.setSpeedZ((int)(this.trackedEntity.motionZ * 8000.0D));
                return spacketspawnobject1;
            }
            else if (this.trackedEntity instanceof EntityEgg)
            {
                return new SPacketSpawnObject(this.trackedEntity, 62);
            }
            else if (this.trackedEntity instanceof EntityTNTPrimed)
            {
                return new SPacketSpawnObject(this.trackedEntity, 50);
            }
            else if (this.trackedEntity instanceof EntityEnderCrystal)
            {
                return new SPacketSpawnObject(this.trackedEntity, 51);
            }
            else if (this.trackedEntity instanceof EntityFallingBlock)
            {
                EntityFallingBlock entityfallingblock = (EntityFallingBlock)this.trackedEntity;
                return new SPacketSpawnObject(this.trackedEntity, 70, Block.getStateId(entityfallingblock.getBlock()));
            }
            else if (this.trackedEntity instanceof EntityArmorStand)
            {
                return new SPacketSpawnObject(this.trackedEntity, 78);
            }
            else if (this.trackedEntity instanceof EntityPainting)
            {
                return new SPacketSpawnPainting((EntityPainting)this.trackedEntity);
            }
            else if (this.trackedEntity instanceof EntityItemFrame)
            {
                EntityItemFrame entityitemframe = (EntityItemFrame)this.trackedEntity;
                return new SPacketSpawnObject(this.trackedEntity, 71, entityitemframe.facingDirection.getHorizontalIndex(), entityitemframe.getHangingPosition());
            }
            else if (this.trackedEntity instanceof EntityLeashKnot)
            {
                EntityLeashKnot entityleashknot = (EntityLeashKnot)this.trackedEntity;
                return new SPacketSpawnObject(this.trackedEntity, 77, 0, entityleashknot.getHangingPosition());
            }
            else if (this.trackedEntity instanceof EntityXPOrb)
            {
                return new SPacketSpawnExperienceOrb((EntityXPOrb)this.trackedEntity);
            }
            else if (this.trackedEntity instanceof EntityAreaEffectCloud)
            {
                return new SPacketSpawnObject(this.trackedEntity, 3);
            }
            else
            {
                throw new IllegalArgumentException("Don\'t know how to add " + this.trackedEntity.getClass() + "!");
            }
        }
     
    Planetguy likes this.
  7. jordsta95

    jordsta95 New Member

    I see nothing wrong here ;)
     
  8. Lethosos

    Lethosos New Member

    That's... a tad bit redundant. I mean, most of this can be easily folded up in the originating entity code; the projectiles I can understand tracking.
     
  9. Strikingwolf

    Strikingwolf New Member

    or y'know having a general method for tracking projectiles and just running anything that implements a projectile interface through that
     
    SatanicSanta likes this.
  10. RavynousHunter

    RavynousHunter New Member

    Teeth...grinding...
     
  11. lucariomaster2

    lucariomaster2 New Member

    Wouldn't a much better solution be to define an abstract static method getTrackingID() in Entity, that each class then implements? Then that entire mess of if/else statements could be condensed to just differentiating between EntityPlayer/EntityLiving/everything else, and returning the SPacketSpawnObject with a call to this.trackedEntity.getTrackingID() for the second argument.

    But I suppose this is Mojang.
     
  12. Lethosos

    Lethosos New Member

    [​IMG]
     
  13. Strikingwolf

    Strikingwolf New Member

    There are many, many better ways to do this, they just didn't decide on any of them, because it's Mojang
     
    SatanicSanta likes this.
  14. RavynousHunter

    RavynousHunter New Member

    That's what I would've done. Then again, I at least try to act like I know what I'm doing.
     
    lucariomaster2 and Lethosos like this.
  15. Reika

    Reika RotaryCraft Dev FTB Mod Dev

    This is very common in Mojang code (my excerpts are from 1.7.10):
    http://i.imgur.com/4GSes67.png
    http://i.imgur.com/H1NlE3g.png
    http://i.imgur.com/EQTkTzh.png
    http://i.imgur.com/cFgLH42.png
    http://i.imgur.com/hh1CE33.png
    http://i.imgur.com/bTZNbO8.png
    http://i.imgur.com/1rioLj8.png
    http://i.imgur.com/DfsBtVL.png

    Honestly, the truth is that it looks like Notch had no idea what a switch() statement was, and even Mojang fails to grasp inheritance and polymorphism.
     
  16. RavynousHunter

    RavynousHunter New Member

    ...
    ...
    ...
    AHHHHHHHHHHHHHHHHHHHHHHHHHHH!

    [​IMG]
     
  17. ratchet freak

    ratchet freak Well-Known Member

    Or the strategy pattern,

    You know the one where you use a Map<ID, IDoingSomething> and reduce all those ifs to "strat.get(input.getID()).doIt(params);". With a null check of course.
     
  18. RavynousHunter

    RavynousHunter New Member

    Never thought of that...I think. Well, would something like this count? (Using C# because its what I know best.)

    Code:
    Dictionary<string, BaseItem> Items = LoadItems();  // Loads item scripts from some local repository.
    {...}
    string CurrentItemDescription = Items[CurrentItemID].Description();
    
    Where BaseItem is an abstract base class and Description() is an abstract method within that must be overridden in any script class that derives from it?
     
  19. Lethosos

    Lethosos New Member

    Could work. May have to bug the Win10 devs to be sure of the implementation, but hey, anything they do would be a step better since MS Games programmers have a tendancy to compulsively optimize their code.

    Sent from my Puzzle Box of Yogg-Saron using Tapatalk 2
     
  20. RavynousHunter

    RavynousHunter New Member

    Hey, me too! I should work for Microsoft. ...I'd actually like that.
     
    SatanicSanta likes this.

Share This Page