Skip to content

Commit 352294a

Browse files
committed
chore: add exclusion zones for configuration panels/tabs when using JEI and EMI
1 parent 11ba670 commit 352294a

File tree

7 files changed

+244
-99
lines changed

7 files changed

+244
-99
lines changed

build.gradle.kts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import java.nio.file.Files
2424
import java.time.LocalDateTime
2525
import java.time.format.DateTimeFormatter
2626

27+
val runJei = project.getProperties().getOrDefault("jei", "false").toString().toBoolean()
28+
val runEmi = project.getProperties().getOrDefault("emi", "false").toString().toBoolean()
29+
val runRei = project.getProperties().getOrDefault("rei", !runJei && !runEmi).toString().toBoolean()
30+
2731
val modId = project.property("mod.id").toString()
2832
val modVersion = project.property("mod.version").toString()
2933
val modName = project.property("mod.name").toString()
@@ -38,6 +42,8 @@ val fabric = project.property("fabric.version").toString()
3842
val clothConfig = project.property("cloth.config.version").toString()
3943
val modmenu = project.property("modmenu.version").toString()
4044
val rei = project.property("rei.version").toString()
45+
val jei = project.property("jei.version").toString()
46+
val emi = project.property("emi.version").toString()
4147
val architectury = project.property("architectury.version").toString()
4248
val wthit = project.property("wthit.version").toString()
4349

@@ -145,6 +151,7 @@ repositories {
145151
maven("https://maven.terraformersmc.com/releases") {
146152
content {
147153
includeGroup("com.terraformersmc")
154+
includeGroup("dev.emi")
148155
}
149156
}
150157
maven("https://maven.shedaniel.me") {
@@ -160,6 +167,11 @@ repositories {
160167
includeGroup("mcp.mobius.waila")
161168
}
162169
}
170+
maven("https://maven.blamejared.com/") {
171+
content {
172+
includeGroup("mezz.jei")
173+
}
174+
}
163175
}
164176

