99import drzhark .mocreatures .entity .tameable .MoCEntityTameableAnimal ;
1010import drzhark .mocreatures .init .MoCLootTables ;
1111import drzhark .mocreatures .init .MoCSoundEvents ;
12- import net .minecraft .entity .Entity ;
1312import net .minecraft .entity .IEntityLivingData ;
1413import net .minecraft .entity .SharedMonsterAttributes ;
1514import net .minecraft .entity .ai .EntityAISwimming ;
3433import net .minecraftforge .common .BiomeDictionary .Type ;
3534
3635import javax .annotation .Nullable ;
37- import java .util .List ;
3836
3937public class MoCEntityBunny extends MoCEntityTameableAnimal {
4038
4139 private static final DataParameter <Boolean > HAS_EATEN = EntityDataManager .createKey (MoCEntityBunny .class , DataSerializers .BOOLEAN );
42- private int bunnyReproduceTickerA ;
43- private int bunnyReproduceTickerB ;
40+ public int bunnyReproduceTickerA ;
41+ public int bunnyReproduceTickerB ;
4442 private int jumpTimer ;
4543
4644 public MoCEntityBunny (World world ) {
4745 super (world );
4846 setAdult (true );
4947 setTamed (false );
50- setAge (50 + this . rand .nextInt (15 ));
51- if (this . rand .nextInt (4 ) == 0 ) {
48+ setAge (50 + getRNG () .nextInt (15 ));
49+ if (getRNG () .nextInt (4 ) == 0 ) {
5250 setAdult (false );
5351 }
5452 setSize (0.5F , 0.5F );
55- this .bunnyReproduceTickerA = this . rand .nextInt (64 );
53+ this .bunnyReproduceTickerA = getRNG () .nextInt (64 );
5654 this .bunnyReproduceTickerB = 0 ;
5755 }
5856
@@ -63,8 +61,9 @@ protected void initEntityAI() {
6361 this .tasks .addTask (2 , new EntityAIPanicMoC (this , 1.0D ));
6462 this .tasks .addTask (3 , new EntityAIFleeFromPlayer (this , 1.0D , 4D ));
6563 this .tasks .addTask (4 , new EntityAIFollowAdult (this , 1.0D ));
66- this .tasks .addTask (5 , new EntityAIWanderMoC2 (this , 0.8D ));
67- this .tasks .addTask (6 , new EntityAIWatchClosest (this , EntityPlayer .class , 6.0F ));
64+ this .tasks .addTask (5 , new EntityAIBunnyReproduce (this ));
65+ this .tasks .addTask (6 , new EntityAIWanderMoC2 (this , 0.8D ));
66+ this .tasks .addTask (7 , new EntityAIWatchClosest (this , EntityPlayer .class , 6.0F ));
6867 }
6968
7069 @ Override
@@ -78,13 +77,13 @@ protected void applyEntityAttributes() {
7877 @ Override
7978 protected void entityInit () {
8079 super .entityInit ();
81- this .dataManager .register (HAS_EATEN , Boolean . FALSE );
80+ this .dataManager .register (HAS_EATEN , false );
8281 }
8382
8483 @ Override
85- public IEntityLivingData onInitialSpawn (DifficultyInstance difficulty , IEntityLivingData par1EntityLivingData ) {
84+ public IEntityLivingData onInitialSpawn (DifficultyInstance difficulty , IEntityLivingData entityLivingData ) {
8685 if (this .world .provider .getDimension () == MoCreatures .proxy .wyvernDimension ) this .enablePersistence ();
87- return super .onInitialSpawn (difficulty , par1EntityLivingData );
86+ return super .onInitialSpawn (difficulty , entityLivingData );
8887 }
8988
9089 public boolean getHasEaten () {
@@ -100,7 +99,7 @@ public void selectType() {
10099 checkSpawningBiome ();
101100
102101 if (getType () == 0 ) {
103- setType (this . rand .nextInt (5 ) + 1 );
102+ setType (getRNG () .nextInt (5 ) + 1 );
104103 }
105104
106105 }
@@ -174,21 +173,21 @@ public boolean processInteract(EntityPlayer player, EnumHand hand) {
174173 return tameResult ;
175174 }
176175
177- final ItemStack stack = player .getHeldItem (hand );
178- if (!stack .isEmpty () && (stack .getItem () == Items .GOLDEN_CARROT ) && !getHasEaten ()) {
179- if (!player .capabilities .isCreativeMode ) stack .shrink (1 );
180- setHasEaten (true );
181- MoCTools .playCustomSound (this , MoCSoundEvents .ENTITY_GENERIC_EAT );
182- return true ;
183- }
184- if (this .getRidingEntity () == null ) {
185- if (this .startRidingPlayer (player )) {
186- this .rotationYaw = player .rotationYaw ;
176+ final ItemStack stack = player .getHeldItemMainhand ();
177+ if (!stack .isEmpty ()) {
178+ if (stack .getItem () == Items .CARROT && !getHasEaten ()) {
179+ if (!player .capabilities .isCreativeMode ) stack .shrink (1 );
180+ setHasEaten (true );
181+ MoCTools .playCustomSound (this , MoCSoundEvents .ENTITY_GENERIC_EAT );
187182 if (!getIsTamed () && !this .world .isRemote ) {
188183 MoCTools .tameWithName (player , this );
189184 }
185+ return true ;
186+ }
187+ } else if (getRidingEntity () == null ) {
188+ if (startRidingPlayer (player )) {
189+ this .rotationYaw = player .rotationYaw ;
190190 }
191-
192191 return true ;
193192 }
194193
@@ -202,54 +201,15 @@ public void onUpdate() {
202201 if (this .getRidingEntity () != null ) {
203202 this .rotationYaw = this .getRidingEntity ().rotationYaw ;
204203 }
205- if (!this .world .isRemote ) {
206204
205+ if (!this .world .isRemote ) {
207206 if (--this .jumpTimer <= 0 && this .onGround && ((this .motionX > 0.05D ) || (this .motionZ > 0.05D ) || (this .motionX < -0.05D ) || (this .motionZ < -0.05D ))) {
208207 this .motionY = 0.3D ;
209208 this .jumpTimer = 15 ;
210209 }
211-
212- if (!getIsTamed () || !getIsAdult () || !getHasEaten () || (this .getRidingEntity () != null )) {
213- return ;
214- }
215- if (this .bunnyReproduceTickerA < 1023 ) {
216- this .bunnyReproduceTickerA ++;
217- } else if (this .bunnyReproduceTickerB < 127 ) {
218- this .bunnyReproduceTickerB ++;
219- } else {
220- List <Entity > list1 = this .world .getEntitiesWithinAABBExcludingEntity (this , getEntityBoundingBox ().grow (4.0D ));
221- for (Entity entity1 : list1 ) {
222- if (!(entity1 instanceof MoCEntityBunny ) || (entity1 == this )) {
223- continue ;
224- }
225- MoCEntityBunny entitybunny = (MoCEntityBunny ) entity1 ;
226- if ((entitybunny .getRidingEntity () != null ) || (entitybunny .bunnyReproduceTickerA < 1023 ) || !entitybunny .getIsAdult () || !entitybunny .getHasEaten ()) {
227- continue ;
228- }
229- MoCEntityBunny entitybunny1 = new MoCEntityBunny (this .world );
230- entitybunny1 .setPosition (this .posX , this .posY , this .posZ );
231- entitybunny1 .setAdult (false );
232- int babytype = this .getType ();
233- if (this .rand .nextInt (2 ) == 0 ) {
234- babytype = entitybunny .getType ();
235- }
236- entitybunny1 .setType (babytype );
237- this .world .spawnEntity (entitybunny1 );
238- MoCTools .playCustomSound (this , SoundEvents .ENTITY_CHICKEN_EGG );
239- proceed ();
240- entitybunny .proceed ();
241- break ;
242- }
243- }
244210 }
245211 }
246212
247- public void proceed () {
248- setHasEaten (false );
249- this .bunnyReproduceTickerB = 0 ;
250- this .bunnyReproduceTickerA = this .rand .nextInt (64 );
251- }
252-
253213 @ Override
254214 public int nameYOffset () {
255215 return -40 ;
@@ -300,5 +260,7 @@ public float getEyeHeight() {
300260 }
301261
302262 @ Override
303- public boolean isReadyToFollowOwnerPlayer () { return !this .isMovementCeased (); }
263+ public boolean isReadyToFollowOwnerPlayer () {
264+ return !this .isMovementCeased ();
265+ }
304266}
0 commit comments