Skip to content

Commit

Permalink
Ship MixinExtras
Browse files Browse the repository at this point in the history
Also converted couple methods to verify functionality
  • Loading branch information
aromaa committed Jan 10, 2025
1 parent f668e0d commit 415ae30
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ dependencies {
exclude(group = "org.apache.commons", module = "commons-lang3")
}
launchConfig(libs.mixin)
launchConfig(libs.mixinextras)
launchConfig(apiLibs.checkerQual)
launchConfig(libs.guava) {
exclude(group = "com.google.code.findbugs", module = "jsr305") // We don't want to use jsr305, use checkerframework
Expand Down
1 change: 1 addition & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ dependencies {
exclude(group = "org.spongepowered", module = "configurate-core")
exclude(group = "org.checkerframework", module = "checker-qual")
}
service(libs.mixinextras)

val game = gameLibrariesConfig.name
game("org.spongepowered:spongeapi:$apiVersion")
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ asm = "9.7"
log4j = "2.22.1"
forgeAutoRenamingTool = "1.0.6"
mixin = "0.8.7"
mixinextras = "0.4.1"
bootstrap = "2.1.1"
modlauncher = "10.2.1"
neo-modlauncher = "11.0.3"
Expand Down Expand Up @@ -54,6 +55,7 @@ configurate-jackson = { module = "org.spongepowered:configurate-jackson" } # ver
guava = { module = "com.google.guava:guava", version.ref = "guava" }
javaxInject = { module = "javax.inject:javax.inject", version = "1" }
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
mixinextras = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
mockito-junitJupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }

Expand Down
8 changes: 8 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,14 @@
<sha256 value="f86cf4333704813b6c48aec578f548b1f2afa5059de864e7965120ddabec9042" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="io.github.llamalad7" name="mixinextras-common" version="0.4.1">
<artifact name="mixinextras-common-0.4.1.jar">
<sha256 value="6a2c6f39f285348635ba1e0e914d066fe718c207e220a49012e8b347cb27fbda" origin="Generated by Gradle"/>
</artifact>
<artifact name="mixinextras-common-0.4.1.pom">
<sha256 value="bc224bc9bb3c376b76a673e146f548dfb5152b15f2cf0a1f1df697cf1a3acc9e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="io.github.llamalad7" name="mixinextras-neoforge" version="0.4.1">
<artifact name="mixinextras-neoforge-0.4.1.jar">
<sha256 value="9f9b6b2b1a2f376a1d62489fc8d928338d5798d69d329d2b3af7f84e420e90e9" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package org.spongepowered.common.mixin.core.server.dedicated;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.datafixers.DataFixer;
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackRequest;
Expand All @@ -38,7 +40,6 @@
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.CallbackInfo;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.adventure.SpongeAdventure;
Expand Down Expand Up @@ -85,10 +86,10 @@ protected void loadLevel() {
return this.shadow$isRunning();
}

@Redirect(method = "initServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/GameProfileCache;save()V"))
private void onSave(final GameProfileCache cache) {
@WrapOperation(method = "initServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/GameProfileCache;save()V"))
private void onSave(final GameProfileCache cache, final Operation<Void> original) {
((GameProfileCacheBridge) cache).bridge$setCanSave(true);
cache.save();
original.call(cache);
((GameProfileCacheBridge) cache).bridge$setCanSave(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
*/
package org.spongepowered.common.mixin.core.server.network;

import com.llamalad7.mixinextras.sugar.Cancellable;
import com.mojang.authlib.GameProfile;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.resource.ResourcePackCallback;
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackRequest;
import net.kyori.adventure.resource.ResourcePackStatus;
import net.minecraft.network.Connection;
import net.minecraft.network.PacketSendListener;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket;
Expand Down Expand Up @@ -91,16 +91,12 @@ public abstract class ServerCommonPacketListenerImplMixin implements ServerCommo
at = @At("HEAD"),
argsOnly = true
)
private @Nullable Packet<?> impl$onClientboundPacketSend(final Packet<?> packet) {
return this.impl$modifyClientBoundPacket(packet);
}

@Inject(method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/Packet;isTerminal()Z"), cancellable = true)
private void impl$onClientboundPacketSendCancelled(final Packet<?> $$0, final PacketSendListener $$1, final CallbackInfo ci) {
if ($$0 == null) {
private @Nullable Packet<?> impl$onClientboundPacketSend(final Packet<?> packet, @Cancellable CallbackInfo ci) {
final @Nullable Packet<?> modifiedPacket = this.impl$modifyClientBoundPacket(packet);
if (modifiedPacket == null) {
ci.cancel();
}
return modifiedPacket;
}

public @Nullable Packet<?> impl$modifyClientBoundPacket(final Packet<?> packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.spongepowered.common.mixin.plugin;

import com.llamalad7.mixinextras.MixinExtrasBootstrap;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand All @@ -38,6 +39,7 @@ public abstract class AbstractMixinConfigPlugin implements IMixinConfigPlugin {

@Override
public void onLoad(final String mixinPackage) {
MixinExtrasBootstrap.init();
}

@Override
Expand Down
1 change: 1 addition & 0 deletions vanilla/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ dependencies {
}

boot(libs.mixin)
boot(libs.mixinextras)
boot(libs.asm.tree)
boot(libs.guava) {
exclude(group = "com.google.errorprone", module = "error_prone_annotations")
Expand Down

0 comments on commit 415ae30

Please sign in to comment.