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