aether-legacy/src/main/java/com/gildedgames/the_aether/entities/hostile/EntityAechorPlant.java

225 lines
5.8 KiB
Java
Raw Normal View History

2020-08-14 08:29:22 +02:00
package com.gildedgames.the_aether.entities.hostile;
2016-12-17 16:28:16 +01:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2018-12-07 05:33:43 +01:00
import net.minecraft.util.MathHelper;
import net.minecraft.world.EnumDifficulty;
2016-12-17 16:28:16 +01:00
import net.minecraft.world.World;
2020-08-14 08:29:22 +02:00
import com.gildedgames.the_aether.blocks.BlocksAether;
import com.gildedgames.the_aether.entities.passive.EntityAetherAnimal;
import com.gildedgames.the_aether.entities.projectile.EntityPoisonNeedle;
import com.gildedgames.the_aether.items.ItemsAether;
import com.gildedgames.the_aether.items.util.EnumSkyrootBucketType;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public class EntityAechorPlant extends EntityAetherAnimal {
2016-12-17 16:28:16 +01:00
public float sinage;
2018-12-07 05:33:43 +01:00
public int poisonRemaining;
private int reloadTime;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public EntityAechorPlant(World world) {
2016-12-17 16:28:16 +01:00
super(world);
this.sinage = this.rand.nextFloat() * 6F;
this.poisonRemaining = this.rand.nextInt(4) + 2;
2018-12-07 05:33:43 +01:00
this.setSize(this.rand.nextInt(4) + 1);
2016-12-17 16:28:16 +01:00
this.setPosition(this.posX, this.posY, this.posZ);
2018-12-07 06:32:48 +01:00
this.setSize(0.75F + ((float) this.getSize() * 0.125F), 0.5F + ((float) this.getSize() * 0.075F));
2016-12-17 16:28:16 +01:00
}
@Override
2018-12-07 06:32:48 +01:00
protected void applyEntityAttributes() {
super.applyEntityAttributes();
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
}
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 06:32:48 +01:00
public void entityInit() {
2018-12-07 05:33:43 +01:00
super.entityInit();
this.dataWatcher.addObject(20, new Byte((byte) 0));
}
2016-12-17 16:28:16 +01:00
2017-08-10 22:10:15 +02:00
@Override
2020-12-29 01:47:43 +01:00
public boolean getCanSpawnHere()
{
return this.rand.nextInt(15) == 0 && super.getCanSpawnHere();
2017-08-10 22:10:15 +02:00
}
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 06:32:48 +01:00
public void onLivingUpdate() {
2018-12-07 05:33:43 +01:00
super.onLivingUpdate();
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
if (this.hurtTime > 0) {
2016-12-17 16:28:16 +01:00
this.sinage += 0.9F;
2018-12-07 06:32:48 +01:00
} else {
if (this.getEntityToAttack() != null) {
2016-12-17 16:28:16 +01:00
this.sinage += 0.3F;
2018-12-07 06:32:48 +01:00
} else {
2016-12-17 16:28:16 +01:00
this.sinage += 0.1F;
}
}
2018-12-07 06:32:48 +01:00
if (this.sinage > 3.141593F * 2F) {
2016-12-17 16:28:16 +01:00
this.sinage -= (3.141593F * 2F);
}
2018-12-07 06:32:48 +01:00
if (this.getEntityToAttack() == null) {
2018-12-07 05:33:43 +01:00
EntityPlayer player = this.worldObj.getClosestVulnerablePlayerToEntity(this, 10.0F);
this.setTarget(player);
}
2018-12-07 06:32:48 +01:00
if (!this.isDead && this.getEntityToAttack() != null) {
2018-12-07 05:33:43 +01:00
double distanceToPlayer = this.getEntityToAttack().getDistanceToEntity(this);
2018-12-07 06:32:48 +01:00
double lookDistance = 5.5D + ((double) this.getSize() / 2D);
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
if (this.getEntityToAttack().isDead || distanceToPlayer > lookDistance) {
2018-12-07 05:33:43 +01:00
this.setTarget(null);
this.reloadTime = 0;
}
2018-12-07 06:32:48 +01:00
if (this.reloadTime == 20 && this.canEntityBeSeen(this.getEntityToAttack())) {
2018-12-07 05:33:43 +01:00
this.shootAtPlayer();
this.reloadTime = -10;
}
2018-12-07 06:32:48 +01:00
if (this.reloadTime != 20) {
2018-12-07 05:33:43 +01:00
++this.reloadTime;
}
2016-12-17 16:28:16 +01:00
}
2018-12-07 06:32:48 +01:00
if (this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) - 1, MathHelper.floor_double(this.posZ)) != BlocksAether.aether_grass) {
2016-12-17 16:28:16 +01:00
this.setDead();
}
2018-12-07 05:33:43 +01:00
}
2018-12-07 06:32:48 +01:00
public void shootAtPlayer() {
if (this.worldObj.difficultySetting.equals(EnumDifficulty.PEACEFUL)) {
2018-12-07 05:33:43 +01:00
return;
}
double x = this.getEntityToAttack().posX - this.posX;
double z = this.getEntityToAttack().posZ - this.posZ;
double y = 0.1D + (Math.sqrt((x * x) + (z * z) + 0.1D) * 0.5D) + ((this.posY - this.getEntityToAttack().posY) * 0.25D);
double distance = 1.5D / Math.sqrt((x * x) + (z * z) + 0.1D);
2016-12-17 16:28:16 +01:00
2018-12-07 05:33:43 +01:00
x = x * distance;
z = z * distance;
EntityPoisonNeedle poisonNeedle = new EntityPoisonNeedle(this.worldObj, this, 0.5F);
poisonNeedle.posY = this.posY + 1D;
2018-12-07 06:32:48 +01:00
this.playSound("random.bow", 1.0F, 1.2F / (this.getRNG().nextFloat() * 0.2F + 0.9F));
2018-12-07 05:33:43 +01:00
this.worldObj.spawnEntityInWorld(poisonNeedle);
2018-12-07 06:32:48 +01:00
poisonNeedle.setThrowableHeading(x, y, z, 0.285F + ((float) y * 0.05F), 1.0F);
2016-12-17 16:28:16 +01:00
}
@Override
2018-12-07 06:32:48 +01:00
public void knockBack(Entity entity, float strength, double xRatio, double zRatio) {
if (this.getHealth() >= 0) {
2016-12-17 16:28:16 +01:00
return;
}
super.knockBack(entity, strength, xRatio, zRatio);
}
@Override
2018-12-07 06:32:48 +01:00
public boolean interact(EntityPlayer player) {
2018-12-07 05:33:43 +01:00
ItemStack heldItem = player.getCurrentEquippedItem();
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
if (heldItem != null && !this.worldObj.isRemote) {
if (heldItem.getItem() == ItemsAether.skyroot_bucket && EnumSkyrootBucketType.getType(heldItem.getItemDamage()) == EnumSkyrootBucketType.Empty && this.poisonRemaining > 0) {
if (--heldItem.stackSize == 0) {
player.setCurrentItemOrArmor(0, new ItemStack(ItemsAether.skyroot_bucket, 1, EnumSkyrootBucketType.Poison.meta));
} else if (!player.inventory.addItemStackToInventory(new ItemStack(ItemsAether.skyroot_bucket, 1, EnumSkyrootBucketType.Poison.meta))) {
player.entityDropItem(new ItemStack(ItemsAether.skyroot_bucket, 1, EnumSkyrootBucketType.Poison.meta), 1.0F);
}
--this.poisonRemaining;
2016-12-17 16:28:16 +01:00
}
}
return false;
}
@Override
2018-12-07 06:32:48 +01:00
public void writeEntityToNBT(NBTTagCompound compound) {
super.writeEntityToNBT(compound);
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
compound.setByte("size", this.getSize());
}
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 06:32:48 +01:00
public void readEntityFromNBT(NBTTagCompound compound) {
super.readEntityFromNBT(compound);
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
this.setSize(compound.getByte("size"));
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public void setSize(int size) {
2018-12-07 05:33:43 +01:00
this.dataWatcher.updateObject(20, (byte) size);
}
2018-12-07 06:32:48 +01:00
public byte getSize() {
2018-12-07 05:33:43 +01:00
return this.dataWatcher.getWatchableObjectByte(20);
}
2018-12-07 06:32:48 +01:00
@Override
protected void dropFewItems(boolean var1, int var2) {
this.dropItem(ItemsAether.aechor_petal, 2);
}
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
@Override
public void applyEntityCollision(Entity entity) {
2018-12-07 05:33:43 +01:00
2018-12-07 06:32:48 +01:00
}
2018-12-07 05:33:43 +01:00
2018-12-07 06:32:48 +01:00
@Override
public void addVelocity(double x, double y, double z) {
}
2018-12-07 05:33:43 +01:00
2018-12-07 06:32:48 +01:00
@Override
protected boolean isMovementBlocked() {
return true;
}
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 EntityAgeable createChild(EntityAgeable baby) {
2016-12-17 16:28:16 +01:00
return null;
}
@Override
2018-12-07 06:32:48 +01:00
protected String getHurtSound() {
return "game.player.hurt";
}
2018-12-07 05:33:43 +01:00
@Override
2018-12-07 06:32:48 +01:00
protected String getDeathSound() {
return "game.player.hurt.fall.big";
}
2016-12-17 16:28:16 +01:00
2018-12-07 05:33:43 +01:00
@Override
2018-12-07 06:32:48 +01:00
public boolean canBePushed() {
2018-12-07 05:33:43 +01:00
return false;
}
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 06:32:48 +01:00
protected boolean canDespawn() {
return true;
}
2016-12-17 16:28:16 +01:00
}