Skip to content

Commit

Permalink
Fixes comparator output on Fluid Hoppers
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaargolo committed Oct 9, 2022
1 parent 74575d0 commit 5ee52f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FluidHopper: HopperBlock(FabricBlockSettings.of(Material.METAL, MapColor.S
override fun hasComparatorOutput(state: BlockState?) = true

override fun getComparatorOutput(state: BlockState?, world: World, pos: BlockPos): Int {
return StorageUtil.calculateComparatorOutput((world.getBlockEntity(pos) as? TankBlockEntity)?.tank)
return StorageUtil.calculateComparatorOutput((world.getBlockEntity(pos) as? FluidHopperBlockEntity)?.tank)
}

override fun onUse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package io.github.lucaargolo.kibe.blocks.miscellaneous

import io.github.lucaargolo.kibe.blocks.getEntityType
import io.github.lucaargolo.kibe.utils.SyncableBlockEntity
import io.github.lucaargolo.kibe.utils.readTank
import io.github.lucaargolo.kibe.utils.writeTank
import net.fabricmc.fabric.api.lookup.v1.block.BlockApiCache
Expand All @@ -23,7 +24,7 @@ import net.minecraft.util.math.Direction
import net.minecraft.world.World
import kotlin.math.min

class FluidHopperBlockEntity(block: FluidHopper, pos: BlockPos, state: BlockState): BlockEntity(getEntityType(block), pos, state) {
class FluidHopperBlockEntity(block: FluidHopper, pos: BlockPos, state: BlockState): SyncableBlockEntity(getEntityType(block), pos, state) {

companion object {
private const val CAPACITY = FluidConstants.BUCKET
Expand All @@ -44,6 +45,16 @@ class FluidHopperBlockEntity(block: FluidHopper, pos: BlockPos, state: BlockStat
val tank = object : SingleVariantStorage<FluidVariant>() {
override fun getBlankVariant(): FluidVariant = FluidVariant.blank()
override fun getCapacity(variant: FluidVariant?): Long = CAPACITY

override fun onFinalCommit() {
markDirtyAndSync()
}
}

fun markDirtyAndSync() {
markDirty()
if(world?.isClient == false)
sync()
}

override fun writeNbt(tag: NbtCompound) {
Expand All @@ -56,6 +67,10 @@ class FluidHopperBlockEntity(block: FluidHopper, pos: BlockPos, state: BlockStat
readTank(tag, tank)
}

override fun writeClientNbt(tag: NbtCompound) = tag.also { writeNbt(it) }

override fun readClientNbt(tag: NbtCompound) = readNbt(tag)

private fun tick(world: ServerWorld, pos: BlockPos, state: BlockState) {
if (!state[HopperBlock.ENABLED]) return

Expand Down

0 comments on commit 5ee52f3

Please sign in to comment.