-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more mixins, and actually apply them
- Loading branch information
Showing
8 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/gregtech/mixins/mui2/ClientEventHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gregtech.mixins.mui2; | ||
|
||
import net.minecraftforge.client.event.GuiScreenEvent; | ||
|
||
import com.cleanroommc.modularui.ClientEventHandler; | ||
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; | ||
|
||
@Mixin(value = ClientEventHandler.class, remap = false) | ||
@SuppressWarnings("UnstableApiUsage") | ||
public abstract class ClientEventHandlerMixin { | ||
|
||
@Inject(method = "onGuiInput(Lnet/minecraftforge/client/event/GuiScreenEvent$MouseInputEvent$Pre;)V", | ||
at = @At("HEAD"), | ||
cancellable = true) | ||
private static void fixMouseInput(GuiScreenEvent.MouseInputEvent.Pre event, CallbackInfo ci) { | ||
ci.cancel(); | ||
} | ||
|
||
@Inject(method = "onGuiInput(Lnet/minecraftforge/client/event/GuiScreenEvent$KeyboardInputEvent$Pre;)V", | ||
at = @At("HEAD"), | ||
cancellable = true) | ||
private static void fixKeyInput(GuiScreenEvent.KeyboardInputEvent.Pre event, CallbackInfo ci) { | ||
ci.cancel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/gregtech/mixins/mui2/PanelSyncHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package gregtech.mixins.mui2; | ||
|
||
import com.cleanroommc.modularui.api.widget.ISynced; | ||
import com.cleanroommc.modularui.screen.ModularPanel; | ||
import com.cleanroommc.modularui.value.sync.ModularSyncManager; | ||
import com.cleanroommc.modularui.value.sync.PanelSyncHandler; | ||
import com.cleanroommc.modularui.value.sync.PanelSyncManager; | ||
import com.cleanroommc.modularui.widget.WidgetTree; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
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 java.util.concurrent.atomic.AtomicInteger; | ||
|
||
@Mixin(PanelSyncHandler.class) | ||
public abstract class PanelSyncHandlerMixin { | ||
|
||
@Shadow | ||
private PanelSyncManager syncManager; | ||
|
||
@Shadow | ||
public abstract boolean isPanelOpen(); | ||
|
||
@Redirect(method = "openPanel(Z)V", | ||
at = @At(value = "INVOKE", | ||
target = "Lcom/cleanroommc/modularui/widget/WidgetTree;collectSyncValues(Lcom/cleanroommc/modularui/value/sync/PanelSyncManager;Lcom/cleanroommc/modularui/screen/ModularPanel;)V")) | ||
protected void redirectCollectValues(PanelSyncManager syncManager, ModularPanel panel) { | ||
gregTech$collectSyncValues(this.syncManager, panel); | ||
} | ||
|
||
@Inject(method = "openPanel(Z)V", at = @At("HEAD"), cancellable = true) | ||
protected void openCheck(boolean syncToServer, CallbackInfo ci) { | ||
if (isPanelOpen()) ci.cancel(); | ||
} | ||
|
||
@Unique | ||
private static void gregTech$collectSyncValues(PanelSyncManager syncManager, ModularPanel panel) { | ||
AtomicInteger id = new AtomicInteger(0); | ||
String syncKey = ModularSyncManager.AUTO_SYNC_PREFIX + panel.getName(); | ||
WidgetTree.foreachChildBFS(panel, widget -> { | ||
if (widget instanceof ISynced<?>synced) { | ||
if (synced.isSynced() && !syncManager.hasSyncHandler(synced.getSyncHandler())) { | ||
syncManager.syncValue(syncKey, id.getAndIncrement(), synced.getSyncHandler()); | ||
} | ||
} | ||
return true; | ||
}, false); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/gregtech/mixins/mui2/PanelSyncManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gregtech.mixins.mui2; | ||
|
||
import gregtech.api.util.GTLog; | ||
|
||
import net.minecraft.network.PacketBuffer; | ||
|
||
import com.cleanroommc.modularui.value.sync.PanelSyncManager; | ||
import com.cleanroommc.modularui.value.sync.SyncHandler; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
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.Map; | ||
|
||
@Mixin(PanelSyncManager.class) | ||
public abstract class PanelSyncManagerMixin { | ||
|
||
@Shadow | ||
@Final | ||
private Map<String, SyncHandler> syncHandlers; | ||
|
||
@Shadow | ||
private String panelName; | ||
|
||
@Inject(method = "receiveWidgetUpdate", at = @At("HEAD"), cancellable = true) | ||
public void injectCheck(String mapKey, int id, PacketBuffer buf, CallbackInfo ci) { | ||
if (!this.syncHandlers.containsKey(mapKey)) { | ||
GTLog.logger.warn("[ModularUI] SyncHandler \"{}\" does not exist for panel \"{}\"! ID was {}.", mapKey, | ||
panelName, id); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package gregtech.mixins.mui2; | ||
|
||
import com.cleanroommc.modularui.api.drawable.IKey; | ||
import com.cleanroommc.modularui.drawable.text.AnimatedText; | ||
import com.cleanroommc.modularui.drawable.text.StyledText; | ||
import com.cleanroommc.modularui.utils.Alignment; | ||
import com.cleanroommc.modularui.widgets.TextWidget; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(value = StyledText.class, remap = false) | ||
public class StyledTextMixin { | ||
|
||
@Shadow | ||
@Final | ||
private IKey key; | ||
|
||
@Shadow | ||
private Alignment alignment; | ||
|
||
@Shadow | ||
private Integer color; | ||
|
||
@Shadow | ||
private float scale; | ||
|
||
@Shadow | ||
private Boolean shadow; | ||
|
||
/** | ||
* @author GTCEu - Ghzdude | ||
* @reason Implement <a href="https://github.com/CleanroomMC/ModularUI/pull/86">MUI2 PR#86</a> | ||
*/ | ||
@Overwrite | ||
public TextWidget asWidget() { | ||
int color = this.color == null ? 0 : this.color; | ||
boolean shadow = this.shadow == null || this.shadow; | ||
return new TextWidget(this.key) | ||
.alignment(this.alignment) | ||
.color(color) | ||
.scale(this.scale) | ||
.shadow(shadow); | ||
} | ||
|
||
/** | ||
* @author GTCEu - Ghzdude | ||
* @reason Implement <a href="https://github.com/CleanroomMC/ModularUI/pull/86">MUI2 PR#86</a> | ||
*/ | ||
@Overwrite | ||
public AnimatedText withAnimation() { | ||
int color = this.color == null ? 0 : this.color; | ||
boolean shadow = this.shadow == null || this.shadow; | ||
return new AnimatedText(this.key) | ||
.alignment(this.alignment) | ||
.color(color) | ||
.scale(this.scale) | ||
.shadow(shadow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package gregtech.mixins.mui2; | ||
|
||
import com.cleanroommc.modularui.widgets.TextWidget; | ||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(value = TextWidget.class, remap = false) | ||
public class TextWidgetMixin { | ||
|
||
@ModifyReturnValue(method = { "getDefaultHeight", "getDefaultWidth" }, at = @At("TAIL")) | ||
public int clamp(int r) { | ||
return Math.max(1, r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters