Compare commits
6 Commits
f870c2cefc
...
3b769fdfd1
Author | SHA1 | Date | |
---|---|---|---|
3b769fdfd1 | |||
08061a69c5 | |||
acd5c06b7a | |||
87de48fffe | |||
a92b893bc9 | |||
9daa3df589 |
@ -22,6 +22,7 @@ import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.get
|
||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||
import ru.dbotthepony.mc.otm.core.isNotSameAs
|
||||
import ru.dbotthepony.mc.otm.menu.decorative.FluidTankMenu
|
||||
import ru.dbotthepony.mc.otm.network.wrap
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
@ -109,7 +110,7 @@ class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery
|
||||
|
||||
val moved1 = moveFluid(source = cap1, destination = fluid)
|
||||
|
||||
if (moved1 != moved0 || moved1.amount != moved0.amount) {
|
||||
if (moved1 isNotSameAs moved0) {
|
||||
LOGGER.error("Error moving fluids in Fluid tank at $blockPos: moved $moved0 during simulation from ${cap.container}, moved $moved1 from ${cap1.container} during execution. This is likely a bug in OTM or other mod!")
|
||||
} else {
|
||||
item.count--
|
||||
@ -161,7 +162,7 @@ class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery
|
||||
|
||||
val moved1 = moveFluid(source = fluid, destination = cap1)
|
||||
|
||||
if (moved1 != moved0 || moved1.amount != moved0.amount) {
|
||||
if (moved1 isNotSameAs moved0) {
|
||||
LOGGER.error("Error moving fluids in Fluid tank at $blockPos: moved $moved0 during simulation from ${cap.container}, moved $moved1 from ${cap1.container} during execution. This is likely a bug in OTM or other mod!")
|
||||
} else {
|
||||
item.count--
|
||||
|
@ -4,6 +4,7 @@ import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.component.DataComponents
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.item.BlockItem
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.component.CustomData
|
||||
@ -39,7 +40,7 @@ open class BlockMatteryFluidHandler(private val _capacity: IntSupplier, field: D
|
||||
/**
|
||||
* Fluid handler for items representing block with [BlockMatteryFluidHandler]
|
||||
*/
|
||||
open class Item(itemStack: ItemStack, capacity: IntSupplier, private val nbtName: String) : ItemMatteryFluidHandler(itemStack, capacity) {
|
||||
open class Item(itemStack: ItemStack, capacity: IntSupplier, private val nbtName: String, private val blockEntityID: ResourceLocation) : ItemMatteryFluidHandler(itemStack, capacity) {
|
||||
override var fluid: FluidStack
|
||||
get() {
|
||||
val custom = itemStack.getOrDefault(DataComponents.BLOCK_ENTITY_DATA, CustomData.EMPTY)
|
||||
@ -51,6 +52,12 @@ open class BlockMatteryFluidHandler(private val _capacity: IntSupplier, field: D
|
||||
|
||||
itemStack[DataComponents.BLOCK_ENTITY_DATA] = CustomData.of(data.copyTag().also {
|
||||
it[nbtName] = value.saveOptional(Registries)
|
||||
|
||||
// workaround for minecraft requiring block entity IDs inside blockitems
|
||||
// but why? it is not used, like, anywhere.
|
||||
if ("id" !in it) {
|
||||
it["id"] = blockEntityID.toString()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class PainterScreen(menu: PainterMenu, inventory: Inventory, title: Component) :
|
||||
}
|
||||
|
||||
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
||||
val frame = FramePanel(this, 200f, 120f, title)
|
||||
val frame = FramePanel(this, 244f, 120f, title)
|
||||
|
||||
val strip = EditablePanel(this, frame, width = AbstractSlotPanel.SIZE)
|
||||
strip.dock = Dock.LEFT
|
||||
@ -142,7 +142,7 @@ class PainterScreen(menu: PainterMenu, inventory: Inventory, title: Component) :
|
||||
for (recipe in recipes) {
|
||||
val recipeOutput = recipe.value.getOutput(menu.inputContainer)
|
||||
|
||||
object : ButtonPanel<PainterScreen>(this@PainterScreen, canvas.canvas) {
|
||||
object : ButtonPanel<PainterScreen>(this@PainterScreen, canvas.canvas, width = 18f, height = 18f) {
|
||||
init {
|
||||
buttons.add(this)
|
||||
dockRight = 1f
|
||||
|
@ -483,9 +483,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
||||
}
|
||||
|
||||
if (upgrades != null) {
|
||||
upgradesButton = addButton(object : ButtonPanel<S>(
|
||||
screen, this@DeviceControls,
|
||||
) {
|
||||
upgradesButton = addButton(object : ButtonPanel<S>(screen, this@DeviceControls, width = 18f, height = 18f) {
|
||||
init {
|
||||
tooltips.add(TranslatableComponent("otm.gui.upgrades"))
|
||||
}
|
||||
@ -590,7 +588,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
||||
}
|
||||
}
|
||||
).also {
|
||||
tooltips.add(TranslatableComponent("otm.gui.sides.item_config"))
|
||||
it.tooltips.add(TranslatableComponent("otm.gui.sides.item_config"))
|
||||
})
|
||||
} else {
|
||||
itemConfigButton = null
|
||||
@ -610,7 +608,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
||||
}
|
||||
}
|
||||
).also {
|
||||
tooltips.add(TranslatableComponent("otm.gui.sides.energy_config"))
|
||||
it.tooltips.add(TranslatableComponent("otm.gui.sides.energy_config"))
|
||||
})
|
||||
} else {
|
||||
energyConfigButton = null
|
||||
@ -630,7 +628,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
||||
}
|
||||
}
|
||||
).also {
|
||||
tooltips.add(TranslatableComponent("otm.gui.sides.fluid_config"))
|
||||
it.tooltips.add(TranslatableComponent("otm.gui.sides.fluid_config"))
|
||||
})
|
||||
} else {
|
||||
fluidConfigButton = null
|
||||
|
@ -41,7 +41,7 @@ open class TextInputPanel<out S : Screen>(
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 60f,
|
||||
height: Float = 15f,
|
||||
height: Float = 11f,
|
||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
||||
private data class TextSelection(val cursor: Int, val shift: Int) {
|
||||
val isLeft get() = shift < 0
|
||||
@ -159,7 +159,7 @@ open class TextInputPanel<out S : Screen>(
|
||||
|
||||
init {
|
||||
scissor = true
|
||||
dockPadding = DockProperty(3f, 3f, 3f, 3f)
|
||||
dockPadding = DockProperty(3f, 2f, 3f, 2f)
|
||||
}
|
||||
|
||||
private var oldText = ArrayList<String>()
|
||||
|
@ -15,7 +15,6 @@ import net.minecraft.Util
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Holder
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.HolderSet
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.SectionPos
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
@ -568,3 +567,28 @@ fun <T : Any> Registry<T>.getHolderOrThrow(value: T): Holder<T> {
|
||||
fun <T : Any> Registry<T>.getReverseTag(value: T): Stream<TagKey<T>> {
|
||||
return getHolder(value)?.tags() ?: Stream.empty()
|
||||
}
|
||||
|
||||
// forge > neoforge moment
|
||||
infix fun FluidStack.isSameFluidSameComponents(other: FluidStack): Boolean {
|
||||
return FluidStack.isSameFluidSameComponents(this, other)
|
||||
}
|
||||
|
||||
infix fun FluidStack.isSameFluid(other: FluidStack): Boolean {
|
||||
return FluidStack.isSameFluid(this, other)
|
||||
}
|
||||
|
||||
infix fun FluidStack.isNotSameFluidSameComponents(other: FluidStack): Boolean {
|
||||
return !FluidStack.isSameFluidSameComponents(this, other)
|
||||
}
|
||||
|
||||
infix fun FluidStack.isNotSameFluid(other: FluidStack): Boolean {
|
||||
return !FluidStack.isSameFluid(this, other)
|
||||
}
|
||||
|
||||
infix fun FluidStack.isSameAs(other: FluidStack): Boolean {
|
||||
return FluidStack.isSameFluidSameComponents(this, other) && amount == other.amount
|
||||
}
|
||||
|
||||
infix fun FluidStack.isNotSameAs(other: FluidStack): Boolean {
|
||||
return !FluidStack.isSameFluidSameComponents(this, other) && amount == other.amount
|
||||
}
|
||||
|
@ -7,9 +7,11 @@ import net.minecraft.world.item.BlockItem
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.TooltipFlag
|
||||
import net.minecraft.world.item.context.UseOnContext
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType
|
||||
import net.neoforged.neoforge.capabilities.Capabilities
|
||||
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent
|
||||
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions
|
||||
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent
|
||||
import ru.dbotthepony.mc.otm.block.decorative.FluidTankBlock
|
||||
import ru.dbotthepony.mc.otm.block.entity.decorative.FluidTankBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.fluid.BlockMatteryFluidHandler
|
||||
@ -18,19 +20,23 @@ import ru.dbotthepony.mc.otm.core.TooltipList
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.item.FluidCapsuleItem
|
||||
import ru.dbotthepony.mc.otm.registry.CapabilitiesRegisterListener
|
||||
import java.util.function.Consumer
|
||||
import ru.dbotthepony.mc.otm.registry.ClientExtensionsListener
|
||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||
import java.util.function.IntSupplier
|
||||
|
||||
class FluidTankItem(block: FluidTankBlock, properties: Properties, val capacity: IntSupplier) : BlockItem(block, properties),
|
||||
CapabilitiesRegisterListener {
|
||||
class FluidTankItem(block: FluidTankBlock, properties: Properties, val capacity: IntSupplier) : BlockItem(block, properties), CapabilitiesRegisterListener, ClientExtensionsListener {
|
||||
val tooltips = TooltipList()
|
||||
|
||||
init {
|
||||
tooltips.itemFluid()
|
||||
}
|
||||
|
||||
private val blockEntityRegistryId by lazy {
|
||||
BlockEntityType.getKey(MBlockEntities.FLUID_TANK)!!
|
||||
}
|
||||
|
||||
override fun registerCapabilities(event: RegisterCapabilitiesEvent) {
|
||||
event.registerItem(Capabilities.FluidHandler.ITEM, { o, c -> BlockMatteryFluidHandler.Item(o, capacity, FluidTankBlockEntity.FLUID_KEY) }, this)
|
||||
event.registerItem(Capabilities.FluidHandler.ITEM, { o, c -> BlockMatteryFluidHandler.Item(o, capacity, FluidTankBlockEntity.FLUID_KEY, blockEntityRegistryId) }, this)
|
||||
}
|
||||
|
||||
override fun onItemUseFirst(stack: ItemStack, pContext: UseOnContext): InteractionResult {
|
||||
@ -43,12 +49,7 @@ class FluidTankItem(block: FluidTankBlock, properties: Properties, val capacity:
|
||||
pContext.clickedFace
|
||||
)
|
||||
|
||||
if (FluidCapsuleItem.canInteract(
|
||||
pContext.itemInHand,
|
||||
pContext.player ?: return InteractionResult.FAIL,
|
||||
context
|
||||
)
|
||||
)
|
||||
if (FluidCapsuleItem.canInteract(pContext.itemInHand, pContext.player ?: return InteractionResult.FAIL, context))
|
||||
return FluidCapsuleItem.interact(pContext.itemInHand, pContext.player!!, context)
|
||||
|
||||
return super.onItemUseFirst(stack, pContext)
|
||||
@ -76,13 +77,11 @@ class FluidTankItem(block: FluidTankBlock, properties: Properties, val capacity:
|
||||
tooltips.assemble(pStack, p_339594_, pTooltip::add)
|
||||
}
|
||||
|
||||
override fun initializeClient(consumer: Consumer<IClientItemExtensions>) {
|
||||
super.initializeClient(consumer)
|
||||
|
||||
consumer.accept(object : IClientItemExtensions {
|
||||
override fun registerClientExtensions(event: RegisterClientExtensionsEvent) {
|
||||
event.registerItem(object : IClientItemExtensions {
|
||||
override fun getCustomRenderer(): BlockEntityWithoutLevelRenderer {
|
||||
return FluidTankRenderer.FluidTankItemRenderer
|
||||
}
|
||||
})
|
||||
}, this)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user