diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt index ab5974e82..ecbd85b62 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt @@ -27,6 +27,7 @@ import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.container.balance import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.menu.tech.PoweredFurnaceMenu +import ru.dbotthepony.mc.otm.registry.MBlockEntities class PoweredFurnaceBlockEntity( type: BlockEntityType, @@ -80,8 +81,13 @@ class PoweredFurnaceBlockEntity( super.tick() } - override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { - return PoweredFurnaceMenu(containerID, inventory, this) + override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu? { + return when (type) { + MBlockEntities.POWERED_FURNACE -> PoweredFurnaceMenu.furnace(containerID, inventory, this) + MBlockEntities.POWERED_BLAST_FURNACE -> PoweredFurnaceMenu.blasting(containerID, inventory, this) + MBlockEntities.POWERED_SMOKER -> PoweredFurnaceMenu.smoking(containerID, inventory, this) + else -> null + } } override fun onJobFinish(status: JobStatus, id: Int) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterEntanglerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterEntanglerScreen.kt index 1141205bf..b706d73ed 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterEntanglerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterEntanglerScreen.kt @@ -13,6 +13,8 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel +import ru.dbotthepony.mc.otm.compat.jei.MatterEntanglerRecipeCategory +import ru.dbotthepony.mc.otm.compat.jei.PlatePressRecipeCategory import ru.dbotthepony.mc.otm.menu.matter.MatterEntanglerMenu class MatterEntanglerScreen(menu: MatterEntanglerMenu, inventory: Inventory, title: Component) : MatteryScreen(menu, inventory, title) { @@ -35,6 +37,7 @@ class MatterEntanglerScreen(menu: MatterEntanglerMenu, inventory: Inventory, tit it.dock = Dock.LEFT it.dockHorizontal(4f) it.dockResize = DockResizeMode.NONE + it.setRecipeType { listOf(MatterEntanglerRecipeCategory.recipeType) } } SlotPanel(this, frame, menu.outputs[0]).also { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/ChemicalGeneratorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/ChemicalGeneratorScreen.kt index 2f84ddd7e..c56e2283c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/ChemicalGeneratorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/ChemicalGeneratorScreen.kt @@ -1,5 +1,6 @@ package ru.dbotthepony.mc.otm.client.screen.tech +import mezz.jei.api.constants.RecipeTypes import net.minecraft.network.chat.Component import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.client.screen.MatteryScreen @@ -30,6 +31,9 @@ class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory, } progress.flop = true + + progress.setRecipeType { listOf(RecipeTypes.FUELING) } + SlotPanel(this, frame, menu.residueSlot, 56f, PROGRESS_SLOT_TOP) SlotPanel(this, frame, menu.fuelSlot, 104f, PROGRESS_SLOT_TOP) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt index 3a3d28b6e..8fd28ea77 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel +import ru.dbotthepony.mc.otm.compat.jei.PlatePressRecipeCategory import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Component) : @@ -20,7 +21,7 @@ class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Compon BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.inputSlot, 56f, PROGRESS_SLOT_TOP) - ProgressGaugePanel(this, frame, menu.progressGauge, 78f, PROGRESS_ARROW_TOP) + ProgressGaugePanel(this, frame, menu.progressGauge, 78f, PROGRESS_ARROW_TOP).setRecipeType { listOf(PlatePressRecipeCategory.recipeType) } SlotPanel(this, frame, menu.outputSlot, 104f, PROGRESS_SLOT_TOP) makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, energyConfig = menu.energyConfig, itemConfig = menu.itemConfig, upgrades = menu.upgrades) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PoweredFurnaceScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PoweredFurnaceScreen.kt index 2f124d235..35f43914b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PoweredFurnaceScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PoweredFurnaceScreen.kt @@ -1,5 +1,6 @@ package ru.dbotthepony.mc.otm.client.screen.tech +import mezz.jei.api.constants.RecipeTypes import net.minecraft.network.chat.Component import net.minecraft.world.entity.player.Inventory import ru.dbotthepony.mc.otm.client.screen.MatteryScreen @@ -11,6 +12,7 @@ import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.menu.tech.PoweredFurnaceMenu import ru.dbotthepony.mc.otm.menu.tech.TwinPlatePressMenu +import ru.dbotthepony.mc.otm.registry.MMenus class PoweredFurnaceScreen(menu: PoweredFurnaceMenu, inventory: Inventory, title: Component) : MatteryScreen(menu, inventory, title) { @@ -21,15 +23,32 @@ class PoweredFurnaceScreen(menu: PoweredFurnaceMenu, inventory: Inventory, title BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.inputSlots[0], 56f, PROGRESS_SLOT_TOP - 10f) - ProgressGaugePanel(this, frame, menu.progressGauge[0], 78f, PROGRESS_ARROW_TOP - 10f) + val a = ProgressGaugePanel(this, frame, menu.progressGauge[0], 78f, PROGRESS_ARROW_TOP - 10f) SlotPanel(this, frame, menu.outputSlots[0], 104f, PROGRESS_SLOT_TOP - 10f) SlotPanel(this, frame, menu.inputSlots[1], 56f, PROGRESS_SLOT_TOP + 10f) - ProgressGaugePanel(this, frame, menu.progressGauge[1], 78f, PROGRESS_ARROW_TOP + 10f) + val b = ProgressGaugePanel(this, frame, menu.progressGauge[1], 78f, PROGRESS_ARROW_TOP + 10f) SlotPanel(this, frame, menu.outputSlots[1], 104f, PROGRESS_SLOT_TOP + 10f) makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, energyConfig = menu.energyConfig, itemConfig = menu.itemConfig, balanceInputs = menu.balanceInputs, upgrades = menu.upgrades) + when (menu.type) { + MMenus.POWERED_FURNACE -> { + a.setRecipeType { listOf(RecipeTypes.SMELTING) } + b.setRecipeType { listOf(RecipeTypes.SMELTING) } + } + + MMenus.POWERED_BLAST_FURNACE -> { + a.setRecipeType { listOf(RecipeTypes.BLASTING) } + b.setRecipeType { listOf(RecipeTypes.BLASTING) } + } + + MMenus.POWERED_SMOKER -> { + a.setRecipeType { listOf(RecipeTypes.SMOKING) } + b.setRecipeType { listOf(RecipeTypes.SMOKING) } + } + } + return frame } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/TwinPlatePressScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/TwinPlatePressScreen.kt index 946201340..a762523c2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/TwinPlatePressScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/TwinPlatePressScreen.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel +import ru.dbotthepony.mc.otm.compat.jei.PlatePressRecipeCategory import ru.dbotthepony.mc.otm.menu.tech.TwinPlatePressMenu class TwinPlatePressScreen(menu: TwinPlatePressMenu, inventory: Inventory, title: Component) : @@ -20,11 +21,11 @@ class TwinPlatePressScreen(menu: TwinPlatePressMenu, inventory: Inventory, title BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.inputSlots[0], 56f, PROGRESS_SLOT_TOP - 10f) - ProgressGaugePanel(this, frame, menu.progressGauge0, 78f, PROGRESS_ARROW_TOP - 10f) + ProgressGaugePanel(this, frame, menu.progressGauge0, 78f, PROGRESS_ARROW_TOP - 10f).setRecipeType { listOf(PlatePressRecipeCategory.recipeType) } SlotPanel(this, frame, menu.outputSlots[0], 104f, PROGRESS_SLOT_TOP - 10f) SlotPanel(this, frame, menu.inputSlots[1], 56f, PROGRESS_SLOT_TOP + 10f) - ProgressGaugePanel(this, frame, menu.progressGauge1, 78f, PROGRESS_ARROW_TOP + 10f) + ProgressGaugePanel(this, frame, menu.progressGauge1, 78f, PROGRESS_ARROW_TOP + 10f).setRecipeType { listOf(PlatePressRecipeCategory.recipeType) } SlotPanel(this, frame, menu.outputSlots[1], 104f, PROGRESS_SLOT_TOP + 10f) makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, energyConfig = menu.energyConfig, itemConfig = menu.itemConfig, balanceInputs = menu.balanceInputs, upgrades = menu.upgrades) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/ProgressGaugePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/ProgressGaugePanel.kt index eb1b4db49..3bb7a8b89 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/ProgressGaugePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/ProgressGaugePanel.kt @@ -1,7 +1,9 @@ package ru.dbotthepony.mc.otm.client.screen.widget +import com.mojang.blaze3d.platform.InputConstants import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.PoseStack +import mezz.jei.api.recipe.RecipeType import net.minecraft.ChatFormatting import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.screens.Screen @@ -9,22 +11,28 @@ import net.minecraft.network.chat.Component import ru.dbotthepony.mc.otm.client.render.UVWindingOrder import ru.dbotthepony.mc.otm.client.render.WidgetLocation import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel +import ru.dbotthepony.mc.otm.client.screen.panels.button.AbstractButtonPanel +import ru.dbotthepony.mc.otm.compat.jei.JEIPlugin +import ru.dbotthepony.mc.otm.compat.jei.isJeiLoaded +import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget +import java.util.function.Supplier import kotlin.math.roundToInt -open class ProgressGaugePanel @JvmOverloads constructor( +open class ProgressGaugePanel( screen: S, parent: EditablePanel<*>? = null, val widget: ProgressGaugeWidget, x: Float = 0f, y: Float = 0f -): EditablePanel(screen, parent, x, y, width = GAUGE_BACKGROUND.width, height = GAUGE_BACKGROUND.height) { +): AbstractButtonPanel(screen, parent, x, y, width = GAUGE_BACKGROUND.width, height = GAUGE_BACKGROUND.height) { init { scissor = true } var flop = false + private var recipeTypeSupplier: Supplier>>? = null protected open fun makeTooltip(): MutableList { val tooltip: MutableList @@ -46,6 +54,11 @@ open class ProgressGaugePanel @JvmOverloads constructor( ) } + if (recipeTypeSupplier != null) { + tooltip.add(TextComponent("")) + tooltip.add(TranslatableComponent("jei.tooltip.show.recipes").withStyle(ChatFormatting.GRAY)) + } + return tooltip } @@ -78,6 +91,25 @@ open class ProgressGaugePanel @JvmOverloads constructor( return false } + override fun test(value: Int): Boolean { + return recipeTypeSupplier != null && value == InputConstants.MOUSE_BUTTON_LEFT + } + + override fun onClick(mouseButton: Int) { + val recipeTypeSupplier = recipeTypeSupplier ?: return + JEIPlugin.RUNTIME.recipesGui.showTypes(recipeTypeSupplier.get()) + } + + private fun setRecipeType0(provider: Supplier>>) { + recipeTypeSupplier = provider + } + + fun setRecipeType(provider: Supplier>>) { + if (isJeiLoaded) { + setRecipeType0(provider) + } + } + companion object { val GAUGE_BACKGROUND = WidgetLocation.PROGRESS_ARROWS.sprite(y = 0f, width = 22f, height = 15f) val GAUGE_FOREGROUND = WidgetLocation.PROGRESS_ARROWS.sprite(y = 15f, width = 22f, height = 15f) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt index 70ada7c72..93fc4db5d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/jei/JEIPlugin.kt @@ -13,6 +13,7 @@ import mezz.jei.api.registration.IRecipeCategoryRegistration import mezz.jei.api.registration.IRecipeRegistration import mezz.jei.api.registration.IRecipeTransferRegistration import mezz.jei.api.runtime.IClickableIngredient +import mezz.jei.api.runtime.IJeiRuntime import net.minecraft.client.renderer.Rect2i import net.minecraft.resources.ResourceLocation import net.minecraft.world.item.ItemStack @@ -40,6 +41,11 @@ class JEIPlugin : IModPlugin { var helpers: IJeiHelpers by Delegates.notNull() private set + + private var _RUNTIME: IJeiRuntime? = null + + val RUNTIME: IJeiRuntime + get() = checkNotNull(_RUNTIME) { "JEI runtime is unavailable" } } init { @@ -63,6 +69,14 @@ class JEIPlugin : IModPlugin { registration.addRecipeCatalyst(ItemStack(MItems.MATTER_ENTANGLER), MatterEntanglerRecipeCategory.recipeType) } + override fun onRuntimeAvailable(jeiRuntime: IJeiRuntime) { + _RUNTIME = jeiRuntime + } + + override fun onRuntimeUnavailable() { + _RUNTIME = null + } + override fun registerCategories(registration: IRecipeCategoryRegistration) { helpers = registration.jeiHelpers registration.addRecipeCategories(PlatePressRecipeCategory) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt index b567e9ac3..a39411c6c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt @@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.menu.tech import net.minecraft.server.level.ServerPlayer import net.minecraft.world.entity.player.Inventory +import net.minecraft.world.inventory.MenuType import ru.dbotthepony.mc.otm.block.entity.tech.PoweredFurnaceBlockEntity import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.menu.OutputSlot @@ -16,10 +17,11 @@ import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class PoweredFurnaceMenu( + type: MenuType, containerID: Int, inventory: Inventory, tile: PoweredFurnaceBlockEntity? = null -) : MatteryPoweredMenu(MMenus.POWERED_FURNACE, containerID, inventory, tile) { +) : MatteryPoweredMenu(type, containerID, inventory, tile) { val inputSlots = makeSlots(tile?.inputs, 2, ::MatterySlot) val outputSlots = makeSlots(tile?.outputs, 2) { c, s -> OutputSlot(c, s) { tile?.popExperience(player as ServerPlayer) } } @@ -38,4 +40,30 @@ class PoweredFurnaceMenu( addStorageSlot(outputSlots) addInventorySlots() } + + companion object { + fun furnace( + containerID: Int, + inventory: Inventory, + tile: PoweredFurnaceBlockEntity? = null + ) : PoweredFurnaceMenu { + return PoweredFurnaceMenu(MMenus.POWERED_FURNACE, containerID, inventory, tile) + } + + fun blasting( + containerID: Int, + inventory: Inventory, + tile: PoweredFurnaceBlockEntity? = null + ) : PoweredFurnaceMenu { + return PoweredFurnaceMenu(MMenus.POWERED_BLAST_FURNACE, containerID, inventory, tile) + } + + fun smoking( + containerID: Int, + inventory: Inventory, + tile: PoweredFurnaceBlockEntity? = null + ) : PoweredFurnaceMenu { + return PoweredFurnaceMenu(MMenus.POWERED_SMOKER, containerID, inventory, tile) + } + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt index 1c3af7f75..25f1c43ab 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt @@ -95,7 +95,9 @@ object MMenus { val ENERGY_COUNTER: MenuType by registry.register(MNames.ENERGY_COUNTER) { MenuType(::EnergyCounterMenu, FeatureFlags.VANILLA_SET) } val CHEMICAL_GENERATOR: MenuType by registry.register(MNames.CHEMICAL_GENERATOR) { MenuType(::ChemicalGeneratorMenu, FeatureFlags.VANILLA_SET) } val PLATE_PRESS: MenuType by registry.register(MNames.PLATE_PRESS) { MenuType(::PlatePressMenu, FeatureFlags.VANILLA_SET) } - val POWERED_FURNACE: MenuType by registry.register(MNames.POWERED_FURNACE) { MenuType(::PoweredFurnaceMenu, FeatureFlags.VANILLA_SET) } + val POWERED_FURNACE: MenuType by registry.register(MNames.POWERED_FURNACE) { MenuType(PoweredFurnaceMenu::furnace, FeatureFlags.VANILLA_SET) } + val POWERED_BLAST_FURNACE: MenuType by registry.register(MNames.POWERED_BLAST_FURNACE) { MenuType(PoweredFurnaceMenu::blasting, FeatureFlags.VANILLA_SET) } + val POWERED_SMOKER: MenuType by registry.register(MNames.POWERED_SMOKER) { MenuType(PoweredFurnaceMenu::smoking, FeatureFlags.VANILLA_SET) } val TWIN_PLATE_PRESS: MenuType by registry.register(MNames.TWIN_PLATE_PRESS) { MenuType(::TwinPlatePressMenu, FeatureFlags.VANILLA_SET) } val MATTER_RECYCLER: MenuType by registry.register(MNames.MATTER_RECYCLER) { MenuType(::MatterRecyclerMenu, FeatureFlags.VANILLA_SET) } val ENERGY_SERVO: MenuType by registry.register(MNames.ENERGY_SERVO) { MenuType(::EnergyServoMenu, FeatureFlags.VANILLA_SET) } @@ -148,6 +150,8 @@ object MMenus { MenuScreens.register(ITEM_REPAIER, ::MatterReconstructorScreen) MenuScreens.register(FLUID_TANK, ::FluidTankScreen) MenuScreens.register(POWERED_FURNACE, ::PoweredFurnaceScreen) + MenuScreens.register(POWERED_BLAST_FURNACE, ::PoweredFurnaceScreen) + MenuScreens.register(POWERED_SMOKER, ::PoweredFurnaceScreen) MenuScreens.register(PAINTER, ::PainterScreen) MenuScreens.register(MATTER_ENTANGLER, ::MatterEntanglerScreen) }