Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Improved AC block break reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
pan4ur committed Aug 3, 2024
1 parent 70d5397 commit aac4421
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void hasExtendedReachHook(CallbackInfoReturnable<Boolean> cir) {
}
*/

@Inject(method = "breakBlock", at = @At("HEAD"), cancellable = true)
@Inject(method = "breakBlock", at = @At("RETURN"), cancellable = true)
public void breakBlockHook(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if(Module.fullNullCheck()) return;
EventBreakBlock event = new EventBreakBlock(pos);
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/thunder/hack/modules/combat/AutoCrystal.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.decoration.EndCrystalEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
Expand Down Expand Up @@ -366,14 +367,29 @@ public void onPacketReceive(PacketEvent.Receive e) {
}
}

/*
@EventHandler
public void onBlockDestruct(EventSetBlockState e) {
public void onBlockBreakServer(EventSetBlockState e) {
if (mc.player == null || mc.world == null) return;
if (e.getPrevState() == null || e.getState() == null)
return;
if (target != null && target.squaredDistanceTo(e.getPos().toCenterPos()) <= 4 && e.getState().isAir() && !e.getPrevState().isAir() && blockRecalcTimer.every(200)) {
ThunderHack.asyncManager.run(() -> calcPosition(2f, e.getPos().toCenterPos()));
calcPosition(2f, e.getPos().toCenterPos());
debug("break server");
}
}
*/

@EventHandler
public void onBlockBreakClient(EventBreakBlock e) {
if (mc.player == null || mc.world == null) return;

if (target != null && target.squaredDistanceTo(e.getPos().toCenterPos()) <= 4) {
calcPosition(2f, e.getPos().toCenterPos());
debug("break client");
blockRecalcTimer.reset();
}
}

