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.monster.EntityMob;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.ChatComponentText;
- import net.minecraft.world.World;
- import com.wwy.mod.blocks.techno.BlockTechnoReplenisher;
- import com.wwy.mod.util.Timer;
- public class TETechnoReplenisher extends TileEntity {
- 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 += 5;
- this.markDirty();
- this.timer.tick();
- if (this.datum >= 1000 && timer.currentCountdown == 0 && !this.worldObj.isRemote) {
- this.searchAndHeal();
- }
- }
- private void searchAndHeal() {
- World world = this.getWorldObj();
- AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xCoord-5, yCoord-5, zCoord-5, xCoord+5, yCoord+5, zCoord+5);
- List<Entity> raw = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb);
- 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 && !(target instanceof EntityMob)) {
- entities.add(target);
- }
- }
- if (!players.isEmpty()) {
- float lowestHealth = 2000000;
- 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;
- };
- }
- if (!world.isRemote) {
- if (priority != null) {
- priority.heal(4);
- float f = priority.getHealth();
- priority.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(f + 4);
- }
- }
- if (priority != null) {
- List<String> messages = new ArrayList<>();
- messages.add(priority.getDisplayName() + ", a replenisher has found you as the target.");
- messages.add("You are healed for 2 hearts, and you have been boosted for another 2 hearts.");
- for (String text : messages) {
- ChatComponentText message = new ChatComponentText(text);
- priority.addChatComponentMessage(message);
- }
- world.spawnParticle("instantSpell", xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
- }
- timer.reset();
- this.datum -= 1000;
- return;
- }
- if (!entities.isEmpty()) {
- Random random = new Random();
- EntityLivingBase target = (EntityLivingBase) entities.get(random.nextInt(entities.size()));
- target.heal(4);
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Successfully found and healed a Creature.");
- timer.reset();
- this.datum -= 1000;
- return;
- }
- }
- public void printInfo() {
- // TODO Auto-generated method stub
- Minecraft.getMinecraft().thePlayer.sendChatMessage("Current datum: " + this.datum);
- }
- @Override
- public void readFromNBT(NBTTagCompound tag) {
- if (!worldObj.isRemote) {
- System.out.println("Reading from NBT.");
- super.readFromNBT(tag);
- this.datum = tag.getInteger("Datum");
- }
- }
- @Override
- public void writeToNBT(NBTTagCompound tag) {
- if (!worldObj.isRemote) {
- System.out.println("Writing to NBT.");
- super.writeToNBT(tag);
- tag.setInteger("Datum", this.datum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment