Move fluid items to tooltiplist
This commit is contained in:
parent
c988c4b869
commit
e86299460b
@ -289,13 +289,13 @@ fun moveEnergy(source: IEnergyStorage, destination: IEnergyStorage, amount: Deci
|
||||
return Decimal.ZERO
|
||||
}
|
||||
|
||||
internal fun IFluidHandler.fluidLevel(tooltips: MutableList<Component>) {
|
||||
internal fun IFluidHandler.fluidLevel(tooltips: (Component) -> Unit) {
|
||||
val fluid = getFluidInTank(0)
|
||||
|
||||
if (fluid.isEmpty) {
|
||||
tooltips.add(formatFluidLevel(0, getTankCapacity(0), formatAsReadable = ShiftPressedCond).withStyle(ChatFormatting.GRAY))
|
||||
tooltips(formatFluidLevel(0, getTankCapacity(0), formatAsReadable = ShiftPressedCond).withStyle(ChatFormatting.GRAY))
|
||||
} else {
|
||||
tooltips.add(formatFluidLevel(fluid.amount, getTankCapacity(0), fluid.displayName, formatAsReadable = ShiftPressedCond).withStyle(ChatFormatting.GRAY))
|
||||
tooltips(formatFluidLevel(fluid.amount, getTankCapacity(0), fluid.displayName, formatAsReadable = ShiftPressedCond).withStyle(ChatFormatting.GRAY))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.item.BlockItem
|
||||
import net.minecraft.world.item.DyeColor
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.energy
|
||||
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
||||
@ -16,6 +17,7 @@ import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl
|
||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.batteryLevel
|
||||
import ru.dbotthepony.mc.otm.capability.fluidLevel
|
||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||
import ru.dbotthepony.mc.otm.client.ShiftPressedCond
|
||||
import ru.dbotthepony.mc.otm.client.isShiftDown
|
||||
@ -138,4 +140,12 @@ class TooltipList {
|
||||
fun doubleProcessing() {
|
||||
add(TranslatableComponent("otm.gui.double_processing").withStyle(ChatFormatting.GRAY))
|
||||
}
|
||||
|
||||
fun itemFluid() {
|
||||
addNormal { itemStack, acceptor ->
|
||||
itemStack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).ifPresentK {
|
||||
it.fluidLevel(acceptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||
import ru.dbotthepony.mc.otm.core.orNull
|
||||
import java.util.function.IntSupplier
|
||||
|
||||
class FluidCapsuleItem(val capacity: IntSupplier) : Item(Properties().stacksTo(64)) {
|
||||
class FluidCapsuleItem(val capacity: IntSupplier) : MatteryItem(Properties().stacksTo(64)) {
|
||||
// TODO: Так как использование предмета заблокировано за player.abilities.canBuild
|
||||
// капсулу нельзя использовать в режиме приключения
|
||||
// почему же можно использовать вёдра на котлах?
|
||||
@ -72,12 +72,8 @@ class FluidCapsuleItem(val capacity: IntSupplier) : Item(Properties().stacksTo(6
|
||||
return super.getName(pStack)
|
||||
}
|
||||
|
||||
override fun appendHoverText(pStack: ItemStack, pLevel: Level?, pTooltipComponents: MutableList<Component>, pIsAdvanced: TooltipFlag) {
|
||||
super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced)
|
||||
|
||||
pStack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).ifPresentK {
|
||||
it.fluidLevel(pTooltipComponents)
|
||||
}
|
||||
init {
|
||||
tooltips.itemFluid()
|
||||
}
|
||||
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||
|
@ -17,12 +17,19 @@ import ru.dbotthepony.mc.otm.block.entity.decorative.FluidTankBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.fluid.BlockMatteryFluidHandler
|
||||
import ru.dbotthepony.mc.otm.capability.fluidLevel
|
||||
import ru.dbotthepony.mc.otm.client.render.blockentity.FluidTankRenderer
|
||||
import ru.dbotthepony.mc.otm.core.TooltipList
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.IntSupplier
|
||||
|
||||
class FluidTankItem(block: FluidTankBlock, properties: Properties, val capacity: IntSupplier) : BlockItem(block, properties) {
|
||||
val tooltips = TooltipList()
|
||||
|
||||
init {
|
||||
tooltips.itemFluid()
|
||||
}
|
||||
|
||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
||||
return BlockMatteryFluidHandler.Item(stack, capacity, FluidTankBlockEntity.FLUID_KEY)
|
||||
}
|
||||
@ -53,10 +60,7 @@ class FluidTankItem(block: FluidTankBlock, properties: Properties, val capacity:
|
||||
|
||||
override fun appendHoverText(pStack: ItemStack, pLevel: Level?, pTooltip: MutableList<Component>, pFlag: TooltipFlag) {
|
||||
super.appendHoverText(pStack, pLevel, pTooltip, pFlag)
|
||||
|
||||
pStack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).ifPresentK {
|
||||
it.fluidLevel(pTooltip)
|
||||
}
|
||||
tooltips.assemble(pStack, pTooltip::add)
|
||||
}
|
||||
|
||||
override fun initializeClient(consumer: Consumer<IClientItemExtensions>) {
|
||||
|
Loading…
Reference in New Issue
Block a user