Use networked field directly as backing fluid field
This commit is contained in:
parent
7e5ea3be8d
commit
a5c1d7fbf8
@ -62,7 +62,7 @@ class FluidTankBlock : RotatableMatteryBlock(DEFAULT_MACHINE_PROPERTIES), Entity
|
||||
val tile = level?.getExistingBlockEntity(pos) ?: lightLevel
|
||||
|
||||
if (tile is FluidTankBlockEntity) {
|
||||
val fluid = tile.synchronizedFluid
|
||||
val fluid = tile.fluid.fluid
|
||||
|
||||
if (!fluid.isEmpty) {
|
||||
val newLevel = fluid.fluid.fluidType.getLightLevel(fluid)
|
||||
|
@ -27,12 +27,15 @@ import ru.dbotthepony.mc.otm.menu.decorative.FluidTankMenu
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
|
||||
class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.FLUID_TANK, blockPos, blockState) {
|
||||
val fluid = BlockMatteryFluidHandler(::onChanged, ItemsConfig::FLUID_TANK_CAPACITY)
|
||||
var synchronizedFluid by synchronizer.Field(FluidStack.EMPTY, FluidStackValueCodec, setter = { value, access, remote ->
|
||||
val fluid = BlockMatteryFluidHandler(ItemsConfig::FLUID_TANK_CAPACITY, synchronizer.Field(FluidStack.EMPTY, FluidStackValueCodec, setter = { value, access, remote ->
|
||||
access.write(value)
|
||||
|
||||
level?.lightEngine?.checkBlock(blockPos)
|
||||
})
|
||||
|
||||
if (!remote) {
|
||||
markDirtyFast()
|
||||
}
|
||||
}))
|
||||
|
||||
val fillInput = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
|
||||
val drainInput = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
|
||||
@ -73,11 +76,6 @@ class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery
|
||||
savetables.stateful(::output)
|
||||
}
|
||||
|
||||
private fun onChanged(new: FluidStack, old: FluidStack) {
|
||||
synchronizedFluid = new.copy()
|
||||
markDirtyFast()
|
||||
}
|
||||
|
||||
private fun drainItem() {
|
||||
val item = drainInput[0]
|
||||
|
||||
|
@ -7,18 +7,14 @@ import net.minecraftforge.common.util.INBTSerializable
|
||||
import net.minecraftforge.fluids.FluidStack
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.core.tagNotNull
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.IMutableField
|
||||
import java.util.function.IntSupplier
|
||||
|
||||
/**
|
||||
* Fluid handler for blocks
|
||||
*/
|
||||
class BlockMatteryFluidHandler(val onChanged: (new: FluidStack, old: FluidStack) -> Unit, private val _capacity: IntSupplier) : AbstractMatteryFluidHandler(), INBTSerializable<CompoundTag?> {
|
||||
override var fluid: FluidStack = FluidStack.EMPTY
|
||||
set(value) {
|
||||
val old = field
|
||||
field = value
|
||||
onChanged(value, old)
|
||||
}
|
||||
open class BlockMatteryFluidHandler(private val _capacity: IntSupplier, field: IMutableField<FluidStack>) : AbstractMatteryFluidHandler(), INBTSerializable<CompoundTag?> {
|
||||
override var fluid by field
|
||||
|
||||
override val capacity: Int
|
||||
get() = _capacity.asInt
|
||||
|
@ -32,7 +32,7 @@ class FluidTankRenderer(private val context: BlockEntityRendererProvider.Context
|
||||
packedLight: Int,
|
||||
packedOverlay: Int
|
||||
) {
|
||||
renderFluidInTank(tile.fluid, tile.synchronizedFluid, poseStack, bufferSource, packedLight, packedOverlay)
|
||||
renderFluidInTank(tile.fluid, tile.fluid.fluid, poseStack, bufferSource, packedLight, packedOverlay)
|
||||
}
|
||||
|
||||
object FluidTankItemRenderer : BlockEntityWithoutLevelRenderer(minecraft.blockEntityRenderDispatcher, minecraft.entityModels) {
|
||||
|
Loading…
Reference in New Issue
Block a user