Files
CustomNPC-Plus/src/main/java/noppes/npcs/ai/EntityAIBustDoor.java
T

72 lines
2.7 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.ai;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIDoorInteract;
import net.minecraft.init.Blocks;
2025-03-13 17:14:45 -04:00
public class EntityAIBustDoor extends EntityAIDoorInteract {
2018-09-13 12:03:28 -04:00
private int breakingTime;
private int field_75358_j = -1;
2025-03-13 17:14:45 -04:00
public EntityAIBustDoor(EntityLiving par1EntityLiving) {
2018-09-13 12:03:28 -04:00
super(par1EntityLiving);
}
/**
* Returns whether the EntityAIBase should begin execution.
*/
2025-03-13 17:14:45 -04:00
public boolean shouldExecute() {
2018-09-13 12:03:28 -04:00
return !super.shouldExecute() ? false : (!this.theEntity.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing") ? false : !this.field_151504_e.func_150015_f(this.theEntity.worldObj, this.entityPosX, this.entityPosY, this.entityPosZ));
}
/**
* Execute a one shot task or start executing a continuous task
*/
2025-03-13 17:14:45 -04:00
public void startExecuting() {
2018-09-13 12:03:28 -04:00
super.startExecuting();
this.breakingTime = 0;
}
/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
2025-03-13 17:14:45 -04:00
public boolean continueExecuting() {
double var1 = this.theEntity.getDistanceSq((double) this.entityPosX, (double) this.entityPosY, (double) this.entityPosZ);
2018-09-13 12:03:28 -04:00
return this.breakingTime <= 240 && !this.field_151504_e.func_150015_f(this.theEntity.worldObj, this.entityPosX, this.entityPosY, this.entityPosZ) && var1 < 4.0D;
}
/**
* Resets the task
*/
2025-03-13 17:14:45 -04:00
public void resetTask() {
2018-09-13 12:03:28 -04:00
super.resetTask();
this.theEntity.worldObj.destroyBlockInWorldPartially(this.theEntity.getEntityId(), this.entityPosX, this.entityPosY, this.entityPosZ, -1);
}
/**
* Updates the task
*/
2025-03-13 17:14:45 -04:00
public void updateTask() {
2018-09-13 12:03:28 -04:00
super.updateTask();
2025-03-13 17:14:45 -04:00
if (this.theEntity.getRNG().nextInt(20) == 0) {
2018-09-13 12:03:28 -04:00
this.theEntity.worldObj.playAuxSFX(1010, this.entityPosX, this.entityPosY, this.entityPosZ, 0);
this.theEntity.swingItem();
}
++this.breakingTime;
2025-03-13 17:14:45 -04:00
int var1 = (int) ((float) this.breakingTime / 240.0F * 10.0F);
2018-09-13 12:03:28 -04:00
2025-03-13 17:14:45 -04:00
if (var1 != this.field_75358_j) {
2018-09-13 12:03:28 -04:00
this.theEntity.worldObj.destroyBlockInWorldPartially(this.theEntity.getEntityId(), this.entityPosX, this.entityPosY, this.entityPosZ, var1);
this.field_75358_j = var1;
}
2025-03-13 17:14:45 -04:00
if (this.breakingTime == 240) {
2018-09-13 12:03:28 -04:00
this.theEntity.worldObj.setBlock(this.entityPosX, this.entityPosY, this.entityPosZ, Blocks.air);
this.theEntity.worldObj.playAuxSFX(1012, this.entityPosX, this.entityPosY, this.entityPosZ, 0);
this.theEntity.worldObj.playAuxSFX(2001, this.entityPosX, this.entityPosY, this.entityPosZ, Block.getIdFromBlock(this.field_151504_e));
}
}
}