EntityAIVillagerMate .java

net.minecraft.entity.ai.EntityAIVillagerMate (class, 142 lines): members: matingTimeout, mate, villagerObj, villageObj, worldObj, updateTask, resetTask.

net.minecraft.entity.aiclass142 linescommonextends EntityAIBase4.1 KB

API Surface (5)

boolean shouldExecute()
void startExecuting()
void resetTask()
boolean continueExecuting()
void updateTask()

Fields & Constants (5)

villagerObj
mate
worldObj
matingTimeout
villageObj

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EntityAIVillagerMate.java142 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.ai;
2
3
import net.minecraft.entity.Entity;
4
import net.minecraft.entity.passive.EntityVillager;
5
import net.minecraft.util.BlockPos;
6
import net.minecraft.village.Village;
7
import net.minecraft.world.World;
8
9
public class EntityAIVillagerMate extends EntityAIBase
10
{
11
    private EntityVillager villagerObj;
12
    private EntityVillager mate;
13
    private World worldObj;
14
    private int matingTimeout;
15
    Village villageObj;
16
17
    public EntityAIVillagerMate(EntityVillager villagerIn)
18
    {
19
        this.villagerObj = villagerIn;
20
        this.worldObj = villagerIn.worldObj;
21
        this.setMutexBits(3);
22
    }
23
24
    /**
25
     * Returns whether the EntityAIBase should begin execution.
26
     */
27
    public boolean shouldExecute()
28
    {
29
        if (this.villagerObj.getGrowingAge() != 0)
30
        {
31
            return false;
32
        }
33
        else if (this.villagerObj.getRNG().nextInt(500) != 0)
34
        {
35
            return false;
36
        }
37
        else
38
        {
39
            this.villageObj = this.worldObj.getVillageCollection().getNearestVillage(new BlockPos(this.villagerObj), 0);
40
41
            if (this.villageObj == null)
42
            {
43
                return false;
44
            }
45
            else if (this.checkSufficientDoorsPresentForNewVillager() && this.villagerObj.getIsWillingToMate(true))
46
            {
47
                Entity entity = this.worldObj.findNearestEntityWithinAABB(EntityVillager.class, this.villagerObj.getEntityBoundingBox().expand(8.0D, 3.0D, 8.0D), this.villagerObj);
48
49
                if (entity == null)
50
                {
51
                    return false;
52
                }
53
                else
54
                {
55
                    this.mate = (EntityVillager)entity;
56
                    return this.mate.getGrowingAge() == 0 && this.mate.getIsWillingToMate(true);
57
                }
58
            }
59
            else
60
            {
61
                return false;
62
            }
63
        }
64
    }
65
66
    /**
67
     * Execute a one shot task or start executing a continuous task
68
     */
69
    public void startExecuting()
70
    {
71
        this.matingTimeout = 300;
72
        this.villagerObj.setMating(true);
73
    }
74
75
    /**
76
     * Resets the task
77
     */
78
    public void resetTask()
79
    {
80
        this.villageObj = null;
81
        this.mate = null;
82
        this.villagerObj.setMating(false);
83
    }
84
85
    /**
86
     * Returns whether an in-progress EntityAIBase should continue executing
87
     */
88
    public boolean continueExecuting()
89
    {
90
        return this.matingTimeout >= 0 && this.checkSufficientDoorsPresentForNewVillager() && this.villagerObj.getGrowingAge() == 0 && this.villagerObj.getIsWillingToMate(false);
91
    }
92
93
    /**
94
     * Updates the task
95
     */
96
    public void updateTask()
97
    {
98
        --this.matingTimeout;
99
        this.villagerObj.getLookHelper().setLookPositionWithEntity(this.mate, 10.0F, 30.0F);
100
101
        if (this.villagerObj.getDistanceSqToEntity(this.mate) > 2.25D)
102
        {
103
            this.villagerObj.getNavigator().tryMoveToEntityLiving(this.mate, 0.25D);
104
        }
105
        else if (this.matingTimeout == 0 && this.mate.isMating())
106
        {
107
            this.giveBirth();
108
        }
109
110
        if (this.villagerObj.getRNG().nextInt(35) == 0)
111
        {
112
            this.worldObj.setEntityState(this.villagerObj, (byte)12);
113
        }
114
    }
115
116
    private boolean checkSufficientDoorsPresentForNewVillager()
117
    {
118
        if (!this.villageObj.isMatingSeason())
119
        {
120
            return false;
121
        }
122
        else
123
        {
124
            int i = (int)((double)((float)this.villageObj.getNumVillageDoors()) * 0.35D);
125
            return this.villageObj.getNumVillagers() < i;
126
        }
127
    }
128
129
    private void giveBirth()
130
    {
131
        EntityVillager entityvillager = this.villagerObj.createChild(this.mate);
132
        this.mate.setGrowingAge(6000);
133
        this.villagerObj.setGrowingAge(6000);
134
        this.mate.setIsWillingToMate(false);
135
        this.villagerObj.setIsWillingToMate(false);
136
        entityvillager.setGrowingAge(-24000);
137
        entityvillager.setLocationAndAngles(this.villagerObj.posX, this.villagerObj.posY, this.villagerObj.posZ, 0.0F, 0.0F);
138
        this.worldObj.spawnEntityInWorld(entityvillager);
139
        this.worldObj.setEntityState(entityvillager, (byte)12);
140
    }
141
}
142

Deobfuscated MCP 1.8.9 source of EntityAIVillagerMate from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/ai/EntityAIVillagerMate.java), stored verbatim.