Skip to content

Commit

Permalink
Real world bug fixes
Browse files Browse the repository at this point in the history
- Incorrect effect names
- Opaque invis entities
- Not fireing unknown packet events
  • Loading branch information
connorslade committed Jun 29, 2024
1 parent 083c406 commit 1e8f039
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 20 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/connorcode/sigmautils/misc/Consts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.connorcode.sigmautils.misc;

import net.minecraft.util.Identifier;

public class Consts {
public static final Identifier DUMMY_IDENT = Identifier.ofVanilla("dummy");
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static com.connorcode.sigmautils.misc.Consts.DUMMY_IDENT;

@Mixin(ClientCommonNetworkHandler.class)
public class ClientCommonNetworkHandlerMixin {
@Inject(method = "onCustomPayload", at = @At("HEAD"))
@Inject(method = "onCustomPayload(Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;)V", at = @At("HEAD"), cancellable = true)
void onCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) {
// var buf = packet.getPayload();
// var event = new UnknownPacketEvent(buf, packet.payload().getId().id());
System.out.println("CUSTOM PAYLOAD:" + packet.payload().getClass().getSimpleName());
if (packet.payload().getId().id() == DUMMY_IDENT) ci.cancel();
}
}


// @Inject(method = "readPayload", at = @At("HEAD"), cancellable = true)
// private static void onReadPayload(Identifier id, PacketByteBuf buf, CallbackInfoReturnable<CustomPayload> cir) {
// if (ID_TO_READER.containsKey(id)) return;
//
// var event = new UnknownPacketEvent(buf, id);
// SigmaUtils.eventBus.post(event);
//
// if (event.isCancelled()) cir.setReturnValue(new CancelledUnknownPacket(id));
// else cir.setReturnValue(readUnknownPayload(id, buf));
// }
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@

import com.connorcode.sigmautils.config.Config;
import com.connorcode.sigmautils.modules.rendering.FlippedEntities;
import com.connorcode.sigmautils.modules.rendering.ShowInvisibleEntities;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntityRenderer.class)
public class LivingEntityRendererMixin<T extends LivingEntity, M extends EntityModel<T>> {
@Inject(method = "shouldFlipUpsideDown", at = @At("HEAD"), cancellable = true)
private static void shouldFlipUpsideDown(LivingEntity entity, CallbackInfoReturnable<Boolean> cir) {
if (Config.getEnabled(FlippedEntities.class) && FlippedEntities.isFlipped(entity))
cir.setReturnValue(true);
if (Config.getEnabled(FlippedEntities.class) && FlippedEntities.isFlipped(entity)) cir.setReturnValue(true);
}

@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;isVisible(Lnet/minecraft/entity/LivingEntity;)Z"))
boolean isVisible(LivingEntityRenderer<T, M> livingEntityRenderer, T entity) {
return !entity.getFlag(5);
}

@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isInvisibleTo(Lnet/minecraft/entity/player/PlayerEntity;)Z"))
boolean isVisibleTo(LivingEntity instance, PlayerEntity playerEntity) {
if (Config.getEnabled(ShowInvisibleEntities.class) && ShowInvisibleEntities.isVisible(instance)) return false;
return instance.isInvisibleTo(playerEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class OptionsScreenMixin extends Screen {

@Unique
void positionButton() {
if (soundButton == null) return;
muteButton.setX(soundButton.getX() + soundButton.getWidth() + 5);
muteButton.setY(soundButton.getY());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.connorcode.sigmautils.mixin;

import com.connorcode.sigmautils.SigmaUtils;
import com.connorcode.sigmautils.event.network.UnknownPacketEvent;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.UnknownCustomPayload;
import net.minecraft.util.Identifier;
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;

import static com.connorcode.sigmautils.misc.Consts.DUMMY_IDENT;

@Mixin(UnknownCustomPayload.class)
public class UnknownCustomPayloadMixin {
@Inject(method = "method_56491(ILnet/minecraft/util/Identifier;Lnet/minecraft/network/PacketByteBuf;)Lnet/minecraft/network/packet/UnknownCustomPayload;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;skipBytes(I)Lnet/minecraft/network/PacketByteBuf;", shift = At.Shift.BEFORE), cancellable = true)
private static void onUnknownCustomPayload(int i, Identifier identifier, PacketByteBuf buf, CallbackInfoReturnable<UnknownCustomPayload> cir) {
var event = new UnknownPacketEvent(buf, identifier);
SigmaUtils.eventBus.post(event);
if (event.isCancelled()) cir.setReturnValue(new UnknownCustomPayload(DUMMY_IDENT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -28,7 +29,9 @@ public List<String> lines() {
Map<RegistryEntry<StatusEffect>, StatusEffectInstance> effectMap = Objects.requireNonNull(client.player).getActiveStatusEffects();

for (var i : effectMap.entrySet()) {
out.add(String.format("§r%sEffect: §f%s %d %ds", color, i.getKey().value(), i.getValue().getAmplifier() + 1, i.getValue().getDuration() / 20));
var name = Text.translatable(i.getValue().getTranslationKey()).getString();
out.add(String.format("§r%sEffect: §f%s %d %ds", color, name, i.getValue().getAmplifier() + 1, i.getValue()
.getDuration() / 20));
}

return out;
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/sigma-utils.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
"UnknownCustomPayloadMixin"
]
}

0 comments on commit 1e8f039

Please sign in to comment.