Skip to content

Commit

Permalink
Fix hitbox collision/pushing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
P0keDev committed Mar 4, 2021
1 parent 5b5fd33 commit a94f79a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
8 changes: 7 additions & 1 deletion src/main/java/com/wynntils/core/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class Utils {
private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("wynntils-utilities-%d").build());
private static Random random = new Random();

private static String previousTeam = null;

/**
* Runs a runnable after the determined time
*
Expand Down Expand Up @@ -165,10 +167,13 @@ public static ScorePlayerTeam createFakeScoreboard(String name, Team.CollisionRu
Scoreboard mc = Minecraft.getMinecraft().world.getScoreboard();
if (mc.getTeam(name) != null) return mc.getTeam(name);

String player = Minecraft.getMinecraft().player.getName();
if (mc.getPlayersTeam(player) != null) previousTeam = mc.getPlayersTeam(player).getName();

ScorePlayerTeam team = mc.createTeam(name);
team.setCollisionRule(rule);

mc.addPlayerToTeam(Minecraft.getMinecraft().player.getName(), name);
mc.addPlayerToTeam(player, name);
return team;
}

Expand All @@ -182,6 +187,7 @@ public static void removeFakeScoreboard(String name) {
if (mc.getTeam(name) == null) return;

mc.removeTeam(mc.getTeam(name));
if (previousTeam != null) mc.addPlayerToTeam(Minecraft.getMinecraft().player.getName(), previousTeam);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ public static class Identifications extends SettingsClass {
@SettingsInfo(name = "afk", displayPath = "Utilities/AFK Protection")
public static class AfkProtection extends SettingsClass {
public static AfkProtection INSTANCE;
@Setting(displayName = "Block Player Collision When AFK", description = "Should player collision be blocked when you are AFK?")
public boolean blockAfkPushs = true;

@Setting(displayName = "AFK Protection", description = "Should you enter the class selection menu when you are AFK?")
public boolean afkProtection = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import net.minecraft.network.play.server.SPacketEntityMetadata;
import net.minecraft.network.play.server.SPacketSetSlot;
import net.minecraft.network.play.server.SPacketTitle;
import net.minecraft.scoreboard.Team;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.TextComponentString;
Expand All @@ -68,7 +67,6 @@
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import org.lwjgl.opengl.Display;

import java.time.*;
import java.time.format.DateTimeFormatter;
Expand All @@ -84,7 +82,6 @@ public class ClientEvents implements Listener {
private static GuiScreen scheduledGuiScreen = null;
private static boolean firstNullOccurred = false;

private static boolean pushBlockingEnabled = false;
private static boolean afkProtectionEnabled = false;
private static boolean afkProtectionActivated = false;
private static boolean afkProtectionRequested = false;
Expand Down Expand Up @@ -137,7 +134,6 @@ public void classDialog(GuiOverlapEvent.ChestOverlap.DrawGuiContainerBackgroundL

@SubscribeEvent
public void classChange(WynnClassChangeEvent e) {
pushBlockingEnabled = false;
afkProtectionEnabled = false;
afkProtectionActivated = false;

Expand All @@ -154,7 +150,7 @@ public void clientTick(TickEvent.ClientTickEvent e) {

DailyReminderManager.checkDailyReminder(ModCore.mc().player);

if (!UtilitiesConfig.AfkProtection.INSTANCE.blockAfkPushs && !UtilitiesConfig.AfkProtection.INSTANCE.afkProtection) return;
if (!UtilitiesConfig.AfkProtection.INSTANCE.afkProtection) return;

if (afkProtectionRequested) {
afkProtectionRequested = false;
Expand All @@ -165,22 +161,6 @@ public void clientTick(TickEvent.ClientTickEvent e) {
long currentTime = System.currentTimeMillis();
long timeSinceActivity = currentTime - this.lastUserInput;

if (UtilitiesConfig.AfkProtection.INSTANCE.blockAfkPushs) {
if (!pushBlockingEnabled) {
if (timeSinceActivity >= 10000 || !Display.isActive()) {
// If not enabled, but we lose focus or no activity for 10 seconds, turn on
Utils.createFakeScoreboard("Afk", Team.CollisionRule.NEVER);
pushBlockingEnabled = true;
}
} else {
if (timeSinceActivity < 10000 && Display.isActive()) {
// If turned on, but we gain focus or have activity, turn off
pushBlockingEnabled = false;
Utils.removeFakeScoreboard("Afk");
}
}
}

if (UtilitiesConfig.AfkProtection.INSTANCE.afkProtection) {
if (afkProtectionActivated) {
lastUserInput = currentTime;
Expand Down

0 comments on commit a94f79a

Please sign in to comment.