Skip to content

Commit

Permalink
Chat open close animation
Browse files Browse the repository at this point in the history
  • Loading branch information
pastimee committed May 5, 2024
1 parent f4b423f commit ebb2651
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void buildCommand(LiteralArgumentBuilder<CommandSource> builder) {
ChatUtil.error("No Nbt tags on this item!");
return 0;
}
ChatUtil.clientSendMessage(mc.player.getMainHandStack().getNbt().toString());
ChatUtil.clientSendMessage(mainhand.getNbt().toString());
return 1;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import net.shoreline.client.api.command.Command;
import net.shoreline.client.util.chat.ChatUtil;

public class SoundReloadCommand extends Command {
public SoundReloadCommand() {
super("SoundReload", "Reloads the Minecraft sound system", literal("soundreload"));
public class ReloadSoundCommand extends Command {
public ReloadSoundCommand() {
super("ReloadSound", "Reloads the Minecraft sound system", literal("reloadsound"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CommandManager() {
new OpenFolderCommand(),
new PrefixCommand(),
new ResetCommand(),
new SoundReloadCommand(),
new ReloadSoundCommand(),
new ToggleCommand(),
new VanishCommand(),
new VClipCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
import net.shoreline.client.api.module.ModuleCategory;
import net.shoreline.client.api.module.ToggleModule;
import net.shoreline.client.api.render.RenderManager;
import net.shoreline.client.impl.event.ScreenOpenEvent;
import net.shoreline.client.impl.event.gui.hud.RenderOverlayEvent;
import net.shoreline.client.init.Managers;
import net.shoreline.client.init.Modules;
import net.shoreline.client.util.StreamUtils;
import net.shoreline.client.util.render.ColorUtil;
import net.shoreline.client.util.render.animation.Animation;
import net.shoreline.client.util.render.animation.Easing;
import net.shoreline.client.util.string.EnumFormatter;

import java.awt.*;
import java.text.DecimalFormat;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -74,9 +75,10 @@ public class HUDModule extends ToggleModule {
//
private final DecimalFormat decimal = new DecimalFormat("0.0");

int rainbowOffset;
float topLeft, topRight, bottomLeft, bottomRight;
boolean renderingUp;
private int rainbowOffset;
private float topLeft, topRight, bottomLeft, bottomRight;
private boolean renderingUp;
private final Animation chatOpenAnimation = new Animation(false, 200L, Easing.LINEAR);

public HUDModule() {
super("HUD", "Displays the HUD (heads up display) screen.",
Expand Down Expand Up @@ -118,10 +120,8 @@ public void onRenderOverlayPost(RenderOverlayEvent.Post event) {
bottomRight = bottomLeft;
// center = res.getScaledHeight() - 11 / 2.0f
renderingUp = renderingConfig.getValue() == Rendering.UP;
if (mc.currentScreen instanceof ChatScreen) {
bottomLeft -= 14.0f;
bottomRight -= 14.0f;
}
bottomLeft -= (float) (14.0f * chatOpenAnimation.getFactor());
bottomRight -= (float) (14.0f * chatOpenAnimation.getFactor());
if (potionHudConfig.getValue() == VanillaHud.MOVE
&& !mc.player.getStatusEffects().isEmpty()) {
topRight += 27.0f;
Expand All @@ -143,7 +143,6 @@ public void onRenderOverlayPost(RenderOverlayEvent.Post event) {
case ALPHABETICAL -> StreamUtils.sortCached(moduleStream, Module::getName);
case LENGTH -> StreamUtils.sortCached(moduleStream, m -> -RenderManager.textWidth(getFormattedModule(m)));
};

moduleStream.forEach(t -> arrayListRenderModule(event, t));
}
if (potionEffectsConfig.getValue()) {
Expand Down Expand Up @@ -321,6 +320,15 @@ public void onRenderOverlayPost(RenderOverlayEvent.Post event) {
}
}

@EventListener
public void onChatOpen(ScreenOpenEvent event) {
if (event.getScreen() == null && chatOpenAnimation.getState()) {
chatOpenAnimation.setState(false);
} else if (event.getScreen() instanceof ChatScreen) {
chatOpenAnimation.setState(true);
}
}

@EventListener
public void onRenderOverlayStatusEffect(RenderOverlayEvent.StatusEffect event) {
if (potionHudConfig.getValue() == VanillaHud.HIDE) {
Expand Down Expand Up @@ -386,6 +394,10 @@ public static int alpha(long offset) {
return Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
}

public float getChatAnimation() {
return (float) chatOpenAnimation.getFactor();
}

public enum VanillaHud {
MOVE,
HIDE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author xgraza
* @since 1.0
*/
public final class BackTrackModule extends ToggleModule
public final class BacktrackModule extends ToggleModule
{
Config<Integer> delayConfig = new NumberConfig<>("Delay", "The delay before throttling packets again", 0, 100, 1000);

Expand All @@ -42,9 +42,9 @@ public final class BackTrackModule extends ToggleModule
private Vec3d lastServerPos, serverPos;
private Box hitBox;

public BackTrackModule()
public BacktrackModule()
{
super("BackTrack", "funny", ModuleCategory.COMBAT);
super("Backtrack", "funny", ModuleCategory.COMBAT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
package net.shoreline.client.impl.module.combat;

import net.minecraft.entity.LivingEntity;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.common.CommonPingS2CPacket;
import net.minecraft.network.packet.s2c.common.KeepAliveS2CPacket;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.shoreline.client.api.config.Config;
import net.shoreline.client.api.config.setting.NumberConfig;
import net.shoreline.client.api.event.listener.EventListener;
import net.shoreline.client.api.module.ModuleCategory;
import net.shoreline.client.api.module.ToggleModule;
import net.shoreline.client.api.render.RenderManager;
import net.shoreline.client.impl.event.network.PacketEvent;
import net.shoreline.client.impl.event.network.PlayerTickEvent;
import net.shoreline.client.impl.event.render.RenderWorldEvent;
import net.shoreline.client.init.Managers;
import net.shoreline.client.init.Modules;
import net.shoreline.client.util.math.timer.TickTimer;
import net.shoreline.client.util.math.timer.Timer;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
* @author xgraza
* @since 1.0
*/
public final class BacktrackModule extends ToggleModule
{
Config<Integer> delayConfig = new NumberConfig<>("Delay", "The delay before throttling packets again", 0, 100, 1000);

private final Queue<Packet<?>> packetQueue = new ConcurrentLinkedQueue<>();
private boolean blockingPackets;

private final Timer timer = new TickTimer();
private LivingEntity attackingEntity;
private PacketListener packetListener;
private Vec3d lastServerPos, serverPos;
private Box hitBox;

public BacktrackModule()
{
super("Backtrack", "funny", ModuleCategory.COMBAT);
}

@Override
protected void onDisable()
{
super.onDisable();

if (packetListener != null)
{
emptyPackets();
}
packetQueue.clear();
packetListener = null;

serverPos = null;
attackingEntity = null;
hitBox = null;
}

@EventListener
public void onPacketInbound(final PacketEvent.Inbound event)
{
if (mc.world != null && mc.player != null)
{
packetListener = event.getPacketListener();
}
else
{
packetQueue.clear();
blockingPackets = false;
}

if (event.getPacket() instanceof EntityPositionS2CPacket packet)
{
if (attackingEntity != null && attackingEntity.getId() == packet.getId())
{
lastServerPos = serverPos;
serverPos = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
}
}

if (!blockingPackets || packetListener == null)
{
return;
}

if (shouldCancelPacket(event.getPacket()))
{
event.setCanceled(true);
packetQueue.add(event.getPacket());
}
}

@EventListener
public void onPlayerTick(final PlayerTickEvent event)
{
final AuraModule auraModule = Modules.AURA;
if (!auraModule.isEnabled() || !(auraModule.getEntityTarget() instanceof LivingEntity auraTarget))
{
attackingEntity = null;
if (blockingPackets)
{
emptyPackets();
}
blockingPackets = false;
serverPos = null;
lastServerPos = null;
hitBox = null;
return;
}

attackingEntity = auraTarget;

if (!timer.passed(delayConfig.getValue() / 50))
{
return;
}

if (hitBox != null)
{
final Vec3d eyes = Managers.POSITION.getEyePos();
final double dist = eyes.distanceTo(attackingEntity.getPos());
if (!auraModule.isInAttackRange(dist, eyes, attackingEntity.getPos()) && dist <= auraModule.searchRangeConfig.getValue())
{
blockingPackets = true;
}
else
{
blockingPackets = false;
timer.reset();
emptyPackets();
}
}
}

@EventListener
public void onRenderWorld(final RenderWorldEvent event)
{
if (mc.player == null || mc.world == null)
{
return;
}

hitBox = getBackTrackedBox(event.getTickDelta());

if (hitBox != null)
{
RenderManager.renderBox(event.getMatrices(), hitBox, Modules.COLORS.getRGB(120));
RenderManager.renderBoundingBox(event.getMatrices(), hitBox, 1.5f, Modules.COLORS.getRGB());
}
}

private Box getBackTrackedBox(final float tickDelta)
{
if (serverPos == null || attackingEntity == null)
{
return null;
}

// final double intX = MathHelper.lerp(tickDelta, lastServerPos.x, serverPos.x);
// final double intY = MathHelper.lerp(tickDelta, lastServerPos.y, serverPos.y);
// final double intZ = MathHelper.lerp(tickDelta, lastServerPos.z, serverPos.z);

return attackingEntity.getDimensions(attackingEntity.getPose()).getBoxAt(serverPos.x, serverPos.y, serverPos.z);
}

private boolean shouldCancelPacket(final Packet<?> packet)
{
if (Modules.VELOCITY.isEnabled())
{
return !(packet instanceof EntityVelocityUpdateS2CPacket || packet instanceof ExplosionS2CPacket);
}

return !(packet instanceof HealthUpdateS2CPacket
|| packet instanceof PlaySoundS2CPacket
|| packet instanceof StopSoundS2CPacket
|| packet instanceof EntitySpawnS2CPacket
|| packet instanceof EntityStatusS2CPacket
|| packet instanceof TeamS2CPacket
|| packet instanceof CommonPingS2CPacket
|| packet instanceof KeepAliveS2CPacket);
}

private void emptyPackets()
{
if (packetQueue.isEmpty() || packetListener == null)
{
return;
}

while (!packetQueue.isEmpty())
{
final Packet<?> polled = packetQueue.poll();
if (polled == null)
{
break;
}

packetListener.accepts(polled);
}
}
}
Loading

0 comments on commit ebb2651

Please sign in to comment.