Replace shulker box gui

This commit is contained in:
DBotThePony 2025-03-07 11:45:35 +07:00
parent b4977ea6ae
commit ebc49b03c4
Signed by: DBot
GPG Key ID: DCC23B5715498507
8 changed files with 139 additions and 62 deletions

View File

@ -0,0 +1,16 @@
package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import ru.dbotthepony.mc.otm.compat.vanilla.MatteryShulkerBoxMenu;
@Mixin(ShulkerBoxBlockEntity.class)
public abstract class ShulkerBoxBlockEntityMixin {
@Overwrite(remap = false)
public AbstractContainerMenu createMenu(int p_59312_, Inventory p_59313_) {
return new MatteryShulkerBoxMenu(p_59312_, p_59313_, (ShulkerBoxBlockEntity) (Object) this);
}
}

View File

@ -44,6 +44,7 @@ import ru.dbotthepony.mc.otm.client.render.blockentity.MatterBatteryBankRenderer
import ru.dbotthepony.mc.otm.compat.curios.isCuriosLoaded
import ru.dbotthepony.mc.otm.compat.curios.onCuriosSlotModifiersUpdated
import ru.dbotthepony.mc.otm.compat.vanilla.MatteryChestMenu
import ru.dbotthepony.mc.otm.compat.vanilla.VanillaMenuTypes
import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.config.CablesConfig
import ru.dbotthepony.mc.otm.config.ClientConfig
@ -127,7 +128,7 @@ object OverdriveThatMatters {
MLootNumberProviders.register(MOD_BUS)
StorageStack.register(MOD_BUS)
MatteryChestMenu.register(MOD_BUS)
VanillaMenuTypes.register(MOD_BUS)
MCreativeTabs.initialize(MOD_BUS)

View File

@ -0,0 +1,30 @@
package ru.dbotthepony.mc.otm.compat.vanilla
import net.minecraft.world.Container
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.MenuType
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
abstract class AbstractVanillaChestMenu(
type: MenuType<*>,
containerId: Int,
inventory: Inventory,
val container: Container
) : MatteryMenu(type, containerId, inventory) {
abstract val rows: Int
abstract val columns: Int
abstract val containerSlots: List<MatteryMenuSlot>
val sort = SortInput(container, playerSortSettings)
override fun stillValid(player: Player): Boolean {
return container.stillValid(player)
}
override fun removed(player: Player) {
super.removed(player)
container.stopOpen(player)
}
}

View File

@ -1,118 +1,74 @@
package ru.dbotthepony.mc.otm.compat.vanilla
import net.minecraft.core.registries.Registries
import net.minecraft.world.Container
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.flag.FeatureFlags
import net.minecraft.world.inventory.MenuType
import net.neoforged.bus.api.IEventBus
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.makeSlots
import ru.dbotthepony.mc.otm.registry.MDeferredRegister
class MatteryChestMenu(
type: MenuType<*>, containerId: Int,
inventory: Inventory, val rows: Int, val columns: Int,
val container: Container = SimpleContainer(rows * columns)
) : MatteryMenu(type, containerId, inventory) {
val chestSlots = makeSlots(container, ::MatteryMenuSlot)
val sort = SortInput(container, playerSortSettings)
inventory: Inventory, override val rows: Int, override val columns: Int,
container: Container = EnhancedContainer(rows * columns)
) : AbstractVanillaChestMenu(type, containerId, inventory, container) {
override val containerSlots = makeSlots(container, ::MatteryMenuSlot)
init {
require(rows * columns == container.containerSize) { "Provided container $container has different dimensions than specified rows x columns: ${container.containerSize} vs $rows x $columns (${rows * columns})" }
container.startOpen(player)
addStorageSlot(chestSlots)
addStorageSlot(containerSlots)
addInventorySlots()
}
override fun stillValid(player: Player): Boolean {
return container.stillValid(player)
}
override fun removed(player: Player) {
super.removed(player)
container.stopOpen(player)
}
companion object {
private val registrar = MDeferredRegister(Registries.MENU, OverdriveThatMatters.MOD_ID)
private val GENERIC_9x1 by registrar.register("generic_9x1") { MenuType(::c9x1, FeatureFlags.VANILLA_SET) }
private val GENERIC_9x2 by registrar.register("generic_9x2") { MenuType(::c9x2, FeatureFlags.VANILLA_SET) }
private val GENERIC_9x3 by registrar.register("generic_9x3") { MenuType(::c9x3, FeatureFlags.VANILLA_SET) }
private val GENERIC_9x4 by registrar.register("generic_9x4") { MenuType(::c9x4, FeatureFlags.VANILLA_SET) }
private val GENERIC_9x5 by registrar.register("generic_9x5") { MenuType(::c9x5, FeatureFlags.VANILLA_SET) }
private val GENERIC_9x6 by registrar.register("generic_9x6") { MenuType(::c9x6, FeatureFlags.VANILLA_SET) }
private val GENERIC_3x3 by registrar.register("generic_3x3") { MenuType(::c3x3, FeatureFlags.VANILLA_SET) }
private val HOPPER by registrar.register("hopper") { MenuType(::hopper, FeatureFlags.VANILLA_SET) }
@JvmStatic
@JvmOverloads
fun c9x1(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_9x1, containerId, inventory, 1, 9, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_9x1, containerId, inventory, 1, 9, container)
}
@JvmStatic
@JvmOverloads
fun c9x2(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 2)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_9x2, containerId, inventory, 2, 9, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_9x2, containerId, inventory, 2, 9, container)
}
@JvmStatic
@JvmOverloads
fun c9x3(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 3)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_9x3, containerId, inventory, 3, 9, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_9x3, containerId, inventory, 3, 9, container)
}
@JvmStatic
@JvmOverloads
fun c9x4(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 4)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_9x4, containerId, inventory, 4, 9, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_9x4, containerId, inventory, 4, 9, container)
}
@JvmStatic
@JvmOverloads
fun c9x5(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 5)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_9x5, containerId, inventory, 5, 9, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_9x5, containerId, inventory, 5, 9, container)
}
@JvmStatic
@JvmOverloads
fun c9x6(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 6)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_9x6, containerId, inventory, 6, 9, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_9x6, containerId, inventory, 6, 9, container)
}
@JvmStatic
@JvmOverloads
fun c3x3(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(3 * 3)): MatteryChestMenu {
return MatteryChestMenu(GENERIC_3x3, containerId, inventory, 3, 3, container)
return MatteryChestMenu(VanillaMenuTypes.GENERIC_3x3, containerId, inventory, 3, 3, container)
}
@JvmStatic
@JvmOverloads
fun hopper(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(5)): MatteryChestMenu {
return MatteryChestMenu(HOPPER, containerId, inventory, 1, 5, container)
}
fun register(bus: IEventBus) {
registrar.register(bus)
bus.addListener(this::registerScreens)
}
private fun registerScreens(event: RegisterMenuScreensEvent) {
event.register(GENERIC_9x1, ::MatteryChestScreen)
event.register(GENERIC_9x2, ::MatteryChestScreen)
event.register(GENERIC_9x3, ::MatteryChestScreen)
event.register(GENERIC_9x4, ::MatteryChestScreen)
event.register(GENERIC_9x5, ::MatteryChestScreen)
event.register(GENERIC_9x6, ::MatteryChestScreen)
event.register(GENERIC_3x3, ::MatteryChestScreen)
event.register(HOPPER, ::MatteryChestScreen)
return MatteryChestMenu(VanillaMenuTypes.HOPPER, containerId, inventory, 1, 5, container)
}
}
}

