mirror of
https://github.com/Lucaslah/No-Report-Button.git
synced 2026-01-05 04:57:52 +00:00
feat: add forge support
This commit is contained in:
8
common/build.gradle
Normal file
8
common/build.gradle
Normal file
@@ -0,0 +1,8 @@
|
||||
architectury {
|
||||
injectInjectables = false
|
||||
common(rootProject.properties["enabled_platforms"].split(","))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}"
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package me.lucaslah.nrb.mixin;
|
||||
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.GridWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.text.Text;
|
||||
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.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Mixin(GameMenuScreen.class)
|
||||
public abstract class GameMenuScreenMixin extends Screen {
|
||||
protected GameMenuScreenMixin(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Inject(method = "initWidgets()V", at = @At(value = "RETURN"))
|
||||
public void initWidgets(CallbackInfo ci) {
|
||||
final List<Element> widgets = ((ScreenAccessor) this).getChildren();
|
||||
List<? extends Element> buttons = null;
|
||||
|
||||
for (Element clickableWidget : widgets) {
|
||||
if (clickableWidget instanceof GridWidget widget) {
|
||||
List<? extends Element> children = widget.children();
|
||||
|
||||
if (children != null) {
|
||||
buttons = children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (buttons != null) {
|
||||
for (Element element : buttons) {
|
||||
if (element instanceof ClickableWidget button) {
|
||||
if (button.getMessage().getString().equals(I18n.translate("menu.playerReporting"))) {
|
||||
if (this.client != null) {
|
||||
button.active = this.client.isIntegratedServerRunning() && !Objects.requireNonNull(this.client.getServer()).isRemote();
|
||||
}
|
||||
|
||||
button.setMessage(Text.translatable("menu.shareToLan"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package me.lucaslah.nrb.mixin;
|
||||
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(Screen.class)
|
||||
public interface ScreenAccessor {
|
||||
@Accessor
|
||||
List<Element> getChildren();
|
||||
}
|
||||
2
common/src/main/resources/architectury.common.json
Normal file
2
common/src/main/resources/architectury.common.json
Normal file
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
BIN
common/src/main/resources/assets/noreportbutton/icon.png
Normal file
BIN
common/src/main/resources/assets/noreportbutton/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
13
common/src/main/resources/noreportbutton.mixins.json
Normal file
13
common/src/main/resources/noreportbutton.mixins.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "me.lucaslah.nrb.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"client": [
|
||||
"GameMenuScreenMixin",
|
||||
"ScreenAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user