From 5ee52f3a3cf7e05dbacb086ea3e79135c3528b53 Mon Sep 17 00:00:00 2001 From: lucaargolo Date: Sun, 9 Oct 2022 17:32:32 -0300 Subject: [PATCH] Fixes comparator output on Fluid Hoppers --- .../kibe/blocks/miscellaneous/FluidHopper.kt | 2 +- .../miscellaneous/FluidHopperBlockEntity.kt | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopper.kt b/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopper.kt index acc154b4..7f31936a 100644 --- a/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopper.kt +++ b/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopper.kt @@ -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( diff --git a/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopperBlockEntity.kt b/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopperBlockEntity.kt index 128e4771..0bbe581d 100644 --- a/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopperBlockEntity.kt +++ b/src/main/kotlin/io/github/lucaargolo/kibe/blocks/miscellaneous/FluidHopperBlockEntity.kt @@ -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 @@ -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 @@ -44,6 +45,16 @@ class FluidHopperBlockEntity(block: FluidHopper, pos: BlockPos, state: BlockStat val tank = object : SingleVariantStorage() { 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) { @@ -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