Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wwy.mod.te.techno;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityCreature;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.potion.PotionEffect;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.world.World;
- import com.wwy.mod.blocks.techno.BlockTechnoReplenisher;
- import com.wwy.mod.util.Timer;
- public class TETechnoReplenisher extends TETechnoMachine {
- int datum;
- int cooldown = 2*40;
- int maxCooldown;
- int currentCooldown;
- BlockTechnoReplenisher block;
- Timer timer;
- public TETechnoReplenisher(BlockTechnoReplenisher block) {
- this.block = block;
- this.timer = new Timer(80, true, false);
- }
- @Override
- public void updateEntity() {
- this.datum += 100;
- this.markDirty();
- this.timer.tick();
- if (this.datum >= 1000 && this.timer.currentCountdown == 0 && !this.worldObj.isRemote) {
- this.searchAndHeal();
- }
- }
- private void searchAndHeal() {
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Searching for a valid target.");
- World world = this.getWorldObj();
- AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xCoord-5, yCoord-5, zCoord-5, xCoord+5, yCoord+5, zCoord+5);
- // Minecraft.getMinecraft().thePlayer.sendChatMessage("AABB: " + aabb);
- List<Entity> raw = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb);
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Found " + raw.size() + " targets");
- List<Entity> entities = new ArrayList<>();
- List<EntityPlayer> players = new ArrayList<>();
- for (Entity target : raw) {
- if (target instanceof EntityPlayer) {
- // It is first priority
- players.add((EntityPlayer) target);
- } else if (target instanceof EntityCreature) {
- entities.add(target);
- }
- }
- if (!players.isEmpty()) {
- float lowestHealth = 100;
- EntityPlayer priority = null;
- for (EntityPlayer player : players) {
- if (player.getHealth() < lowestHealth) {
- lowestHealth = player.getHealth();
- Minecraft.getMinecraft().thePlayer.sendChatMessage("The health is: " + player.getHealth());
- priority = player;
- };
- }
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Target is: " + priority);
- if (!world.isRemote) {
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Healing target for 20.");
- priority.heal(20);
- // priority.setHealth(priority.getHealth() + 5);
- // priority.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40);
- // priority.addPotionEffect(new PotionEffect(6, 100, 2));
- }
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Healing complete. Resultant health: " + priority.getHealth());
- timer.reset();
- this.datum -= 1000;
- return;
- }
- if (!entities.isEmpty()) {
- Random random = new Random();
- EntityLivingBase target = (EntityLivingBase) entities.get(random.nextInt(entities.size()));
- target.heal(3);
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Target is: " + target);
- return;
- }
- }
- public void printInfo() {
- // TODO Auto-generated method stub
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Current datum: " + this.datum);
- }
- @Override
- public void readFromNBT(NBTTagCompound tag) {
- this.datum = tag.getInteger("Datum");
- }
- @Override
- public void writeToNBT(NBTTagCompound tag) {
- tag.setInteger("Datum", this.datum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment