Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arctic.betterPets.entities.ai;
- import com.arctic.betterPets.entities.IBetterPet;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.ai.EntityAIMoveToBlock;
- import net.minecraft.entity.passive.EntityTameable;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.util.EnumChatFormatting;
- @SuppressWarnings("StatementWithEmptyBody")
- public abstract class EntityAIGoToBlock extends EntityAIMoveToBlock {
- protected final IBetterPet pet;
- protected final boolean shouldSearch;
- protected boolean hasAnnouncedNeed = false;
- protected State state = State.OFF;
- public EntityAIGoToBlock(IBetterPet pet, double speedIn, int length, boolean shouldSearch) {
- super(pet.getEntity(), speedIn, length);
- this.setMutexBits(3);
- this.pet = pet;
- this.shouldSearch = shouldSearch;
- }
- protected enum State {
- OFF,START,EXECUTING,FINISH,POST,DONE
- }
- protected abstract float getNeed();
- protected abstract float getMaxNeed();
- protected abstract void setNeed(float need);
- protected abstract String getNeedName(boolean past);
- protected abstract EnumChatFormatting getColor();
- protected abstract boolean doesNeedNeedToBeFullFilled();
- protected void sendMessageToOwner(String msg){
- EntityTameable tamable = pet.getEntity();
- EntityLivingBase owner = tamable.getOwner();
- if (owner != null && owner instanceof EntityPlayer){
- ((EntityPlayer) owner).addChatComponentMessage(
- tamable.getDisplayName().appendText(
- " " + getColor() + msg
- )
- );
- }
- }
- @Override
- public boolean shouldExecute() {
- if (state == State.POST) return true;
- state = State.OFF;
- boolean subResult = doesNeedNeedToBeFullFilled();
- if (!subResult) return false;
- int delay = 0;
- if (runDelay > delay) runDelay = delay;
- boolean superResult = super.shouldExecute();
- if (!hasAnnouncedNeed){
- hasAnnouncedNeed = true;
- sendMessageToOwner("has to "+getNeedName(false)+"!");
- }
- if (destinationBlock.up().equals(pet.getEntity().getPosition())) {
- finish(true);
- return false;
- }
- return superResult;
- }
- @Override
- public void startExecuting() {
- //if (state==State.OFF)name = pet.getEntity().getName();
- if (state==State.OFF)sendMessageToOwner(destinationBlock.toString());
- if (shouldSearch) {
- super.startExecuting();
- if (state==State.OFF) {
- sendMessageToOwner("is looking to " + getNeedName(false) + "!");
- state = State.START;
- }
- } else {
- state = State.FINISH;
- }
- }
- @Override
- public boolean continueExecuting() {
- if (!doesNeedNeedToBeFullFilled()) return false;
- boolean superResult = super.continueExecuting();
- boolean isAtDest = getIsAboveDestination();
- boolean resultA = superResult && !isAtDest;
- /*sendMessageToOwner("super: " + superResult +
- ", dest: " + isAtDest +
- ", resultA: " + resultA +
- ", resultB: " + resultB +
- ", result: " + result
- );*/
- if ((!superResult||isAtDest)) {
- if (state == State.EXECUTING) state = State.FINISH;
- }
- switch (state){
- default: case OFF: break;
- case FINISH: finish(isAtDest); return true;
- case START: state = State.EXECUTING; break;
- case DONE:
- state = State.OFF;
- return false;
- case POST: return true;
- }
- return resultA;
- }
- @Override
- public void updateTask() {
- if (state == State.POST){
- executeExtra();
- //return;
- }
- super.updateTask();
- }
- protected abstract void finish(boolean atDest);
- protected abstract void executeExtra();
- }
Advertisement
Add Comment
Please, Sign In to add comment