Skip to content

Commit

Permalink
Abstraction of List Setting as well some changes in Notifications, Cr…
Browse files Browse the repository at this point in the history
…iticals, and some other places.
  • Loading branch information
tanishisherewithhh committed Jun 24, 2024
1 parent 59082a6 commit 381c8a0
Show file tree
Hide file tree
Showing 48 changed files with 1,042 additions and 1,564 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public Entity getTarget() {
return target;
}

@Cancelable
public static class PRE extends PlayerAttackEntityEvent {

public PRE(PlayerEntity player, Entity target) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean load() {
} catch (Exception e) {
HeliosClient.LOGGER.error("Error occurred while loading config. Loading default config....", e);

//Save the config,i.e load a new empty config.
//Save the config,i.e. load a new empty config.
save(name);
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/heliosclient/managers/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static List<EventListener> getListeners(Class<?> eventClass) {

public static void unregister(Listener listener) {
for (List<EventListener> eventListeners : new CopyOnWriteArraySet<>(listeners.values())) {
eventListeners.removeIf(el -> el.listener.getClass() == listener.getClass());
eventListeners.removeIf(el -> el.listener == listener);
}
}

Expand Down Expand Up @@ -98,6 +98,7 @@ private static void handleException(Throwable e, Listener listener, Event event)
private record EventListener(Listener listener, Method method) {
public void accept(Event event) {
try {
if(method != null)
method.invoke(listener, event);
} catch (Throwable e) {
handleException(e, listener, event);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/heliosclient/managers/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static void init() {
new NewChunks(),
new AutoNametag(),
new BetterPortals(),
new LiquidInteract(),
new Painter(),
new AutoSign(),
new Collisions(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ private static void updateNotifications() {
// Remove expired notifications
displayedNotifications.removeIf(Notification::isExpired);

updatePositions();

// Add notifications from the queue until the maximum number is reached
while (displayedNotifications.size() < MAX_DISPLAYED && !notificationQueue.isEmpty()) {
Notification notification = notificationQueue.poll();
if (notification == null) return;

notification.creationTime = System.currentTimeMillis();
displayedNotifications.addFirst(notification);
notification.playSound(notification.soundEvent, notification.volume, notification.pitch);
displayedNotifications.addFirst(notification);
updatePositions();
}

updatePositions();
}

private static void updatePositions() {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/dev/heliosclient/mixin/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import dev.heliosclient.module.modules.player.NoMiningTrace;
import dev.heliosclient.module.modules.render.NoRender;
import dev.heliosclient.module.modules.render.Zoom;
import dev.heliosclient.module.modules.world.LiquidInteract;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.hit.HitResult;
Expand All @@ -21,6 +23,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
Expand Down Expand Up @@ -71,6 +74,18 @@ private void onUpdateTargetedEntity(float tickDelta, CallbackInfo info) {
}
}

@Redirect(method = "updateTargetedEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;"))
private HitResult redirectCrosshairTargetValue(Entity entity, double maxDistance, float tickDelta, boolean includeFluids) {
if (ModuleManager.get(LiquidInteract.class).isActive()) {
HitResult result = entity.raycast(maxDistance, tickDelta, includeFluids);
if (result.getType() != HitResult.Type.MISS) return result;

return entity.raycast(maxDistance, tickDelta, true);
}
return entity.raycast(maxDistance, tickDelta, includeFluids);
}


@ModifyExpressionValue(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F"))
private float applyCameraTransformationsMathHelperLerpProxy(float original) {
return NoRender.get().isActive() && NoRender.get().noNausea.value ? 0 : original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public abstract class MixinBlockEntityRenderDispatcher {
@Inject(at = @At("HEAD"), method = "render(Lnet/minecraft/block/entity/BlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;)V", cancellable = true)
private <E extends BlockEntity> void render(E blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, CallbackInfo ci) {
if (ModuleManager.get(Xray.class).isActive() && !ModuleManager.get(Xray.class).shouldXray(BlockUtils.getBlock(blockEntity.getPos()))) {
if (!ModuleManager.get(Xray.class).shouldXray(BlockUtils.getBlock(blockEntity.getPos()))) {
ci.cancel();
}

Expand Down
55 changes: 0 additions & 55 deletions src/main/java/dev/heliosclient/mixin/MixinBlockModelRenderer.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,8 @@
package dev.heliosclient.mixin;

import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.render.Xray;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.block.BlockModelRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Credits: Meteor Client
*/
@Mixin(BlockModelRenderer.class)
public abstract class MixinBlockModelRenderer {

@Unique
private final ThreadLocal<Integer> alphas = new ThreadLocal<>();

@Inject(method = "render(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V", at = @At("HEAD"), cancellable = true)
private void onRender(BlockRenderView world, BakedModel model, BlockState state, BlockPos pos, MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random, long seed, int overlay, CallbackInfo info) {
int alpha = (int) ModuleManager.get(Xray.class).alpha.value;

if (alpha == 0) info.cancel();
else alphas.set(alpha);
}

@Inject(method = "renderQuad(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/model/BakedQuad;FFFFIIIII)V", at = @At("TAIL"))
private void onRenderQuad(BlockRenderView world, BlockState state, BlockPos pos, VertexConsumer vertexConsumer, MatrixStack.Entry matrixEntry, BakedQuad quad, float brightness0, float brightness1, float brightness2, float brightness3, int light0, int light1, int light2, int light3, int overlay, CallbackInfo ci) {
int alpha = alphas.get();
if (alpha != -1) rewriteBuffer(vertexConsumer, alpha);
}

@Unique
private void rewriteBuffer(VertexConsumer vertexConsumer, int alpha) {
if (vertexConsumer instanceof BufferBuilder bufferBuilder) {
AccessorBufferBuilder bufferBuilderAccessor = ((AccessorBufferBuilder) bufferBuilder);

int prevOffset = bufferBuilderAccessor.getElementOffset();

if (prevOffset > 0) {
int i = bufferBuilderAccessor.getVertexFormat().getVertexSizeByte();

for (int l = 1; l <= 4; l++) {
bufferBuilderAccessor.setElementOffset(prevOffset - i * l);
bufferBuilder.putByte(15, (byte) (alpha));
}

bufferBuilderAccessor.setElementOffset(prevOffset);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void onAttackEntity(PlayerEntity player, Entity target, CallbackInfo ci)
@Inject(method = "attackEntity", at = @At(value = "HEAD"), cancellable = true)
private void onAttackEntityPRE(PlayerEntity player, Entity target, CallbackInfo ci) {
Freecam freecam = ModuleManager.get(Freecam.class);
if(freecam.isActive() && player instanceof FreeCamEntity && target == client.player){
if(freecam.isActive() && target == client.player){
ci.cancel();
}

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/dev/heliosclient/mixin/MixinPlayerEntity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package dev.heliosclient.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import dev.heliosclient.HeliosClient;
import dev.heliosclient.event.events.player.*;
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.movement.Sprint;
import dev.heliosclient.module.modules.world.SpeedMine;
import dev.heliosclient.util.BlockUtils;
import dev.heliosclient.util.player.FreeCamEntity;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
Expand All @@ -17,17 +18,23 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.stat.Stat;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
public abstract class MixinPlayerEntity extends LivingEntity {
@Shadow public abstract void increaseStat(Stat<?> stat, int amount);

protected MixinPlayerEntity(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);

Expand Down Expand Up @@ -72,6 +79,16 @@ public float ongetBlockBreakingSpeed(float ogBreakSpeed, BlockState block) {

return ogBreakSpeed;
}
@WrapWithCondition(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"))
private boolean keepSprint$setVelocity(PlayerEntity instance, Vec3d vec3d) {
return ModuleManager.get(Sprint.class).shouldStopSprinting();
}

@Redirect(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setSprinting(Z)V"))
private void onAttack$setSprinting(PlayerEntity instance, boolean b) {
instance.setSprinting(ModuleManager.get(Sprint.class).shouldStopSprinting());
}


@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
private void onPlayerDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
Expand Down
15 changes: 1 addition & 14 deletions src/main/java/dev/heliosclient/mixin/MixinRenderLayers.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
package dev.heliosclient.mixin;

import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.modules.render.Xray;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
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.CallbackInfoReturnable;

@Mixin(RenderLayers.class)
public abstract class MixinRenderLayers {
@Inject(method = "getBlockLayer", at = @At("HEAD"), cancellable = true)
private static void setBlockLayer(BlockState state, CallbackInfoReturnable<RenderLayer> info) {
int alpha = (int) ModuleManager.get(Xray.class).alpha.value;
if (ModuleManager.get(Xray.class).isActive() && !ModuleManager.get(Xray.class).shouldXray(state.getBlock()) && alpha > 0 && alpha < 255) {
info.setReturnValue(RenderLayer.getTranslucent());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.heliosclient.mixin;

import dev.heliosclient.system.mixininterface.IPlayerInteractEntityC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;


@Mixin(PlayerInteractEntityC2SPacket.class)
public abstract class PlayerInteractEntityC2SPacketMixin implements IPlayerInteractEntityC2SPacket {
@Shadow
@Final
private PlayerInteractEntityC2SPacket.InteractTypeHandler type;

@Override
@SuppressWarnings("all")
public PlayerInteractEntityC2SPacket.InteractType getType() {
return type.getType();
}
}
Loading

0 comments on commit 381c8a0

Please sign in to comment.