add Surround module
Alongside the InteractionUtil air-place fix it consumes: mc.hitResult may be an EntityHitResult and cannot be cast blindly.
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
package cc.fros.features.modules.combat;
|
||||
|
||||
import cc.fros.Fros;
|
||||
import cc.fros.event.impl.entity.DeathEvent;
|
||||
import cc.fros.event.impl.entity.player.TickEvent;
|
||||
import cc.fros.event.impl.render.Render3DEvent;
|
||||
import cc.fros.event.system.Subscribe;
|
||||
import cc.fros.features.modules.Module;
|
||||
import cc.fros.features.settings.Setting;
|
||||
import cc.fros.util.InteractionUtil;
|
||||
import cc.fros.util.inventory.InventoryUtil;
|
||||
import cc.fros.util.inventory.Result;
|
||||
import cc.fros.util.models.Angles;
|
||||
import cc.fros.util.render.RenderUtil;
|
||||
import cc.fros.util.world.CrystalUtil;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Surround -- places blast resistant blocks around your feet.
|
||||
* Ported from meteor-client's {@code Surround}.
|
||||
*/
|
||||
public class SurroundModule extends Module {
|
||||
private static final Direction[] SIDES = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST};
|
||||
|
||||
// ---- General ----
|
||||
private final Setting<BlockMode> blockMode = mode("Block", BlockMode.Auto);
|
||||
private final Setting<Integer> delay = num("Delay", 0, 0, 20);
|
||||
private final Setting<Integer> blocksPerTick = num("BlocksPerTick", 1, 1, 4);
|
||||
private final Setting<Center> center = mode("Center", Center.Incomplete);
|
||||
private final Setting<Boolean> doubleHeight = bool("DoubleHeight", false);
|
||||
private final Setting<Boolean> onlyOnGround = bool("OnlyOnGround", true);
|
||||
private final Setting<Boolean> airPlace = bool("AirPlace", true);
|
||||
private final Setting<Boolean> rotate = bool("Rotate", true);
|
||||
private final Setting<Boolean> protect = bool("Protect", true);
|
||||
|
||||
// ---- Toggles ----
|
||||
private final Setting<Boolean> toggleOnYChange = bool("ToggleOnYChange", true);
|
||||
private final Setting<Boolean> toggleOnComplete = bool("ToggleOnComplete", false);
|
||||
private final Setting<Boolean> toggleOnDeath = bool("ToggleOnDeath", true);
|
||||
|
||||
// ---- Render ----
|
||||
private final Setting<Boolean> render = bool("Render", true);
|
||||
private final Setting<Boolean> renderBelow = bool("RenderBelow", false);
|
||||
private final Setting<Color> fillColor = color("FillColor", 0, 0, 0, 100);
|
||||
private final Setting<Color> lineColor = color("OutlineColor", 255, 255, 255, 255);
|
||||
|
||||
private int timer;
|
||||
|
||||
public SurroundModule() {
|
||||
super("Surround", "Surrounds you with blocks to prevent crystal damage.", Category.COMBAT);
|
||||
renderBelow.setVisibility(v -> render.getValue());
|
||||
fillColor.setVisibility(v -> render.getValue());
|
||||
lineColor.setVisibility(v -> render.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Place immediately on activation, the delay only kicks in afterwards
|
||||
timer = delay.getValue();
|
||||
if (!nullCheck() && center.getValue() == Center.OnActivate) centerPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Placing
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
@Subscribe
|
||||
public void onPreTick(TickEvent.Pre event) {
|
||||
if (nullCheck() || !mc.player.isAlive()) return;
|
||||
|
||||
if (timer++ < delay.getValue()) return;
|
||||
|
||||
// Toggle off when our y level changes (step, jumping, levitating, ...)
|
||||
if (toggleOnYChange.getValue() && mc.player.yo != mc.player.getY()) {
|
||||
disable();
|
||||
return;
|
||||
}
|
||||
|
||||
if (onlyOnGround.getValue() && !mc.player.onGround()) return;
|
||||
|
||||
Result block = findBlock();
|
||||
if (!block.found()) return;
|
||||
|
||||
List<BlockPos> feet = feet(mc.player.blockPosition());
|
||||
boolean feetComplete = isComplete(feet);
|
||||
boolean complete = feetComplete && isComplete(head(feet));
|
||||
|
||||
if (center.getValue() == Center.Always || (center.getValue() == Center.Incomplete && !complete)) {
|
||||
centerPlayer();
|
||||
feet = feet(mc.player.blockPosition());
|
||||
feetComplete = isComplete(feet);
|
||||
complete = feetComplete && isComplete(head(feet));
|
||||
}
|
||||
|
||||
List<BlockPos> toPlace = placePositions(feet, feetComplete);
|
||||
if (toPlace.isEmpty()) {
|
||||
timer = 0;
|
||||
if (complete && toggleOnComplete.getValue()) disable();
|
||||
return;
|
||||
}
|
||||
|
||||
timer = 0;
|
||||
|
||||
List<BlockPos> batch = toPlace.subList(0, Math.min(blocksPerTick.getValue(), toPlace.size()));
|
||||
Runnable action = () -> InventoryUtil.withSwap(block, () -> {
|
||||
for (BlockPos pos : batch) place(pos, block.hand());
|
||||
});
|
||||
|
||||
if (rotate.getValue()) Fros.rotationManager.motion(aim(batch.get(0)), 0, action);
|
||||
else action.run();
|
||||
}
|
||||
|
||||
/** The four blocks at foot level, in placement order. */
|
||||
private List<BlockPos> feet(BlockPos playerPos) {
|
||||
List<BlockPos> list = new ArrayList<>(SIDES.length);
|
||||
for (Direction side : SIDES) list.add(playerPos.relative(side));
|
||||
return list;
|
||||
}
|
||||
|
||||
/** The layer above the feet ring, only filled once the feet ring is done. */
|
||||
private List<BlockPos> head(List<BlockPos> feet) {
|
||||
List<BlockPos> list = new ArrayList<>(feet.size());
|
||||
if (!doubleHeight.getValue()) return list;
|
||||
for (BlockPos pos : feet) list.add(pos.above());
|
||||
return list;
|
||||
}
|
||||
|
||||
private boolean isComplete(List<BlockPos> targets) {
|
||||
for (BlockPos pos : targets) {
|
||||
if (mc.level.getBlockState(pos).canBeReplaced()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Blocks that are still empty and can be attempted this tick. */
|
||||
private List<BlockPos> placePositions(List<BlockPos> feet, boolean feetComplete) {
|
||||
List<BlockPos> list = new ArrayList<>();
|
||||
for (BlockPos pos : feet) {
|
||||
if (mc.level.getBlockState(pos).canBeReplaced()) {
|
||||
// No neighbour to click against, drop a support block below first
|
||||
if (!airPlace.getValue() && isAirPlace(pos)) list.add(pos.below());
|
||||
list.add(pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (doubleHeight.getValue() && feetComplete) {
|
||||
for (BlockPos pos : feet) {
|
||||
if (mc.level.getBlockState(pos.above()).canBeReplaced()) list.add(pos.above());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void place(BlockPos pos, InteractionHand hand) {
|
||||
boolean placed = InteractionUtil.place(pos, airPlace.getValue(), hand);
|
||||
|
||||
// A crystal blew the spot out, clear it out before trying again
|
||||
if (protect.getValue() && !placed && mc.level.getBlockState(pos).canBeReplaced()) {
|
||||
breakCrystals(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private void breakCrystals(BlockPos pos) {
|
||||
float totalHealth = mc.player.getHealth() + mc.player.getAbsorptionAmount();
|
||||
AABB box = new AABB(
|
||||
pos.getX() - 1, pos.getY() - 1, pos.getZ() - 1,
|
||||
pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1
|
||||
);
|
||||
|
||||
for (EndCrystal crystal : mc.level.getEntitiesOfClass(EndCrystal.class, box)) {
|
||||
if (!crystal.isAlive()) continue;
|
||||
if (CrystalUtil.calculateDamage(mc.player, crystal.position(), false) >= totalHealth) continue;
|
||||
|
||||
mc.gameMode.attack(mc.player, crystal);
|
||||
mc.player.swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
|
||||
/** Where to look so {@link InteractionUtil#place} clicks the right face. */
|
||||
private Angles aim(BlockPos pos) {
|
||||
Direction side = InteractionUtil.calcSide(pos);
|
||||
if (side == null) return Angles.pos(Vec3.atCenterOf(pos));
|
||||
return Angles.pos(Vec3.atCenterOf(pos.relative(side)).relative(side.getOpposite(), 0.5));
|
||||
}
|
||||
|
||||
private boolean isAirPlace(BlockPos pos) {
|
||||
for (Direction direction : Direction.values()) {
|
||||
if (!mc.level.getBlockState(pos.relative(direction)).canBeReplaced()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void centerPlayer() {
|
||||
mc.player.setPos(Math.floor(mc.player.getX()) + 0.5, mc.player.getY(), Math.floor(mc.player.getZ()) + 0.5);
|
||||
}
|
||||
|
||||
private Result findBlock() {
|
||||
return switch (blockMode.getValue()) {
|
||||
case Obsidian -> InventoryUtil.find(Items.OBSIDIAN, InventoryUtil.HOTBAR_SCOPE);
|
||||
case CryingObsidian -> InventoryUtil.find(Items.CRYING_OBSIDIAN, InventoryUtil.HOTBAR_SCOPE);
|
||||
case Netherite -> InventoryUtil.find(Items.NETHERITE_BLOCK, InventoryUtil.HOTBAR_SCOPE);
|
||||
case Auto -> {
|
||||
Result result = InventoryUtil.find(Items.OBSIDIAN, InventoryUtil.HOTBAR_SCOPE);
|
||||
if (!result.found()) result = InventoryUtil.find(Items.CRYING_OBSIDIAN, InventoryUtil.HOTBAR_SCOPE);
|
||||
if (!result.found()) result = InventoryUtil.find(Items.NETHERITE_BLOCK, InventoryUtil.HOTBAR_SCOPE);
|
||||
yield result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Toggles / rendering
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
@Subscribe
|
||||
public void onDeath(DeathEvent event) {
|
||||
if (!toggleOnDeath.getValue()) return;
|
||||
if (event.getEntity() != mc.player) return;
|
||||
disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRender3D(Render3DEvent event) {
|
||||
if (!render.getValue() || nullCheck()) return;
|
||||
|
||||
BlockPos playerPos = mc.player.blockPosition();
|
||||
for (Direction side : SIDES) {
|
||||
BlockPos pos = playerPos.relative(side);
|
||||
draw(event, pos);
|
||||
if (doubleHeight.getValue()) draw(event, pos.above());
|
||||
}
|
||||
|
||||
if (renderBelow.getValue()) draw(event, playerPos.below());
|
||||
}
|
||||
|
||||
private void draw(Render3DEvent event, BlockPos pos) {
|
||||
AABB box = new AABB(pos);
|
||||
RenderUtil.drawBoxFilled(event.getMatrix(), box, fillColor.getValue());
|
||||
RenderUtil.drawBox(event.getMatrix(), box, lineColor.getValue(), 1.5f);
|
||||
}
|
||||
|
||||
public enum BlockMode {
|
||||
Obsidian, CryingObsidian, Netherite, Auto
|
||||
}
|
||||
|
||||
public enum Center {
|
||||
Never, OnActivate, Incomplete, Always
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import cc.fros.features.modules.combat.KillAuraModule;
|
||||
import cc.fros.features.modules.combat.CrystalAuraModule;
|
||||
import cc.fros.features.modules.combat.CriticalsModule;
|
||||
import cc.fros.features.modules.combat.KeyPearlModule;
|
||||
import cc.fros.features.modules.combat.SurroundModule;
|
||||
import cc.fros.features.modules.hud.ArrayListHudModule;
|
||||
import cc.fros.features.modules.hud.ArmorHudModule;
|
||||
import cc.fros.features.modules.hud.ServerHudModule;
|
||||
@@ -83,6 +84,7 @@ public class ModuleManager implements Jsonable, Util {
|
||||
register(new KeyPearlModule());
|
||||
register(new KillAuraModule());
|
||||
register(new CrystalAuraModule());
|
||||
register(new SurroundModule());
|
||||
register(new FastAccelModule());
|
||||
|
||||
LOGGER.info("Registered {} modules", modules.size());
|
||||
|
||||
@@ -77,7 +77,11 @@ public class InteractionUtil implements Util {
|
||||
Direction direction = calcSide(pos);
|
||||
if (direction == null) {
|
||||
if (airPlace)
|
||||
direction = mc.hitResult != null ? ((BlockHitResult) mc.hitResult).getDirection() : Direction.DOWN;
|
||||
// mc.hitResult is an EntityHitResult whenever an entity is under the
|
||||
// crosshair, so it cannot be cast blindly here
|
||||
direction = mc.hitResult instanceof BlockHitResult blockHit
|
||||
? blockHit.getDirection()
|
||||
: Direction.DOWN;
|
||||
else return false;
|
||||
}
|
||||
BlockPos bp = airPlace ? pos : pos.relative(direction);
|
||||
|
||||
Reference in New Issue
Block a user