Hopper and dispenser/dropper menus?
This commit is contained in:
parent
6fc06a620f
commit
af2d621cee
@ -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.DispenserBlockEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Overwrite;
|
||||||
|
import ru.dbotthepony.mc.otm.compat.vanilla.MatteryChestMenu;
|
||||||
|
|
||||||
|
@Mixin(DispenserBlockEntity.class)
|
||||||
|
public abstract class DispenserBlockEntityMixin {
|
||||||
|
@Overwrite
|
||||||
|
public AbstractContainerMenu createMenu(int p_59312_, Inventory p_59313_) {
|
||||||
|
return MatteryChestMenu.c3x3(p_59312_, p_59313_, (DispenserBlockEntity) (Object) this);
|
||||||
|
}
|
||||||
|
}
|
@ -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.HopperBlockEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Overwrite;
|
||||||
|
import ru.dbotthepony.mc.otm.compat.vanilla.MatteryChestMenu;
|
||||||
|
|
||||||
|
@Mixin(HopperBlockEntity.class)
|
||||||
|
public abstract class HopperBlockEntityMixin {
|
||||||
|
@Overwrite
|
||||||
|
public AbstractContainerMenu createMenu(int p_59312_, Inventory p_59313_) {
|
||||||
|
return MatteryChestMenu.hopper(p_59312_, p_59313_, (HopperBlockEntity) (Object) this);
|
||||||
|
}
|
||||||
|
}
|
@ -19,13 +19,14 @@ import ru.dbotthepony.mc.otm.menu.makeSlots
|
|||||||
|
|
||||||
class MatteryChestMenu(
|
class MatteryChestMenu(
|
||||||
type: MenuType<*>, containerId: Int,
|
type: MenuType<*>, containerId: Int,
|
||||||
inventory: Inventory, val rows: Int,
|
inventory: Inventory, val rows: Int, val columns: Int,
|
||||||
val container: Container = SimpleContainer(rows * 9)
|
val container: Container = SimpleContainer(rows * columns)
|
||||||
) : MatteryMenu(type, containerId, inventory) {
|
) : MatteryMenu(type, containerId, inventory) {
|
||||||
val chestSlots = makeSlots(container, ::MatterySlot)
|
val chestSlots = makeSlots(container, ::MatterySlot)
|
||||||
val sort = SortInput(container, playerSortSettings)
|
val sort = SortInput(container, playerSortSettings)
|
||||||
|
|
||||||
init {
|
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)
|
container.startOpen(player)
|
||||||
addStorageSlot(chestSlots)
|
addStorageSlot(chestSlots)
|
||||||
addInventorySlots()
|
addInventorySlots()
|
||||||
@ -49,41 +50,55 @@ class MatteryChestMenu(
|
|||||||
private val GENERIC_9x4 by registrar.register("generic_9x4") { MenuType(::c9x4, 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_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_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
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun c9x1(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9)): MatteryChestMenu {
|
fun c9x1(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9)): MatteryChestMenu {
|
||||||
return MatteryChestMenu(GENERIC_9x1, containerId, inventory, 1, container)
|
return MatteryChestMenu(GENERIC_9x1, containerId, inventory, 1, 9, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun c9x2(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 2)): MatteryChestMenu {
|
fun c9x2(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 2)): MatteryChestMenu {
|
||||||
return MatteryChestMenu(GENERIC_9x2, containerId, inventory, 2, container)
|
return MatteryChestMenu(GENERIC_9x2, containerId, inventory, 2, 9, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun c9x3(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 3)): MatteryChestMenu {
|
fun c9x3(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 3)): MatteryChestMenu {
|
||||||
return MatteryChestMenu(GENERIC_9x3, containerId, inventory, 3, container)
|
return MatteryChestMenu(GENERIC_9x3, containerId, inventory, 3, 9, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun c9x4(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 4)): MatteryChestMenu {
|
fun c9x4(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 4)): MatteryChestMenu {
|
||||||
return MatteryChestMenu(GENERIC_9x4, containerId, inventory, 4, container)
|
return MatteryChestMenu(GENERIC_9x4, containerId, inventory, 4, 9, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun c9x5(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 5)): MatteryChestMenu {
|
fun c9x5(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 5)): MatteryChestMenu {
|
||||||
return MatteryChestMenu(GENERIC_9x5, containerId, inventory, 5, container)
|
return MatteryChestMenu(GENERIC_9x5, containerId, inventory, 5, 9, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun c9x6(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 6)): MatteryChestMenu {
|
fun c9x6(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(9 * 6)): MatteryChestMenu {
|
||||||
return MatteryChestMenu(GENERIC_9x6, containerId, inventory, 6, container)
|
return MatteryChestMenu(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)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
|
fun hopper(containerId: Int, inventory: Inventory, container: Container = SimpleContainer(5)): MatteryChestMenu {
|
||||||
|
return MatteryChestMenu(HOPPER, containerId, inventory, 1, 5, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun register(bus: IEventBus) {
|
internal fun register(bus: IEventBus) {
|
||||||
@ -99,6 +114,8 @@ class MatteryChestMenu(
|
|||||||
MenuScreens.register(GENERIC_9x4, ::MatteryChestScreen)
|
MenuScreens.register(GENERIC_9x4, ::MatteryChestScreen)
|
||||||
MenuScreens.register(GENERIC_9x5, ::MatteryChestScreen)
|
MenuScreens.register(GENERIC_9x5, ::MatteryChestScreen)
|
||||||
MenuScreens.register(GENERIC_9x6, ::MatteryChestScreen)
|
MenuScreens.register(GENERIC_9x6, ::MatteryChestScreen)
|
||||||
|
MenuScreens.register(GENERIC_3x3, ::MatteryChestScreen)
|
||||||
|
MenuScreens.register(HOPPER, ::MatteryChestScreen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@ import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
|
|||||||
|
|
||||||
class MatteryChestScreen(menu: MatteryChestMenu, inventory: Inventory, title: Component) : MatteryScreen<MatteryChestMenu>(menu, inventory, title) {
|
class MatteryChestScreen(menu: MatteryChestMenu, inventory: Inventory, title: Component) : MatteryScreen<MatteryChestMenu>(menu, inventory, title) {
|
||||||
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
||||||
val frame = FramePanel.padded(this, AbstractSlotPanel.SIZE * 9f, AbstractSlotPanel.SIZE * menu.rows + 4f, title)
|
val frame = FramePanel.padded(this, AbstractSlotPanel.SIZE * menu.columns.coerceAtLeast(9), AbstractSlotPanel.SIZE * menu.rows + 4f, title)
|
||||||
|
|
||||||
frame.makeCloseButton()
|
frame.makeCloseButton()
|
||||||
frame.onClose { onClose() }
|
frame.onClose { onClose() }
|
||||||
|
|
||||||
val grid = GridPanel.slots(this, frame, 9, menu.rows)
|
val grid = GridPanel.slots(this, frame, menu.columns, menu.rows)
|
||||||
grid.dock = Dock.FILL
|
grid.dock = Dock.FILL
|
||||||
grid.gravity = RenderGravity.BOTTOM_CENTER
|
grid.gravity = RenderGravity.BOTTOM_CENTER
|
||||||
|
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
"MixinAbstractHurtingProjectile",
|
"MixinAbstractHurtingProjectile",
|
||||||
"SimpleCriterionTriggerMixin",
|
"SimpleCriterionTriggerMixin",
|
||||||
"InventoryChangeTriggerMixin",
|
"InventoryChangeTriggerMixin",
|
||||||
"MixinPlayer"
|
"MixinPlayer",
|
||||||
|
"HopperBlockEntityMixin",
|
||||||
|
"DispenserBlockEntityMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"MixinGameRenderer",
|
"MixinGameRenderer",
|
||||||
|
Loading…
Reference in New Issue
Block a user