Skip to content

Commit

Permalink
Merge pull request #42 from connorslade/update-mc-1.21
Browse files Browse the repository at this point in the history
Update to Minecraft 1.21
  • Loading branch information
connorslade authored Jun 29, 2024
2 parents b15b45f + 1e8f039 commit 6137bd3
Show file tree
Hide file tree
Showing 70 changed files with 517 additions and 1,022 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
strategy:
matrix:
java: [ 17 ]
java: [ 21 ]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SigmaUtils ![build](https://github.com/Basicprogrammer10/SigmaUtils/actions/workflows/build.yml/badge.svg) ![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/Basicprogrammer10/SigmaUtils?include_prereleases) ![GitHub all releases](https://img.shields.io/github/downloads/Basicprogrammer10/SigmaUtils/total)

Requires: <kbd>[Minecraft 1.20.4](https://minecraft.wiki/w/Java_Edition_1.20.4)</kbd> <kbd>[Fabric API](https://modrinth.com/mod/fabric-api/version/0.92.0+1.20.4)</kbd>
Requires: <kbd>[Minecraft 1.21](https://minecraft.wiki/w/Java_Edition_1.21)</kbd> <kbd>[Fabric API](https://modrinth.com/mod/fabric-api)</kbd>

SigmaUtils is a utility mod for Minecraft 1.20.4.
SigmaUtils is a utility mod for Minecraft 1.21.
It is made up of 'modules', which are discrete features that can be toggled and configured.
By default, SigmaUtils changes nothing about the game, except adding a button to the title screen to open the config
GUI.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.3
minecraft_version=1.21
yarn_mappings=1.21+build.4
loader_version=0.15.11
# Mod Properties
mod_version=0.1.9-alpha
mod_version=0.1.10-alpha
maven_group=com.connorcode
archives_base_name=sigma-utils
# Dependencies
fabric_version=0.92.0+1.20.4
mod_menu_version=9.0.0
fabric_version=0.100.4+1.21
mod_menu_version=11.0.1
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions src/main/java/com/connorcode/sigmautils/SigmaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@Environment(EnvType.CLIENT)
public class SigmaUtils implements ClientModInitializer {
public static final String VERSION = "0.1.9-alpha";
public static final String VERSION = "0.1.10-alpha";
public static final MinecraftClient client = MinecraftClient.getInstance();
public static final Logger logger = LogUtils.getLogger();

Expand Down Expand Up @@ -88,5 +88,5 @@ void onClientStop(GameLifecycle.ClientStoppingEvent event) throws IOException {
// TODO: camera no clip - disable culling
// TODO: Entiry selector custom type
// TODO: Allow viewing / specifing resource pack uuids

// TODO Document Hid, Meta, and Misc packages
// TODO Document Hid, Meta, and Misc packages
// TODO: fix ShowInvisableEntites opacity property
30 changes: 10 additions & 20 deletions src/main/java/com/connorcode/sigmautils/commands/About.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,17 @@

public class About implements Command {
public void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(ClientCommandManager.literal("util")
.then(ClientCommandManager.literal("about")
.executes(context -> {
var gameVersion = client.getGameVersion();
var fabricVersion = FabricLoader.getInstance()
.getModContainer("fabricloader")
.orElseThrow()
.getMetadata()
.getVersion()
.getFriendlyString();
var fabricDebug = FabricLoader.getInstance().isDevelopmentEnvironment() ? " (debug)" : "";
var sigmaUtilsVersion = SigmaUtils.VERSION;
var protocolVersion = SharedConstants.getGameVersion().getProtocolVersion();
dispatcher.register(ClientCommandManager.literal("util").then(ClientCommandManager.literal("about").executes(context -> {
var gameVersion = client.getGameVersion();
var fabricVersion = FabricLoader.getInstance().getModContainer("fabricloader").orElseThrow().getMetadata().getVersion().getFriendlyString();
var fabricDebug = FabricLoader.getInstance().isDevelopmentEnvironment() ? " (debug)" : "";
var sigmaUtilsVersion = SigmaUtils.VERSION;
var protocolVersion = SharedConstants.getGameVersion().getProtocolVersion();

var message =
Text.of(String.format("SigmaUtils v%s\nFabric v%s%s\nMinecraft v%s\nProtocol v%s",
sigmaUtilsVersion, fabricVersion, fabricDebug, gameVersion,
protocolVersion));
var message = Text.of(String.format("SigmaUtils v%s\nFabric v%s%s\nMinecraft v%s\nProtocol v%s", sigmaUtilsVersion, fabricVersion, fabricDebug, gameVersion, protocolVersion));

Objects.requireNonNull(client.player).sendMessage(message, false);
return 0;
})));
Objects.requireNonNull(client.player).sendMessage(message, false);
return 0;
})));
}
}
18 changes: 0 additions & 18 deletions src/main/java/com/connorcode/sigmautils/commands/Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.connorcode.sigmautils.SigmaUtils;
import com.connorcode.sigmautils.config.Config;
import com.connorcode.sigmautils.config.settings.*;
import com.connorcode.sigmautils.misc.util.NetworkUtils;
import com.connorcode.sigmautils.module.Category;
import com.connorcode.sigmautils.module.DocumentedEnum;
import com.connorcode.sigmautils.module.Module;
Expand Down Expand Up @@ -54,23 +53,6 @@ int execute(CommandContext<FabricClientCommandSource> context) throws IOExceptio
var dumps = directory.resolve("dump").toFile();
dumps.mkdirs();

if (resource.equals("packets")) {
StringBuilder out = new StringBuilder("# Generated with `/util dump packets` (only works in dev builds)\n");
var mr = FabricLoader.getInstance().getMappingResolver();
for (var i : NetworkUtils.getPackets()
.keySet()
.stream()
.sorted(Comparator.comparing(Class::getSimpleName))
.toList())
out.append(mr.unmapClassName("intermediary", i.getName()))
.append(" ")
.append(i.getSimpleName())
.append("\n");
Files.write(dumps.toPath().resolve("packets.txt"), out.toString().getBytes());
context.getSource().sendFeedback(Text.of("Dumped packets to " + dumps.toPath().resolve("packets.txt")));
return 0;
}

if (resource.equals("docs")) {
var docs = directory.resolve("dump").resolve("docs").toFile();
docs.mkdirs();
Expand Down
71 changes: 21 additions & 50 deletions src/main/java/com/connorcode/sigmautils/commands/Map.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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;
import net.minecraft.item.Items;
import net.minecraft.item.map.MapState;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Pair;
Expand All @@ -28,81 +27,54 @@

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, mapState).texture.getImage().writeTo(mapFile);
} catch (IOException e) {
e.printStackTrace();
}

client.player.sendMessage(Text.literal(String.format("Σ] Saved Map #%d", mapId))
client.player.sendMessage(Text.literal(String.format("[SigmaUtils::Map] Saved Map #%d", mapId.id()))
.formatted(Formatting.UNDERLINE)
.styled(style -> style.withClickEvent(
new ClickEvent(ClickEvent.Action.OPEN_FILE, mapFile.getAbsolutePath()))));
return 0;
}

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();

MutableText out = Text.empty()
// Id
.append(Text.literal("\nΣ] Id: ")
.formatted(Formatting.BOLD))
.append(Text.literal(String.valueOf(mapId))
.formatted(Formatting.RESET))

// Scale
.append(Text.literal("\nΣ] Scale: ")
.formatted(Formatting.BOLD))
.append(Text.literal(String.format("1:%d", (int) Math.pow(2, mapState.scale)))
.formatted(Formatting.RESET))

// Locked
.append(Text.literal("\nΣ] Locked: ")
.formatted(Formatting.BOLD))
.append(Text.literal(String.valueOf(mapState.locked))
.formatted(Formatting.RESET));

var mapId = rawMap.get().getLeft();
MapState mapState = rawMap.get().getRight();

var out = String.format("[SigmaUtils::Map] { ID: %d, Scale: 1:%d, Locked: %b }", mapId.id(), (int) Math.pow(2, mapState.scale), mapState.locked);
context.getSource()
.getPlayer()
.sendMessage(out);
.getPlayer().sendMessage(Text.of(out));
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 +83,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
2 changes: 0 additions & 2 deletions src/main/java/com/connorcode/sigmautils/commands/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static net.minecraft.command.CommandSource.suggestMatching;




/*
New note system:
- /util note <global | server> <new | delete | list | edit> <name>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/connorcode/sigmautils/config/ConfigGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ protected void init() {
}

public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
int padding = getPadding();
this.renderBackground(drawContext, mouseX, mouseY, delta);

int padding = getPadding();
super.render(drawContext, mouseX, mouseY, delta);

for (int x = 0; x < Category.realValues().length; x++)
drawContext.drawCenteredTextWithShadow(textRenderer,
Text.of("§f§n§l" + Category.realValues()[x].toString()),
75 + padding + x * (150 + padding), padding, 0);

super.render(drawContext, mouseX, mouseY, delta);
}

public void close() {
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,16 @@ protected ResourceAddScreen(Screen _super, ResourceManager<K> renderer) {

@Override
protected void init() {
this.searchField =
new TextFieldWidget(SigmaUtils.client.textRenderer, 0, 10, entryWidth / 2, 20, this.searchField,
Text.empty());
focusOn(this.searchField);
this.searchField = new TextFieldWidget(SigmaUtils.client.textRenderer, 0, 10, entryWidth / 2, 20, this.searchField, Text.empty());
setFocused(this.searchField);
searchField.setX(width / 2 - searchField.getWidth() / 2);
var y = padding * 6 + 30 - (int) this.scroll;
var x = 20 + padding + startX();

var search = searchField.getText();
var res = renderer.getAllResources();
count = res.size();
for (var i : res
.stream()
.filter(r -> search.isEmpty() || search(r, search))
for (var i : res.stream().filter(r -> search.isEmpty() || search(r, search))
.toList()) {
if (y < -entryHeight - padding) {
y += entryHeight + padding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,16 @@ protected ResourceSelectScreen(Screen _super, ResourceManager<K> renderer) {

@Override
protected void init() {
this.searchField =
new TextFieldWidget(SigmaUtils.client.textRenderer, 0, 10, entryWidth / 2, 20, this.searchField,
Text.empty());
focusOn(this.searchField);
this.searchField = new TextFieldWidget(SigmaUtils.client.textRenderer, 0, 10, entryWidth / 2, 20, this.searchField, Text.empty());
setFocused(this.searchField);
searchField.setX(width / 2 - searchField.getWidth() / 2);
var y = padding * 6 + 30 - (int) this.scroll;
var x = 20 + padding + startX();

var search = searchField.getText();
var res = renderer.getAllResources();
count = res.size();
for (var i : res
.stream()
.filter(r -> search.isEmpty() || search(r, search))
for (var i : res.stream().filter(r -> search.isEmpty() || search(r, search))
.toList()) {
if (y < -entryHeight - padding) {
y += entryHeight + padding;
Expand Down
Loading

0 comments on commit 6137bd3

Please sign in to comment.