Skip to content

Commit

Permalink
Added documentation to Notification, made NoFall clutch work with the…
Browse files Browse the repository at this point in the history
… new changes, added some TODOs, and some BlockUtils changes.
  • Loading branch information
tanishisherewithhh committed Nov 25, 2024
1 parent 61d920b commit 9e7ea96
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 71 deletions.
8 changes: 4 additions & 4 deletions src/main/java/dev/heliosclient/managers/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static <T extends Module_> T get(Class<T> moduleClazz) {
public static ArrayList<Module_> getModuleByNameSearch(String moduleName, int amount) {
ArrayList<Module_> moduleS = new ArrayList<>();
if (moduleName.isEmpty()) return moduleS;
moduleName = moduleName.trim();
moduleName = moduleName.trim().toLowerCase();

for (Module_ module : modules) {
if (moduleS.size() >= amount) {
Expand All @@ -229,15 +229,15 @@ public static ArrayList<Module_> getModuleByNameSearch(String moduleName, int am
moduleS.add(module);
return moduleS; // Exact match found, return immediately
}
if (module.name.trim().toLowerCase().contains(moduleName.toLowerCase())) {
if (module.name.trim().toLowerCase().contains(moduleName)) {
moduleS.add(module);
}
}

String finalModuleName = moduleName;
moduleS.sort((m1, m2) -> {
int m1Score = StringUtils.getLevenshteinDistance(m1.name.trim().toLowerCase(), finalModuleName.toLowerCase());
int m2Score = StringUtils.getLevenshteinDistance(m2.name.trim().toLowerCase(), finalModuleName.toLowerCase());
int m1Score = StringUtils.getLevenshteinDistance(m1.name.trim().toLowerCase(), finalModuleName);
int m2Score = StringUtils.getLevenshteinDistance(m2.name.trim().toLowerCase(), finalModuleName);

// First, sort by the score
int scoreComparison = Integer.compare(m1Score, m2Score);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static void updateNotifications() {
// Add notifications from the queue until the maximum number is reached
while (displayedNotifications.size() < MAX_DISPLAYED && !notificationQueue.isEmpty()) {
Notification notification = notificationQueue.poll();
if (notification == null) return;
if (notification == null) continue;

notification.setCreationTime(System.currentTimeMillis());
notification.playSound(notification.soundEvent, notification.volume, notification.pitch);
Expand All @@ -76,6 +76,7 @@ private static void updatePositions() {
POSITION_MODE == Notification.PositionMode.BOTTOM_LEFT)
? screenHeight - VERTICAL_SPACING
: VERTICAL_SPACING;

int targetX = calculateInitialTargetX(screenWidth);

for (Notification notification : displayedNotifications) {
Expand Down Expand Up @@ -103,7 +104,6 @@ private static void updatePositions() {
default -> targetY;
};

// Update X position based on position mode and horizontal spacing
int newX = calculateNotificationX(screenWidth, notification.getWidth(), targetX);

notification.smoothMoveY(targetOffset);
Expand All @@ -126,7 +126,6 @@ private static int calculateNotificationX(int screenWidth, int notificationWidth
};
}

// Add method to set horizontal spacing
public static void setHorizontalSpacing(int spacing) {
HORIZONTAL_SPACING = Math.max(0, spacing);
}
Expand Down
99 changes: 56 additions & 43 deletions src/main/java/dev/heliosclient/module/modules/movement/NoFall.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

import dev.heliosclient.event.SubscribeEvent;
import dev.heliosclient.event.events.TickEvent;
import dev.heliosclient.event.events.player.PlayerMotionEvent;
import dev.heliosclient.mixin.AccessorMinecraftClient;
import dev.heliosclient.module.Categories;
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.system.mixininterface.IVec3d;
import dev.heliosclient.util.ChatUtils;
import dev.heliosclient.util.blocks.BlockUtils;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.player.InventoryUtils;
import dev.heliosclient.util.player.RotationUtils;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
Expand Down Expand Up @@ -53,7 +55,7 @@ public class NoFall extends Module_ {
.name("Mode")
.description("Mode which should save player from fall height ")
.onSettingChange(this)
.defaultValue(List.of("Classic", "AlwaysOnGround", "Clutch", "Disconnect (annoying)"))
.defaultValue(List.of("PositionAndOnGround", "OnGroundOnly", "Clutch", "Disconnect (annoying)"))
.defaultListIndex(0)
.build()
);
Expand Down Expand Up @@ -118,14 +120,18 @@ public void onEnable() {
@Override
public void onSettingChange(Setting<?> setting) {
super.onSettingChange(setting);
if (cancelBounce.value && mode.value == 2) {
if ((setting == cancelBounce || setting == mode) && cancelBounce.value && mode.value == 2) {
ChatUtils.sendHeliosMsg("(NoFall Clutch) SlimeBlocks will cause fall damage with cancelBounce on!");
}
}

@SubscribeEvent
public void onTick(TickEvent.PLAYER event) {
assert mc.player != null;
if (mode.value == 2) {
if (shouldResetClutch()) {
cm.resetClutch();
}
}
if (mc.player.fallDistance >= fallHeight.value && !mc.player.isCreative()) {
if (mode.value == 0) {
// Second condition is to check if the y velocity of player is fast enough to cause damage.
Expand All @@ -143,20 +149,12 @@ public void onTick(TickEvent.PLAYER event) {
)
);
} else if (mode.value == 1) {
// Prevents the half-heart damage from classic mode
// Prevents the half-heart damage from PositionAndOnGround mode
mc.player.networkHandler.sendPacket(
new PlayerMoveC2SPacket.OnGroundOnly(
true
)
);

//Clutch mode!
} else if (mode.value == 2) {

if (shouldResetClutch()) {
cm.resetClutch();
}
clutch();
} else if (mode.value == 3) {
int distance = 0;
int y = (int) mc.player.getY();
Expand All @@ -177,45 +175,56 @@ public void onTick(TickEvent.PLAYER event) {
}
}
}
@SubscribeEvent
public void onMotion(PlayerMotionEvent event) {
if (mc.player.fallDistance >= fallHeight.value && !mc.player.isCreative()) {
clutch(event);
}
}

private void clutch() {
private void clutch(PlayerMotionEvent event) {
float health = mc.player.getHealth();
boolean shouldClutch = !onlyApplyNearDeath.value || DamageUtils.calcFallDamage(mc.player) >= health - 2;

if (shouldClutch) {
BlockHitResult result = mc.world.raycast(new RaycastContext(mc.player.getPos(), mc.player.getPos().subtract(0, 4, 0), RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, mc.player));
double prevX = mc.player.getVelocity().x;
double prevZ = mc.player.getVelocity().z;

if (stop.value) {
event.modifyMovement().heliosClient$setXZ(0, 0);
}

BlockHitResult result = mc.world.raycast(new RaycastContext(mc.player.getPos(), mc.player.getPos().subtract(0, mc.interactionManager.getReachDistance() - 1, 0), RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, mc.player));

if (result != null && result.getType() == HitResult.Type.BLOCK) {
BlockPos bpDown = result.getBlockPos();

if (!isPlayerAlreadySafe(bpDown)) {
if (!isPlayerAlreadySafe(result.getBlockPos())) {
for (ClutchItem item : ClutchItem.values()) {
cm.clutch(item, bpDown);
cm.clutch(item, bpDown,event);
if (cm.hasClutchedProperly()) {
break;
}
}
}

}
if (stop.value)
event.modifyMovement().heliosClient$setXZ(prevX, prevZ);
}
}

private boolean shouldResetClutch() {
return mc.player.isOnGround() || mc.player.getBlockStateAtPos().getFluidState() != Fluids.EMPTY.getDefaultState();
return mc.player.isOnGround() ||
mc.player.getBlockStateAtPos().getFluidState() != Fluids.EMPTY.getDefaultState() ||
mc.player.fallDistance < fallHeight.value;
}

public boolean isPlayerAlreadySafe(BlockPos bpDown) {
Block block = mc.world.getBlockState(bpDown).getBlock();

public boolean isPlayerAlreadySafe(BlockPos blockPos) {
if (forcePlace.value) {
return false;
}

//If the block is air, then it's not safe.
if (BlockUtils.airBreed(block)) {
return false;
}
Block block = mc.world.getBlockState(blockPos).getBlock();

//If block is clutch item then it's probably safe. (probably because we are not accounting fallDistance for now,
// meaning haybales and slimeblocks may still kill you).
Expand Down Expand Up @@ -266,12 +275,13 @@ public class ClutchManager {
private boolean hasClutchedProperly = false;


public void clutch(ClutchItem item, BlockPos pos) {
public void clutch(ClutchItem item, BlockPos pos, PlayerMotionEvent event) {
if (item == ClutchItem.WATER_BUCKET && mc.world.getDimensionKey() == DimensionTypes.THE_NETHER) {
return;
}

int slot = InventoryUtils.findItemInHotbar(item.getItem());

if (slot == -1) {
hasClutchedProperly = false;
return;
Expand All @@ -282,29 +292,31 @@ public void clutch(ClutchItem item, BlockPos pos) {
ItemStack stack = mc.player.getInventory().getStack(slot);
int count = InventoryUtils.getItemStackCountSafe(stack);


InventoryUtils.swapToSlot(slot, true);

//We want to rotate only when the player has set the rotate setting for blocks
rotate(rotate.value, pos.toCenterPos(), item.getResultItem());

double prevX = mc.player.getVelocity().x;
double prevZ = mc.player.getVelocity().z;

if (stop.value)
((IVec3d) mc.player.getVelocity()).heliosClient$setXZ(0, 0);
InventoryUtils.swapToSlot(slot, true);

if (item.getResultItem() == null) {
double prevY = mc.player.getVelocity().y;
double prevY = event.getMovement().y;

((IVec3d) mc.player.getVelocity()).heliosClient$setY(0);
event.modifyMovement().heliosClient$setY(0);

BlockUtils.place(pos, rotate.value,false, airPlace.value, slot == InventoryUtils.OFFHAND ? Hand.OFF_HAND : Hand.MAIN_HAND);

((IVec3d) mc.player.getVelocity()).heliosClient$setY(prevY);
BlockUtils.place(pos.up(), rotate.value,airPlace.value, slot == InventoryUtils.OFFHAND ? Hand.OFF_HAND : Hand.MAIN_HAND);

event.modifyMovement().heliosClient$setY(prevY);
} else {
Block block = mc.world.getBlockState(pos).getBlock();
if (BlockUtils.isClickable(block) || block instanceof LeavesBlock) {
mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
mc.player.setSneaking(true);
}
((AccessorMinecraftClient) mc).rightClick();

if (BlockUtils.isClickable(block) || block instanceof LeavesBlock) {
mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
mc.player.setSneaking(false);
}
}

if (item.getResultItem() != null) {
Expand All @@ -315,14 +327,15 @@ public void clutch(ClutchItem item, BlockPos pos) {
hasClutchedProperly = newStack.getCount() != count;
}

if (stop.value)
((IVec3d) mc.player.getVelocity()).heliosClient$setXZ(prevX, prevZ);
if(hasClutchedProperly){
InventoryUtils.swapBackHotbar();
}
}

public void rotate(boolean rotate, Vec3d vec, Item resultItem) {
if (resultItem == null && !rotate) return;

RotationUtils.lookAt(vec);
RotationUtils.instaLookAt(vec);
}

public boolean hasClutchedProperly() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ private boolean placeBlockPos(BlockPos pos, int itemSlot) {

if (autoSwitch.value) {
ScaffoldCount.setScaffoldStack(mc.player.getInventory().getStack(itemSlot));
placeResult = BlockUtils.place(pos, airPlace.value, rotate.value, true, itemSlot, silentSwitch.value);
placeResult = BlockUtils.place(pos, airPlace.value, rotate.value, itemSlot, silentSwitch.value);
} else {
ScaffoldCount.setScaffoldStack(mc.player.getInventory().getMainHandStack());
placeResult = BlockUtils.place(pos, airPlace.value, rotate.value, true);
placeResult = BlockUtils.place(pos, airPlace.value, rotate.value);
}

if (placeResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void onTick(TickEvent.CLIENT event) {
boolean swapped = InventoryUtils.swapToSlot(slot, false);

if (swapped) {
BlockUtils.place(changedPos, playerRotate.value,false, airPlace.value, slot == InventoryUtils.OFFHAND ? Hand.OFF_HAND : Hand.MAIN_HAND);
BlockUtils.place(changedPos, playerRotate.value,airPlace.value, slot == InventoryUtils.OFFHAND ? Hand.OFF_HAND : Hand.MAIN_HAND);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;

//TODO: Make this pretty
public class HeliosClientInfoScreen extends Screen {
public static HeliosClientInfoScreen INSTANCE = new HeliosClientInfoScreen();
private final ThreePartsLayoutWidget layout = new ThreePartsLayoutWidget(this);
Expand Down Expand Up @@ -40,5 +41,4 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackground(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
}

}
Loading

0 comments on commit 9e7ea96

Please sign in to comment.