Amazon Ad

Saturday, June 3, 2017

Entities Part 1: Setting Up

At long last, we are going to start learning how to create an entity. So let's get into defining what an entity is in minecraft.

There are two different kinds of entities: Entities and Mobs

Entities are anything that exist in the world that are not in the inventory and are not blocks. Some entities are spawned in the world to hurt other entities while some only occur in the world as items, which are EntityItems. Entities have a world, x, y, z, and some have acceleration depending on what kind of entity it is. There are also ThrowableEntities which, as examples, are like splash potions and ender pearls.

Now Mobs are another story. Mobs are anything that aren't items or blocks and have an AI. Mobs have many different fields that go with it by default including posX, posY, posZ, motionX, motionY, and motionZ, just to name a few. You can register and render a mob using the EntityRegistry in the Forge API.

So what kind of activity can we do to practice with entities. I thought of an entity that we can make. It's a lion-like creature that fires a ball of lightning and will stun the player upon contact (a mob that fires an entity). The way we are going to do this is we will do the basic entity setup in this tutorial and in the next tutorial we will do the AI. After that, we will set up the entity for the stun bolt, then we will put it all together. This will all occur over a span of about ~1-1/2 months as I have my own mods to do as well as school to stay on task with.

So let's start with creating a directory for our entities and create a class for our mob and call it EntityKao. We will extend it to EntityMob which is the class we will inherit from for all of our mob's properties. We will need to inherit a few methods from EntityMob including,


  • initEntityAI
  • applyEntityAttributes
The initEntityAI method is how we set what AI we want for the mob. There is a whole list of AI and there is a rule of thumb for the execution of the AI. Certain AI cannot be executed at once as others while some can be executed with others. Here's the list of AI and the categories that they belong in:

Category 1
  • EntityAIAvoidEntity
  • EntityAICreeperSwell
  • EntityAIDefendVillage 
  • EntityAIFleeSun 
  • EntityAIHurtByTarget 
  • EntityAIMoveIndoors 
  • EntityAIMoveThroughVillage  
  • EntityAIMoveTowardsRestriction 
  • EnttiyAIMoveTowardsTarget 
  • EntityAINearestAttackableTarget 
  • EntityAIOwnerHurtByTarget 
  • EntityAIOwnerHurtTarget 
  • EntityAIPanic 
  • EntityAIPlay 
  • EntityAIRunAroundLikeCrazy 
  • EntityAIWander 
  • EntityAIWanderAvoidWater 

Category 2
  • EntityAIBeg 
  • EntityAIWatchClosest 
  • EntityAIWatchClosest2 

Category 3
  • EntityAIAttackMelee 
  • EntityAIAttackRanged 
  • EntityAIAttackRangedBow 
  • EntityAIFollowGolem 
  • EntityAIFollowOwner 
  • EntityAILookAtVillager 
  • EntityAILookIdle 
  • EntityAIMate 
  • EntityAIOcelotAttack 
  • EntityAITempt 
  • EntityAIVillagerMate 
  • EntityAIZombieAttack 


Category 4
  • EntityAISwimming 

Category 5
  • EntityAILeapAtTarget 
  • EntityAILlamaFollowCaravan 
  • EntityAIMoveToBlock 
  • EntityAISit 
  • EntityAITradePlayer 


Category 7
  • EntityAIEatGrass 

Unknown Category
  • EntityAIDoorInteract 
  • EntityAIFindNearest 
  • EntityAIFindNearestPlayer 
  • EntityAIFollowParent 
  • EntityAIHarvestFarmland 
  • EntityAILookAtTradePlayer 
  • EntityAIOcelotSit 
  • EntityAIOpenDoor 
  • EntityAIRestrictOpenDoor 
  • EntityAIRestrictSun 
  • EntityAISkeletonRiders 
  • EntityAITarget 
  • EntityAITargetNonTamed 
  • EntityAIVillagerInteract 

When you want to add an AI to your mob, you have to add it to a task. Some have to be added to a targetTask, because they search for targets. A few examples would be EntityAIAttackMelee, EntityAIAttackRanged, EntityAIFindNearestAttackableTarget, etc.

So let's add some AI to our mob. We will add three AI for now, which will be EntityAILookIdle, EntityAIWander, and EntityAIAttackMelee. We have to give them a priority of when we want them to fire. This is how they should look like in our class (I know, at long last enough of me babbling)

Next, we want to set the entity attributes, which are stuff like health and speed. So we can add in lines just like you see below. There's really not much. If you wanna explore then by all means, go on ahead, but this is as much as I am going to show.


Well, this concludes this part of the entities tutorials. I hope this at least gets you started in creating a mob.

2 comments:

  1. Could you potentially show more of your code? I'm trying to use this as a model to create my own mob and would find that very helpful.

    Keep up the great work!

    ReplyDelete
  2. Good game choice for an article, thanks for taking your time to publish it. Really interesting graphics, the screenshots looks very good. I have a blog about games too, you can visit it at:

    > Minecraft Mod GAMES FREE DOWNLOAD <

    ReplyDelete