aether-legacy/src/main/java/com/gildedgames/the_aether/entities/passive/mountable/EntityAerbunny.java

253 lines
7.5 KiB
Java
Raw Normal View History

2020-08-14 08:29:22 +02:00
package com.gildedgames.the_aether.entities.passive.mountable;
2016-12-17 16:28:16 +01:00
2021-01-04 17:29:40 +01:00
import com.gildedgames.the_aether.AetherConfig;
2020-08-14 08:29:22 +02:00
import com.gildedgames.the_aether.entities.passive.EntityAetherAnimal;
2018-12-07 05:33:43 +01:00
import io.netty.buffer.ByteBuf;
2016-12-17 16:28:16 +01:00
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
2020-08-14 08:29:22 +02:00
import com.gildedgames.the_aether.entities.ai.aerbunny.AerbunnyAIHop;
import com.gildedgames.the_aether.player.PlayerAether;
2016-12-17 16:28:16 +01:00
2018-12-07 05:33:43 +01:00
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
2018-12-07 06:32:48 +01:00
public class EntityAerbunny extends EntityAetherAnimal implements IEntityAdditionalSpawnData {
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
private int puff;
2017-03-05 05:09:31 +01:00
2018-12-07 06:32:48 +01:00
public int puffiness;
2016-12-17 16:28:16 +01:00
private int jumpTicks;
private int jumps;
2018-12-07 06:32:48 +01:00
public EntityAerbunny(World world) {
2016-12-17 16:28:16 +01:00
super(world);
this.ignoreFrustumCheck = true;
this.setSize(0.4F, 0.4F);
2016-12-24 18:39:38 +01:00
this.tasks.addTask(0, new EntityAISwimming(this));
2018-12-07 05:33:43 +01:00
this.tasks.addTask(1, new EntityAIWander(this, 2D));
2016-12-17 16:28:16 +01:00
this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
this.tasks.addTask(6, new AerbunnyAIHop(this));
}
2018-12-07 06:32:48 +01:00
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
2018-12-07 05:33:43 +01:00
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(5.0D);
2016-12-17 16:28:16 +01:00
this.setHealth(5.0F);
2018-12-07 06:32:48 +01:00
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
@Override
public boolean isInRangeToRenderDist(double par1) {
2016-12-17 16:28:16 +01:00
return true;
}
2018-12-07 06:32:48 +01:00
@Override
public double getYOffset() {
2016-12-17 16:28:16 +01:00
return 0.4D;
}
2021-01-04 17:29:40 +01:00
@Override
public boolean getCanSpawnHere() {
return this.rand.nextInt(AetherConfig.getAerbunnySpawnrate()) == 0 && super.getCanSpawnHere();
}
2018-12-07 06:32:48 +01:00
@Override
protected void jump() {
2016-12-17 16:28:16 +01:00
this.spawnExplosionParticle();
this.setPuffiness(11);
--this.jumps;
super.jump();
}
2018-12-07 06:32:48 +01:00
@Override
public void spawnExplosionParticle() {
for (int i = 0; i < 5; ++i) {
2018-12-07 05:33:43 +01:00
double d0 = this.rand.nextGaussian() * 0.02D;
double d1 = this.rand.nextGaussian() * 0.02D;
double d2 = this.rand.nextGaussian() * 0.02D;
double d3 = 10.0D;
2018-12-07 06:32:48 +01:00
this.worldObj.spawnParticle("explode", this.posX + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width - d0 * d3, this.posY + (double) (this.rand.nextFloat() * this.height) - d1 * d3, this.posZ + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width - d2 * d3, d0, d1, d2);
2016-12-17 16:28:16 +01:00
}
}
2018-12-07 06:32:48 +01:00
public int getPuffinessClient() {
return this.puffiness;
2016-12-17 16:28:16 +01:00
}
2018-12-07 06:32:48 +01:00
public int getPuffiness() {
2018-12-07 05:33:43 +01:00
return this.puff;
2017-03-05 05:09:31 +01:00
}
2018-12-07 06:32:48 +01:00
public void setPuffinessClient(int i) {
this.puffiness = i;
2016-12-17 16:28:16 +01:00
}
2018-12-07 06:32:48 +01:00
public void setPuffiness(int i) {
this.puff = i;
2016-12-17 16:28:16 +01:00
}
2018-12-07 06:32:48 +01:00
public void onUpdate() {
this.setPuffinessClient(this.getPuffinessClient() - 1);
2016-12-17 16:28:16 +01:00
this.setPuffiness(this.getPuffiness() - 1);
2018-12-07 06:32:48 +01:00
if (this.getPuffinessClient() < 0) {
this.setPuffinessClient(0);
2017-03-05 05:09:31 +01:00
}
2018-12-07 06:32:48 +01:00
if (this.getPuffiness() < 0) {
2016-12-17 16:28:16 +01:00
this.setPuffiness(0);
}
super.onUpdate();
}
2018-12-07 06:32:48 +01:00
public void onLivingUpdate() {
if (this.onGround) {
2016-12-17 16:28:16 +01:00
this.jumps = 1;
this.jumpTicks = 10;
2018-12-07 06:32:48 +01:00
} else if (this.jumpTicks > 0) {
2016-12-17 16:28:16 +01:00
--this.jumpTicks;
}
2018-12-07 06:32:48 +01:00
if (this.onGround) {
this.jump();
2018-12-07 05:33:43 +01:00
}
2018-12-07 06:32:48 +01:00
if (this.isJumping && !this.isInWater() && !this.handleLavaMovement() && !this.onGround && this.jumpTicks == 0 && this.jumps > 0) {
if (this.moveForward != 0.0F) {
2018-12-07 05:33:43 +01:00
//this.jump();
2018-12-07 06:32:48 +01:00
}
2018-12-07 05:33:43 +01:00
2016-12-17 16:28:16 +01:00
this.jumpTicks = 10;
}
2018-12-07 06:32:48 +01:00
if (this.motionY < -0.1D) {
2016-12-17 16:28:16 +01:00
this.motionY = -0.1D;
}
2018-12-07 06:32:48 +01:00
if (this.ridingEntity != null && this.ridingEntity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) this.ridingEntity;
if (this.worldObj.isRemote) {
for (int k = 0; k < 3; k++) {
double d2 = (float) this.posX + this.rand.nextFloat() * 0.25F;
double d5 = (float) this.posY + this.height + 0.125F;
double d8 = (float) this.posZ + this.rand.nextFloat() * 0.25F;
2018-12-07 05:33:43 +01:00
float f1 = this.rand.nextFloat() * 360F;
this.worldObj.spawnParticle("smoke", -Math.sin(0.01745329F * f1) * 0.75D, d5 - 0.25D, Math.cos(0.01745329F * f1) * 0.75D, d2, 0.125D, d8);
2016-12-17 16:28:16 +01:00
}
}
this.getNavigator().clearPathEntity();
2017-03-05 05:09:31 +01:00
this.setRotation(player.rotationYaw, player.rotationPitch);
2016-12-17 16:28:16 +01:00
2017-03-05 05:09:31 +01:00
player.fallDistance = 0.0F;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
if (!player.onGround) {
if (!player.capabilities.isFlying) {
player.motionY += 0.05000000074505806D;
}
player.fallDistance = 0.0F;
if (player.motionY < -0.22499999403953552D) {
if (PlayerAether.get((EntityPlayer) this.ridingEntity).isJumping()) {
this.setPuffinessClient(11);
this.spawnExplosionParticle();
player.motionY = 0.125D;
}
}
2016-12-17 16:28:16 +01:00
}
}
super.onLivingUpdate();
}
@Override
2018-12-07 06:32:48 +01:00
public void fall(float distance) {
}
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 06:32:48 +01:00
public boolean isEntityInsideOpaqueBlock() {
2016-12-17 16:28:16 +01:00
return false;
}
@Override
2018-12-07 06:32:48 +01:00
public boolean isOnLadder() {
2016-12-17 16:28:16 +01:00
return false;
}
2018-12-07 05:33:43 +01:00
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 06:32:48 +01:00
public boolean interact(EntityPlayer entityplayer) {
2018-12-07 05:33:43 +01:00
ItemStack itemstack = entityplayer.inventory.getCurrentItem();
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
if (itemstack != null && (itemstack.getItem() == Items.name_tag)) {
2018-12-07 05:33:43 +01:00
return super.interact(entityplayer);
2018-12-07 06:32:48 +01:00
} else {
this.worldObj.playSound(this.posX, this.posY, this.posZ, "aether_legacy:aemob.aerbunny.lift", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F, false);
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
if (this.isRiding()) {
this.mountEntity(null);
} else {
this.mountEntity(entityplayer);
2016-12-17 16:28:16 +01:00
}
return true;
}
}
@Override
2018-12-07 06:32:48 +01:00
protected void dropFewItems(boolean recentlyHit, int var2) {
2018-12-07 05:33:43 +01:00
this.dropItem(Items.string, 1);
2016-12-17 16:28:16 +01:00
}
@Override
2018-12-07 06:32:48 +01:00
public boolean attackEntityFrom(DamageSource source, float damage) {
2018-12-07 05:33:43 +01:00
return source.getEntity() == this.ridingEntity ? false : super.attackEntityFrom(source, damage);
2016-12-17 16:28:16 +01:00
}
@Override
2018-12-07 06:32:48 +01:00
protected boolean canTriggerWalking() {
2016-12-17 16:28:16 +01:00
return this.onGround;
}
@Override
2018-12-07 06:32:48 +01:00
protected String getHurtSound() {
2018-12-07 05:33:43 +01:00
return "aether_legacy:aemob.aerbunny.hurt";
2016-12-17 16:28:16 +01:00
}
@Override
2018-12-07 06:32:48 +01:00
protected String getDeathSound() {
2018-12-07 05:33:43 +01:00
return "aether_legacy:aemob.aerbunny.death";
2016-12-17 16:28:16 +01:00
}
@Override
2018-12-07 06:32:48 +01:00
public EntityAgeable createChild(EntityAgeable entityageable) {
2016-12-17 16:28:16 +01:00
return new EntityAerbunny(this.worldObj);
}
2018-12-07 06:32:48 +01:00
@Override
public void writeSpawnData(ByteBuf buffer) {
buffer.writeInt(this.getPuffiness());
}
@Override
public void readSpawnData(ByteBuf buffer) {
this.setPuffiness(buffer.readInt());
}
2018-12-07 05:33:43 +01:00
2016-12-17 16:28:16 +01:00
}