Skip to content

Commit

Permalink
hacky "fix" for progress syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttdoy committed Jul 4, 2024
1 parent 95f0058 commit a48d54a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class DoughMachineScreen(
pGuiGraphics.blit(texture, leftPos, topPos, 0, 0, imageWidth, imageHeight)

renderProgressArrow(pGuiGraphics)
println(menu.parent.progress)
println(menu.parent.maxProgress)
renderEnergyMeter(pGuiGraphics)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import net.minecraft.client.renderer.GameRenderer
import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory
import net.minecraftforge.common.capabilities.ForgeCapabilities
import kotlin.jvm.optionals.getOrNull

class WheatCrusherScreen(
pMenu: WheatCrusherMenu,
Expand All @@ -34,7 +33,7 @@ class WheatCrusherScreen(

renderProgressArrow(pGuiGraphics)
println(menu.parent.progress)
println(menu.parent.currentRecipe.getOrNull()?.time ?: "null recipe")
println(menu.parent.maxProgress)
renderEnergyMeter(pGuiGraphics)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(
protected set
var progress = 0
protected set
var maxProgress = 0
protected set

open fun tick(pLevel: Level, pPos: BlockPos, pState: BlockState, pBlockEntity: Progressive<T,R>) {
preTick(pLevel, pPos, pState, pBlockEntity)
Expand All @@ -116,14 +118,14 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(
final override fun adjustSaveAdditional(pTag: CompoundTag) {
adjustSaveAdditionalProgressive(pTag)
// currentRecipe.ifPresent { pTag.putInt(PROGRESS_KEY, progress) } // todo figure out why progress isn't syncing to the client
pTag.putInt(PROGRESS_KEY, progress)
pTag.putInt(PROGRESS_KEY, progress); pTag.putInt(MAX_PROGRESS_KEY, maxProgress)
}

open fun adjustLoadProgressive(pTag: CompoundTag) {}
final override fun adjustLoad(pTag: CompoundTag) {
adjustLoadProgressive(pTag)
// currentRecipe.ifPresent { progress = pTag.getInt(PROGRESS_KEY) } // TODO RVW
progress = pTag.getInt(PROGRESS_KEY)
progress = pTag.getInt(PROGRESS_KEY); maxProgress = pTag.getInt(MAX_PROGRESS_KEY)
}

open fun noRecipeTick (pLevel: Level, pPos: BlockPos, pState: BlockState, pBlockEntity: Progressive<T,R>) {}
Expand Down Expand Up @@ -175,6 +177,7 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(
val recipe = recipeDial.getRecipeFor(this, sLevel)
recipe.ifPresent {
if (consumeRecipe(pLevel, pPos, pState, pBlockEntity, it)) currentRecipe = recipe
maxProgress = it.time
}
} else {
pLevel.setBlockAndUpdate(pPos, pState.setValue(BlockStateProperties.POWERED, false))
Expand All @@ -187,6 +190,7 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(

private companion object {
const val PROGRESS_KEY = "progress"
const val MAX_PROGRESS_KEY = "maxProgress"
//const val RECIPE_KEY = "currentRecipe"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DoughMachineMenu(
ModMenuTypes.DOUGH_MACHINE.get(),
pContainerId, inventory, parent, 142, 84
) {
override fun getScaledProgress(): Int = parent.currentRecipe.getOrNull()?.let { ((parent.progress.toFloat() / it.time) * 24).toInt() } ?: 0
override fun getScaledProgress(): Int = ((parent.progress.toFloat() / parent.maxProgress.toFloat()) * 24).toInt()

constructor(pContainerId: Int, inventory: Inventory, byteBuf: FriendlyByteBuf) : this(
pContainerId, inventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import breadmod.registry.screen.ModMenuTypes
import net.minecraft.network.FriendlyByteBuf
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.Slot
import kotlin.jvm.optionals.getOrNull

class WheatCrusherMenu(
pContainerId: Int,
Expand All @@ -17,7 +16,7 @@ class WheatCrusherMenu(
ModMenuTypes.WHEAT_CRUSHER.get(),
pContainerId, inventory, parent, 174, 116
) {
override fun getScaledProgress(): Int = parent.currentRecipe.getOrNull()?.let { ((parent.progress.toFloat() / it.time) * 48).toInt() } ?: 0
override fun getScaledProgress(): Int = ((parent.progress.toFloat() / parent.maxProgress.toFloat()) * 48).toInt()

constructor(pContainerId: Int, inventory: Inventory, byteBuf: FriendlyByteBuf) : this(
pContainerId, inventory,
Expand Down

0 comments on commit a48d54a

Please sign in to comment.