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 5ada685 commit 27fb345
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version_range=[4,)
mod_id=sophisticatedbackpacks
mod_name=Sophisticated Backpacks
mod_license=GNU General Public License v3.0
mod_version=3.21.0
mod_version=3.21.1
mod_group_id=sophisticatedbackpacks
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional backpacks.
Expand All @@ -34,7 +34,7 @@ chipped_cf_file_id=5506938
resourcefullib_cf_file_id=5483169
athena_cf_file_id=5431579
curios_cf_file_id=5546342
sc_version=[1.21-1.0.8,1.22)
sc_version=[1.21-1.0.9,1.22)

#publish
curseforge_id=422301
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
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.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SmithingRecipe;
import net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.BackpackWrapper;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.IBackpackWrapper;
Expand Down Expand Up @@ -99,12 +102,28 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
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, RecipeHolder<CraftingRecipe>>(handlerHelper, stackHelper) {
@Override
public Class<BackpackContainer> getContainerClass() {
return BackpackContainer.class;
}

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

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

@Override
public mezz.jei.api.recipe.RecipeType<RecipeHolder<SmithingRecipe>> getRecipeType() {
return RecipeTypes.SMITHING;
}
}, RecipeTypes.SMITHING);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
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.minecraft.world.item.crafting.SmithingRecipeInput;
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 +90,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 +182,14 @@ public void slotsChanged(Container pInventory) {
createResult();
onResultChanged.run();
}

public Container getInputSlots() {
return inputSlots;
}

public void setSelectedRecipe(ResourceLocation recipeId) {
SmithingRecipeInput smithingRecipeInput = new SmithingRecipeInput(getTemplateSlot().getItem(), getBaseSlot().getItem(), getAdditionalSlot().getItem());
RecipeHelper.safeGetRecipeFor(RecipeType.SMITHING, smithingRecipeInput, 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 @@ -15,6 +15,7 @@ public net.minecraft.client.renderer.entity.EntityRenderDispatcher renderers
protected net.minecraft.world.inventory.ItemCombinerMenu createInputSlots(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V
protected net.minecraft.world.inventory.ItemCombinerMenu createContainer(I)Lnet/minecraft/world/SimpleContainer;
protected net.minecraft.world.inventory.ItemCombinerMenu createResultSlot(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V
protected net.minecraft.world.inventory.SmithingMenu selectedRecipe
public net.minecraft.client.gui.screens.inventory.SmithingScreen ARMOR_STAND_TRANSLATION
public net.minecraft.client.gui.screens.inventory.SmithingScreen ARMOR_STAND_ANGLE
public net.minecraft.client.gui.screens.inventory.SmithingScreen EMPTY_SLOT_SMITHING_TEMPLATES
Expand Down

0 comments on commit 27fb345

Please sign in to comment.