Skip to content

Commit

Permalink
I love mixins, goodbye reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru committed Oct 1, 2024
1 parent 5043f73 commit 6dd99ab
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 63 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ apiPackage = api
accessTransformersFile =

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
usesMixins = true

# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =

# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false
usesMixinDebug = true

# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =

# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage =
mixinsPackage = mixin.mixins

# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass =
coreModClass = mixin.EarlyMixinLoader

# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import com.github.dcysteine.neicustomdiagram.api.draw.Dimension;
import com.github.dcysteine.neicustomdiagram.api.draw.Point;
import com.github.dcysteine.neicustomdiagram.main.Reflection;
import com.github.dcysteine.neicustomdiagram.main.config.ConfigOptions;
import com.github.dcysteine.neicustomdiagram.mixin.mixins.early.GuiContainerAccessor;

import codechicken.lib.gui.GuiDraw;
import codechicken.nei.recipe.GuiRecipe;
Expand Down Expand Up @@ -113,8 +113,8 @@ public Point getRelativeMousePosition(int recipe) {
java.awt.Point mouse = GuiDraw.getMousePosition();
java.awt.Point offset = gui.getRecipePosition(recipe);

int x = mouse.x + horizontalScrollbar.getScroll() - (Reflection.GUI_LEFT.get(gui) + offset.x);
int y = mouse.y + verticalScrollbar.getScroll() - (Reflection.GUI_TOP.get(gui) + offset.y);
int x = mouse.x + horizontalScrollbar.getScroll() - (((GuiContainerAccessor) gui).getGuiLeft() + offset.x);
int y = mouse.y + verticalScrollbar.getScroll() - (((GuiContainerAccessor) gui).getGuiTop() + offset.y);
return Point.create(x, y);
}

Expand All @@ -132,7 +132,9 @@ Point getViewportPosition() {
}
GuiRecipe<?> gui = guiOptional.get();

return Point.create(Reflection.GUI_LEFT.get(gui) + SIDE_MARGIN, Reflection.GUI_TOP.get(gui) + TOP_MARGIN);
return Point.create(
((GuiContainerAccessor) gui).getGuiLeft() + SIDE_MARGIN,
((GuiContainerAccessor) gui).getGuiTop() + TOP_MARGIN);
}

Dimension getViewportDimension() {
Expand All @@ -144,8 +146,8 @@ Dimension getViewportDimension() {
GuiRecipe<?> gui = guiOptional.get();

return Dimension.create(
Reflection.X_SIZE.get(gui) - 2 * SIDE_MARGIN,
Reflection.Y_SIZE.get(gui) - (TOP_MARGIN + BOTTOM_MARGIN));
((GuiContainerAccessor) gui).getXSize() - 2 * SIDE_MARGIN,
((GuiContainerAccessor) gui).getYSize() - (TOP_MARGIN + BOTTOM_MARGIN));
}

private void setScissor() {
Expand All @@ -162,7 +164,7 @@ private void setScissor() {
final int guiLeft = (int) matBuf.get(12);
final int guiTop = (int) matBuf.get(13);
final int left = guiLeft + SIDE_MARGIN + SCISSOR_MODELVIEW_OFFSET_X;
final int bottom = gui.height - (guiTop + Reflection.Y_SIZE.get(gui))
final int bottom = gui.height - (guiTop + ((GuiContainerAccessor) gui).getYSize())
+ BOTTOM_MARGIN
+ SCISSOR_MODELVIEW_OFFSET_Y;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.dcysteine.neicustomdiagram.mixin;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;

import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;

@IFMLLoadingPlugin.MCVersion("1.7.10")
public class EarlyMixinLoader implements IFMLLoadingPlugin, IEarlyMixinLoader {

@Override
public String[] getASMTransformerClass() {
return null;
}

@Override
public String getModContainerClass() {
return null;
}

@Override
public String getSetupClass() {
return null;
}

@Override
public void injectData(Map<String, Object> data) {}

@Override
public String getAccessTransformerClass() {
return null;
}

@Override
public String getMixinConfig() {
return "mixins.neicustomdiagram.early.json";
}

@Override
public List<String> getMixins(Set<String> loadedCoreMods) {
if (FMLLaunchHandler.side().isClient()) {
return Collections.singletonList("GuiContainerAccessor");
}
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.dcysteine.neicustomdiagram.mixin.mixins.early;

import net.minecraft.client.gui.inventory.GuiContainer;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(GuiContainer.class)
public interface GuiContainerAccessor {

@Accessor
int getXSize();

@Accessor
int getYSize();

@Accessor
int getGuiLeft();

@Accessor
int getGuiTop();

}
8 changes: 8 additions & 0 deletions src/main/resources/mixins.neicustomdiagram.early.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "com.github.dcysteine.neicustomdiagram.mixin.mixins.early",
"refmap": "mixins.neicustomdiagram.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
}
7 changes: 7 additions & 0 deletions src/main/resources/mixins.neicustomdiagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"refmap": "mixins.neicustomdiagram.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8"
}

0 comments on commit 6dd99ab

Please sign in to comment.