Expand Down Expand Up @@ -621,13 +637,18 @@ public void attackCrystal(EndCrystalEntity crystal) {
deadManager.setDead(crystal.getId(), System.currentTimeMillis());
rotationTicks = 10;

for (Entity ent : Lists.newArrayList(mc.world.getEntities()))
for (Entity ent : Lists.newArrayList(mc.world.getEntities())) {
if (ent instanceof EndCrystalEntity exCrystal
&& exCrystal.squaredDistanceTo(crystal.getX(), crystal.getY(), crystal.getZ()) <= 144
&& !deadManager.isDead(exCrystal.getId())) {
deadManager.setDead(exCrystal.getId(), System.currentTimeMillis());
}

// if (ent instanceof ItemEntity && ent.squaredDistanceTo(crystal.getX(), crystal.getY(), crystal.getZ()) <= 144) {
// sendMessage("item detected");
// }
}

if (prevSlot != -1) {
if (antiWeakness.getValue() == Switch.SILENT) {
mc.player.getInventory().selectedSlot = prevSlot;
Expand Down Expand Up @@ -1023,6 +1044,9 @@ public boolean checkEntities(@NotNull BlockPos base) {
if (ent instanceof ExperienceOrbEntity)
continue;

if (ent instanceof ItemEntity && ent.age < 3)
continue;

if (ent instanceof EndCrystalEntity cr && canAttackCrystal(cr))
continue;
return true;
Expand All @@ -1044,6 +1068,9 @@ private boolean checkOtherEntities(Box posBoundingBox) {

if (ent instanceof EndCrystalEntity cr && deadManager.isDead(cr.getId()))
continue;

if (ent instanceof ItemEntity && ent.age < 3)
continue;
/*
if (breakTimer.passedTicks(facePlacing ? lowBreakDelay.getValue() : breakDelay.getValue()) && ent instanceof EndCrystalEntity cr
&& canAttackCrystal(cr, true)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/thunder/hack/modules/combat/Breaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private void onSync(EventSync event) {
return;

if (blockPos != null) {
if (mc.player.squaredDistanceTo(blockPos.toCenterPos()) > (ModuleManager.speedMine.isEnabled() ? ModuleManager.speedMine.range.getPow2Value() : ModuleManager.reach.isEnabled() ? ModuleManager.reach.blocksRange.getPow2Value() : 9)) {
blockPos = null;
return;
}

if (ModuleManager.speedMine.isEnabled()) {
if (SpeedMine.minePosition == blockPos || (SpeedMine.minePosition != null && !mc.world.isAir(SpeedMine.minePosition)))
return;
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/thunder/hack/modules/player/SpeedMine.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class SpeedMine extends Module {
private final Setting<Float> factor = new Setting<>("Factor", 1f, 0.5f, 2f, v -> mode.getValue() != Mode.Damage);
private final Setting<Float> rebreakfactor = new Setting<>("RebreakFactor", 7f, 0.5f, 20f, v -> mode.getValue() == Mode.GrimInstant);
private final Setting<Float> speed = new Setting<>("Speed", 0.5f, 0f, 1f, v -> mode.getValue() == Mode.Damage);
private final Setting<Float> range = new Setting<>("Range", 4.2f, 3.0f, 10.0f, v -> mode.getValue() != Mode.Damage);
public final Setting<Float> range = new Setting<>("Range", 4.2f, 3.0f, 10.0f, v -> mode.getValue() != Mode.Damage);
private final Setting<Boolean> rotate = new Setting<>("Rotate", false, v -> mode.getValue() != Mode.Damage);
private final Setting<Boolean> placeCrystal = new Setting<>("PlaceCrystal", true, v -> mode.getValue() == Mode.GrimInstant);
private final Setting<Boolean> resetOnSwitch = new Setting<>("ResetOnSwitch", true, v -> mode.getValue() != Mode.Damage);
Expand Down Expand Up @@ -165,6 +165,8 @@ public void onUpdate() {
InventoryUtility.switchTo(prevSlot);
}

mc.interactionManager.breakBlock(minePosition);

progress = 0;
mineBreaks++;
}
Expand Down Expand Up @@ -467,7 +469,13 @@ private boolean canBreak(BlockPos pos) {
}

public void placeCrystal() {
if (AutoCrystal.target == null)
return;

BlockState prevState = mc.world.getBlockState(minePosition);
mc.world.setBlockState(minePosition, Blocks.AIR.getDefaultState());
AutoCrystal.PlaceData data = getBestData();
mc.world.setBlockState(minePosition, prevState);

if (data != null) {
ModuleManager.autoCrystal.placeCrystal(data.bhr(), true, false);
Expand All @@ -479,20 +487,29 @@ public void placeCrystal() {


public AutoCrystal.PlaceData getBestData() {

if (mc.world.isAir(minePosition.down())) {
if (ExplosionUtility.getSelfExplosionDamage(minePosition.down().toCenterPos().add(0,0.5,0), 0, false) > ModuleManager.autoCrystal.maxSelfDamage.getValue())
return null;

AutoCrystal.PlaceData autoMineData = ModuleManager.autoCrystal.getPlaceData(minePosition, null, mc.player.getPos());
if (autoMineData != null)
return autoMineData;
}

for (Direction dir : Direction.values()) {
if (dir == Direction.UP || dir == Direction.DOWN) continue;
if (ExplosionUtility.getSelfExplosionDamage(minePosition.down().offset(dir).toCenterPos().add(0,0.5,0), 0, false) > ModuleManager.autoCrystal.maxSelfDamage.getValue())
continue;

AutoCrystal.PlaceData autoMineData = ModuleManager.autoCrystal.getPlaceData(minePosition.down().offset(dir), null, mc.player.getPos());
if (autoMineData != null)
return autoMineData;
}

AutoCrystal.PlaceData autoMineData = ModuleManager.autoCrystal.getPlaceData(minePosition, null, mc.player.getPos());
if (ExplosionUtility.getSelfExplosionDamage(minePosition.toCenterPos().add(0,0.5,0), 0, false) > ModuleManager.autoCrystal.maxSelfDamage.getValue())
return null;
return autoMineData;
}

Expand Down

0 comments on commit aac4421

Please sign in to comment.