Guest User

Untitled

a guest
Jun 14th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.64 KB | None | 0 0
  1. package com.wwy.mod.te.techno;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.EntityCreature;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.SharedMonsterAttributes;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.potion.PotionEffect;
  15. import net.minecraft.tileentity.TileEntity;
  16. import net.minecraft.util.AxisAlignedBB;
  17. import net.minecraft.world.World;
  18.  
  19. import com.wwy.mod.blocks.techno.BlockTechnoReplenisher;
  20. import com.wwy.mod.util.Timer;
  21.  
  22. public class TETechnoReplenisher extends TETechnoMachine {
  23.  
  24.     int datum;
  25.     int cooldown = 2*40;
  26.     int maxCooldown;
  27.     int currentCooldown;
  28.     BlockTechnoReplenisher block;
  29.     Timer timer;
  30.    
  31.     public TETechnoReplenisher(BlockTechnoReplenisher block) {
  32.         this.block = block;
  33.         this.timer = new Timer(80, true, false);
  34.     }
  35.    
  36.     @Override
  37.     public void updateEntity() {
  38.         this.datum += 100;
  39.         this.markDirty();
  40.         this.timer.tick();
  41.         if (this.datum >= 1000 && this.timer.currentCountdown == 0 && !this.worldObj.isRemote) {
  42.             this.searchAndHeal();
  43.         }
  44.     }
  45.  
  46.     private void searchAndHeal() {
  47.         Minecraft.getMinecraft().thePlayer.sendChatMessage("Searching for a valid target.");
  48.         World world = this.getWorldObj();
  49.         AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xCoord-5, yCoord-5, zCoord-5, xCoord+5, yCoord+5, zCoord+5);
  50.         // Minecraft.getMinecraft().thePlayer.sendChatMessage("AABB: " + aabb);
  51.         List<Entity> raw = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb);
  52.         Minecraft.getMinecraft().thePlayer.sendChatMessage("Found " + raw.size() + " targets");
  53.         List<Entity> entities = new ArrayList<>();
  54.         List<EntityPlayer> players = new ArrayList<>();
  55.         for (Entity target : raw) {
  56.             if (target instanceof EntityPlayer) {
  57.                 // It is first priority
  58.                 players.add((EntityPlayer) target);
  59.             } else if (target instanceof EntityCreature) {
  60.                 entities.add(target);
  61.             }
  62.         }
  63.        
  64.         if (!players.isEmpty()) {
  65.             float lowestHealth = 100;
  66.             EntityPlayer priority = null;
  67.             for (EntityPlayer player : players) {
  68.                 if (player.getHealth() < lowestHealth) {
  69.                     lowestHealth = player.getHealth();
  70.                     Minecraft.getMinecraft().thePlayer.sendChatMessage("The health is: " + player.getHealth());
  71.                     priority = player;
  72.                 };
  73.             }
  74.             Minecraft.getMinecraft().thePlayer.sendChatMessage("Target is: " + priority);
  75.             if (!world.isRemote) {
  76.                 Minecraft.getMinecraft().thePlayer.sendChatMessage("Healing target for 20.");
  77.                 priority.heal(20);
  78.                 // priority.setHealth(priority.getHealth() + 5);
  79.                 // priority.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40);
  80.                 // priority.addPotionEffect(new PotionEffect(6, 100, 2));
  81.             }
  82.             Minecraft.getMinecraft().thePlayer.sendChatMessage("Healing complete. Resultant health: " + priority.getHealth());
  83.             timer.reset();
  84.             this.datum -= 1000;
  85.             return;
  86.         }
  87.        
  88.         if (!entities.isEmpty()) {
  89.             Random random = new Random();
  90.             EntityLivingBase target = (EntityLivingBase) entities.get(random.nextInt(entities.size()));
  91.             target.heal(3);
  92.             Minecraft.getMinecraft().thePlayer.sendChatMessage("Target is: " + target);
  93.             return;
  94.         }
  95.     }
  96.  
  97.     public void printInfo() {
  98.         // TODO Auto-generated method stub
  99.         Minecraft.getMinecraft().thePlayer.sendChatMessage("Current datum: " + this.datum);
  100.     }
  101.  
  102.     @Override
  103.     public void readFromNBT(NBTTagCompound tag) {
  104.         this.datum = tag.getInteger("Datum");
  105.     }
  106.  
  107.     @Override
  108.     public void writeToNBT(NBTTagCompound tag) {
  109.         tag.setInteger("Datum", this.datum);
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment