Skip to content

Commit

Permalink
fixed recipe looking up related bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Takakura-Anri committed Mar 22, 2020
1 parent daf14c6 commit 517c053
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GuiContainerStove(override val container: ContainerStove) : GuiContainerMa
val i = (width - xSize) / 2
val j = (height - ySize) / 2

widgetHeat.draw(i + 81, j + 48, mouseX, mouseY, partialTicks)
widgetHeat.draw(i + 81, j + 36, mouseX, mouseY, partialTicks)

if (fuelHandler.hasWork()) {
this.drawTexturedModalRect(i + 83, j + 22, 176, 14, 9, 9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.minecraft.nbt.NBTTagCompound
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityBeverageMaking : TileEntityFluidRecipeMachine<BeverageMakingRecipe>(BEVERAGE_MAKING_RECIPES, 8000, 2, 0..0, 1..1, 5) {
override val minProgress = FcConfig.machineConfig.beverageMakingProgress

val heatHandler = FuelHeatHandler()
val coolHandler = FuelHeatHandler()

Expand Down Expand Up @@ -87,6 +89,4 @@ class TileEntityBeverageMaking : TileEntityFluidRecipeMachine<BeverageMakingReci
}
return false
}

override fun canFinish(): Boolean = progress >= FcConfig.machineConfig.beverageMakingProgress
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.projecturanus.foodcraft.common.recipe.BREW_BARREL_RECIPES
import com.projecturanus.foodcraft.common.recipe.BrewBarrelRecipe

class TileEntityBrewBarrel : TileEntityFluidRecipeMachine<BrewBarrelRecipe>(BREW_BARREL_RECIPES, 8000, 5, 0..2, 3..4, 6) {
override val minProgress = FcConfig.machineConfig.brewBarrelProgress

override fun reset() {
}

override fun beforeProgress() {
}

override fun canProgress(): Boolean = true

override fun canFinish(): Boolean = progress >= FcConfig.machineConfig.brewBarrelProgress
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.projecturanus.foodcraft.common.block.entity

import com.projecturanus.foodcraft.common.config.FcConfig
import com.projecturanus.foodcraft.common.recipe.CHOPPING_BOARD_RECIPES
import com.projecturanus.foodcraft.common.recipe.ChoppingBoardRecipe
import com.projecturanus.foodcraft.common.util.get
import com.projecturanus.foodcraft.common.util.set
import net.minecraft.item.ItemStack

class TileEntityChoppingBoard : TileEntityRecipeMachine<ChoppingBoardRecipe>(CHOPPING_BOARD_RECIPES, 0..2, 3..3, 5) {
override val minProgress = FcConfig.machineConfig.choppingBoardProgress

override fun onLoad() {
super.onLoad()
}
Expand All @@ -23,6 +26,4 @@ class TileEntityChoppingBoard : TileEntityRecipeMachine<ChoppingBoardRecipe>(CHO
}

override fun canProgress(): Boolean = !inventory[4].isEmpty

override fun canFinish(): Boolean = progress >= 20
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.minecraft.nbt.NBTTagCompound
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityFryingPan : TileEntityFluidRecipeMachine<FryingPanRecipe>(FRYING_PAN_RECIPES, 4000, 2, 0..0, 1..1, 4) {
override val minProgress = FcConfig.machineConfig.fryingPanProgress

val heatHandler = FuelHeatHandler()

override fun onLoad() {
Expand Down Expand Up @@ -48,8 +50,6 @@ class TileEntityFryingPan : TileEntityFluidRecipeMachine<FryingPanRecipe>(FRYING
return heatHandler.temperature >= ITemperature.ZERO_CELCIUS + FcConfig.machineConfig.fryingPanHeat
}

override fun canFinish(): Boolean = progress >= FcConfig.machineConfig.fryingPanProgress

override fun readFromNBT(nbt: NBTTagCompound) {
super.readFromNBT(nbt)
heatHandler.deserializeNBT(nbt.getCompoundTag("heat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.minecraft.nbt.NBTTagCompound
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityMill : TileEntityRecipeMachine<MillRecipe>(MILL_RECIPES, 0..0, 1..1, 3) {
override val minProgress = FcConfig.machineConfig.millProgress

val heatHandler = FuelHeatHandler()

override fun onLoad() {
Expand Down Expand Up @@ -48,8 +50,6 @@ class TileEntityMill : TileEntityRecipeMachine<MillRecipe>(MILL_RECIPES, 0..0, 1
return heatHandler.temperature > ITemperature.ZERO_CELCIUS + FcConfig.machineConfig.millHeat
}

override fun canFinish(): Boolean = progress >= FcConfig.machineConfig.millProgress

override fun readFromNBT(nbt: NBTTagCompound) {
super.readFromNBT(nbt)
heatHandler.deserializeNBT(nbt.getCompoundTag("heat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.minecraft.item.ItemStack
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityPan : TileEntityHeatRecipeMachine<PanRecipe>(PAN_RECIPES, 0..0, 1..1, 3) {
override var minProgress = recipe?.minTime ?: 10000

var waitingExtract = false

init {
Expand All @@ -27,25 +29,29 @@ class TileEntityPan : TileEntityHeatRecipeMachine<PanRecipe>(PAN_RECIPES, 0..0,

beforeProgress()

if (waitingExtract && progress > recipe?.maxTime ?: Int.MAX_VALUE) { // Overcooked
inventory.shrink(1)
inventory.insertItem(2, ItemStack(FCRItems.OVERCOOKED_FOOD), false)
reset()
}

if (recipe != null) {
// Finish
if (canFinish()) {
consumeInput()
working = false
val stack = recipe?.getRecipeOutput()?.copy()?: ItemStack.EMPTY
val stack = recipe?.getRecipeOutput()?.copy() ?: ItemStack.EMPTY
inventory.insertItem(1, stack, false)
waitingExtract = true
markDirty()
} else if (waitingExtract && progress > recipe!!.maxTime) { // Overcooked
inventory.shrink(1)
inventory.insertItem(2, ItemStack(FCRItems.OVERCOOKED_FOOD), false)
reset()
} else {
if (canProgress())
progress++
working = true
}
} else if (progress > 0) {
} else if (waitingExtract) {
progress++
} else if (!waitingExtract && progress > 0) {
progress = 0
working = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import net.minecraft.item.ItemStack
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityPot : TileEntityHeatRecipeMachine<PotRecipe>(POT_RECIPES, 0..11, 12..12, 14) {
override var minProgress = recipe?.minTime ?: 10000

var waitingExtract = false

init {
Expand All @@ -28,6 +30,12 @@ class TileEntityPot : TileEntityHeatRecipeMachine<PotRecipe>(POT_RECIPES, 0..11,

beforeProgress()

if (waitingExtract && progress > recipe?.maxTime ?: Int.MAX_VALUE) { // Overcooked
inventory.shrink(12)
inventory.insertItem(13, ItemStack(FCRItems.OVERCOOKED_FOOD), false)
reset()
}

if (recipe != null) {
// Finish
if (canFinish()) {
Expand All @@ -37,15 +45,13 @@ class TileEntityPot : TileEntityHeatRecipeMachine<PotRecipe>(POT_RECIPES, 0..11,
inventory.insertItem(12, stack, false)
waitingExtract = true
markDirty()
} else if (waitingExtract && progress > recipe!!.maxTime) { // Overcooked
inventory.shrink(12)
inventory.insertItem(13, ItemStack(FCRItems.OVERCOOKED_FOOD), false)
reset()
} else {
if (canProgress())
progress++
working = true
}
} else if (waitingExtract) {
progress++
} else if (!waitingExtract && progress > 0) {
progress = 0
working = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.minecraft.nbt.NBTTagCompound
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature

class TileEntityPressureCooker : TileEntityFluidRecipeMachine<PressureCookerRecipe>(PRESSURE_COOKER_RECIPES, 4000, 4, 0..2, 3..3, 6) {
override val minProgress = FcConfig.machineConfig.pressureCookerProgress

val heatHandler = FuelHeatHandler()

override fun onLoad() {
Expand Down Expand Up @@ -48,8 +50,6 @@ class TileEntityPressureCooker : TileEntityFluidRecipeMachine<PressureCookerReci
return heatHandler.temperature >= ITemperature.ZERO_CELCIUS + FcConfig.machineConfig.pressureCookerHeat
}

override fun canFinish(): Boolean = progress >= FcConfig.machineConfig.pressureCookerProgress

override fun readFromNBT(nbt: NBTTagCompound) {
super.readFromNBT(nbt)
heatHandler.deserializeNBT(nbt.getCompoundTag("heat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import net.minecraftforge.registries.IForgeRegistry
import kotlin.properties.Delegates

abstract class TileEntityRecipeMachine<T>(val recipeRegistry: IForgeRegistry<T>, val inputSlots: IntRange, val outputSlots: IntRange, slots: Int) : TileEntityMachine(slots) where T : FcRecipe<T> {
abstract val minProgress: Int

var recipe: T? = null
var progress = 0
var working by Delegates.observable(false) { property, old, new ->
Expand All @@ -25,7 +27,10 @@ abstract class TileEntityRecipeMachine<T>(val recipeRegistry: IForgeRegistry<T>,

override fun onLoad() {
inventory.contentChangedListener += {
if (it in inputSlots || it in outputSlots) recipe = findRecipe()
if (it in inputSlots || it in outputSlots) {
// When there is only one item left in machine, do not lookup recipes again
if (recipe == null) recipe = findRecipe()
}
}
inventory.validation = { slot, stack ->
when (slot) {
Expand Down Expand Up @@ -123,5 +128,5 @@ abstract class TileEntityRecipeMachine<T>(val recipeRegistry: IForgeRegistry<T>,
abstract fun reset()
abstract fun beforeProgress()
abstract fun canProgress(): Boolean
abstract fun canFinish(): Boolean
open fun canFinish(): Boolean = progress >= minProgress
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static class MachineConfig {
@Config.RangeInt(min = 1)
public int brewBarrelProgress = 3600;

@Config.Comment("Ticks to progress Chopping Board Recipes")
@Config.RangeInt(min = 1)
public int choppingBoardProgress = 20;

@Config.Comment("Minimum temperature (in celsius degrees) to start a recipe for Frying Pan Recipes")
public double fryingPanHeat = 90;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ object MachineProvider : IProbeInfoProvider {
val column = probeInfo.vertical()

val row = column.horizontal()
tileEntity.inventory[tileEntity.inputSlots].asSequence().filter { !it.isEmpty }.forEach { probeInfo.item(it) }
tileEntity.inventory[tileEntity.outputSlots].asSequence().filter { !it.isEmpty }.forEach { probeInfo.item(it) }

tileEntity.inventory[tileEntity.inputSlots].asSequence().filter { !it.isEmpty }.forEach { row.item(it) }
row.progress(tileEntity.progress, tileEntity.minProgress)
tileEntity.inventory[tileEntity.outputSlots].asSequence().filter { !it.isEmpty }.forEach { row.item(it) }
}

override fun getID(): String = "$MODID:machine_info"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"result": {
"item": "foodcraftreloaded:iron_plate",
"count": 8
"count": 4
}
}

0 comments on commit 517c053

Please sign in to comment.