Skip to content

Commit

Permalink
initial work on 1.21 update
Browse files Browse the repository at this point in the history
  • Loading branch information
triphora committed Jun 25, 2024
1 parent 179a122 commit 5a3174b
Show file tree
Hide file tree
Showing 27 changed files with 352 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 17
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
gradle-version: release-candidate
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 17
java-version: 21
- uses: gradle/gradle-build-action@v2
with:
gradle-version: release-candidate
Expand Down
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ subprojects {
repositories {
[
['Modrinth', 'api.modrinth.com/maven', ['maven.modrinth'], []],
['NeoForge', 'maven.neoforged.net/releases', [], []],
].forEach { var mavenInfo ->
exclusiveContent {
forRepository {
Expand All @@ -34,7 +35,10 @@ subprojects {

dependencies {
minecraft libs.minecraft
mappings variantOf(libs.yarn) { classifier 'v2' }
mappings loom.layered() {
it.mappings variantOf(libs.yarn) { classifier 'v2' }
it.mappings libs.yarn.patch
}
}

loom {
Expand All @@ -59,7 +63,7 @@ allprojects {

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release.set 17
options.release.set 21
}

java.withSourcesJar()
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ dependencies {
modImplementation libs.fabric.loader
}

architectury.common 'fabric', 'forge'
architectury.common 'fabric', 'forge', 'neoforge'

loom.accessWidenerPath.set file('src/main/resources/emcutils.accesswidener')
2 changes: 1 addition & 1 deletion common/src/main/java/coffee/waffle/emcutils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public static String plural(long count) {
}

public static Identifier id(String id) {
return new Identifier(MODID, id);
return Identifier.of(MODID, id);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package coffee.waffle.emcutils.event;

import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item.TooltipContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;

import java.util.List;

@FunctionalInterface
public interface TooltipCallback {
Event<TooltipCallback> ITEM = new Event<>(TooltipCallback.class, (listeners) -> (itemStack, list, tooltipContext) -> {
for (TooltipCallback listener : listeners) listener.append(itemStack, list, tooltipContext);
Event<TooltipCallback> ITEM = new Event<>(TooltipCallback.class, (listeners) -> (itemStack, list, tooltipContext, type) -> {
for (TooltipCallback listener : listeners) listener.append(itemStack, list, tooltipContext, type);
});

void append(ItemStack itemStack, List<Text> list, TooltipContext tooltipContext);
void append(ItemStack itemStack, List<Text> list, TooltipContext tooltipContext, TooltipType type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.client.MinecraftClient;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand All @@ -15,7 +15,7 @@

public class UsableItems {
public static void init() {
TooltipCallback.ITEM.register((itemStack, list, tooltipContext) -> {
TooltipCallback.ITEM.register((itemStack, list, tooltipContext, type) -> {
if (!Util.isOnEMC || !isUsableItemWithCooldown(itemStack)) return;

for (Text text : list) {
Expand All @@ -33,14 +33,16 @@ public static void init() {
list.add(Text.of("Can be used now").copy().formatted(Formatting.GREEN));
}

itemStack.getItem().appendTooltip(itemStack, MinecraftClient.getInstance().world, list, tooltipContext);
itemStack.getItem().appendTooltip(itemStack, tooltipContext, list, type);
});
}

private static boolean isUsableItemWithCooldown(ItemStack item) {
if (item == null || item.getNbt() == null || item.getNbt().get("display") == null) return false;
if (item == null ||
item.get(DataComponentTypes.CUSTOM_DATA) == null ||
item.get(DataComponentTypes.CUSTOM_DATA).copyNbt().get("display") == null) return false;

String displayString = item.getNbt().get("display").toString();
String displayString = item.get(DataComponentTypes.CUSTOM_DATA).copyNbt().get("display").toString();

JsonObject display = JsonParser.parseString(displayString).getAsJsonObject();
JsonArray originalLore = display.getAsJsonArray("OriginalLore");
Expand All @@ -49,24 +51,27 @@ private static boolean isUsableItemWithCooldown(ItemStack item) {

if (originalLore != null) {
for (int i = 0; i < originalLore.size(); i++) {
JsonObject metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject();
JsonObject metaLine;
try {
metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject();
} catch (IllegalStateException e) {
continue;
}

if (metaLine.has("extra")) {
JsonElement extra = metaLine.getAsJsonArray("extra").get(0);

String text = extra.getAsJsonObject().get("text").getAsString();
String text = metaLine.getAsJsonArray("extra").get(0).toString();

if (text.equals("__usableItem")) usable = true;
if (text.equals("\"__usableItem\"")) usable = true;

if (text.equals("useTimer") && usable) return true;
if (text.equals("\"useTimer\"") && usable) return true;
}
}
}
return false;
}

private static long getSecondsUntilUsable(ItemStack item) {
String displayString = item.getNbt().get("display").toString();
String displayString = item.get(DataComponentTypes.CUSTOM_DATA).copyNbt().get("display").toString();

JsonObject display = JsonParser.parseString(displayString).getAsJsonObject();
JsonArray originalLore = display.getAsJsonArray("OriginalLore");
Expand All @@ -76,21 +81,24 @@ private static long getSecondsUntilUsable(ItemStack item) {
int useTimerLine = -1;

for (int i = 0; i < originalLore.size(); i++) {
JsonObject metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject();
JsonObject metaLine;
try {
metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject();
} catch (IllegalStateException e) {
continue;
}

if (metaLine.has("extra")) {
JsonElement extra = metaLine.getAsJsonArray("extra").get(0);

String text = extra.getAsJsonObject().get("text").getAsString();
String text = metaLine.getAsJsonArray("extra").get(0).toString();

if (text.equals("useTimer")) useTimerLine = i;
if (text.equals("\"useTimer\"")) useTimerLine = i;
}
}

if (useTimerLine == -1) return 0L;

long time = JsonParser.parseString(originalLore.get(useTimerLine + 1).getAsString())
.getAsJsonObject().get("text").getAsLong();
String unparsed = originalLore.get(useTimerLine + 1).getAsString();
long time = Long.parseLong(unparsed.substring(1, unparsed.length() - 1));

return Math.max(0, (time - System.currentTimeMillis()) / 1000L);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package coffee.waffle.emcutils.feature;

import coffee.waffle.emcutils.Config;
import coffee.waffle.emcutils.Util;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.blaze3d.systems.RenderSystem;
Expand All @@ -10,12 +9,11 @@
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ProfileComponent;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -59,12 +57,11 @@ private ItemStack getHead(int amount, boolean positive) {
"ZTNmYzUyMjY0ZDhhZDllNjU0ZjQxNWJlZjAxYTIzOTQ3ZWRiY2NjY2Y2NDkzNzMyODliZWE0ZDE0OTU0MWY3MC" :
"NWYxMzNlOTE5MTlkYjBhY2VmZGMyNzJkNjdmZDg3YjRiZTg4ZGM0NGE5NTg5NTg4MjQ0NzRlMjFlMDZkNTNlNi") + "J9fX0=";

stack.setCustomName(formattedText(String.format("Go %s %s page%s", positive ? "forward" : "back", amount, plural(amount))));
stack.set(DataComponentTypes.CUSTOM_NAME, formattedText(String.format("Go %s %s page%s", positive ? "forward" : "back", amount, plural(amount))));
GameProfile profile = new GameProfile(UUID.fromString("1635371d-8f8b-4a90-8495-4e7df6c946b2"), "MrFrydae");
profile.getProperties().put("textures", new Property("Value", head));

assert stack.getNbt() != null;
stack.getNbt().put("SkullOwner", NbtHelper.writeGameProfile(new NbtCompound(), profile));
stack.set(DataComponentTypes.PROFILE, new ProfileComponent(profile));

return stack;
}
Expand All @@ -81,7 +78,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
}

ItemStack chest = Items.CHEST.getDefaultStack();
chest.setCustomName(formattedText("View your vaults"));
chest.set(DataComponentTypes.CUSTOM_NAME, formattedText("View your vaults"));
drawButton(context, chest, mouseX, mouseY, slotOffsets[4], "");

//noinspection ConstantValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import coffee.waffle.emcutils.Util;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.multiplayer.ConnectScreen;
import net.minecraft.client.network.CookieStorage;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -12,8 +13,8 @@

@Mixin(ConnectScreen.class)
abstract class ConnectScreenMixin {
@Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;)V", at = @At("HEAD"))
void emcutils$onConnect(MinecraftClient client, ServerAddress address, ServerInfo info, CallbackInfo ci) {
@Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;Lnet/minecraft/client/network/CookieStorage;)V", at = @At("HEAD"))
void emcutils$onConnect(MinecraftClient client, ServerAddress address, ServerInfo info, CookieStorage cs, CallbackInfo ci) {
Util.isOnEMC = address.getAddress().matches("(.*\\.)?(emc\\.gs|empire\\.us|empireminecraft\\.com)");
}
}
2 changes: 1 addition & 1 deletion common/src/main/resources/emcutils-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "coffee.waffle.emcutils.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"client": [
"ChatScreenMixin",
"ClientPlayNetworkHandlerMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void onInitializeClient() {

HandledScreens.register(VaultScreen.GENERIC_9X7, VaultScreen::new);

ItemTooltipCallback.EVENT.register((stack, context, lines) -> {
TooltipCallback.ITEM.invoker().append(stack, lines, context);
ItemTooltipCallback.EVENT.register((stack, context, type, lines) -> {
TooltipCallback.ITEM.invoker().append(stack, lines, context, type);
});

LOG.info("Initialized " + MODID);
Expand Down
4 changes: 4 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ apply from: '../gradle/loader.gradle'

architectury.forge()

remapJar {
enabled = false
}

loom.forge {
mixinConfig 'emcutils-common.mixins.json'
convertAccessWideners.set true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public void clientSetupEvent(FMLClientSetupEvent event) {

@SubscribeEvent
public static void tooltipEvent(ItemTooltipEvent event) {
TooltipCallback.ITEM.invoker().append(event.getItemStack(), event.getToolTip(), event.getFlags());
//TooltipCallback.ITEM.invoker().append(event.getItemStack(), event.getToolTip(), event.get(), event.getFlags());
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true

mod_version=8.0.0
mod_version=9.0.0-alpha.1
42 changes: 23 additions & 19 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
[versions]
minecraft = '1.20.4'
minecraft = '1.21'

[libraries]
# MC, loaders, and mappings
minecraft = { module = 'com.mojang:minecraft', version.ref = 'minecraft' }
# https://fabricmc.net/develop
yarn = 'net.fabricmc:yarn:1.20.4+build.3'
fabric_loader = 'net.fabricmc:fabric-loader:0.15.6'
fabric_api = 'net.fabricmc.fabric-api:fabric-api:0.93.1+1.20.4'
# https://files.minecraftforge.net/net/minecraftforge/forge/index_1.20.4.html
forge = 'net.minecraftforge:forge:1.20.4-49.0.27'
yarn = 'net.fabricmc:yarn:1.21+build.2'
fabric_loader = 'net.fabricmc:fabric-loader:0.15.11'
fabric_api = 'net.fabricmc.fabric-api:fabric-api:0.100.3+1.21'
# https://maven.architectury.dev/dev/architectury/yarn-mappings-patch-neoforge/1.21%2Bbuild.4/
yarn_patch = "dev.architectury:yarn-mappings-patch-neoforge:1.21+build.4"
# https://files.minecraftforge.net/net/minecraftforge/forge/index_1.21.html
forge = 'net.minecraftforge:forge:1.21-51.0.18'
# https://neoforged.net
neoforge = 'net.neoforged:neoforge:21.0.37-beta'

# Fabric subproject
# https://modrinth.com/mod/midnightlib/version/latest?loader=fabric&game_version=1.20.4
midnightlib = 'maven.modrinth:midnightlib:1.5.3-fabric'
# https://modrinth.com/mod/modmenu/version/latest?loader=fabric&game_version=1.20.4
modmenu = 'maven.modrinth:modmenu:9.0.0'
# https://modrinth.com/mod/midnightlib/version/latest?loader=fabric&game_version=1.21
midnightlib = 'maven.modrinth:midnightlib:1.5.7-fabric'
# https://modrinth.com/mod/modmenu/version/latest?loader=fabric&game_version=1.21
modmenu = 'maven.modrinth:modmenu:11.0.1'

# Journey subproject
# https://jm.gserv.me/service/rest/repository/browse/maven-public/info/journeymap/journeymap-api/
journeymap_api = 'info.journeymap:journeymap-api:1.20.2-1.9-fabric-SNAPSHOT'
# https://modrinth.com/mod/journeymap/version/latest?loader=fabric&game_version=1.20.4
journeymap = 'maven.modrinth:journeymap:1.20.4-5.9.20-fabric'
# https://jm.gserv.me/service/rest/repository/browse/maven-public/info/journeymap/journeymap-api-fabric/
journeymap_api = 'info.journeymap:journeymap-api-fabric:2.0.0-1.21-SNAPSHOT'
# https://modrinth.com/mod/journeymap/version/latest?loader=fabric&game_version=1.21
journeymap = 'maven.modrinth:journeymap:1.20.6-5.10.0-fabric'

# Xaero subproject
# https://modrinth.com/mod/xaeros-minimap/version/latest?loader=fabric&game_version=1.20.4
xaeros_minimap = 'maven.modrinth:xaeros-minimap:23.9.7_Fabric_1.20.4'
# https://modrinth.com/mod/xaeros-world-map/version/latest?loader=fabric&game_version=1.20.4
xaeros_world_map = 'maven.modrinth:xaeros-world-map:1.37.8_Fabric_1.20.4'
# https://modrinth.com/mod/xaeros-minimap/version/latest?loader=fabric&game_version=1.21
xaeros_minimap = 'maven.modrinth:xaeros-minimap:24.2.1_Fabric_1.21'
# https://modrinth.com/mod/xaeros-world-map/version/latest?loader=fabric&game_version=1.21
xaeros_world_map = 'maven.modrinth:xaeros-world-map:1.38.8_Fabric_1.21'

[plugins]
architectury_plugin = 'architectury-plugin:3.4.+'
architectury_loom = 'dev.architectury.loom:1.4.+'
architectury_loom = 'dev.architectury.loom:1.6.+'

minotaur = 'com.modrinth.minotaur:2.+'
shadow = 'com.github.johnrengelman.shadow:8.+'
8 changes: 7 additions & 1 deletion gradle/loader.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ loom.accessWidenerPath.set commonAW

String projectName = "${name.substring(0, 1).toUpperCase()}${name.substring(1)}"

if (projectName == 'Neoforge') projectName = 'NeoForge'

configurations {
common
shadowCommon
Expand All @@ -22,9 +24,13 @@ shadowJar {
archiveClassifier = 'dev-shadow'
}

tasks.register('gabagool') {
print remapJar.getTaskDependencies().getDependencies(remapJar)
}

remapJar {
inputFile.set shadowJar.archiveFile
dependsOn shadowJar

archiveClassifier = null
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/map-integrations.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply from: '../gradle/fabric-based.gradle'

dependencies {
api project(':common')
api project(':fabric')
compileOnly project(':common')
compileOnly project(':fabric')
}

loom.enableTransitiveAccessWideners = false
Loading

0 comments on commit 5a3174b

Please sign in to comment.