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

Commit

Permalink
Changed MovementService a bit to prevent allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
3arthqu4ke committed Apr 7, 2024
1 parent d04f112 commit 8b3528f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/main/java/me/earth/phobot/PhobotPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public void unload() {

private Phobot initalizePhobot(PingBypass pingBypass, ExecutorService executor, PluginUnloadingService unloadingService) {
WorldVersionService worldVersionService = subscribe(unloadingService, new WorldVersionService());
MovementService movementService = new MovementService();

Holes holes = new Holes(pingBypass, executor);
unloadingService.registerModule(holes);
Expand All @@ -79,6 +78,11 @@ private Phobot initalizePhobot(PingBypass pingBypass, ExecutorService executor,

DamageService damageService = subscribe(unloadingService, new DamageService(protectionCacheService, pingBypass.getMinecraft()));

ServerService serverService = subscribe(unloadingService, new ServerService());
AntiCheat antiCheat = new AntiCheat(pingBypass, serverService);
unloadingService.registerModule(antiCheat);
MovementService movementService = new MovementService(antiCheat);

Pathfinding pathfinding = new Pathfinding(pingBypass, executor);
unloadingService.registerModule(pathfinding);
NavigationMeshManager navigationMeshManager = subscribe(unloadingService,
Expand All @@ -91,10 +95,6 @@ private Phobot initalizePhobot(PingBypass pingBypass, ExecutorService executor,
Pathfinder pathfinder = subscribe(unloadingService,
new Pathfinder(pingBypass, unloadingService.getEventBus(), navigationMeshManager, executor, taskService, pathfinding));

ServerService serverService = subscribe(unloadingService, new ServerService());
AntiCheat antiCheat = new AntiCheat(pingBypass, serverService);
unloadingService.registerModule(antiCheat);

subscribe(unloadingService, new TickPredictionService(pingBypass.getMinecraft()));
LocalPlayerPositionService localPlayerPositionService = subscribe(unloadingService, new LocalPlayerPositionService(pingBypass.getMinecraft()));
InvincibilityFrameService invincibilityFrameService = subscribe(unloadingService, new InvincibilityFrameService(pingBypass.getMinecraft(), antiCheat, localPlayerPositionService));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package me.earth.phobot.modules.client.anticheat;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.earth.phobot.movement.BunnyHop;
import me.earth.phobot.movement.BunnyHopCC;
import me.earth.phobot.movement.BunnyHopNcp;
import me.earth.phobot.movement.Movement;

@Getter
@RequiredArgsConstructor
public enum MovementAntiCheat {
Vanilla,
Ncp,
CC,
Grim
Vanilla(new BunnyHop()), // TODO: vanilla bhop is just 3arth 1.12.2 bhop
Ncp(new BunnyHopNcp()),
CC(new BunnyHopCC()),
Grim(new BunnyHopCC()); // TODO: for now, this needs a real one

// TODO: should probably go into a separate bhop mode setting or something
private final Movement movement;

}
2 changes: 1 addition & 1 deletion src/main/java/me/earth/phobot/modules/movement/Speed.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void onEvent(MoveEvent event, LocalPlayer player, ClientLevel level, Mult
}

if (player.fallDistance <= 5.0 && (player.xxa != 0.0f || player.zza != 0.0f)) {
state = phobot.getMovementService().getMovement(phobot).move(player, mc.level, state, getDirectionAndYMovement(player));
state = phobot.getMovementService().getMovement().move(player, mc.level, state, getDirectionAndYMovement(player));
if (!state.isReset()) {
player.setDeltaMovement(player.getDeltaMovement().x, state.getDelta().y, player.getDeltaMovement().z);
event.setVec(new Vec3(state.getDelta().x, state.getDelta().y, state.getDelta().z));
Expand Down
22 changes: 5 additions & 17 deletions src/main/java/me/earth/phobot/services/MovementService.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
package me.earth.phobot.services;

import lombok.Getter;
import me.earth.phobot.Phobot;
import me.earth.phobot.movement.BunnyHop;
import me.earth.phobot.movement.BunnyHopCC;
import me.earth.phobot.movement.BunnyHopNcp;
import lombok.RequiredArgsConstructor;
import me.earth.phobot.modules.client.anticheat.AntiCheat;
import me.earth.phobot.movement.Movement;

@Getter
@RequiredArgsConstructor
public class MovementService {
private Movement movement;

public Movement getMovement(Phobot phobot) {
switch(phobot.getAntiCheat().getMovement().getValue()) {
case CC -> movement = new BunnyHopCC();
case Ncp -> movement = new BunnyHopNcp();
case Grim, Vanilla -> movement = new BunnyHop();
}
return movement;
}
private final AntiCheat antiCheat;

public Movement getMovement() {
return new BunnyHopCC();
return antiCheat.getMovement().getValue().getMovement();
}

}

0 comments on commit 8b3528f

Please sign in to comment.