Skip to content

Commit

Permalink
improve pit lag hider
Browse files Browse the repository at this point in the history
  • Loading branch information
MicrocontrollersDev committed Jan 30, 2024
1 parent e54f8d6 commit 4618c6b
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classes
# gradle
build
.gradle
libs

#Netbeans
.nb-gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class PitLagReducer {

/** The y-position of the spawn platform in The Pit. */
private double pitSpawnPos;
public static double pitSpawnPos;

@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
public class EntityLivingBaseMixin_MiningFatigue {
private final EntityLivingBase $this = (EntityLivingBase) (Object) this;


@Inject(method = "addPotionEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;onNewPotionEffect(Lnet/minecraft/potion/PotionEffect;)V"))
private void onPotionEffect(PotionEffect potioneffectIn, CallbackInfo ci) {
if (HytilsConfig.notifyMiningFatigue && potioneffectIn.getPotionID() == Potion.digSlowdown.getId() && LocrawUtil.INSTANCE.getLocrawInfo() != null && ($this instanceof EntityPlayerSP) && (!HytilsConfig.disableNotifyMiningFatigueSkyblock || !(LocrawUtil.INSTANCE.getLocrawInfo().getGameType() == LocrawInfo.GameType.SKYBLOCK))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.polyfrost.hytils.mixin;

import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawInfo;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import org.polyfrost.hytils.config.HytilsConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static org.polyfrost.hytils.handlers.game.pit.PitLagReducer.pitSpawnPos;

@Mixin(RendererLivingEntity.class)
public class RenderingLivingEntityMixin_HideNametags<T extends EntityLivingBase> extends Render<T> {
protected RenderingLivingEntityMixin_HideNametags(RenderManager renderManager) {
super(renderManager);
}

protected ResourceLocation getEntityTexture(T entity) {
return null;
}

@Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At("HEAD"), cancellable = true)
private void hideNametag(T entity, double x, double y, double z, CallbackInfo ci) {
if (!HypixelUtils.INSTANCE.isHypixel()) {
return;
}

LocrawInfo locraw = LocrawUtil.INSTANCE.getLocrawInfo();
if (locraw == null || locraw.getGameType() != LocrawInfo.GameType.PIT) {
return;
}

if (HytilsConfig.pitLagReducer) {
// If the entity being rendered is at spawn, and you are below spawn, cancel the rendering.
if (entity.posY > pitSpawnPos && Minecraft.getMinecraft().thePlayer.posY < pitSpawnPos) {
ci.cancel();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.polyfrost.hytils.mixin.compat;

import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawInfo;
import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil;
import club.sk1er.mods.levelhead.render.AboveHeadRender;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.client.event.RenderLivingEvent;
import org.polyfrost.hytils.config.HytilsConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static org.polyfrost.hytils.handlers.game.pit.PitLagReducer.pitSpawnPos;

@Pseudo
@Mixin(value = AboveHeadRender.class, remap = false)
public class AboveHeadRendererMixin_RemoveLevelheadPit {
@Inject(method = "render(Lnet/minecraftforge/client/event/RenderLivingEvent$Specials$Post;)V", at = @At("HEAD"), cancellable = true)
private void removeLevelhead(RenderLivingEvent.Specials.Post<EntityLivingBase> event, CallbackInfo ci) {
if (!HypixelUtils.INSTANCE.isHypixel()) {
return;
}

LocrawInfo locraw = LocrawUtil.INSTANCE.getLocrawInfo();
if (locraw == null || locraw.getGameType() != LocrawInfo.GameType.PIT) {
return;
}

if (HytilsConfig.pitLagReducer) {
// If the entity being rendered is at spawn, and you are below spawn, cancel the rendering.
if (event.entity.posY > pitSpawnPos && Minecraft.getMinecraft().thePlayer.posY < pitSpawnPos) {
ci.cancel();
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/mixins.hytils.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"MinecraftMixin_LeftClickInteract",
"MinecraftMixin_LimboLimiter",
"RenderEntityItemMixin_UHCOverlay",
"RenderingLivingEntityMixin_HideNametags",
"beds.BlockModelShapesMixin",
"beds.BlockRendererDispatcherMixin",
"beds.ModelLoaderMixin",
"compat.AboveHeadRendererMixin_RemoveLevelheadPit",
"cosmetics.RenderEntityItemMixin",
"cosmetics.WorldMixin",
"lineseparator.GuiNewChatMixin",
Expand Down

0 comments on commit 4618c6b

Please sign in to comment.