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

Commit

Permalink
Fixed 1.21 explosion damage calc
Browse files Browse the repository at this point in the history
  • Loading branch information
pan4ur committed Jul 29, 2024
1 parent 49aa996 commit a35da76
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 109 deletions.
101 changes: 46 additions & 55 deletions src/main/java/thunder/hack/modules/player/SpeedMine.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public final class SpeedMine extends Module {
private Direction mineFacing;
private int mineBreaks;
public static float progress, prevProgress;
public boolean worth = false;

private final Timer attackTimer = new Timer();

Expand Down Expand Up @@ -132,6 +131,9 @@ public void onUpdate() {
if (hotBarPickSlot == -1 && switchMode.getValue() != SwitchMode.Alternative) return;

if (progress >= 1) {
if (placeCrystal.getValue())
placeCrystal();

if (switchMode.getValue() == SwitchMode.Alternative) {
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, invPickSlot < 9 ? invPickSlot + 36 : invPickSlot, mc.player.getInventory().selectedSlot, SlotActionType.SWAP, mc.player);
closeScreen();
Expand Down Expand Up @@ -199,16 +201,8 @@ public void onUpdate() {
if (hotBarPickSlot == -1 && switchMode.getValue() != SwitchMode.Alternative) return;

if (progress >= 1) {
if (placeCrystal.getValue()) {
AutoCrystal.PlaceData placeCrystalData = ModuleManager.autoCrystal.getPlaceData(SpeedMine.minePosition, null, mc.player.getPos());
if (placeCrystalData != null) {
ModuleManager.autoCrystal.placeCrystal(placeCrystalData.bhr(), true, false);
debug("placing..");
} else
debug("placeCrystalData is null");
ModuleManager.autoTrap.pause();
ModuleManager.breaker.pause();
}
if (placeCrystal.getValue())
placeCrystal();

if (switchMode.getValue() == SwitchMode.Alternative) {
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, invPickSlot < 9 ? invPickSlot + 36 : invPickSlot, mc.player.getInventory().selectedSlot, SlotActionType.SWAP, mc.player);
Expand Down Expand Up @@ -236,6 +230,9 @@ public void onUpdate() {

progress = 0;
mineBreaks++;

if (placeCrystal.getValue())
placeCrystal();
}
prevProgress = progress;
progress += getBlockStrength(mc.world.getBlockState(minePosition), minePosition) * (mineBreaks >= 1 ? rebreakfactor.getValue() : 1);
Expand All @@ -248,7 +245,6 @@ public void onUpdate() {

@Override
public void onRender3D(MatrixStack stack) {
worth = checkWorth();

if (mode.getValue() == Mode.Damage
|| mc.world == null
Expand Down Expand Up @@ -331,7 +327,7 @@ && canBreak(event.getBlockPos())
@SuppressWarnings("unused")
private void onSync(EventSync event) {
if (rotate.getValue() && progress > 0.95 && minePosition != null && mc.player != null) {
float[] angle = PlayerManager.calcAngle(mc.player.getEyePos(), minePosition.toCenterPos());
float[] angle = PlayerManager.calcAngle(mc.player.getEyePos(), minePosition.toCenterPos().add(0, -0.25f, 0));

mc.player.setYaw(angle[0]);
mc.player.setPitch(angle[1]);
Expand Down Expand Up @@ -360,40 +356,6 @@ private void closeScreen() {
sendPacket(new CloseHandledScreenC2SPacket(mc.player.currentScreenHandler.syncId));
}

private boolean checkWorth() {
return checkWorth(7.5f, minePosition);
}

public boolean checkWorth(float damage, BlockPos pos) {
if (isDisabled()
|| mode.getValue() == Mode.Damage
|| pos == null
|| mc.world == null
|| progress < 0.95
|| mc.world.getBlockState(pos).getBlock() != Blocks.OBSIDIAN)
return false;

for (PlayerEntity player : ThunderHack.asyncManager.getAsyncPlayers()) {
if (player == null
|| player == mc.player
|| ThunderHack.friendManager.isFriend(player))
continue;

BlockState currentState = mc.world.getBlockState(pos);
mc.world.removeBlock(pos, false);
float dmg = ExplosionUtility.getExplosionDamage(pos.toCenterPos(), player, false);
float selfDamage = ExplosionUtility.getExplosionDamage(pos.toCenterPos(), mc.player, false);
mc.world.setBlockState(pos, currentState);

boolean overrideDamage = ModuleManager.autoCrystal.shouldOverrideDamage(damage, selfDamage);

if (dmg > damage && ModuleManager.autoCrystal.isSafe(dmg, selfDamage, overrideDamage))
return true;
}

return false;
}

private float getBlockStrength(@NotNull BlockState state, BlockPos position) {
if (state == Blocks.AIR.getDefaultState()) {
return 0.02f;
Expand Down Expand Up @@ -424,10 +386,13 @@ public float getDigSpeed(BlockState state, BlockPos position) {
float digSpeed = getDestroySpeed(position, state);

if (digSpeed > 1) {
ItemStack itemstack = mc.player.getInventory().getStack(getTool(position));
int efficiencyModifier = EnchantmentHelper.getLevel(mc.world.getRegistryManager().get(Enchantments.EFFICIENCY.getRegistryRef()).getEntry(Enchantments.EFFICIENCY).get(), itemstack);
if (efficiencyModifier > 0 && !itemstack.isEmpty()) {
digSpeed += (float) (StrictMath.pow(efficiencyModifier, 2) + 1);
int slot = getTool(position);
if (slot != -1) {
ItemStack itemstack = mc.player.getInventory().getStack(slot);
int efficiencyModifier = EnchantmentHelper.getLevel(mc.world.getRegistryManager().get(Enchantments.EFFICIENCY.getRegistryRef()).getEntry(Enchantments.EFFICIENCY).get(), itemstack);
if (efficiencyModifier > 0 && !itemstack.isEmpty()) {
digSpeed += (float) (StrictMath.pow(efficiencyModifier, 2) + 1);
}
}
}

Expand Down Expand Up @@ -501,12 +466,38 @@ private boolean canBreak(BlockPos pos) {
fixColorValue(startColor.getAlpha() + (int) (aDiff * progress)));
}

private int fixColorValue(int colorVal) {
return colorVal > 255 ? 255 : Math.max(colorVal, 0);
public void placeCrystal() {
AutoCrystal.PlaceData data = getBestData();

if (data != null) {
ModuleManager.autoCrystal.placeCrystal(data.bhr(), true, false);
debug("placing..");
ModuleManager.autoTrap.pause();
ModuleManager.breaker.pause();
}
}


public AutoCrystal.PlaceData getBestData() {
if (mc.world.isAir(minePosition.down())) {
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;
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());
return autoMineData;
}

public boolean isWorth() {
return worth;
private int fixColorValue(int colorVal) {
return colorVal > 255 ? 255 : Math.max(colorVal, 0);
}

public void addBlockToMine(BlockPos pos, @Nullable Direction facing, boolean allowReMine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void update() {

if (!cache.isEmpty()) {
cache.forEach((crystal, deathTime) -> {
if (System.currentTimeMillis() - deathTime > ServerManager.getPing() * 3L) {
if (System.currentTimeMillis() - deathTime > ServerManager.getPing() * 2L) {
deadCrystals.remove(crystal);
}
});
Expand Down
Loading

0 comments on commit a35da76

Please sign in to comment.