Skip to content

Commit

Permalink
feat: remove trash slot from Bio-Lab UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Aug 1, 2023
1 parent 74e73e5 commit eaef2ad
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.util.GeckoLibUtil;

import java.util.Arrays;
import java.util.List;

public class BioLabBlockEntity extends MachineBlockEntity<BioLabRecipe, BioLabStateData> implements MenuProvider, IAnimatable {

public static final int FUEL_SLOTS = 1;
public static final int INPUT_SLOTS = BioLabRecipe.MAX_INGREDIENTS + BioLabRecipe.MAX_REACTANT;
public static final int OUTPUT_SLOTS = 2;
public static final int OUTPUT_SLOTS = 1;

public static final int MAX_FUEL = 1_000;
public static final short BASE_COST = 2;
Expand Down Expand Up @@ -141,45 +140,6 @@ protected boolean doesRecipeResultFitIntoOutputInv(BioLabRecipe craftingGoal, It
return outputInventory.getItem(0).isEmpty() || outputInventory.doesItemStackFit(0, stackToCraft);
}

private boolean canContainerItemsFitIntoTrashSlot(List<IngredientStack> ingredients, int[] ingredientCost) {
int lastIndex = inputInventory.getContainerSize() - 1;
int trashAmount = outputInventory.getItem(1).getCount();

if (trashAmount >= outputInventory.getMaxStackSize()) return false;
if (trashAmount < 1) return true;

for (int idx = 0; idx < lastIndex; idx++) {
final ItemStack foundStack = inputInventory.getItem(idx);
if (!foundStack.isEmpty() && foundStack.hasCraftingRemainingItem()) {
ItemStack containerItem = foundStack.getCraftingRemainingItem();
if (!containerItem.isEmpty()) {
for (int i = 0; i < ingredients.size(); i++) {
int remainingCost = ingredientCost[i];
if (remainingCost > 0 && ingredients.get(i).testItem(foundStack)) {
int amount = Math.min(remainingCost, foundStack.getCount());
ingredientCost[i] -= amount;
containerItem.setCount(amount);
if (!outputInventory.doesItemStackFit(1, containerItem)) return false;
break;
}
}
}
}
}

return true;
}

private void outputContainerItems(ItemStack foundStack, int amount) {
if (foundStack.hasCraftingRemainingItem()) {
ItemStack containerItem = foundStack.getCraftingRemainingItem();
if (!containerItem.isEmpty()) {
containerItem.setCount(amount);
outputInventory.insertItemStack(1, containerItem);
}
}
}

@Nullable
@Override
protected BioLabRecipe resolveRecipeFromInput(Level level) {
Expand Down Expand Up @@ -261,9 +221,6 @@ protected boolean craftRecipe(BioLabRecipe recipeToCraft, Level level) {
ingredientCost[i] = ingredients.get(i).count();
}

//check if we can output all container items
if (!canContainerItemsFitIntoTrashSlot(ingredients, Arrays.copyOf(ingredientCost, ingredientCost.length))) return false;

//consume reactant
final int lastIndex = inputInventory.getContainerSize() - 1;
inputInventory.removeItem(lastIndex, 1);
Expand All @@ -277,7 +234,6 @@ protected boolean craftRecipe(BioLabRecipe recipeToCraft, Level level) {
if (remainingCost > 0 && ingredients.get(i).testItem(foundStack)) {
int amount = Math.min(remainingCost, foundStack.getCount());
inputInventory.removeItem(idx, amount);
outputContainerItems(foundStack, amount);
ingredientCost[i] -= amount;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ protected BioLabMenu(int id, Inventory playerInventory, BehavioralInventory<?> f
addSlot(new Slot(inputInventory, 4, 80, 62)); // reactant/vial slot

addSlot(new OutputSlot(outputInventory, 0, 80, 88));
addSlot(new OutputSlot(outputInventory, 1, 116, 88)); // trash slot for empty vials

addDataSlots(stateData);
}
Expand Down
Binary file modified src/main/resources/assets/biomancy/textures/gui/menu_bio_lab.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eaef2ad

Please sign in to comment.