View File

@ -0,0 +1,32 @@
package ru.dbotthepony.mc.otm.compat.vanilla
import net.minecraft.world.Container
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
import ru.dbotthepony.mc.otm.menu.makeSlots
class MatteryShulkerBoxMenu(
containerId: Int,
inventory: Inventory,
container: Container = EnhancedContainer(27)
) : AbstractVanillaChestMenu(VanillaMenuTypes.SHULKER_BOX, containerId, inventory, container) {
override val containerSlots = makeSlots(container, ::Slot)
override val rows: Int
get() = 3
override val columns: Int
get() = 9
init {
container.startOpen(player)
addStorageSlot(containerSlots)
addInventorySlots()
}
class Slot(container: Container, slot: Int) : MatteryMenuSlot(container, slot) {
override fun mayPlace(stack: ItemStack): Boolean {
return super.mayPlace(stack) && stack.item.canFitInsideContainerItems()
}
}
}

View File

@ -11,7 +11,7 @@ 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
class MatteryChestScreen(menu: MatteryChestMenu, inventory: Inventory, title: Component) : MatteryScreen<MatteryChestMenu>(menu, inventory, title) {
class VanillaChestScreen(menu: AbstractVanillaChestMenu, inventory: Inventory, title: Component) : MatteryScreen<AbstractVanillaChestMenu>(menu, inventory, title) {
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
val frame = FramePanel.padded(this, AbstractSlotPanel.SIZE * menu.columns.coerceAtLeast(9), AbstractSlotPanel.SIZE * menu.rows + 4f, title)
@ -22,7 +22,7 @@ class MatteryChestScreen(menu: MatteryChestMenu, inventory: Inventory, title: Co
grid.dock = Dock.FILL
grid.gravity = RenderGravity.BOTTOM_CENTER
for (slot in menu.chestSlots)
for (slot in menu.containerSlots)
SlotPanel(this, grid, slot)
val controls = DeviceControls(this, frame)

View File

@ -0,0 +1,41 @@
package ru.dbotthepony.mc.otm.compat.vanilla
import net.minecraft.core.registries.Registries
import net.minecraft.world.flag.FeatureFlags
import net.minecraft.world.inventory.MenuType
import net.neoforged.bus.api.IEventBus
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.registry.MDeferredRegister
object VanillaMenuTypes {
private val registrar = MDeferredRegister(Registries.MENU, OverdriveThatMatters.MOD_ID)
val GENERIC_9x1 by registrar.register("generic_9x1") { MenuType(MatteryChestMenu::c9x1, FeatureFlags.VANILLA_SET) }
val GENERIC_9x2 by registrar.register("generic_9x2") { MenuType(MatteryChestMenu::c9x2, FeatureFlags.VANILLA_SET) }
val GENERIC_9x3 by registrar.register("generic_9x3") { MenuType(MatteryChestMenu::c9x3, FeatureFlags.VANILLA_SET) }
val GENERIC_9x4 by registrar.register("generic_9x4") { MenuType(MatteryChestMenu::c9x4, FeatureFlags.VANILLA_SET) }
val GENERIC_9x5 by registrar.register("generic_9x5") { MenuType(MatteryChestMenu::c9x5, FeatureFlags.VANILLA_SET) }
val GENERIC_9x6 by registrar.register("generic_9x6") { MenuType(MatteryChestMenu::c9x6, FeatureFlags.VANILLA_SET) }
val GENERIC_3x3 by registrar.register("generic_3x3") { MenuType(MatteryChestMenu::c3x3, FeatureFlags.VANILLA_SET) }
val HOPPER by registrar.register("hopper") { MenuType(MatteryChestMenu::hopper, FeatureFlags.VANILLA_SET) }
val SHULKER_BOX by registrar.register("shulker_box") { MenuType(::MatteryShulkerBoxMenu, FeatureFlags.VANILLA_SET) }
fun register(bus: IEventBus) {
registrar.register(bus)
bus.addListener(this::registerScreens)
}
private fun registerScreens(event: RegisterMenuScreensEvent) {
event.register(GENERIC_9x1, ::VanillaChestScreen)
event.register(GENERIC_9x2, ::VanillaChestScreen)
event.register(GENERIC_9x3, ::VanillaChestScreen)
event.register(GENERIC_9x4, ::VanillaChestScreen)
event.register(GENERIC_9x5, ::VanillaChestScreen)
event.register(GENERIC_9x6, ::VanillaChestScreen)
event.register(GENERIC_3x3, ::VanillaChestScreen)
event.register(HOPPER, ::VanillaChestScreen)
event.register(SHULKER_BOX, ::VanillaChestScreen)
}
}

View File

@ -19,7 +19,8 @@
"DispenserBlockEntityMixin",
"GuiGraphicsMixin",
"BlockStateBaseMixin",
"LevelMixin"
"LevelMixin",
"ShulkerBoxBlockEntityMixin"
],
"client": [
"MixinGameRenderer",