Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {
name = "Jared's maven"
url = "https://maven.blamejared.com/"
}
maven {
name = "ModMaven"
url = "https://modmaven.dev"
}
}

loom {
Expand All @@ -50,6 +58,9 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modCompileOnly "mezz.jei:jei-${project.minecraft_version}-fabric-api:${project.jei_version}"
modRuntimeOnly "mezz.jei:jei-${project.minecraft_version}-fabric:${project.jei_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
Expand Down Expand Up @@ -125,6 +136,7 @@ modrinth {
uploadFile.set(tasks.remapJar)
dependencies {
required.project("fabric-api")
optional.project("jei")
}
}
tasks.modrinth.dependsOn(tasks.remapJar)
tasks.modrinth.dependsOn(tasks.remapJar)
11 changes: 6 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true

# Fabric Properties
minecraft_version=1.21.11
loader_version=0.18.3
loader_version=0.19.2
loom_version=1.14-SNAPSHOT

# Mod Properties
mod_version=4.0.2
mod_version=4.0.3
maven_group=com.nemonotfound
archives_base_name=nemos-carpentry
mod_id=nemos-carpentry
mod_name=Nemo's Carpentry

# Dependencies
fabric_version=0.140.0+1.21.11
fabric_version=0.141.4+1.21.11
jei_version=27.4.0.22

# Upload
curseforge_project_id=928372
modrinth_project_id=nemos-carpentry
modrinth_project_id=nemos-carpentry
7 changes: 6 additions & 1 deletion src/main/generated/assets/nemos-carpentry/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,5 +631,10 @@
"item.nemos-carpentry.pale_oak_glass_door_frame": "Pale Oak Glass Door Frame",
"item.nemos-carpentry.spruce_glass_door_frame": "Spruce Glass Door Frame",
"item.nemos-carpentry.warped_glass_door_frame": "Warped Glass Door Frame",
"jei.nemos-carpentry.category.carpentry": "Carpenter's Workbench",
"itemGroup.nemos-carpentry.nemos_carpentry": "Nemo's Carpentry",
"itemGroup.nemos-carpentry.outdoor": "Outdoor",
"itemGroup.nemos-carpentry.seats": "Seats",
"itemGroup.nemos-carpentry.tables": "Tables",
"nemos-carpentry.container.carpenters_workbench": "Carpenter's Workbench"
}
}
640 changes: 640 additions & 0 deletions src/main/generated/assets/nemos-carpentry/lang/zh_cn.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ public void generateTranslations(HolderLookup.@NotNull Provider provider, Transl
translationBuilder.add(CarpentryBlocks.SPRUCE_CHAIR_GREGORY, "Spruce Chair \"Gregory\"");
translationBuilder.add(CarpentryBlocks.WARPED_CHAIR_GREGORY, "Warped Chair \"Gregory\"");

translationBuilder.add("jei.nemos-carpentry.category.carpentry", "Carpenter's Workbench");
translationBuilder.add("itemGroup.nemos-carpentry.nemos_carpentry", "Nemo's Carpentry");
translationBuilder.add("itemGroup.nemos-carpentry.seats", "Seats");
translationBuilder.add("itemGroup.nemos-carpentry.tables", "Tables");
translationBuilder.add("itemGroup.nemos-carpentry.outdoor", "Outdoor");

try {
Optional<Path> optionalPath = dataOutput.getModContainer().findPath("en_us.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void registerItemGroups() {
private static void registerNemosCarpentryItemGroup(Item iconItem) {
CreativeModeTab ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(iconItem))
.title(Component.literal("Nemo's Carpentry"))
.title(Component.translatable("itemGroup.nemos-carpentry.nemos_carpentry"))
.displayItems((context, entries) -> {
entries.accept(CarpentryItems.CARPENTERS_WORKBENCH);
entries.accept(CarpentryItems.ACACIA_LADDER);
Expand Down Expand Up @@ -670,11 +670,10 @@ private static void registerNemosCarpentryItemGroup(Item iconItem) {
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, Identifier.fromNamespaceAndPath(MOD_ID, NEMOS_CARPENTRY_GROUP_ID), ITEM_GROUP);
}

//TODO: Add translation
private static void registerSeatsItemGroup(Item iconItem) {
CreativeModeTab ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(iconItem))
.title(Component.translatable("Seats"))
.title(Component.translatable("itemGroup.nemos-carpentry.seats"))
.displayItems((context, entries) -> {
entries.accept(CarpentryItems.ACACIA_CHAIR);
entries.accept(CarpentryItems.BAMBOO_CHAIR);
Expand Down Expand Up @@ -1037,11 +1036,10 @@ private static void registerSeatsItemGroup(Item iconItem) {
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, Identifier.fromNamespaceAndPath(MOD_ID, NEMOS_CARPENTRY_GROUP_ID + "_seats"), ITEM_GROUP);
}

//TODO: add translation
private static void registerTablesItemGroup(Item iconItem) {
CreativeModeTab ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(iconItem))
.title(Component.translatable("Tables"))
.title(Component.translatable("itemGroup.nemos-carpentry.tables"))
.displayItems((context, entries) -> {
entries.accept(CarpentryItems.ACACIA_TABLE_THE_CLASSIC);
entries.accept(CarpentryItems.BAMBOO_TABLE_THE_CLASSIC);
Expand Down Expand Up @@ -1097,11 +1095,10 @@ private static void registerTablesItemGroup(Item iconItem) {
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, Identifier.fromNamespaceAndPath(MOD_ID, NEMOS_CARPENTRY_GROUP_ID + "_tables"), ITEM_GROUP);
}

//TODO: add translation
private static void registerOutdoorItemGroup(Item iconItem) {
CreativeModeTab ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(iconItem))
.title(Component.translatable("Outdoor"))
.title(Component.translatable("itemGroup.nemos-carpentry.outdoor"))
.displayItems((context, entries) -> {
entries.accept(CarpentryItems.ACACIA_LADDER);
entries.accept(CarpentryItems.BAMBOO_LADDER);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.nemonotfound.nemos.carpentry.jei;

import com.nemonotfound.nemos.carpentry.item.CarpentryItems;
import com.nemonotfound.nemos.carpentry.recipe.display.CarpentryRecipeDisplay;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.category.AbstractRecipeCategory;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

import java.util.List;

public class CarpentryRecipeCategory extends AbstractRecipeCategory<CarpentryRecipeDisplay.GroupEntry> {

public static final int WIDTH = 82;
public static final int HEIGHT = 52;

public CarpentryRecipeCategory(IGuiHelper guiHelper) {
super(
NemosCarpentryJeiRecipeTypes.CARPENTRY,
Component.translatable("jei.nemos-carpentry.category.carpentry"),
guiHelper.createDrawableItemLike(CarpentryItems.CARPENTERS_WORKBENCH),
WIDTH,
HEIGHT
);
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, CarpentryRecipeDisplay.GroupEntry recipe, IFocusGroup focuses) {
List<Ingredient> ingredients = recipe.ingredients();
List<Integer> inputCounts = recipe.inputCounts();

addInputSlot(builder, ingredients, inputCounts, 0, 1, ingredients.size() > 1 ? 1 : 9);
if (ingredients.size() > 1) {
addInputSlot(builder, ingredients, inputCounts, 1, 1, 27);
}

builder.addOutputSlot(61, 18)
.setOutputSlotBackground()
.add(recipe.recipe().optionDisplay());
}

@Override
public void createRecipeExtras(IRecipeExtrasBuilder builder, CarpentryRecipeDisplay.GroupEntry recipe, IFocusGroup focuses) {
if (recipe.ingredients().size() > 1) {
builder.addRecipePlusSign().setPosition(22, 19);
}
builder.addRecipeArrow().setPosition(34, 18);
}

@Override
public Identifier getIdentifier(CarpentryRecipeDisplay.GroupEntry recipe) {
return recipe.recipe().recipe()
.map(recipeHolder -> recipeHolder.id().identifier())
.orElse(null);
}

private static void addInputSlot(IRecipeLayoutBuilder builder, List<Ingredient> ingredients, List<Integer> inputCounts, int index, int x, int y) {
builder.addInputSlot(x, y)
.setStandardSlotBackground()
.addItemStacks(copyWithCount(ingredients.get(index), inputCounts.get(index)));
}

private static List<ItemStack> copyWithCount(Ingredient ingredient, int count) {
return ingredient.items()
.map(holder -> new ItemStack(holder.value(), count))
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.nemonotfound.nemos.carpentry.jei;

import com.nemonotfound.nemos.carpentry.interfaces.CarpentryRecipeManagerGetter;
import com.nemonotfound.nemos.carpentry.item.CarpentryItems;
import com.nemonotfound.nemos.carpentry.recipe.display.CarpentryRecipeDisplay;
import com.nemonotfound.nemos.carpentry.screen.CarpentryMenu;
import com.nemonotfound.nemos.carpentry.screen.CarpentryMenuTypes;
import com.nemonotfound.nemos.carpentry.screen.CarpentryScreen;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import mezz.jei.api.registration.IRecipeCatalystRegistration;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.api.registration.IRecipeRegistration;
import mezz.jei.api.registration.IRecipeTransferRegistration;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static com.nemonotfound.nemos.carpentry.NemosCarpentry.MOD_ID;

@JeiPlugin
public class NemosCarpentryJeiPlugin implements IModPlugin {

private static final Identifier UID = Identifier.fromNamespaceAndPath(MOD_ID, "jei_plugin");
private static final Set<String> REGISTERED_RECIPE_KEYS = new HashSet<>();
private static @Nullable IJeiRuntime runtime;

@Override
public @NotNull Identifier getPluginUid() {
return UID;
}

@Override
public void registerCategories(IRecipeCategoryRegistration registration) {
IGuiHelper guiHelper = registration.getJeiHelpers().getGuiHelper();
registration.addRecipeCategories(new CarpentryRecipeCategory(guiHelper));
}

@Override
public void registerRecipes(IRecipeRegistration registration) {
List<CarpentryRecipeDisplay.GroupEntry> recipes = getCarpentryRecipes();
if (!recipes.isEmpty()) {
registration.addRecipes(NemosCarpentryJeiRecipeTypes.CARPENTRY, recipes);
recipes.stream().map(NemosCarpentryJeiPlugin::recipeKey).forEach(REGISTERED_RECIPE_KEYS::add);
}
}

@Override
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addCraftingStation(NemosCarpentryJeiRecipeTypes.CARPENTRY, CarpentryItems.CARPENTERS_WORKBENCH);
}

@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
registration.addRecipeTransferHandler(CarpentryMenu.class, CarpentryMenuTypes.CARPENTRY_SCREEN_HANDLER,
NemosCarpentryJeiRecipeTypes.CARPENTRY, 0, 2, 3, 36);
}

@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addRecipeClickArea(CarpentryScreen.class, 134, 28, 24, 24, NemosCarpentryJeiRecipeTypes.CARPENTRY);
}

@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
runtime = jeiRuntime;
addRecipesAtRuntime(getCarpentryRecipes());
}

@Override
public void onRuntimeUnavailable() {
runtime = null;
REGISTERED_RECIPE_KEYS.clear();
}

public static void onCarpentryRecipesSynced(CarpentryRecipeDisplay.Grouping grouping) {
addRecipesAtRuntime(grouping.entries());
}

private static List<CarpentryRecipeDisplay.GroupEntry> getCarpentryRecipes() {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft.level == null) {
return List.of();
}

CarpentryRecipeDisplay.Grouping grouping = ((CarpentryRecipeManagerGetter) minecraft.level)
.nemo_sCarpentry$getModRecipeManager()
.carpentryRecipes();

return grouping.entries();
}

private static void addRecipesAtRuntime(List<CarpentryRecipeDisplay.GroupEntry> recipes) {
IJeiRuntime currentRuntime = runtime;
if (currentRuntime == null || recipes.isEmpty()) {
return;
}

List<CarpentryRecipeDisplay.GroupEntry> newRecipes = recipes.stream()
.filter(recipe -> !REGISTERED_RECIPE_KEYS.contains(recipeKey(recipe)))
.toList();

if (!newRecipes.isEmpty()) {
currentRuntime.getRecipeManager().addRecipes(NemosCarpentryJeiRecipeTypes.CARPENTRY, newRecipes);
newRecipes.stream().map(NemosCarpentryJeiPlugin::recipeKey).forEach(REGISTERED_RECIPE_KEYS::add);
}
}

private static String recipeKey(CarpentryRecipeDisplay.GroupEntry recipe) {
return recipe.recipe().recipe()
.map(recipeHolder -> recipeHolder.id().identifier().toString())
.orElseGet(() -> recipe.ingredients().stream()
.map(ingredient -> ingredient.items()
.map(holder -> BuiltInRegistries.ITEM.getKey(holder.value()).toString())
.sorted()
.collect(Collectors.joining("|")))
.collect(Collectors.joining(",")) + ";" + recipe.inputCounts() + "->" + recipe.recipe().optionDisplay());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.nemonotfound.nemos.carpentry.jei;

import com.nemonotfound.nemos.carpentry.recipe.display.CarpentryRecipeDisplay;
import mezz.jei.api.recipe.types.IRecipeType;

import static com.nemonotfound.nemos.carpentry.NemosCarpentry.MOD_ID;

public final class NemosCarpentryJeiRecipeTypes {

public static final IRecipeType<CarpentryRecipeDisplay.GroupEntry> CARPENTRY =
IRecipeType.create(MOD_ID, "carpentry", CarpentryRecipeDisplay.GroupEntry.class);

private NemosCarpentryJeiRecipeTypes() {
}

public static IRecipeType<CarpentryRecipeDisplay.GroupEntry> carpentry() {
return CARPENTRY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,15 @@ protected ClientPacketListenerMixin(Minecraft minecraft, Connection connection,
Minecraft minecraft = ((MinecraftGetter) this).nemo_sCarpentry$getMinecraft();
PacketUtils.ensureRunningOnSameThread(packet, this, minecraft.packetProcessor());
this.modRecipeManager = new ClientCarpentryRecipeManager(packet.carpentryRecipes());
nemo_sCarpentry$syncJeiRecipes(packet.carpentryRecipes());
}

@Unique
private static void nemo_sCarpentry$syncJeiRecipes(CarpentryRecipeDisplay.Grouping grouping) {
try {
Class<?> pluginClass = Class.forName("com.nemonotfound.nemos.carpentry.jei.NemosCarpentryJeiPlugin");
pluginClass.getMethod("onCarpentryRecipesSynced", CarpentryRecipeDisplay.Grouping.class).invoke(null, grouping);
} catch (ReflectiveOperationException | LinkageError ignored) {
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
"item.nemos-carpentry.warped_glass_door_frame": "Warped Glass Door Frame",

"nemos-carpentry.container.carpenters_workbench": "Carpenter's Workbench",
"jei.nemos-carpentry.category.carpentry": "Carpenter's Workbench",

"block.nemos-carpentry.acacia_chair_lukas": "Acacia Chair \"Lukas\"",
"block.nemos-carpentry.bamboo_chair_lukas": "Bamboo Chair \"Lukas\"",
Expand All @@ -309,4 +310,4 @@
"block.nemos-carpentry.oak_chair_lukas_natural": "Oak Chair \"Lukas\" - Natural",
"block.nemos-carpentry.spruce_chair_lukas_natural": "Spruce Chair \"Lukas\" - Natural",
"block.nemos-carpentry.warped_chair_lukas_natural": "Warped Chair \"Lukas\" - Natural"
}
}
Loading