package me.bebeli555.cookieclient.mods.world;
import java.util.Iterator;
import me.bebeli555.cookieclient.Mod;
import me.bebeli555.cookieclient.gui.Group;
import me.bebeli555.cookieclient.gui.Mode;
import me.bebeli555.cookieclient.gui.Setting;
import me.bebeli555.cookieclient.utils.BlockUtil;
import me.bebeli555.cookieclient.utils.CrystalUtil;
import me.bebeli555.cookieclient.utils.InventoryUtil;
import me.bebeli555.cookieclient.utils.RotationUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
public class CrystalBlock extends Mod {
public static Setting range;
public CrystalBlock() {
super(Group.WORLD, "CrystalBlock", new String[]{"Places obsidian to the best spot between", "You and the end crystal to block damage"});
}
public void onEnabled() {
if (!InventoryUtil.hasBlock(Blocks.field_150343_Z)) {
this.sendMessage("You need obsidian", true);
this.disable();
} else {
EntityEnderCrystal best = null;
double mostDamage = -2.147483648E9;
Iterator var4 = CrystalUtil.getCrystals(10.0).iterator();
while(var4.hasNext()) {
EntityEnderCrystal crystal = (EntityEnderCrystal)var4.next();
double damage = (double)CrystalUtil.calculateDamage(crystal.func_174791_d(), mc.field_71439_g);
if (damage > 0.0 && damage > mostDamage) {
mostDamage = damage;
best = crystal;
}
}
if (best == null) {
this.sendMessage("Found no nearby crystals to block", true);
this.disable();
} else {
BlockPos bestPlace = null;
double lowestDamage = 2.147483647E9;
Iterator var7 = BlockUtil.getAll(range.intValue()).iterator();
while(var7.hasNext()) {
BlockPos pos = (BlockPos)var7.next();
if (BlockUtil.canPlaceBlock(pos)) {
IBlockState old = mc.field_71441_e.func_180495_p(pos);
mc.field_71441_e.func_175656_a(pos, Blocks.field_150343_Z.func_176223_P());
double damage = (double)CrystalUtil.calculateDamage(best.func_174791_d(), mc.field_71439_g);
mc.field_71441_e.func_175656_a(pos, old);
if (damage < lowestDamage) {
lowestDamage = damage;
bestPlace = pos;
}
}
}
if (bestPlace == null) {
this.sendMessage("Found no spot to place block on to block dmg", true);
this.disable();
} else {
BlockUtil.placeBlockOnThisThread(Blocks.field_150343_Z, bestPlace, true);
this.disable();
}
}
}
}
public void onDisabled() {
RotationUtil.stopRotating();
}
static {
range = new Setting(Mode.INTEGER, "Range", 4, new String[]{"Range around player to search for", "Spots to place the obby on"});
}
}