Skip to content

Commit

Permalink
feat: ✨ Added transfer from JEI to Smithing upgrade so that the conve…
Browse files Browse the repository at this point in the history
…nient plus sign can be just clicked to fill all 3 input slots in
  • Loading branch information
P3pp3rF1y committed Dec 30, 2024
1 parent 9313735 commit a8d8157
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedbackpacks
mod_group_id=sophisticatedbackpacks
mod_version=3.21.0
mod_version=3.21.1
sonar_project_key=sophisticatedbackpacks:SophisticatedBackpacks
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedBackpacks

Expand Down Expand Up @@ -31,5 +31,5 @@ crafting_tweaks_cf_file_id=4596466
chipped_cf_file_id=5077656
resourcefullib_cf_file_id=5070629
athena_cf_file_id=4764357
sc_version=[1.20.1-1.0.3,1.20.4)
sc_version=[1.20.1-1.0.4,1.20.4)
parchment_version=2023.09.03-1.20.1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.SmithingRecipe;
import net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks;
import net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper;
import net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen;
Expand Down Expand Up @@ -90,19 +92,36 @@ public void registerRecipes(IRecipeRegistration registration) {
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addRecipeCatalyst(new ItemStack(ModItems.CRAFTING_UPGRADE.get()), RecipeTypes.CRAFTING);
registration.addRecipeCatalyst(new ItemStack(ModItems.STONECUTTER_UPGRADE.get()), RecipeTypes.STONECUTTING);
registration.addRecipeCatalyst(new ItemStack(ModItems.SMITHING_UPGRADE.get()), RecipeTypes.SMITHING);
additionalCatalystRegistrar.accept(registration);
}

@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
IRecipeTransferHandlerHelper handlerHelper = registration.getTransferHelper();
IStackHelper stackHelper = registration.getJeiHelpers().getStackHelper();
registration.addRecipeTransferHandler(new CraftingContainerRecipeTransferHandlerBase<BackpackContainer>(handlerHelper, stackHelper) {
registration.addRecipeTransferHandler(new CraftingContainerRecipeTransferHandlerBase<BackpackContainer, CraftingRecipe>(handlerHelper, stackHelper) {
@Override
public Class<BackpackContainer> getContainerClass() {
return BackpackContainer.class;
}

@Override
public mezz.jei.api.recipe.RecipeType<CraftingRecipe> getRecipeType() {
return RecipeTypes.CRAFTING;
}
}, RecipeTypes.CRAFTING);
}

registration.addRecipeTransferHandler(new CraftingContainerRecipeTransferHandlerBase<BackpackContainer, SmithingRecipe>(handlerHelper, stackHelper) {
@Override
public Class<BackpackContainer> getContainerClass() {
return BackpackContainer.class;
}

@Override
public mezz.jei.api.recipe.RecipeType<SmithingRecipe> getRecipeType() {
return RecipeTypes.SMITHING;
}
}, RecipeTypes.SMITHING);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.p3pp3rf1y.sophisticatedcore.common.gui.ICraftingContainer;
import net.p3pp3rf1y.sophisticatedcore.common.gui.SlotSuppliedHandler;
import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerBase;
import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerType;
import net.p3pp3rf1y.sophisticatedcore.upgrades.IUpgradeWrapper;
import net.p3pp3rf1y.sophisticatedcore.util.NBTHelper;
import net.p3pp3rf1y.sophisticatedcore.util.RecipeHelper;

public class SmithingUpgradeContainer extends UpgradeContainerBase<SmithingUpgradeWrapper, SmithingUpgradeContainer> {
import java.util.List;

public class SmithingUpgradeContainer extends UpgradeContainerBase<SmithingUpgradeWrapper, SmithingUpgradeContainer> implements ICraftingContainer {
private static final String DATA_SHIFT_CLICK_INTO_STORAGE = "shiftClickIntoStorage";
private final Slot resultSlot;
private Runnable onResultChanged = () -> {};
Expand Down Expand Up @@ -83,6 +89,26 @@ public Slot getResultSlot() {
return smithingMenuDelegate.getSlot(SmithingMenu.RESULT_SLOT);
}

@Override
public List<Slot> getRecipeSlots() {
return List.of(getTemplateSlot(), getBaseSlot(), getAdditionalSlot());
}

@Override
public Container getCraftMatrix() {
return smithingMenuDelegate.getInputSlots();
}

@Override
public void setRecipeUsed(ResourceLocation recipeId) {
smithingMenuDelegate.setSelectedRecipe(recipeId);
}

@Override
public RecipeType<?> getRecipeType() {
return RecipeType.SMITHING;
}

private class PersistableSmithingMenu extends SmithingMenu {

public PersistableSmithingMenu(Inventory playerInventory) {
Expand Down Expand Up @@ -155,5 +181,13 @@ public void slotsChanged(Container pInventory) {
createResult();
onResultChanged.run();
}

public Container getInputSlots() {
return inputSlots;
}

public void setSelectedRecipe(ResourceLocation recipeId) {
RecipeHelper.safeGetRecipeFor(RecipeType.SMITHING, inputSlots, recipeId).ifPresent(recipe -> selectedRecipe = recipe);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected net.minecraft.world.inventory.AnvilMenu f_39001_ # itemName
protected net.minecraft.world.inventory.ItemCombinerMenu m_266254_(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V # createInputSlots
protected net.minecraft.world.inventory.ItemCombinerMenu m_266190_(I)Lnet/minecraft/world/SimpleContainer; # createContainer
protected net.minecraft.world.inventory.ItemCombinerMenu m_266430_(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V # createResultSlot
protected net.minecraft.world.inventory.SmithingMenu f_40242_ # selectedRecipe
public net.minecraft.client.gui.screens.inventory.SmithingScreen f_265883_ # EMPTY_SLOT_SMITHING_TEMPLATES
public net.minecraft.client.gui.screens.inventory.SmithingScreen f_266014_ # ERROR_TOOLTIP
public net.minecraft.client.gui.screens.inventory.SmithingScreen f_266043_ # MISSING_TEMPLATE_TOOLTIP

0 comments on commit a8d8157

Please sign in to comment.