Skip to content

Commit

Permalink
Complete easy upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Jun 27, 2024
1 parent fd7d175 commit 915a818
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 108 deletions.
44 changes: 18 additions & 26 deletions src/main/java/com/connorcode/sigmautils/commands/Map.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.connorcode.sigmautils.commands;

import com.connorcode.sigmautils.mixin.MapRendererAccessor;
import com.connorcode.sigmautils.mixin.MapTextureAccessor;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.MapIdComponent;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.item.FilledMapItem;
import net.minecraft.item.ItemStack;
Expand All @@ -28,19 +28,15 @@

public class Map implements Command {
private static int save(CommandContext<FabricClientCommandSource> context) {
Optional<Pair<Integer, MapState>> rawMap = getMap(context);
Optional<Pair<MapIdComponent, MapState>> rawMap = getMap(context);
if (rawMap.isEmpty()) return 0;
int mapId = rawMap.get()
.getLeft();
MapState mapState = rawMap.get()
.getRight();
var mapId = rawMap.get().getLeft();
MapState mapState = rawMap.get().getRight();
assert client.player != null;

File mapFile = getNewFile(mapId);
try {
Objects.requireNonNull(
((MapTextureAccessor) (((MapRendererAccessor) client.gameRenderer.getMapRenderer()).invokeGetMapTexture(
mapId, mapState))).getTexture().getImage()).writeTo(mapFile);
client.gameRenderer.getMapRenderer().getMapTexture(mapId.id(), mapState).texture.getImage().writeTo(mapFile);
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -53,12 +49,10 @@ private static int save(CommandContext<FabricClientCommandSource> context) {
}

private static int info(CommandContext<FabricClientCommandSource> context) {
Optional<Pair<Integer, MapState>> rawMap = getMap(context);
Optional<Pair<MapIdComponent, MapState>> rawMap = getMap(context);
if (rawMap.isEmpty()) return 0;
int mapId = rawMap.get()
.getLeft();
MapState mapState = rawMap.get()
.getRight();
var mapId = rawMap.get().getLeft();
MapState mapState = rawMap.get().getRight();

MutableText out = Text.empty()
// Id
Expand Down Expand Up @@ -86,23 +80,22 @@ private static int info(CommandContext<FabricClientCommandSource> context) {
return 0;
}

static Optional<Pair<Integer, MapState>> getMap(CommandContext<FabricClientCommandSource> context) {
static Optional<Pair<MapIdComponent, MapState>> getMap(CommandContext<FabricClientCommandSource> context) {
assert client.player != null;

ItemStack itemStack = client.player.getInventory().getMainHandStack();
if (!itemStack.isOf(Items.FILLED_MAP) &&
Objects.requireNonNull(client.crosshairTarget).getType() == HitResult.Type.ENTITY &&
((EntityHitResult) client.crosshairTarget).getEntity() instanceof ItemFrameEntity itemFrame)
itemStack = itemFrame.getHeldItemStack();
if (!itemStack.isOf(Items.FILLED_MAP) && Objects.requireNonNull(client.crosshairTarget).getType() == HitResult.Type.ENTITY &&
((EntityHitResult) client.crosshairTarget).getEntity() instanceof ItemFrameEntity itemFrame) itemStack = itemFrame.getHeldItemStack();


if (!itemStack.isOf(Items.FILLED_MAP)) {
// if (!itemStack.isOf(Items.FILLED_MAP)) {
if (!(itemStack.getItem() instanceof FilledMapItem filledMapItem)) {
context.getSource().sendError(Text.of("You must be holding or looking at a map!"));
return Optional.empty();
}

Integer mapId = FilledMapItem.getMapId(itemStack);
MapState mapState = FilledMapItem.getMapState(mapId, client.world);
var mapId = itemStack.get(DataComponentTypes.MAP_ID);
var mapState = FilledMapItem.getMapState(mapId, client.world);
if (mapId == null) {
context.getSource().sendError(Text.of("Map ID is null?"));
return Optional.empty();
Expand All @@ -111,11 +104,10 @@ static Optional<Pair<Integer, MapState>> getMap(CommandContext<FabricClientComma
return Optional.of(new Pair<>(mapId, mapState));
}

static File getNewFile(int id) {
static File getNewFile(MapIdComponent id) {
int i = 1;
while (true) {
File file = new File(new File(client.runDirectory, "screenshots"),
String.format("map_%d%s.png", id, (i++ == 1 ? "" : "_" + i)));
File file = new File(new File(client.runDirectory, "screenshots"), String.format("map_%d%s.png", id.id(), (i++ == 1 ? "" : "_" + i)));
if (!file.exists()) return file;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void init() {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
renderBackgroundTexture(context);
renderDarkening(context);
super.render(context, mouseX, mouseY, delta);
context.fill(22, 0, width, height, 0x00000017);
}
Expand Down

This file was deleted.

This file was deleted.

21 changes: 8 additions & 13 deletions src/main/java/com/connorcode/sigmautils/modules/hud/EffectHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.connorcode.sigmautils.module.ModuleInfo;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static com.connorcode.sigmautils.SigmaUtils.client;

Expand All @@ -23,17 +25,10 @@ public EffectHud() {
public List<String> lines() {
List<String> out = new ArrayList<>();
String color = this.getTextColor();
Map<StatusEffect, StatusEffectInstance> effectMap = Objects.requireNonNull(client.player)
.getActiveStatusEffects();
Map<RegistryEntry<StatusEffect>, StatusEffectInstance> effectMap = Objects.requireNonNull(client.player).getActiveStatusEffects();

for (Map.Entry<StatusEffect, StatusEffectInstance> i : effectMap.entrySet()) {
Optional<RegistryKey<StatusEffect>> effectKey = Registries.STATUS_EFFECT.getKey(i.getKey());
if (effectKey.isEmpty()) continue;

out.add(String.format("§r%sEffect: §f%s %d %ds", color, effectKey.get()
.getValue(), i.getValue()
.getAmplifier() + 1, i.getValue()
.getDuration() / 20));
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));
}

return out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ void onRender(WorldRender.PostWorldRenderEvent event) {
var d = c | 0x80 << 24;

for (var y = minY; y <= maxY; y += step.value()) {
layer.vertex(matrices, boxX, y, boxZ).color(c).next();
layer.vertex(matrices, boxX - 128, y, boxZ).color(d).next();
layer.vertex(matrices, boxX - 128, y, boxZ).color(c).next();
layer.vertex(matrices, boxX - 128, y, boxZ - 128).color(d).next();
layer.vertex(matrices, boxX - 128, y, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX, y, boxZ - 128).color(d).next();
layer.vertex(matrices, boxX, y, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX, y, boxZ).color(d).next();
layer.vertex(matrices, boxX, y, boxZ).color(c);
layer.vertex(matrices, boxX - 128, y, boxZ).color(d);
layer.vertex(matrices, boxX - 128, y, boxZ).color(c);
layer.vertex(matrices, boxX - 128, y, boxZ - 128).color(d);
layer.vertex(matrices, boxX - 128, y, boxZ - 128).color(c);
layer.vertex(matrices, boxX, y, boxZ - 128).color(d);
layer.vertex(matrices, boxX, y, boxZ - 128).color(c);
layer.vertex(matrices, boxX, y, boxZ).color(d);
}

layer.vertex(matrices, boxX, maxY, boxZ).color(c).next();
layer.vertex(matrices, boxX - 128, minY, boxZ).color(c).next();
layer.vertex(matrices, boxX - 128, minY, boxZ).color(c).next();
layer.vertex(matrices, boxX - 128, maxY, boxZ).color(d).next();
layer.vertex(matrices, boxX, maxY, boxZ).color(c);
layer.vertex(matrices, boxX - 128, minY, boxZ).color(c);
layer.vertex(matrices, boxX - 128, minY, boxZ).color(c);
layer.vertex(matrices, boxX - 128, maxY, boxZ).color(d);

layer.vertex(matrices, boxX - 128, maxY, boxZ).color(c).next();
layer.vertex(matrices, boxX, minY, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX, minY, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX, maxY, boxZ - 128).color(d).next();
layer.vertex(matrices, boxX - 128, maxY, boxZ).color(c);
layer.vertex(matrices, boxX, minY, boxZ - 128).color(c);
layer.vertex(matrices, boxX, minY, boxZ - 128).color(c);
layer.vertex(matrices, boxX, maxY, boxZ - 128).color(d);

layer.vertex(matrices, boxX, maxY, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX - 128, minY, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX - 128, minY, boxZ - 128).color(c).next();
layer.vertex(matrices, boxX - 128, maxY, boxZ - 128).color(d).next();
layer.vertex(matrices, boxX, maxY, boxZ - 128).color(c);
layer.vertex(matrices, boxX - 128, minY, boxZ - 128).color(c);
layer.vertex(matrices, boxX - 128, minY, boxZ - 128).color(c);
layer.vertex(matrices, boxX - 128, maxY, boxZ - 128).color(d);

immediate.draw();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
import com.connorcode.sigmautils.module.ModuleInfo;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.SoulSpeedEnchantment;
import net.minecraft.enchantment.SwiftSneakEnchantment;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
Expand Down Expand Up @@ -148,8 +145,7 @@ void onPacketReceive_SetTradeOffers(PacketReceiveEvent packet) {
return;
}
case EnchantedBook -> {
if (i.getSellItem().getItem() != Items.ENCHANTED_BOOK) continue;
var data = EnchantedBookItem.getEnchantmentNbt(i.getSellItem());
if (!(i.getSellItem().getItem() instanceof EnchantedBookItem data)) continue;
var settingEnchantment = Registries.ENCHANTMENT.getId(this.enchantment.value());
for (int j = 0; j < data.size(); j++) {
var enchantment = new Identifier(data.getCompound(j).getString("id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
@ModuleInfo(description = "Shows badlion timers in the HUD",
documentation = "The Badlion client has a feature where a server can define countdown timers that will be displayed on the HUD ([image](https://user-images.githubusercontent.com/50306817/215306367-3b2b640c-898e-401b-8ee2-c97e7879e4c8.png)). This module intercepts the timer packets and renders the timers in the SigmaUtils HUD.")
public class BadlionTimers extends HudModule {
private static final Identifier BADLION_TIMER = new Identifier("badlion", "timers");
private static final EnumSetting<Util.TimeFormat> timeFormat =
new EnumSetting<>(BadlionTimers.class, "Time Format", Util.TimeFormat.class).value(Util.TimeFormat.HMS)
.description(
"The format of the time played. (HMS = Hours:Minutes:Seconds) (BestFit = 5 seconds, 3 hours")
.build();
private static final Identifier BADLION_TIMER = Identifier.of("badlion", "timers");
private static final EnumSetting<Util.TimeFormat> timeFormat = new EnumSetting<>(BadlionTimers.class, "Time Format", Util.TimeFormat.class).value(Util.TimeFormat.HMS)
.description("The format of the time played. (HMS = Hours:Minutes:Seconds) (BestFit = 5 seconds, 3 hours")
.build();
private static final List<Timer> timers = new ArrayList<>();
private static long lastTick = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void init() {
void onPacketReceive_TitleS2CPacket(PacketReceiveEvent packet) {
if (!this.enabled || !(packet.get() instanceof TitleS2CPacket title)) return;
var regex = Pattern.compile(endRegex.value());
if (!regex.matcher(title.getTitle().getString()).matches()) return;
if (!regex.matcher(title.text().getString()).matches()) return;
info("Downloading Wool");
download();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void onPacketReceive(PacketReceiveEvent packet) {
// just ignore the following todo
// TODO: Let settings convert to different types (callback on builder)
var regex = Pattern.compile(victoryRegex.value());
muted = regex.matcher(title.getTitle().getString()).matches();
muted = regex.matcher(title.text().getString()).matches();
}

if (packet.get() instanceof GameJoinS2CPacket) muted = false;
Expand Down
26 changes: 15 additions & 11 deletions src/main/resources/sigma_utils.accesswidener
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
accessWidener v1 named
# for future reference
# https://fabricmc.net/wiki/tutorial:accesswideners
accessible class net/minecraft/client/render/MapRenderer$MapTexture

## Misc ##
accessible method net/minecraft/client/font/TextRenderer tweakTransparency (I)I
accessible field net/minecraft/network/NetworkState packetHandlers Ljava/util/Map;
accessible class net/minecraft/network/NetworkState$InternalPacketHandler
accessible field net/minecraft/network/NetworkState$PacketHandler backingHandler Lnet/minecraft/network/NetworkState$InternalPacketHandler;
accessible field net/minecraft/network/NetworkState$InternalPacketHandler packetIds Lit/unimi/dsi/fastutil/objects/Object2IntMap;
accessible method net/minecraft/entity/Entity getFlag (I)Z
accessible method net/minecraft/client/gui/screen/option/OptionsScreen createButton (Lnet/minecraft/text/Text;Ljava/util/function/Supplier;)Lnet/minecraft/client/gui/widget/ButtonWidget;

## Gui Stuff ##
accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/List;
extendable method net/minecraft/client/gui/widget/ClickableWidget render (Lnet/minecraft/client/gui/DrawContext;IIF)V

## Network Stuff ##

## Map Command ##
accessible class net/minecraft/client/render/MapRenderer$MapTexture
accessible method net/minecraft/client/render/MapRenderer getMapTexture (Lnet/minecraft/component/type/MapIdComponent;Lnet/minecraft/item/map/MapState;)Lnet/minecraft/client/render/MapRenderer$MapTexture;
accessible field net/minecraft/client/render/MapRenderer$MapTexture texture Lnet/minecraft/client/texture/NativeImageBackedTexture;

## BridgeAnalisys ##
accessible field net/minecraft/client/world/ClientChunkManager chunks Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;
accessible field net/minecraft/client/world/ClientChunkManager$ClientChunkMap chunks Ljava/util/concurrent/atomic/AtomicReferenceArray;
accessible method net/minecraft/client/network/ClientPlayerInteractionManager sendSequencedPacket (Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/network/SequencedPacketCreator;)V
accessible field net/minecraft/world/chunk/PalettedContainer data Lnet/minecraft/world/chunk/PalettedContainer$Data;
accessible field net/minecraft/world/chunk/PalettedContainer paletteProvider Lnet/minecraft/world/chunk/PalettedContainer$PaletteProvider;
accessible field net/minecraft/world/chunk/PalettedContainer$Data storage Lnet/minecraft/util/collection/PaletteStorage;
accessible field net/minecraft/world/chunk/PalettedContainer$PaletteProvider edgeBits I
accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/List;
extendable method net/minecraft/client/gui/widget/ClickableWidget render (Lnet/minecraft/client/gui/DrawContext;IIF)V
accessible method net/minecraft/client/gui/widget/CheckboxWidget <init> (IILnet/minecraft/text/Text;Lnet/minecraft/client/font/TextRenderer;ZLnet/minecraft/client/gui/widget/CheckboxWidget$Callback;)V

## BridgeAnalisys ##
accessible field net/minecraft/client/world/ClientChunkManager$ClientChunkMap diameter I
accessible field net/minecraft/client/world/ClientChunkManager$ClientChunkMap radius I
accessible field net/minecraft/client/world/ClientChunkManager$ClientChunkMap centerChunkX I
Expand Down

0 comments on commit 915a818

Please sign in to comment.