Sheepuff now eat grass.

This commit is contained in:
bconlon 2020-06-04 16:42:12 -07:00
parent 55995c3a74
commit f6d905cf59
2 changed files with 63 additions and 37 deletions

View file

@ -2,6 +2,7 @@ package com.legacy.aether.entities.ai;
import net.minecraft.block.Block;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import com.legacy.aether.blocks.BlocksAether;
@ -15,21 +16,33 @@ public class SheepuffAIEatAetherGrass extends EntityAIBase {
int eatingGrassTimer;
public SheepuffAIEatAetherGrass(EntitySheepuff sheepuff) {
public SheepuffAIEatAetherGrass(EntitySheepuff sheepuff)
{
this.sheepuff = sheepuff;
this.entityWorld = sheepuff.worldObj;
this.setMutexBits(7);
}
public boolean shouldExecute() {
if (this.sheepuff.getRNG().nextInt(1000) != 0) {
public boolean shouldExecute()
{
System.out.println(eatingGrassTimer);
if (this.sheepuff.getRNG().nextInt(this.sheepuff.isChild() ? 50 : 1000) != 0)
{
return false;
} else {
return this.entityWorld.getBlock((int) this.sheepuff.posX, (int) this.sheepuff.posY - 1, (int) this.sheepuff.posZ) == BlocksAether.aether_grass;
}
else
{
int i = MathHelper.floor_double(this.sheepuff.posX);
int j = MathHelper.floor_double(this.sheepuff.posY);
int k = MathHelper.floor_double(this.sheepuff.posZ);
return this.entityWorld.getBlock(i, j - 1, k) == BlocksAether.aether_grass;
}
}
public void startExecuting() {
public void startExecuting()
{
this.eatingGrassTimer = 40;
this.entityWorld.setEntityState(this.sheepuff, (byte) 10);
this.sheepuff.getNavigator().clearPathEntity();
@ -47,15 +60,22 @@ public class SheepuffAIEatAetherGrass extends EntityAIBase {
return this.eatingGrassTimer;
}
public void updateTask() {
public void updateTask()
{
this.eatingGrassTimer = Math.max(0, this.eatingGrassTimer - 1);
if (this.eatingGrassTimer == 4) {
if (this.eatingGrassTimer == 4)
{
int i = MathHelper.floor_double(this.sheepuff.posX);
int j = MathHelper.floor_double(this.sheepuff.posY);
int k = MathHelper.floor_double(this.sheepuff.posZ);
if (this.entityWorld.getBlock((int) this.sheepuff.posX, (int) this.sheepuff.posY - 1, (int) this.sheepuff.posZ) == BlocksAether.aether_grass) {
if (this.entityWorld.getGameRules().getGameRuleBooleanValue("mobGriefing")) {
this.entityWorld.playAuxSFX(2001, (int) this.sheepuff.posX, (int) this.sheepuff.posY - 1, (int) this.sheepuff.posZ, Block.getIdFromBlock(BlocksAether.aether_grass));
this.entityWorld.setBlock((int) this.sheepuff.posX, (int) this.sheepuff.posY - 1, (int) this.sheepuff.posZ, BlocksAether.aether_dirt);
if (this.entityWorld.getBlock(i, j - 1, k) == BlocksAether.aether_grass)
{
if (this.entityWorld.getGameRules().getGameRuleBooleanValue("mobGriefing"))
{
this.entityWorld.playAuxSFX(2001, i, j - 1, k, Block.getIdFromBlock(BlocksAether.aether_grass));
this.entityWorld.setBlock(i, j - 1, k, BlocksAether.aether_dirt);
}
this.sheepuff.eatGrassBonus();

View file

@ -26,7 +26,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class EntitySheepuff extends EntityAetherAnimal {
private SheepuffAIEatAetherGrass entityAIEatGrass;
private SheepuffAIEatAetherGrass entityAIEatGrass = new SheepuffAIEatAetherGrass(this);
private int sheepTimer, amountEaten;
@ -38,33 +38,16 @@ public class EntitySheepuff extends EntityAetherAnimal {
this.setFleeceColor(getRandomFleeceColor(rand));
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIPanic(this, 1.25D));
this.tasks.addTask(5, this.entityAIEatGrass = new SheepuffAIEatAetherGrass(this));
this.tasks.addTask(5, this.entityAIEatGrass);
this.tasks.addTask(6, new EntityAIWander(this, 1.0D));
this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
this.tasks.addTask(8, new EntityAILookIdle(this));
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
}
@Override
protected void entityInit() {
super.entityInit();
this.dataWatcher.addObject(16, new Byte((byte) 0));
this.dataWatcher.addObject(17, new Byte((byte) 0));
this.dataWatcher.addObject(18, new Byte((byte) 0));
}
@Override
protected void dropFewItems(boolean var1, int ammount) {
if (!this.getSheared()) {
this.entityDropItem(new ItemStack(Blocks.wool, 1 + this.rand.nextInt(2), this.getFleeceColor()), 0.0F);
}
protected boolean isAIEnabled()
{
return true;
}
@Override
@ -82,6 +65,29 @@ public class EntitySheepuff extends EntityAetherAnimal {
super.onLivingUpdate();
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
}
@Override
protected void entityInit() {
super.entityInit();
this.dataWatcher.addObject(16, (byte) 0);
this.dataWatcher.addObject(17, (byte) 0);
this.dataWatcher.addObject(18, (byte) 0);
}
@Override
protected void dropFewItems(boolean var1, int ammount) {
if (!this.getSheared()) {
this.entityDropItem(new ItemStack(Blocks.wool, 1 + this.rand.nextInt(2), this.getFleeceColor()), 0.0F);
}
}
@SideOnly(Side.CLIENT)
public void handleHealthUpdate(byte id) {
if (id == 10) {
@ -177,14 +183,14 @@ public class EntitySheepuff extends EntityAetherAnimal {
}
}
if (this.amountEaten == 5 && !this.getSheared() && !this.getPuffed()) {
if (this.amountEaten >= 2 && !this.getSheared() && !this.getPuffed()) {
this.setPuffed(true);
this.amountEaten = 0;
}
if (this.amountEaten == 10 && this.getSheared() && !this.getPuffed()) {
if (this.amountEaten == 1 && this.getSheared() && !this.getPuffed()) {
this.setSheared(false);
this.setFleeceColor(15);
this.setFleeceColor(0);
this.amountEaten = 0;
}
}