Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use the declaring class to access fields in child class #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/main/java/coffee/client/feature/module/impl/combat/MCE.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public MCE() {

@Override
public void onFastTick() {
if (client.options.pickItemKey.isPressed()){
if(client.currentScreen instanceof GenericContainerScreen) return;
if (Module.client.options.pickItemKey.isPressed()){
if(Module.client.currentScreen instanceof GenericContainerScreen) return;
pealcount = InvUtils.getamount(Items.ENDER_PEARL);

if (pealcount == 0) return;
Expand All @@ -35,18 +35,18 @@ public void onFastTick() {
int index = InvUtils.findItemInHotbar(Items.ENDER_PEARL);
if(index == -1) return;

int priorslot = client.player.getInventory().selectedSlot;
client.player.getInventory().selectedSlot = index;
client.interactionManager.interactItem(client.player, Hand.MAIN_HAND);
client.player.getInventory().selectedSlot = priorslot;
int priorslot = Module.client.player.getInventory().selectedSlot;
Module.client.player.getInventory().selectedSlot = index;
Module.client.interactionManager.interactItem(Module.client.player, Hand.MAIN_HAND);
Module.client.player.getInventory().selectedSlot = priorslot;
}

case FULLINV -> {
int index = InvUtils.finditem(Items.ENDER_PEARL);
if(index == -1) return;

putinmain(index);
client.interactionManager.interactItem(client.player, Hand.MAIN_HAND);
Module.client.interactionManager.interactItem(Module.client.player, Hand.MAIN_HAND);
putback(index);
}
}
Expand All @@ -55,13 +55,13 @@ public void onFastTick() {
}

private void putinmain(int slot){
client.interactionManager.clickSlot(0, InvUtils.getslot(slot), 0, SlotActionType.PICKUP, client.player);
client.interactionManager.clickSlot(0, 36, 0, SlotActionType.PICKUP, client.player);
Module.client.interactionManager.clickSlot(0, InvUtils.getslot(slot), 0, SlotActionType.PICKUP, Module.client.player);
Module.client.interactionManager.clickSlot(0, 36, 0, SlotActionType.PICKUP, Module.client.player);
}

private void putback(int slot){
client.interactionManager.clickSlot(0, 36, 0, SlotActionType.PICKUP, client.player);
client.interactionManager.clickSlot(0, InvUtils.getslot(slot), 0, SlotActionType.PICKUP, client.player);
Module.client.interactionManager.clickSlot(0, 36, 0, SlotActionType.PICKUP, Module.client.player);
Module.client.interactionManager.clickSlot(0, InvUtils.getslot(slot), 0, SlotActionType.PICKUP, Module.client.player);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public AutoRespawn() {

@Override
public void onFastTick() {
if (client.currentScreen instanceof DeathScreen){
client.player.requestRespawn();
if (Module.client.currentScreen instanceof DeathScreen){
Module.client.player.requestRespawn();
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/coffee/client/feature/module/impl/misc/Automount.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ public Automount() {

@Override
public void onFastTick() {
if (client.player.hasVehicle()) return;
if (Module.client.player.hasVehicle()) return;

for (Entity entity : client.world.getEntities()){
if (entity.distanceTo(client.player) <= 4){
for (Entity entity : Module.client.world.getEntities()){
if (entity.distanceTo(Module.client.player) <= 4){
if (entity instanceof HorseEntity && horse.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
} else if (entity instanceof DonkeyEntity && donkey.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
} else if (entity instanceof MuleEntity && mule.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
} else if (entity instanceof BoatEntity && boat.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
} else if (entity instanceof MinecartEntity && minecart.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
} else if (entity instanceof PigEntity && pig.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
} else if (entity instanceof LlamaEntity && llama.getValue()){
client.interactionManager.interactEntity(client.player, entity, Hand.MAIN_HAND);
Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
}
}
}
Comment on lines 30 to 53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is repetitive and could be refactored to improve readability and maintainability. Consider creating a map of entity classes and their corresponding settings, then use a loop to check and interact with the entities. This would reduce the number of if statements and make the code easier to extend in the future.

Map<Class<? extends Entity>, BooleanSetting> entitySettings = new HashMap<>();
entitySettings.put(HorseEntity.class, horse);
entitySettings.put(DonkeyEntity.class, donkey);
entitySettings.put(MuleEntity.class, mule);
entitySettings.put(BoatEntity.class, boat);
entitySettings.put(MinecartEntity.class, minecart);
entitySettings.put(PigEntity.class, pig);
entitySettings.put(LlamaEntity.class, llama);

for (Entity entity : Module.client.world.getEntities()){
    if (entity.distanceTo(Module.client.player) <= 4){
        BooleanSetting setting = entitySettings.get(entity.getClass());
        if (setting != null && setting.getValue()){
            Module.client.interactionManager.interactEntity(Module.client.player, entity, Hand.MAIN_HAND);
        }
    }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ void cleanupNeighbours() {
}

boolean isValidChestNeighbor(BlockPos owner, BlockPos bp) {
BlockState bs = client.world.getBlockState(bp);
BlockState bs1 = client.world.getBlockState(owner);
BlockState bs = Module.client.world.getBlockState(bp);
BlockState bs1 = Module.client.world.getBlockState(owner);
return bs1.getBlock() == bs.getBlock();
}
Comment on lines 122 to 126
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function isValidChestNeighbor checks if the block at the given position bp is the same as the block at the position owner. This function assumes that the world state is consistent and that the blocks at the given positions exist. If the world state changes between the two calls to getBlockState, this function may return incorrect results. Consider adding error handling to account for this possibility.


Expand All @@ -134,7 +134,7 @@ void send(PacketEvent.Sent pe) {
if (childrenMap.values().stream().anyMatch(blockPos -> blockPos.contains(lastPos))) {
return; // already part of another chest
}
BlockState bs = client.world.getBlockState(lastPos);
BlockState bs = Module.client.world.getBlockState(lastPos);
Block block = bs.getBlock();
List<Block> blocks = Arrays.asList(ALLOW_LIST);
if (blocks.contains(block)) {
Comment on lines 134 to 140
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function send checks if the block at the given position lastPos is in the ALLOW_LIST. This function assumes that the world state is consistent and that the block at the given position exists. If the world state changes between the call to getBlockState and the check against ALLOW_LIST, this function may return incorrect results. Consider adding error handling to account for this possibility.

Expand All @@ -155,7 +155,7 @@ void send(PacketEvent.Sent pe) {
int x = (int) (-Math.round(Math.sin(v1)));
int z = (int) Math.round(Math.cos(v1));
BlockPos secondPos = lastPos.add(x, 0, z);
BlockState bs1 = client.world.getBlockState(secondPos);
BlockState bs1 = Module.client.world.getBlockState(secondPos);
if (bs1.getBlock() == block && bs1.get(ChestBlock.CHEST_TYPE) == chestType.getOpposite() && bs1.get(ChestBlock.FACING) == direction) {
stacks.remove(secondPos); // if the neighbour was already indexed, remove him and use this pos instead
childrenMap.computeIfAbsent(lastPos, blockPos -> new ArrayList<>()).add(secondPos);
Comment on lines 155 to 161
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function send updates the stacks and childrenMap based on the state of the world. This function assumes that the world state is consistent and that the blocks at the given positions exist. If the world state changes between the calls to getBlockState and the updates to stacks and childrenMap, this function may behave incorrectly. Consider adding error handling to account for this possibility.

Expand All @@ -176,7 +176,7 @@ void send(PacketEvent.Sent pe) {
}
this.stacks.putIfAbsent(this.currentPosClicked, new Int2ObjectArrayMap<>());
Int2ObjectMap<ItemStack> itemStackInt2ObjectMap = this.stacks.get(this.currentPosClicked);
DefaultedList<Slot> slots = client.player.currentScreenHandler.slots;
DefaultedList<Slot> slots = Module.client.player.currentScreenHandler.slots;
int contentLength = slots.size() - 9 * 4; // this one includes the actual inventory so we remove it from the index
for (int i = 0; i < contentLength; i++) {
Slot slot = slots.get(i);
Comment on lines 176 to 182
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function send updates the stacks based on the state of the player's inventory. This function assumes that the player's inventory state is consistent and that the slots in the inventory exist. If the inventory state changes between the call to getStack and the updates to stacks, this function may behave incorrectly. Consider adding error handling to account for this possibility.

Expand All @@ -194,10 +194,10 @@ void send(PacketEvent.Sent pe) {
public void tick() {
if (updateTimer.hasExpired(5_000)) {
for (BlockPos blockPos : new ArrayList<>(stacks.keySet())) {
if (!blockPos.isWithinDistance(client.player.getBlockPos(), 64)) {
if (!blockPos.isWithinDistance(Module.client.player.getBlockPos(), 64)) {
continue; // dont update this one we have no fucking idea whats in it
}
BlockState bs = client.world.getBlockState(blockPos);
BlockState bs = Module.client.world.getBlockState(blockPos);
if (!Arrays.asList(ALLOW_LIST).contains(bs.getBlock())) {
stacks.remove(blockPos);
}
Comment on lines 194 to 203
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function tick updates the stacks based on the state of the world. This function assumes that the world state is consistent and that the blocks at the given positions exist. If the world state changes between the calls to getBlockState and the updates to stacks, this function may behave incorrectly. Consider adding error handling to account for this possibility.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Test() {
@Override
public void enable() {
new Thread(() -> {
pf = new PathFinder(client.player.getBlockPos(), new BlockPos(100, 100, 100));
pf = new PathFinder(Module.client.player.getBlockPos(), new BlockPos(100, 100, 100));
pf.find();
}).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ void onPacket(coffee.client.helper.event.impl.PacketEvent.Sent event) {

@Override
public void tick() {
if (client.player == null || client.getNetworkHandler() == null) {
if (Module.client.player == null || client.getNetworkHandler() == null) {
return;
}
Comment on lines +52 to 54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for client.getNetworkHandler() == null has not been updated to Module.client.getNetworkHandler() == null. This should be updated for consistency and to avoid potential null pointer exceptions.

- if (Module.client.player == null || client.getNetworkHandler() == null) {
+ if (Module.client.player == null || Module.client.getNetworkHandler() == null) {

57:
The client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); line has not been updated to use Module.client. This should be updated for consistency.

- case Packet -> client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true));
+ case Packet -> Module.client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true));

Commitable suggestion (Beta)
Suggested change
if (Module.client.player == null || client.getNetworkHandler() == null) {
return;
}
if (Module.client.player == null || Module.client.getNetworkHandler() == null) {
return;
}

[ISSUE][REFINE]

57:
The client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); line has not been updated to use Module.client. This should be updated for consistency.

- case Packet -> client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true));
+ case Packet -> Module.client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true));

[ISSUE][REFINE]

if (client.player.fallDistance > fallDist.getValue()) {
if (Module.client.player.fallDistance > fallDist.getValue()) {
switch (mode.getValue()) {
case Packet -> client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true));
case BreakFall -> {
client.player.setVelocity(0, 0.1, 0);
client.player.fallDistance = 0;
Module.client.player.setVelocity(0, 0.1, 0);
Module.client.player.fallDistance = 0;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public void tick() {
@Override
public void enable() {
kb = new Keybind((int) (keybind.getValue() + 0));
before = client.options.getPerspective();
Module.before = client.options.getPerspective();
oldyaw = Objects.requireNonNull(client.player).getYaw();
oldpitch = client.player.getPitch();
newyaw = client.player.getYaw();
newyaw = Module.client.player.getYaw();
if (enableAA.getValue()) {
newpitch = 90;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void disable() {
yaw = pitch = 0f;
client.gameRenderer.setRenderHand(true);
client.player.getAbilities().flying = flewBefore;
client.player.getAbilities().setFlySpeed(0.05f);
client.Module.player.getAbilities().setFlySpeed(0.05f);
client.player.setVelocity(0, 0, 0);

JinxUtils.RemoveFakePlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onFastTick() {
if (!isReady()) {
return;
}
Objects.requireNonNull(client.player).setYaw(client.player.getMovementDirection().asRotation());
Objects.requireNonNull(Module.client.player).setYaw(client.player.getMovementDirection().asRotation());
if (client.player.getPitch() > 83) {
client.player.setPitch(82.5f);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/coffee/client/feature/module/impl/world/Nuker.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void iterateOverRange(double range, Consumer<Vec3d> positionsOffset) {
for (double y = -halfRange; y <= halfRange + 1; y++) {
for (double z = -halfRange; z <= halfRange + 1; z++) {
Vec3d posOff = new Vec3d(x - .5, y, z - .5);
Vec3d actual = client.player.getPos().add(posOff);
if (actual.distanceTo(client.player.getEyePos()) > range) {
Vec3d actual = Module.client.player.getPos().add(posOff);
if (actual.distanceTo(Module.client.player.getEyePos()) > range) {
continue;
}
positionsOffset.accept(actual);
Expand All @@ -60,7 +60,7 @@ void iterateOverRange(double range, Consumer<Vec3d> positionsOffset) {
@Override
public void tick() {
switch (modeSetting.getValue()) {
case Packet -> iterateOverRange(client.interactionManager.getReachDistance(), vec3d -> {
case Packet -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = client.world.getBlockState(bp);
if (bs.isAir()) {
Comment on lines 60 to 66
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client object has been replaced with Module.client in the tick method. However, there is an inconsistency on line 65 where client.world is used instead of Module.client.world. This should be updated for consistency.

- BlockState bs = client.world.getBlockState(bp);
+ BlockState bs = Module.client.world.getBlockState(bp);

Commitable suggestion (Beta)
Suggested change
@Override
public void tick() {
switch (modeSetting.getValue()) {
case Packet -> iterateOverRange(client.interactionManager.getReachDistance(), vec3d -> {
case Packet -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = client.world.getBlockState(bp);
if (bs.isAir()) {
@Override
public void tick() {
switch (modeSetting.getValue()) {
case Packet -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = Module.client.world.getBlockState(bp);
if (bs.isAir()) {

Expand All @@ -78,7 +78,7 @@ public void tick() {
new Vec3d(1, 1, 1),
500);
});
case Griefing -> iterateOverRange(client.interactionManager.getReachDistance(), vec3d -> {
case Griefing -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = client.world.getBlockState(bp);
if (bs.isAir()) {
Comment on lines 78 to 84
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous hunk, client.world is used instead of Module.client.world on line 83. This should be updated for consistency.

- BlockState bs = client.world.getBlockState(bp);
+ BlockState bs = Module.client.world.getBlockState(bp);

Commitable suggestion (Beta)
Suggested change
new Vec3d(1, 1, 1),
500);
});
case Griefing -> iterateOverRange(client.interactionManager.getReachDistance(), vec3d -> {
case Griefing -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = client.world.getBlockState(bp);
if (bs.isAir()) {
new Vec3d(1, 1, 1),
500);
});
case Griefing -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
- BlockState bs = client.world.getBlockState(bp);
+ BlockState bs = Module.client.world.getBlockState(bp);
if (bs.isAir()) {

Expand All @@ -94,7 +94,7 @@ public void tick() {
500);
}
});
case Interaction -> iterateOverRange(client.interactionManager.getReachDistance(), vec3d -> {
case Interaction -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = client.world.getBlockState(bp);
if (bs.isAir()) {
Comment on lines 94 to 100
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, client.world is used instead of Module.client.world on line 99. This should be updated for consistency.

- BlockState bs = client.world.getBlockState(bp);
+ BlockState bs = Module.client.world.getBlockState(bp);

Commitable suggestion (Beta)
Suggested change
500);
}
});
case Interaction -> iterateOverRange(client.interactionManager.getReachDistance(), vec3d -> {
case Interaction -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = client.world.getBlockState(bp);
if (bs.isAir()) {
500);
}
});
case Interaction -> iterateOverRange(Module.client.interactionManager.getReachDistance(), vec3d -> {
BlockPos bp = new BlockPos(BlockPos.ofFloored(vec3d));
BlockState bs = Module.client.world.getBlockState(bp);
if (bs.isAir()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ boolean isBlockApplicable(Block b) {

@Override
public void tick() {
if (client.player == null || client.world == null || client.interactionManager == null || client.getNetworkHandler() == null) {
if (client.player == null || Module.client.world == null || client.interactionManager == null || client.getNetworkHandler() == null) {
return;
}
if (delayPassed < delay.getValue()) {
Expand Down
Loading