Skip to content

Commit

Permalink
feat: recipe delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu committed Feb 26, 2024
1 parent 0d0a647 commit 4521da3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
implementation "info.loenwind.autoconfig:AutoConfig:${project.minecraft.version}-1.0.2"
implementation "info.loenwind.autosave:AutoSave:${project.minecraft.version}-1.0.11"

//compile "curse.maven:spiceoflife-220811:2571951"
implementation rfg.deobf("curse.maven:spiceoflife-220811:2571951")

implementation files("libs/AppleSkin-mc1.12-1.0.9.jar")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ public class KitchenRecipeWidget extends AbstractWidgetGroup implements IRecipeT

private Function<Integer, NBTTagCompound> loadingFunction;
private Consumer<NBTTagCompound> savingFunction;
private Consumer<NBTTagCompound> deletingFunction;
private int recipeCount;
private int recipeShown;
private PhantomRecipeWidget recipeWidget;
private ClickButtonWidget leftArrowWidget;
private ClickButtonWidget rightArrowWidget;
private ClickButtonWidget deleteButtonWidget;
private SimpleTextWidget recipeCountLabel;
private SlotWidget finalResultSlot;
private ItemStackHandler finalResult = new ItemStackHandler(1) {
Expand All @@ -85,7 +87,12 @@ public int getSlotLimit(int slot) {

private List<ItemStack> neededInputs = new ArrayList<>();
private List<FluidStack> neededFluidInputs = new ArrayList<>();
public KitchenRecipeWidget(int x, int y, int width, int height, int recipeCount, Consumer<NBTTagCompound> savingFunction, Function<Integer, NBTTagCompound> loadingFunction, Consumer<ItemStack> resultItemConsumer, ItemStack finalResultStack) {
public KitchenRecipeWidget(int x, int y, int width, int height, int recipeCount,
Consumer<NBTTagCompound> savingFunction,
Function<Integer, NBTTagCompound> loadingFunction,
Consumer<ItemStack> resultItemConsumer,
Consumer<Integer> deletingFunction,
ItemStack finalResultStack) {
super(new Position(x, y), new Size(width, height));
if (finalResultStack != null) {
finalResult.setStackInSlot(0, finalResultStack);
Expand Down Expand Up @@ -123,7 +130,11 @@ public List<IGhostIngredientHandler.Target<?>> getPhantomTargets(Object ingredie
addWidget(rightArrowWidget);
recipeCountLabel = new SimpleTextWidget(x + width / 2, y + 120, "", 0x666666, () -> "Recipe: " + (getRecipeShown() + 1) + "/" + getRecipeCount(), true);
addWidget(recipeCountLabel);

deleteButtonWidget = new ClickButtonWidget(x + width - 50, y + 120, 9, 9, "", (data) -> {
deletingFunction.accept(getRecipeShown());
this.recipeWidget.deserializeNBT(loadingFunction.apply(getRecipeShown()));
}).setButtonTexture(GuiTextures.BUTTON_CLEAR_GRID).setShouldClientCallback(true);
addWidget(deleteButtonWidget);
getNeededInputs();
getNeededFluidInputs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public ModularUI createUI(PlayerInventoryHolder playerInventoryHolder, EntityPla
getRecipeCount(stack),
(tag) -> addRecipe(stack, tag),
(index) -> getRecipe(stack, index),
(finalResult) -> setFinalResult(stack, finalResult), getFinalResult(stack)));
(finalResult) -> setFinalResult(stack, finalResult),
(index) -> deleteRecipe(stack, index),
getFinalResult(stack)));
builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 30, 155);
return builder.build(playerInventoryHolder, entityPlayer);
}
Expand All @@ -53,6 +55,24 @@ private static NBTTagCompound getRecipe(ItemStack stack, int index) {
return stack.getTagCompound().getCompoundTag("recipe" + index);
}

private static void deleteRecipe(ItemStack stack, int location) {
if (!GTFOMetaItem.KITCHEN_RECIPE.isItemEqual(stack))
return;
NBTTagCompound tag = stack.getTagCompound();
if (stack.getTagCompound() == null)
return;
int count = tag.getInteger("recipecount");
if (location >= count)
return;
tag.removeTag("recipe" + location);
for (int i = location; i < count - 1; i++) {
tag.setTag("recipe" + i, tag.getCompoundTag("recipe" + (i + 1)));
}
tag.setInteger("recipecount", count - 1);

stack.setTagCompound(tag);
}

private static int getRecipeCount(ItemStack stack) {
if (!GTFOMetaItem.KITCHEN_RECIPE.isItemEqual(stack))
return 0;
Expand Down

0 comments on commit 4521da3

Please sign in to comment.