跳到主要内容

32REI兼容性

代码

gradle中添加依赖:

repositories {
maven { url "https://maven.shedaniel.me" }
}
dependencies {
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:13.0.666"
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:13.0.666"
}

fabric.mod.json中添加REI的主类:

"entrypoints": {
"rei_client": [
"net.kaupenjoe.tutorialmod.compat.TutorialModREIClientPlugin"
]
},

创建一个compat包:

TutorialModREIClientPlugin:

public class TutorialModREIClientPlugin implements REIClientPlugin {
@Override
public void registerCategories(CategoryRegistry registry) {
registry.add(new GemPolishingCategory());

registry.addWorkstations(GemPolishingCategory.GEM_POLISHING, EntryStacks.of(ModBlocks.GEM_POLISHING_STATION));
}

@Override
public void registerDisplays(DisplayRegistry registry) {
registry.registerRecipeFiller(GemPolishingRecipe.class, GemPolishingRecipe.Type.INSTANCE,
GemPolishingDisplay::new);
}

@Override
public void registerScreens(ScreenRegistry registry) {
registry.registerClickArea(screen -> new Rectangle(75, 30, 20, 30), GemPolishingScreen.class,
GemPolishingCategory.GEM_POLISHING);
}
}

GemPolishingDisplay:

public class GemPolishingDisplay extends BasicDisplay {
public GemPolishingDisplay(List<EntryIngredient> inputs, List<EntryIngredient> outputs) {
super(inputs, outputs);
}

public GemPolishingDisplay(RecipeEntry<GemPolishingRecipe> recipe) {
super(getInputList(recipe.value()), List.of(EntryIngredient.of(EntryStacks.of(recipe.value().getResult(null)))));
}

private static List<EntryIngredient> getInputList(GemPolishingRecipe recipe) {
if(recipe == null) {
return Collections.emptyList();
}
List<EntryIngredient> list = new ArrayList<>();
list.add(EntryIngredients.ofIngredient(recipe.getIngredients().get(0)));
return list;
}

@Override
public CategoryIdentifier<?> getCategoryIdentifier() {
return GemPolishingCategory.GEM_POLISHING;
}
}

GemPolishingCategory:

public class GemPolishingCategory implements DisplayCategory<BasicDisplay> {
public static final Identifier TEXTURE =
new Identifier(TutorialMod.MOD_ID, "textures/gui/gem_polishing_station_gui.png");
public static final CategoryIdentifier<GemPolishingDisplay> GEM_POLISHING =
CategoryIdentifier.of(TutorialMod.MOD_ID, "gem_polishing");

@Override
public CategoryIdentifier<? extends BasicDisplay> getCategoryIdentifier() {
return GEM_POLISHING;
}

@Override
public Text getTitle() {
return Text.literal("Gem Polishing Station");
}

@Override
public Renderer getIcon() {
return EntryStacks.of(ModBlocks.GEM_POLISHING_STATION.asItem().getDefaultStack());
}

@Override
public List<Widget> setupDisplay(BasicDisplay display, Rectangle bounds) {
final Point startPoint = new Point(bounds.getCenterX() - 87, bounds.getCenterY() - 35);
List<Widget> widgets = new LinkedList<>();
widgets.add(Widgets.createTexturedWidget(TEXTURE, new Rectangle(startPoint.x, startPoint.y, 175, 82)));

widgets.add(Widgets.createSlot(new Point(startPoint.x + 80, startPoint.y + 11))
.entries(display.getInputEntries().get(0)));

widgets.add(Widgets.createSlot(new Point(startPoint.x + 80, startPoint.y + 59))
.markOutput().entries(display.getOutputEntries().get(0)));


return widgets;
}

@Override
public int getDisplayHeight() {
return 90;
}
}

效果

按U可以查看合成表

image-20240825181242614

查看煤炭的功能:

image-20240825181319098