use of me.earth.earthhack.impl.util.helpers.blocks.ObbyModule.HELPER in project 3arthh4ck by 3arthqu4ke.
the class ListenerMotion method doObby.
private void doObby(MotionUpdateEvent event, Vec3i[] offsets) {
if (event.getStage() == Stage.PRE) {
// TODO: this looks very similar to AutoTrap,
// maybe its possible to abstract this even further?
module.rotations = null;
module.blocksPlaced = 0;
for (BlockPos confirmed : module.confirmed) {
module.placed.remove(confirmed);
}
module.placed.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() >= module.confirm.getValue());
BlockPos playerPos = PositionUtil.getPosition();
BlockPos[] positions = new BlockPos[offsets.length];
for (int i = 0; i < offsets.length; i++) {
Vec3i offset = offsets[i];
if (module.mode.getValue() == AntiTrapMode.Fill) {
if (mc.world.getBlockState(playerPos.add(offset.getX() / 2, 0, offset.getZ() / 2)).getBlock() == Blocks.BEDROCK) {
continue;
}
}
positions[i] = playerPos.add(offset);
}
if (module.offhand.getValue()) {
if (!InventoryUtil.isHolding(Blocks.OBSIDIAN)) {
module.previous = OFFHAND.returnIfPresent(Offhand::getMode, null);
OFFHAND.computeIfPresent(o -> o.setMode(OffhandMode.CRYSTAL));
return;
}
} else {
module.slot = InventoryUtil.findHotbarBlock(Blocks.OBSIDIAN);
if (module.slot == -1) {
ModuleUtil.disable(module, TextColor.RED + "No Obsidian found.");
return;
}
}
boolean done = true;
List<BlockPos> toPlace = new LinkedList<>();
for (BlockPos pos : positions) {
if (pos == null) {
continue;
}
if (module.mode.getValue() == AntiTrapMode.Fill && !module.highFill.getValue() && pos.getY() > playerPos.getY()) {
continue;
}
if (mc.world.getBlockState(pos).getMaterial().isReplaceable()) {
toPlace.add(pos);
done = false;
}
}
if (done) {
module.disable();
return;
}
boolean hasPlaced = false;
Optional<BlockPos> crystalPos = toPlace.stream().filter(pos -> !mc.world.getEntitiesWithinAABB(EntityEnderCrystal.class, new AxisAlignedBB(pos)).isEmpty() && mc.world.getBlockState(pos).getMaterial().isReplaceable()).findFirst();
if (crystalPos.isPresent()) {
BlockPos pos = crystalPos.get();
hasPlaced = module.placeBlock(pos);
}
// Only after here we need to use the Helper to get the BlockStates.
if (!hasPlaced) {
for (BlockPos pos : toPlace) {
if (!module.placed.containsKey(pos) && HELPER.getBlockState(pos).getMaterial().isReplaceable()) {
module.confirmed.remove(pos);
if (module.placeBlock(pos)) {
break;
}
}
}
}
if (module.rotate.getValue() != Rotate.None) {
if (module.rotations != null) {
event.setYaw(module.rotations[0]);
event.setPitch(module.rotations[1]);
}
} else {
Locks.acquire(Locks.PLACE_SWITCH_LOCK, module::execute);
}
} else {
Locks.acquire(Locks.PLACE_SWITCH_LOCK, module::execute);
}
}
Aggregations