165177
dependencies {
@@ -194,13 +206,26 @@ dependencies {
194206
modCompileOnly("mcp.mobius.waila:wthit-api:fabric-$wthit")
195207
modLocalRuntime("mcp.mobius.waila:wthit:fabric-$wthit")
196208

197-
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei")
198209
modCompileOnly("dev.architectury:architectury-fabric:$architectury")
199-
modLocalRuntime("me.shedaniel:RoughlyEnoughItems-fabric:$rei")
200210

201211
modLocalRuntime(modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:$clothConfig")!!)
202212
modLocalRuntime(modCompileOnly("com.terraformersmc:modmenu:$modmenu")!!)
203213

214+
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei")
215+
if (runRei) {
216+
modLocalRuntime("me.shedaniel:RoughlyEnoughItems-fabric:$rei")
217+
}
218+
219+
modCompileOnly("mezz.jei:jei-$minecraft-fabric-api:$jei")
220+
if (runJei) {
221+
modLocalRuntime("mezz.jei:jei-$minecraft-fabric:$jei")
222+
}
223+
224+
modCompileOnly("dev.emi:emi-fabric:$emi:api")
225+
if (runEmi) {
226+
modLocalRuntime("dev.emi:emi-fabric:$emi")
227+
}
228+
204229
"testmodImplementation"(sourceSets.main.get().output)
205230
"modTestRuntimeOnly"("modTestmodImplementation"("net.fabricmc.fabric-api:fabric-api:$fabric")!!)
206231
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ fabric.version=0.115.4+1.21.1
1919
cloth.config.version=15.0.140
2020
modmenu.version=11.0.2
2121
rei.version=16.0.777
22+
jei.version=19.21.0.247
23+
emi.version=1.1.22+1.21.1
2224
architectury.version=13.0.6
2325
wthit.version=12.4.2

src/main/java/dev/galacticraft/machinelib/client/api/screen/MachineScreen.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import net.minecraft.client.gui.components.PlayerFaceRenderer;
5656
import net.minecraft.client.gui.screens.Screen;
5757
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
58+
import net.minecraft.client.renderer.Rect2i;
5859
import net.minecraft.client.resources.DefaultPlayerSkin;
5960
import net.minecraft.client.resources.PlayerSkin;
6061
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
@@ -578,6 +579,36 @@ public boolean checkConfigurationPanelClick(double mouseX, double mouseY, int bu
578579
return false;
579580
}
580581

582+
/**
583+
* {@return a list of rectangles recipe viewers should avoid placing items in}
584+
*/
585+
public List<Rect2i> getExclusionZones() {
586+
List<Rect2i> areas = new ArrayList<>();
587+
int leftX = this.getX();
588+
int rightX = this.getX() + this.getImageWidth();
589+
int leftY = this.getY() + SPACING;
590+
int rightY = this.getY() + SPACING;
591+
int width;
592+
int height;
593+
for (Tab tab : Tab.values()) {
594+
if (tab.isOpen()) {
595+
width = PANEL_WIDTH;
596+
height = PANEL_HEIGHT;
597+
} else {
598+
width = TAB_WIDTH;
599+
height = TAB_HEIGHT;
600+
}
601+
if (tab.isLeft()) {
602+
areas.add(new Rect2i(leftX - width, leftY, width, height));
603+
leftY += height + SPACING;
604+
} else {
605+
areas.add(new Rect2i(rightX, rightY, width, height));
606+
rightY += height + SPACING;
607+
}
608+
}
609+
return areas;
610+
}
611+
581612
/**
582613
* Sets the accessibility of the machine and syncs it to the server.
583614
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2019-2025 Team Galacticraft
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package dev.galacticraft.machinelib.client.impl.compat;
24+
25+
import dev.emi.emi.api.EmiExclusionArea;
26+
import dev.emi.emi.api.EmiPlugin;
27+
import dev.emi.emi.api.EmiRegistry;
28+
import dev.emi.emi.api.widget.Bounds;
29+
import dev.galacticraft.machinelib.client.api.screen.MachineScreen;
30+
import dev.galacticraft.machinelib.impl.MachineLib;
31+
import net.minecraft.client.gui.screens.Screen;
32+
import net.minecraft.client.renderer.Rect2i;
33+
34+
import java.util.List;
35+
import java.util.function.Consumer;
36+
37+
public class MachineLibEMIPlugin implements EmiPlugin {
38+
@Override
39+
public void register(EmiRegistry registry) {
40+
registry.addGenericExclusionArea((screen, consumer) -> {
41+
if (!(screen instanceof MachineScreen provider)) return;
42+
List<Rect2i> areas = provider.getExclusionZones();
43+
areas.forEach(rect2i -> {
44+
consumer.accept(new Bounds(rect2i.getX(), rect2i.getY(), rect2i.getWidth(), rect2i.getHeight()));
45+
});
46+
});
47+
}
48+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2021-2025 Team Galacticraft
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package dev.galacticraft.machinelib.client.impl.compat;
24+
25+
import dev.galacticraft.machinelib.client.api.screen.MachineScreen;
26+
import dev.galacticraft.machinelib.impl.Constant;
27+
import mezz.jei.api.IModPlugin;
28+
import mezz.jei.api.JeiPlugin;
29+
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
30+
import mezz.jei.api.registration.IGuiHandlerRegistration;
31+
import net.minecraft.client.renderer.Rect2i;
32+
import net.minecraft.resources.ResourceLocation;
33+
34+
import java.util.List;
35+
36+
@JeiPlugin
37+
public class MachineLibJEIPlugin implements IModPlugin {
38+
@Override
39+
public ResourceLocation getPluginUid() {
40+
return Constant.id("jei_plugin");
41+
}
42+
43+
@Override
44+
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
45+
registration.addGenericGuiContainerHandler(MachineScreen.class,
46+
new IGuiContainerHandler<MachineScreen<?, ?>>() {
47+
@Override
48+
public List<Rect2i> getGuiExtraAreas(MachineScreen<?, ?> provider) {
49+
return provider.getExclusionZones();
50+
}
51+
}
52+
);
53+
}
54+
}

src/main/java/dev/galacticraft/machinelib/client/impl/compat/MachineLibREIClientPlugin.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424

2525
import dev.architectury.event.CompoundEventResult;
2626
import dev.galacticraft.machinelib.client.api.screen.MachineScreen;
27-
import dev.galacticraft.machinelib.impl.Constant.TextureCoordinate;
2827
import me.shedaniel.math.Rectangle;
2928
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
3029
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
3130
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
3231
import me.shedaniel.rei.api.common.util.EntryStacks;
32+
import net.minecraft.client.renderer.Rect2i;
3333

34-
import java.util.ArrayList;
3534
import java.util.List;
3635

3736
public class MachineLibREIClientPlugin implements REIClientPlugin {
@@ -50,30 +49,10 @@ public void registerScreens(ScreenRegistry registry) {
5049
@Override
5150
public void registerExclusionZones(ExclusionZones zones) {
5251
zones.register(MachineScreen.class, provider -> {
53-
List<Rectangle> areas = new ArrayList<>();
54-
int leftX = provider.getX();
55-
int rightX = provider.getX() + provider.getImageWidth();
56-
int leftY = provider.getY() + MachineScreen.SPACING;
57-
int rightY = provider.getY() + MachineScreen.SPACING;
58-
int width;
59-
int height;
60-
for (MachineScreen.Tab tab : MachineScreen.Tab.values()) {
61-
if (tab.isOpen()) {
62-
width = TextureCoordinate.PANEL_WIDTH;
63-
height = TextureCoordinate.PANEL_HEIGHT;
64-
} else {
65-
width = TextureCoordinate.TAB_WIDTH;
66-
height = TextureCoordinate.TAB_HEIGHT;
67-
}
68-
if (tab.isLeft()) {
69-
areas.add(new Rectangle(leftX - width, leftY, width, height));
70-
leftY += height + MachineScreen.SPACING;
71-
} else {
72-
areas.add(new Rectangle(rightX, rightY, width, height));
73-
rightY += height + MachineScreen.SPACING;
74-
}
75-
}
76-
return areas;
52+
List<Rect2i> areas = provider.getExclusionZones();
53+
return areas.stream().map(
54+
rect2i -> new Rectangle(rect2i.getX(), rect2i.getY(), rect2i.getWidth(), rect2i.getHeight())
55+
).toList();
7756
});
7857
}
7958
}

0 commit comments

Comments
 (0)