Skip to content

Commit

Permalink
refactor: use the declaring class to access fields in child class
Browse files Browse the repository at this point in the history
Non-private static members of the parent class are accessible by child classes. However, it is a bad practice to do so, because it obscures where a value was actually declared. Always use only the declaring class to access static members.
  • Loading branch information
deepsource-autofix[bot] authored Oct 28, 2023
1 parent 876c912 commit fe83b3c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
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);
}
}
}
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();
}

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)) {
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);
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);
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);
}
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;
}
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()) {
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()) {
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()) {
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

0 comments on commit fe83b3c

Please sign in to comment.