Skip to content

Commit

Permalink
fix: fix machines not displaying nutrient cost
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Nov 6, 2024
1 parent ceea183 commit 10135f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,29 @@ protected void serverTick(final ServerLevel level) {
boolean emitRedstoneSignal = false;
if (craftingGoal == null) {
state.cancelCrafting();
} else {
}
else {
ItemStack itemToCraft = getItemToCraft(level, craftingGoal);
if (itemToCraft.isEmpty()) {
state.cancelCrafting();
} else {
}
else {
if (doesRecipeResultFitIntoOutputInv(craftingGoal, itemToCraft)) {
if (state.getCraftingState() == CraftingState.NONE) { // nothing is being crafted, try to start crafting
if (hasEnoughFuel(craftingGoal)) { //make sure there is enough fuel to craft the recipe
state.setCraftingGoalRecipe(craftingGoal, getInputInventory().getRecipeWrapper());
if (hasEnoughFuel(craftingGoal)) {
state.setCraftingState(CraftingState.IN_PROGRESS);
state.clear(); //safeguard, shouldn't be needed
state.setCraftingGoalRecipe(craftingGoal, getInputInventory().getRecipeWrapper()); // this also sets the time required for crafting
}
} else if (!state.isCraftingCanceled()) { // something is being crafted, check that the crafting goals match
}
else if (!state.isCraftingCanceled()) { // something is being crafted, check that the crafting goals match
R prevCraftingGoal = state.getCraftingGoalRecipe(level).orElse(null);
if (prevCraftingGoal == null || !craftingGoal.isRecipeEqual(prevCraftingGoal)) {
state.cancelCrafting();
}
}
}
else {
if (state.getCraftingState() != CraftingState.COMPLETED) {
state.cancelCrafting();
}
else if (state.getCraftingState() != CraftingState.COMPLETED) {
state.cancelCrafting();
}
}

Expand Down Expand Up @@ -158,13 +158,8 @@ protected void serverTick(final ServerLevel level) {
//clean-up states
if (state.isCraftingCanceled()) {
state.setCraftingState(CraftingState.NONE);
state.clear();
}
else if (state.getCraftingState() == CraftingState.NONE) {
state.clear();
}

//update BlockState to reflect tile state
updateBlockState(level, state, emitRedstoneSignal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public CraftingState getCraftingState() {

public void setCraftingState(CraftingState craftingState) {
this.craftingState = craftingState;
if (craftingState == CraftingState.NONE) {
clear();
}
}

public boolean isCraftingCanceled() {
Expand Down Expand Up @@ -68,11 +71,13 @@ public void setCraftingGoalRecipe(T recipe, Container inputInventory) {
recipeId = recipe.getId();
timeForCompletion = recipe.getCraftingTimeTicks(inputInventory);
nutrientsCost = recipe.getCraftingCostNutrients(inputInventory);
timeElapsed = 0;
}

public abstract int getFuelCost();

public void clear() {
craftingState = CraftingState.NONE;
recipeId = null;
timeElapsed = 0;
timeForCompletion = 0;
Expand Down

0 comments on commit 10135f9

Please sign in to comment.