Skip to content

Commit

Permalink
BackendSimpleGui fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Oct 1, 2024
1 parent a29f333 commit b3e89f5
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 4 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ repositories {
}
}

loom.splitEnvironmentSourceSets()
loom {
accessWidenerPath = file("src/main/resources/${mod_id}.accesswidener")
splitEnvironmentSourceSets()
}

sourceSets {
test {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ audience_version=2.11.1
sgui_version=1.6.1+1.21.1

# Mod Properties
mod_version=1.5.2
mod_version=1.6.0
maven_group=net.mcbrawls
mod_id=brawls-sgui

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/net/mcbrawls/sgui/mixin/BackendSimpleGuiMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.mcbrawls.sgui.mixin;

import eu.pb4.sgui.api.gui.GuiInterface;
import eu.pb4.sgui.api.gui.SlotGuiInterface;
import eu.pb4.sgui.api.gui.layered.LayeredGui;
import net.mcbrawls.sgui.ParentedGui;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

@Mixin(targets = { "eu.pb4.sgui.api.gui.layered.BackendSimpleGui" }, remap = false)
public abstract class BackendSimpleGuiMixin implements SlotGuiInterface, ParentedGui {
@Shadow @Final public LayeredGui gui;

@Unique
@Override
public @Nullable GuiInterface getParent() {
return ParentedGui.Companion.getGuiParent(this.gui);
}

@Unique
@Override
public void setParent(@Nullable GuiInterface parent) {
ParentedGui.Companion.setGuiParent(this.gui, parent);
}

@Override
public void onClose() {
GuiInterface firstParent = ParentedGui.Companion.getFirstParent(this.gui);
if (firstParent != null && !firstParent.canPlayerClose()) {
firstParent.open();
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/net/mcbrawls/sgui/mixin/BaseSlotMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.mcbrawls.sgui.mixin;

import eu.pb4.sgui.api.gui.BaseSlotGui;
import eu.pb4.sgui.api.gui.GuiInterface;
import eu.pb4.sgui.api.gui.SlotGuiInterface;
import net.mcbrawls.sgui.ParentedGui;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(BaseSlotGui.class)
public abstract class BaseSlotMixin implements SlotGuiInterface, ParentedGui {
@Unique
@Nullable
private GuiInterface parent = null;

@Unique
@Override
public @Nullable GuiInterface getParent() {
return this.parent;
}

@Unique
@Override
public void setParent(@Nullable GuiInterface parent) {
this.parent = parent;
}

@Override
public void onClose() {
GuiInterface firstParent = ParentedGui.Companion.getFirstParent(this);
if (firstParent != null && !firstParent.canPlayerClose()) {
firstParent.open();
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/net/mcbrawls/sgui/ParentedGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ParentedGui {
/**
* Sets this GUI's parent GUI.
*/
fun GuiInterface.setGuiParent(parent: GuiInterface) : GuiInterface {
fun GuiInterface.setGuiParent(parent: GuiInterface?) : GuiInterface {
val parented = this as? ParentedGui ?: return this
parented.parent = parent
return this
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/brawls-sgui.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
accessWidener v2 named
2 changes: 2 additions & 0 deletions src/main/resources/brawls-sgui.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"minVersion": "0.8",
"package": "net.mcbrawls.sgui.mixin",
"mixins": [
"BackendSimpleGuiMixin",
"BaseSlotMixin",
"LayeredGuiMixin"
],
"compatibilityLevel": "JAVA_17",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"fabric-language-kotlin": ">=1.9",
"sgui": "*"
},
"mixins": [ "brawls-sgui.mixins.json" ]
"mixins": [ "brawls-sgui.mixins.json" ],
"accessWidener": "brawls-sgui.accesswidener"
}

0 comments on commit b3e89f5

Please sign in to comment.