46 lines
1.3 KiB
Kotlin
46 lines
1.3 KiB
Kotlin
|
package net.shadowfacts.extrahoppers.block.grate
|
||
|
|
||
|
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||
|
import net.fabricmc.fabric.api.util.NbtType
|
||
|
import net.minecraft.block.entity.BlockEntity
|
||
|
import net.minecraft.fluid.FluidState
|
||
|
import net.minecraft.nbt.CompoundTag
|
||
|
import net.minecraft.nbt.NbtHelper
|
||
|
import net.shadowfacts.extrahoppers.init.EHBlockEntities
|
||
|
|
||
|
/**
|
||
|
* @author shadowfacts
|
||
|
*/
|
||
|
class GrateBlockEntity: BlockEntity(EHBlockEntities.GRATE), BlockEntityClientSerializable {
|
||
|
|
||
|
var fluidState: FluidState? = null
|
||
|
|
||
|
override fun toTag(tag: CompoundTag): CompoundTag {
|
||
|
fluidState?.also {
|
||
|
tag.put("fluid", NbtHelper.fromBlockState(it.blockState))
|
||
|
}
|
||
|
return super.toTag(tag)
|
||
|
}
|
||
|
|
||
|
override fun fromTag(tag: CompoundTag) {
|
||
|
super.fromTag(tag)
|
||
|
if (tag.contains("fluid", NbtType.COMPOUND)) {
|
||
|
fluidState = NbtHelper.toBlockState(tag.getCompound("fluid")).fluidState
|
||
|
}
|
||
|
}
|
||
|
|
||
|
override fun toClientTag(tag: CompoundTag): CompoundTag {
|
||
|
fluidState?.also {
|
||
|
tag.put("fluid", NbtHelper.fromBlockState(it.blockState))
|
||
|
}
|
||
|
return tag
|
||
|
}
|
||
|
|
||
|
override fun fromClientTag(tag: CompoundTag) {
|
||
|
if (tag.contains("fluid", NbtType.COMPOUND)) {
|
||
|
fluidState = NbtHelper.toBlockState(tag.getCompound("fluid")).fluidState
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|