Instead of iterating slot indexes iterate slots themselves
This commit is contained in:
parent
23286be3a9
commit
f7ca3a1e11
@ -77,10 +77,10 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
scroll_panel.setDock(Dock.RIGHT);
|
||||
scroll_panel.setupRowMultiplier(() -> {
|
||||
if (tasks_tab.isActive()) {
|
||||
return menu.tasks.size() / GRID_WIDTH;
|
||||
return menu.getTasks().size() / GRID_WIDTH;
|
||||
}
|
||||
|
||||
return menu.patterns.size() / GRID_WIDTH;
|
||||
return menu.getPatterns().size() / GRID_WIDTH;
|
||||
});
|
||||
|
||||
var grid = new GridPanel(this, frame, 0, 0, GRID_WIDTH * AbstractSlotPanel.REGULAR_DIMENSIONS, 0, GRID_WIDTH, GRID_HEIGHT) {
|
||||
@ -100,25 +100,25 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.patterns.size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getPatterns().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.patterns.size()) {
|
||||
if (slot1 >= menu.getPatterns().size()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return menu.patterns.get(slot1).stack();
|
||||
return menu.getPatterns().get(slot1).stack();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.patterns.size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getPatterns().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.patterns.size()) {
|
||||
if (slot1 >= menu.getPatterns().size()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return getPatternTooltip(super.getItemStackTooltip(stack), menu.patterns.get(slot1));
|
||||
return getPatternTooltip(super.getItemStackTooltip(stack), menu.getPatterns().get(slot1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,11 +128,11 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
|
||||
@Override
|
||||
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int flag) {
|
||||
if (slot >= menu.patterns.size()) {
|
||||
if (slot >= menu.getPatterns().size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
openPattern(menu.patterns.get(slot));
|
||||
openPattern(menu.getPatterns().get(slot));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -142,26 +142,26 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.tasks.size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getTasks().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.tasks.size()) {
|
||||
if (slot1 >= menu.getTasks().size()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
var task = menu.tasks.get(slot1);
|
||||
var task = menu.getTasks().get(slot1);
|
||||
return task.stack(Math.max(task.required(), 1));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.tasks.size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
var slot1 = slot + scroll_panel.getScroll(menu.getTasks().size() / GRID_WIDTH) * GRID_WIDTH;
|
||||
|
||||
if (slot1 >= menu.tasks.size()) {
|
||||
if (slot1 >= menu.getTasks().size()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return getTaskTooltip(super.getItemStackTooltip(stack), menu.tasks.get(slot1));
|
||||
return getTaskTooltip(super.getItemStackTooltip(stack), menu.getTasks().get(slot1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -171,11 +171,11 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
|
||||
@Override
|
||||
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int flag) {
|
||||
if (slot >= menu.tasks.size()) {
|
||||
if (slot >= menu.getTasks().size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
openTask(menu.tasks.get(slot));
|
||||
openTask(menu.getTasks().get(slot));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -210,7 +210,7 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (!menu.tasks.contains(task)) {
|
||||
if (!menu.getTasks().contains(task)) {
|
||||
remove();
|
||||
}
|
||||
}
|
||||
@ -220,10 +220,10 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ItemStack getItemStack() {
|
||||
var task1_index = menu.tasks.indexOf(task);
|
||||
var task1_index = menu.getTasks().indexOf(task);
|
||||
|
||||
if (task1_index != -1) {
|
||||
var task1 = menu.tasks.get(task1_index);
|
||||
var task1 = menu.getTasks().get(task1_index);
|
||||
return task1.stack(Math.max(task1.required(), 1));
|
||||
}
|
||||
|
||||
@ -233,11 +233,11 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<Component> getItemStackTooltip(@Nonnull ItemStack stack) {
|
||||
var task1_index = menu.tasks.indexOf(task);
|
||||
var task1_index = menu.getTasks().indexOf(task);
|
||||
List<Component> get_list = super.getItemStackTooltip(stack);
|
||||
|
||||
if (task1_index != -1) {
|
||||
getTaskTooltip(get_list, menu.tasks.get(task1_index));
|
||||
getTaskTooltip(get_list, menu.getTasks().get(task1_index));
|
||||
}
|
||||
|
||||
return get_list;
|
||||
@ -269,7 +269,7 @@ public class MatterPanelScreen extends MatteryScreen<MatterPanelMenu> {
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (!menu.patterns.contains(state)) {
|
||||
if (!menu.getPatterns().contains(state)) {
|
||||
remove();
|
||||
}
|
||||
}
|
||||
|
@ -115,11 +115,11 @@ public abstract class MatteryScreen<T extends MatteryMenu> extends AbstractConta
|
||||
this.menu = menu;
|
||||
playerInventoryTitle = inventory.getDisplayName();
|
||||
|
||||
if (menu.inventorySlots.size() != 0) {
|
||||
if (menu.getPlayerInventorySlots().size() != 0) {
|
||||
inventory_frame = new FramePanel(this, null, 0, 0, INVENTORY_FRAME_WIDTH, INVENTORY_FRAME_HEIGHT, inventory.getDisplayName());
|
||||
panels.add(inventory_frame);
|
||||
|
||||
for (var slot : menu.inventorySlots) {
|
||||
for (var slot : menu.getPlayerInventorySlots()) {
|
||||
new SlotPanel<>(
|
||||
this,
|
||||
inventory_frame,
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
package ru.dbotthepony.mc.otm
|
||||
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
@ -201,3 +202,19 @@ fun <T : Enum<T>> T.prev(values: Array<out T>): T {
|
||||
|
||||
return values[next]
|
||||
}
|
||||
|
||||
inline fun <T> ImmutableList(size: Int, initializer: (index: Int) -> T): ImmutableList<T> {
|
||||
require(size >= 0) { "Invalid list size $size" }
|
||||
|
||||
return when (size) {
|
||||
0 -> ImmutableList.of()
|
||||
1 -> ImmutableList.of(initializer(0))
|
||||
else -> ImmutableList.Builder<T>().let {
|
||||
for (i in 0 until size) {
|
||||
it.add(initializer(i))
|
||||
}
|
||||
|
||||
it.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Co
|
||||
PowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
|
||||
|
||||
for (i in 0 .. 5)
|
||||
SlotPanel(this, frame, menu.containerSlots[i], 44f + 18 * i, 32f)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * i, 32f)
|
||||
|
||||
for (i in 6 .. 11)
|
||||
SlotPanel(this, frame, menu.containerSlots[i], 44f + 18 * (i - 6), 32f + 18f)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * (i - 6), 32f + 18f)
|
||||
|
||||
return frame
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class CargoCrateScreen(menu: CargoCrateMenu, inventory: Inventory, title: Compon
|
||||
val frame = FramePanel(this, null, 0f, 0f, INVENTORY_FRAME_WIDTH, 22f + 4f + 6f * 18f, getTitle())
|
||||
val grid = GridPanel(this, frame, 8f, 18f, 9f * 18f, 6f * 18f, 9, 6)
|
||||
|
||||
for (slot in menu.crateSlots)
|
||||
for (slot in menu.storageSlots)
|
||||
SlotPanel(this, grid, slot)
|
||||
|
||||
return frame
|
||||
|
@ -16,11 +16,11 @@ class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Componen
|
||||
PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
|
||||
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
|
||||
|
||||
SlotPanel(this, frame, menu.drives[0], 71f, 32f)
|
||||
SlotPanel(this, frame, menu.drives[1], 71f + 18f, 32f)
|
||||
SlotPanel(this, frame, menu.storageSlots[0], 71f, 32f)
|
||||
SlotPanel(this, frame, menu.storageSlots[1], 71f + 18f, 32f)
|
||||
|
||||
SlotPanel(this, frame, menu.drives[2], 71f, 32f + 18f)
|
||||
SlotPanel(this, frame, menu.drives[3], 71f + 18f, 32f + 18f)
|
||||
SlotPanel(this, frame, menu.storageSlots[2], 71f, 32f + 18f)
|
||||
SlotPanel(this, frame, menu.storageSlots[3], 71f + 18f, 32f + 18f)
|
||||
|
||||
return frame
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ class MatterBottlerScreen(menu: MatterBottlerMenu, inventory: Inventory, title:
|
||||
SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
|
||||
|
||||
for (i in 0 .. 2) {
|
||||
SlotPanel(this, frame, menu.container[i], 31f + i * 18, PROGRESS_SLOT_TOP)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 31f + i * 18, PROGRESS_SLOT_TOP)
|
||||
}
|
||||
|
||||
for (i in 3 .. 5) {
|
||||
SlotPanel(this, frame, menu.container[i], 116f + (i - 3) * 18, PROGRESS_SLOT_TOP)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 116f + (i - 3) * 18, PROGRESS_SLOT_TOP)
|
||||
}
|
||||
|
||||
progress = ProgressGaugePanel(this, frame, menu.progressWidget, 90f, PROGRESS_ARROW_TOP)
|
||||
|
@ -16,10 +16,10 @@ class MatterCapacitorBankScreen(p_97741_: MatterCapacitorBankMenu, p_97742_: Inv
|
||||
MatterGaugePanel(this, frame, menu.matterGauge, LEFT_MARGIN + m.width, GAUGE_TOP_WITHOUT_SLOT)
|
||||
|
||||
for (i in 0 .. 5)
|
||||
SlotPanel(this, frame, menu.workSlots[i], 44f + 18 * i, 32f)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * i, 32f)
|
||||
|
||||
for (i in 6 .. 11)
|
||||
SlotPanel(this, frame, menu.workSlots[i], 44f + 18 * (i - 6), 32f + 18f)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * (i - 6), 32f + 18f)
|
||||
|
||||
return frame
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ class MatterReplicatorScreen(p_97741_: MatterReplicatorMenu, p_97742_: Inventory
|
||||
ProgressGaugePanel(this, frame, menu.progress, 54f, PROGRESS_ARROW_TOP)
|
||||
|
||||
for (i in 0 until 3)
|
||||
SlotPanel(this, frame, menu.outputSlots[i], 80f + i * 18, PROGRESS_SLOT_TOP)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 80f + i * 18, PROGRESS_SLOT_TOP)
|
||||
|
||||
SlotPanel(this, frame, menu.outputSlots[3], 80f, PROGRESS_SLOT_TOP + 22f)
|
||||
SlotPanel(this, frame, menu.outputSlots[4], 80f + 18f, PROGRESS_SLOT_TOP + 22f)
|
||||
SlotPanel(this, frame, menu.storageSlots[3], 80f, PROGRESS_SLOT_TOP + 22f)
|
||||
SlotPanel(this, frame, menu.storageSlots[4], 80f + 18f, PROGRESS_SLOT_TOP + 22f)
|
||||
|
||||
return frame
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ class PatternStorageScreen(p_97741_: PatternStorageMenu, p_97742_: Inventory, p_
|
||||
PatternGaugePanel(this, frame, menu.storedGrid, LEFT_MARGIN + m.width, GAUGE_TOP_WITHOUT_SLOT)
|
||||
|
||||
for (i in 0 until 4)
|
||||
SlotPanel(this, frame, menu.patternSlots[i], 62f + i * 18, 32f)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 62f + i * 18, 32f)
|
||||
|
||||
for (i in 4 until 8)
|
||||
SlotPanel(this, frame, menu.patternSlots[i], 62f + (i - 4) * 18, 32f + 18f)
|
||||
SlotPanel(this, frame, menu.storageSlots[i], 62f + (i - 4) * 18, 32f + 18f)
|
||||
|
||||
return frame
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.menu
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.block.entity.AndroidStationBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
@ -36,16 +37,9 @@ class AndroidStationMenu @JvmOverloads constructor(
|
||||
) : MatteryPoweredMenu(MMenus.ANDROID_STATION, containerID, inventory, tile) {
|
||||
val androidBattery: MatterySlot = AndroidBatterySlot(AndroidStationContainer(inventory.player), 0)
|
||||
|
||||
override val storageSlots = listOf(addSlot(androidBattery))
|
||||
|
||||
init {
|
||||
addSlot(androidBattery)
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return androidBattery.index
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return androidBattery.index + 1
|
||||
}
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import com.google.common.collect.ImmutableList
|
||||
import net.minecraft.world.Container
|
||||
import kotlin.jvm.JvmOverloads
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import ru.dbotthepony.mc.otm.block.entity.BatteryBankBlockEntity
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.orNull
|
||||
@ -16,25 +19,18 @@ class BatteryBankMenu @JvmOverloads constructor(
|
||||
tile: BatteryBankBlockEntity? = null,
|
||||
) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) {
|
||||
val powerLevel: LevelGaugeWidget
|
||||
val containerSlots: Array<BatterySlot>
|
||||
override val storageSlots: List<MatterySlot>
|
||||
|
||||
init {
|
||||
val container: Container = tile?.container ?: SimpleContainer(BatteryBankBlockEntity.CAPACITY)
|
||||
powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull())
|
||||
containerSlots = Array(BatteryBankBlockEntity.CAPACITY) {
|
||||
|
||||
storageSlots = ImmutableList(BatteryBankBlockEntity.CAPACITY) {
|
||||
val slot = BatterySlot(container, it)
|
||||
addSlot(slot)
|
||||
return@Array slot
|
||||
return@ImmutableList slot
|
||||
}
|
||||
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return BatteryBankBlockEntity.CAPACITY
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.menu
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.CargoCrateBlockEntity
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
|
||||
@ -11,15 +12,15 @@ class CargoCrateMenu @JvmOverloads constructor(
|
||||
inventory: Inventory,
|
||||
tile: CargoCrateBlockEntity? = null
|
||||
) : MatteryMenu(MMenus.CARGO_CRATE, p_38852_, inventory, tile) {
|
||||
val crateSlots: Array<MatterySlot>
|
||||
override val storageSlots: List<MatterySlot>
|
||||
|
||||
init {
|
||||
val container = tile?.container ?: SimpleContainer(CargoCrateBlockEntity.CAPACITY)
|
||||
|
||||
crateSlots = Array(CargoCrateBlockEntity.CAPACITY) {
|
||||
storageSlots = ImmutableList(CargoCrateBlockEntity.CAPACITY) {
|
||||
val slot = MatterySlot(container, it)
|
||||
addSlot(slot)
|
||||
return@Array slot
|
||||
return@ImmutableList slot
|
||||
}
|
||||
|
||||
tile?.onPlayerOpen()
|
||||
@ -30,12 +31,4 @@ class CargoCrateMenu @JvmOverloads constructor(
|
||||
super.removed(p_38940_)
|
||||
(tile as? CargoCrateBlockEntity)?.onPlayerClose()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return CargoCrateBlockEntity.CAPACITY
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraftforge.common.ForgeHooks
|
||||
import net.minecraftforge.energy.CapabilityEnergy
|
||||
@ -38,10 +39,13 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t
|
||||
val energy = LevelGaugeWidget(this, tile?.energy)
|
||||
val burnTime = IntDataContainer()
|
||||
|
||||
override val storageSlots = listOf(
|
||||
addSlot(fuelSlot),
|
||||
addSlot(batterySlot),
|
||||
addSlot(residueSlot),
|
||||
)
|
||||
|
||||
init {
|
||||
addSlot(fuelSlot)
|
||||
addSlot(batterySlot)
|
||||
addSlot(residueSlot)
|
||||
addDataContainer(burnTime)
|
||||
addInventorySlots()
|
||||
}
|
||||
@ -51,12 +55,4 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t
|
||||
progress.updateServer()
|
||||
burnTime.value = (tile as ChemicalGeneratorBlockEntity).workingTicks
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 3
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.DriveRackBlockEntity
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
|
||||
@ -10,29 +12,17 @@ class DriveRackMenu @JvmOverloads constructor(
|
||||
inventory: Inventory,
|
||||
tile: DriveRackBlockEntity? = null
|
||||
) : MatteryPoweredMenu(MMenus.DRIVE_RACK, p_38852_, inventory, tile) {
|
||||
val drives: Array<MatterySlot>
|
||||
override val storageSlots: List<MatterySlot>
|
||||
|
||||
init {
|
||||
val container = tile?.drives ?: SimpleContainer(4)
|
||||
|
||||
val drives = arrayOfNulls<MatterySlot>(4)
|
||||
|
||||
for (i in 0 until container.containerSize) {
|
||||
val slot = DriveSlot(container, i)
|
||||
drives[i] = slot
|
||||
storageSlots = ImmutableList(4) {
|
||||
val slot = DriveSlot(container, it)
|
||||
addSlot(slot)
|
||||
slot
|
||||
}
|
||||
|
||||
this.drives = drives as Array<MatterySlot>
|
||||
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 5
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import com.google.common.collect.ImmutableList
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraftforge.energy.CapabilityEnergy
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.DriveViewerBlockEntity
|
||||
@ -58,6 +60,8 @@ class DriveViewerMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override val storageSlots: List<Slot> = ImmutableList.of(driveSlot, batterySlot)
|
||||
|
||||
val driveFilter = ItemFilter(PortableCondensationDriveItem.MAX_FILTERS) { self, _, _, _ ->
|
||||
if (tile?.container?.get(0)?.item is PortableCondensationDriveItem) {
|
||||
tile.container[0].getOrCreateTag().put(PortableCondensationDriveItem.FILTER_PATH, self.serializeNBT())
|
||||
@ -132,14 +136,6 @@ class DriveViewerMenu @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 2
|
||||
}
|
||||
|
||||
override fun removed(p_38940_: Player) {
|
||||
super.removed(p_38940_)
|
||||
|
||||
@ -149,12 +145,12 @@ class DriveViewerMenu @JvmOverloads constructor(
|
||||
view.removed()
|
||||
}
|
||||
|
||||
override fun quickMoveStack(ply: Player, slot_index: Int): ItemStack {
|
||||
val slot = slots[slot_index]
|
||||
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
|
||||
val slot = slots[slotIndex]
|
||||
val item = slot.item
|
||||
|
||||
if (item.isEmpty || item.getCapability(MatteryCapability.DRIVE).isPresent || item.getCapability(CapabilityEnergy.ENERGY).isPresent)
|
||||
return super.quickMoveStack(ply, slot_index)
|
||||
return super.quickMoveStack(ply, slotIndex)
|
||||
|
||||
val powered = powered
|
||||
if (lastDrive == null || powered == null)
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.menu
|
||||
import net.minecraft.core.Direction
|
||||
import kotlin.jvm.JvmOverloads
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.level.block.Block
|
||||
import ru.dbotthepony.mc.otm.block.EnergyCounterBlock
|
||||
import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity
|
||||
@ -76,13 +77,8 @@ class EnergyCounterMenu @JvmOverloads constructor(
|
||||
super.broadcastChanges()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 0
|
||||
}
|
||||
override val storageSlots: Collection<Slot> get() = emptySet()
|
||||
|
||||
companion object {
|
||||
private val MINUS_ONE = -BigDecimal.ONE
|
||||
|
@ -10,12 +10,10 @@ import net.minecraft.world.item.ItemStack
|
||||
import net.minecraftforge.network.PacketDistributor
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorBlockEntity
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorPlayerSettings
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.get
|
||||
import ru.dbotthepony.mc.otm.menu.data.INetworkedItemViewSupplier
|
||||
import ru.dbotthepony.mc.otm.menu.data.NetworkedItemView
|
||||
import ru.dbotthepony.mc.otm.network.MatteryNetworking
|
||||
import ru.dbotthepony.mc.otm.orThrow
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
import ru.dbotthepony.mc.otm.storage.*
|
||||
import java.util.*
|
||||
@ -133,21 +131,15 @@ class ItemMonitorMenu @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
override val storageSlots: List<Slot> = listOf(batterySlot)
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override fun quickMoveStack(ply: Player, slot_index: Int): ItemStack {
|
||||
if (slot_index in inventorySlotIndexStart..inventorySlotIndexEnd) {
|
||||
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
|
||||
if (slotIndex in inventorySlotIndexStart..inventorySlotIndexEnd) {
|
||||
if (tile == null) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
val slot = slots[slot_index]
|
||||
val slot = slots[slotIndex]
|
||||
|
||||
if (slot.item.isEmpty) {
|
||||
return ItemStack.EMPTY
|
||||
@ -162,30 +154,30 @@ class ItemMonitorMenu @JvmOverloads constructor(
|
||||
val old = slot.item.copy()
|
||||
slot.item.count = leftover.count
|
||||
return old
|
||||
} else if (slot_index in craftingSlots[0].index .. craftingSlots[craftingSlots.size - 1].index) {
|
||||
} else if (slotIndex in craftingSlots[0].index .. craftingSlots[craftingSlots.size - 1].index) {
|
||||
// from crafting grid to inventory
|
||||
val item = slots[slot_index].item
|
||||
val item = slots[slotIndex].item
|
||||
|
||||
if (item.isEmpty) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
var remainder = moveItemStackToSlots(item, inventorySlotIndexStart, inventorySlotIndexEnd)
|
||||
slots[slot_index].set(remainder)
|
||||
var remainder = moveItemStackToSlots(item, playerInventorySlots)
|
||||
slots[slotIndex].set(remainder)
|
||||
|
||||
if (remainder.isEmpty) {
|
||||
return item
|
||||
}
|
||||
|
||||
remainder = view.provider?.insertStack(ItemStackWrapper(remainder), false)?.stack ?: remainder
|
||||
slots[slot_index].set(remainder)
|
||||
slots[slotIndex].set(remainder)
|
||||
|
||||
if (remainder.isEmpty) {
|
||||
return item
|
||||
}
|
||||
|
||||
return if (remainder.count != item.count) item else ItemStack.EMPTY
|
||||
} else if (slot_index == craftingResult.index) {
|
||||
} else if (slotIndex == craftingResult.index) {
|
||||
// quickcraft... god damn it
|
||||
if (!craftingResult.hasItem()) {
|
||||
return ItemStack.EMPTY
|
||||
@ -252,11 +244,11 @@ class ItemMonitorMenu @JvmOverloads constructor(
|
||||
return item
|
||||
}
|
||||
|
||||
remaining = moveItemStackToSlots(remaining, inventorySlotIndexStart, inventorySlotIndexEnd, simulate = true)
|
||||
remaining = moveItemStackToSlots(remaining, playerInventorySlots, simulate = true)
|
||||
|
||||
if (remaining.isEmpty) {
|
||||
remaining = tile.poweredView!!.insertStack(wrapper, false).stack
|
||||
moveItemStackToSlots(remaining, inventorySlotIndexStart, inventorySlotIndexEnd, simulate = false)
|
||||
moveItemStackToSlots(remaining, playerInventorySlots, simulate = false)
|
||||
craftingResult.remove(item.count)
|
||||
return item
|
||||
}
|
||||
@ -265,10 +257,10 @@ class ItemMonitorMenu @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
ItemMonitorPlayerSettings.ResultTarget.MIXED, ItemMonitorPlayerSettings.ResultTarget.ALL_INVENTORY -> {
|
||||
var remaining = moveItemStackToSlots(item, inventorySlotIndexStart, inventorySlotIndexEnd, simulate = true)
|
||||
var remaining = moveItemStackToSlots(item, playerInventorySlots, simulate = true)
|
||||
|
||||
if (remaining.isEmpty) {
|
||||
moveItemStackToSlots(item, inventorySlotIndexStart, inventorySlotIndexEnd, simulate = false)
|
||||
moveItemStackToSlots(item, playerInventorySlots, simulate = false)
|
||||
craftingResult.remove(item.count)
|
||||
return item
|
||||
}
|
||||
@ -277,7 +269,7 @@ class ItemMonitorMenu @JvmOverloads constructor(
|
||||
remaining = tile.poweredView?.insertStack(wrapper, true)?.stack ?: return ItemStack.EMPTY
|
||||
|
||||
if (remaining.isEmpty) {
|
||||
moveItemStackToSlots(item, inventorySlotIndexStart, inventorySlotIndexEnd, simulate = false)
|
||||
moveItemStackToSlots(item, playerInventorySlots, simulate = false)
|
||||
tile.poweredView!!.insertStack(wrapper, false).stack
|
||||
craftingResult.remove(item.count)
|
||||
return item
|
||||
@ -291,6 +283,6 @@ class ItemMonitorMenu @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
return super.quickMoveStack(ply, slot_index)
|
||||
return super.quickMoveStack(ply, slotIndex)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
||||
@ -22,7 +24,8 @@ class MatterBottlerMenu @JvmOverloads constructor(
|
||||
|
||||
val progressWidget: ProgressGaugeWidget
|
||||
val matterWidget: LevelGaugeWidget
|
||||
val container: Array<MatterySlot>
|
||||
|
||||
override val storageSlots: List<MatterySlot>
|
||||
|
||||
init {
|
||||
val container = tile?.container ?: SimpleContainer(6)
|
||||
@ -37,7 +40,7 @@ class MatterBottlerMenu @JvmOverloads constructor(
|
||||
workFlow = BooleanPlayerInputWidget(this, tile::workFlow)
|
||||
}
|
||||
|
||||
this.container = Array(6) { index ->
|
||||
storageSlots = ImmutableList(6) { index ->
|
||||
object : MatterySlot(container, index) {
|
||||
override fun mayPlace(p_40231_: ItemStack): Boolean {
|
||||
val cap = p_40231_.getCapability(MatteryCapability.MATTER).orNull() ?: return false
|
||||
@ -51,7 +54,7 @@ class MatterBottlerMenu @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
this.container.forEach(this::addSlot)
|
||||
storageSlots.forEach(this::addSlot)
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
@ -59,12 +62,4 @@ class MatterBottlerMenu @JvmOverloads constructor(
|
||||
super.broadcastChanges()
|
||||
workFlow.value = (tile as MatterBottlerBlockEntity).workFlow
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 7
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@ package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
@ -16,7 +18,8 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
|
||||
) {
|
||||
val matterGauge: LevelGaugeWidget
|
||||
val totalMatterGauge: LevelGaugeWidget
|
||||
val workSlots: Array<MatterContainerInputSlot>
|
||||
|
||||
override val storageSlots: List<MatterContainerInputSlot>
|
||||
|
||||
init {
|
||||
if (tile == null) {
|
||||
@ -32,26 +35,13 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
val container = tile?.container ?: SimpleContainer(2 * 6)
|
||||
val workSlots = arrayOfNulls<MatterContainerInputSlot>(2 * 6)
|
||||
|
||||
for (row in 0..1) {
|
||||
for (column in 0..5) {
|
||||
val slot = MatterContainerInputSlot(container, row * 6 + column)
|
||||
workSlots[row * 6 + column] = slot
|
||||
addSlot(slot)
|
||||
}
|
||||
storageSlots = ImmutableList(2 * 6) {
|
||||
val slot = MatterContainerInputSlot(container, it)
|
||||
addSlot(slot)
|
||||
slot
|
||||
}
|
||||
|
||||
this.workSlots = workSlots as Array<MatterContainerInputSlot>
|
||||
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 2 * 6
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import com.google.common.collect.ImmutableList
|
||||
import kotlin.jvm.JvmOverloads
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import ru.dbotthepony.mc.otm.block.entity.matter.MatterDecomposerBlockEntity
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.matter.canDecompose
|
||||
@ -31,15 +33,10 @@ class MatterDecomposerMenu @JvmOverloads constructor(
|
||||
override fun mayPlace(p_40231_: ItemStack) = canDecompose(p_40231_)
|
||||
}
|
||||
|
||||
addSlot(input)
|
||||
|
||||
// Выход
|
||||
outputMain = MachineOutputSlot(container, 1)
|
||||
outputStacking = MachineOutputSlot(container, 2)
|
||||
|
||||
addSlot(outputMain)
|
||||
addSlot(outputStacking)
|
||||
|
||||
matterWidget = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.MATTER)?.orNull())
|
||||
|
||||
if (tile == null) {
|
||||
@ -51,11 +48,9 @@ class MatterDecomposerMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 3
|
||||
}
|
||||
override val storageSlots: List<Slot> = ImmutableList.of(
|
||||
addSlot(outputMain),
|
||||
addSlot(outputStacking),
|
||||
addSlot(input),
|
||||
)
|
||||
}
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.menu
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraftforge.network.PacketDistributor
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.block.entity.matter.MatterPanelBlockEntity
|
||||
@ -32,12 +33,8 @@ class MatterPanelMenu @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
// client code
|
||||
@JvmField
|
||||
var patterns = ArrayList<PatternState>()
|
||||
|
||||
@JvmField
|
||||
var tasks = ArrayList<MatterTask>()
|
||||
|
||||
val patterns = ArrayList<PatternState>()
|
||||
val tasks = ArrayList<MatterTask>()
|
||||
var changeset = 0
|
||||
|
||||
fun networkPatternsUpdated(patterns: Collection<PatternState>) {
|
||||
@ -176,11 +173,6 @@ class MatterPanelMenu @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 0
|
||||
}
|
||||
override val storageSlots: Collection<Slot>
|
||||
get() = emptyList()
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import com.google.common.collect.ImmutableList
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity
|
||||
import ru.dbotthepony.mc.otm.item.MatterDustItem
|
||||
@ -37,11 +39,5 @@ class MatterRecyclerMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 2
|
||||
}
|
||||
override val storageSlots: Collection<Slot> = ImmutableList.of(input)
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterReplicatorBlockEntity
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
|
||||
class MatterReplicatorMenu @JvmOverloads constructor(
|
||||
@ -17,15 +19,15 @@ class MatterReplicatorMenu @JvmOverloads constructor(
|
||||
) {
|
||||
val matter: LevelGaugeWidget
|
||||
val progress: ProgressGaugeWidget
|
||||
val outputSlots: Array<MachineOutputSlot>
|
||||
override val storageSlots: List<MachineOutputSlot>
|
||||
|
||||
init {
|
||||
val container = tile?.container ?: SimpleContainer(5)
|
||||
|
||||
outputSlots = Array(5) {
|
||||
storageSlots = ImmutableList(5) {
|
||||
val slot = MachineOutputSlot(container, it)
|
||||
addSlot(slot)
|
||||
return@Array slot
|
||||
return@ImmutableList slot
|
||||
}
|
||||
|
||||
if (tile != null) {
|
||||
@ -38,12 +40,4 @@ class MatterReplicatorMenu @JvmOverloads constructor(
|
||||
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 5
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterScannerBlockEntity
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.matter.canDecompose
|
||||
@ -47,11 +48,5 @@ class MatterScannerMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 2
|
||||
}
|
||||
override val storageSlots: List<MatterySlot> = listOf(input)
|
||||
}
|
@ -22,22 +22,17 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
) : AbstractContainerMenu(p_38851_, p_38852_) {
|
||||
val ply: Player get() = inventory.player
|
||||
|
||||
@JvmField
|
||||
val matteryWidgets = ArrayList<AbstractWidget>()
|
||||
|
||||
@JvmField
|
||||
val inventorySlots = ArrayList<MatterySlot>()
|
||||
private val _playerInventorySlots = ArrayList<MatterySlot>()
|
||||
val playerInventorySlots: List<MatterySlot> = Collections.unmodifiableList(_playerInventorySlots)
|
||||
val multiByteContainers = ArrayList<MultiByteDataContainer>()
|
||||
|
||||
@JvmField
|
||||
protected val lockedInventorySlots: MutableSet<Int> = HashSet()
|
||||
protected open fun isInventorySlotLocked(index: Int): Boolean = lockedInventorySlots.contains(index)
|
||||
|
||||
@JvmField
|
||||
protected var _synchronizer: ContainerSynchronizer? = null
|
||||
|
||||
private val _filterSlots = ArrayList<ItemFilterNetworkSlot>()
|
||||
val filterSlots = Collections.unmodifiableList(_filterSlots)
|
||||
val filterSlots: List<ItemFilterNetworkSlot> = Collections.unmodifiableList(_filterSlots)
|
||||
|
||||
fun addFilterSlots(slots: ItemFilter): List<ItemFilterNetworkSlot> {
|
||||
val result = ArrayList<ItemFilterNetworkSlot>(slots.size)
|
||||
@ -59,11 +54,6 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun setSynchronizer(p_150417_: ContainerSynchronizer) {
|
||||
_synchronizer = p_150417_
|
||||
super.setSynchronizer(p_150417_)
|
||||
}
|
||||
|
||||
fun addWidget(widget: AbstractWidget): Int {
|
||||
val indexOf = matteryWidgets.indexOf(widget)
|
||||
|
||||
@ -99,10 +89,7 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
return multiByteContainers[index]
|
||||
}
|
||||
|
||||
@JvmField
|
||||
protected var inventorySlotIndexStart = 0
|
||||
|
||||
@JvmField
|
||||
protected var inventorySlotIndexEnd = 0
|
||||
|
||||
protected fun addInventorySlots() {
|
||||
@ -120,7 +107,7 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
}
|
||||
}
|
||||
|
||||
inventorySlots.add(slot)
|
||||
_playerInventorySlots.add(slot)
|
||||
addSlot(slot)
|
||||
|
||||
if (first) {
|
||||
@ -144,13 +131,13 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
}
|
||||
|
||||
addSlot(last)
|
||||
inventorySlots.add(last)
|
||||
_playerInventorySlots.add(last)
|
||||
}
|
||||
|
||||
inventorySlotIndexEnd = last!!.index
|
||||
}
|
||||
|
||||
private val pdistributor = PacketDistributor.PLAYER.with { ply as ServerPlayer }
|
||||
private val playerPacketDistributor = PacketDistributor.PLAYER.with { ply as ServerPlayer }
|
||||
|
||||
override fun broadcastChanges() {
|
||||
for (widget in matteryWidgets) {
|
||||
@ -160,7 +147,7 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
for (data in multiByteContainers) {
|
||||
if (data.dirty) {
|
||||
data.dirty = false
|
||||
MatteryNetworking.CHANNEL.send(pdistributor, data.makePacket())
|
||||
MatteryNetworking.CHANNEL.send(playerPacketDistributor, data.makePacket())
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +170,7 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
}
|
||||
|
||||
for (data in multiByteContainers) {
|
||||
MatteryNetworking.CHANNEL.send(pdistributor, data.makePacket())
|
||||
MatteryNetworking.CHANNEL.send(playerPacketDistributor, data.makePacket())
|
||||
}
|
||||
|
||||
super.broadcastFullState()
|
||||
@ -211,40 +198,56 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
return player.distanceToSqr(pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5) <= 64.0
|
||||
}
|
||||
|
||||
protected abstract fun getWorkingSlotStart(): Int
|
||||
protected abstract fun getWorkingSlotEnd(): Int
|
||||
abstract val storageSlots: Collection<Slot>
|
||||
|
||||
// This method receive Player interactor and slot_index where Shift + Right click occurred
|
||||
// It shall return item stack that got moved
|
||||
override fun quickMoveStack(ply: Player, slot_index: Int): ItemStack {
|
||||
// this.moveItemStackTo(ItemStack, int start_slot_index, int end_slot_index, boolean iteration_order)
|
||||
// returns boolean, telling whenever ItemStack was modified (moved or shrank)
|
||||
// false means nothing happened
|
||||
// Last boolean determine order of slot iteration, where:
|
||||
// if TRUE, iteration order is end_slot_index -> start_slot_index
|
||||
// if FALSE iteration order is start_slot_index -> end_slot_index
|
||||
val start = getWorkingSlotStart()
|
||||
val end = getWorkingSlotEnd()
|
||||
override fun quickMoveStack(ply: Player, slotIndex: Int): ItemStack {
|
||||
if (storageSlots.isEmpty()) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
if (start == end) {
|
||||
var moveToPlayer: Boolean? = null
|
||||
|
||||
for (slot in storageSlots) {
|
||||
if (slot.index == slotIndex) {
|
||||
moveToPlayer = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (moveToPlayer == null) {
|
||||
for (slot in playerInventorySlots) {
|
||||
if (slot.index == slotIndex) {
|
||||
moveToPlayer = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (moveToPlayer == null) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
var moved = ItemStack.EMPTY
|
||||
val initialSlot = slots[slot_index]
|
||||
val initialSlot = slots[slotIndex]
|
||||
|
||||
if (initialSlot.hasItem()) {
|
||||
if (!initialSlot.mayPickup(ply)) {
|
||||
return moved
|
||||
}
|
||||
|
||||
val initialItem = initialSlot.item
|
||||
moved = initialItem.copy()
|
||||
|
||||
if (slot_index < inventorySlotIndexStart) {
|
||||
// Moving FROM machine TO inventory
|
||||
if (!moveItemStackTo(initialItem, inventorySlotIndexStart, inventorySlotIndexEnd + 1, false)) {
|
||||
if (moveToPlayer) {
|
||||
if (!moveItemStackTo(initialItem, playerInventorySlots)) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
} else {
|
||||
if (!moveItemStackTo(initialItem, storageSlots)) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
} else if (!moveItemStackTo(initialItem, start, end, false)) {
|
||||
// Moving FROM inventory TO machine
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
if (initialItem.isEmpty) {
|
||||
@ -281,20 +284,29 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
return true
|
||||
}
|
||||
|
||||
fun moveItemStackToSlots(item: ItemStack, initialSlot: Int, finalSlot: Int, inverse: Boolean = false, simulate: Boolean = false): ItemStack {
|
||||
if (initialSlot > finalSlot) {
|
||||
return item
|
||||
fun moveItemStackTo(
|
||||
item: ItemStack,
|
||||
slots: Collection<Slot>
|
||||
): Boolean {
|
||||
val remainder = moveItemStackToSlots(item, slots)
|
||||
|
||||
if (remainder.count == item.count) {
|
||||
return false
|
||||
}
|
||||
|
||||
item.count = remainder.count
|
||||
return true
|
||||
}
|
||||
|
||||
fun moveItemStackToSlots(item: ItemStack, slots: Collection<Slot>, simulate: Boolean = false): ItemStack {
|
||||
val copy = item.copy()
|
||||
|
||||
// first pass - stack with existing slots
|
||||
if (copy.isStackable) {
|
||||
for (i in (if (inverse) finalSlot downTo initialSlot else initialSlot .. finalSlot)) {
|
||||
val slot = slots[i]
|
||||
for (slot in slots) {
|
||||
val limit = slot.getMaxStackSize(copy)
|
||||
|
||||
if (limit > slot.item.count && ItemStack.isSameItemSameTags(slot.item, copy)) {
|
||||
if (limit > slot.item.count && ItemStack.isSameItemSameTags(slot.item, copy) && slot.mayPlace(item)) {
|
||||
val newCount = (slot.item.count + copy.count).coerceAtMost(limit)
|
||||
val diff = newCount - slot.item.count
|
||||
copy.count -= diff
|
||||
@ -312,11 +324,10 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
}
|
||||
|
||||
// second pass - drop stack into first free slot
|
||||
for (i in (if (inverse) finalSlot downTo initialSlot else initialSlot .. finalSlot)) {
|
||||
val slot = slots[i]
|
||||
for (slot in slots) {
|
||||
val limit = slot.getMaxStackSize(copy)
|
||||
|
||||
if (!slot.hasItem()) {
|
||||
if (!slot.hasItem() && slot.mayPlace(item)) {
|
||||
val newCount = copy.count.coerceAtMost(limit)
|
||||
|
||||
if (!simulate) {
|
||||
@ -335,6 +346,23 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
|
||||
return copy
|
||||
}
|
||||
|
||||
fun moveItemStackToSlots(item: ItemStack, initialSlot: Int, finalSlot: Int, inverse: Boolean = false, simulate: Boolean = false): ItemStack {
|
||||
if (initialSlot > finalSlot) {
|
||||
return item
|
||||
}
|
||||
|
||||
require(initialSlot >= 0) { "Invalid initial slot $initialSlot" }
|
||||
require(finalSlot < slots.size) { "Final slot $finalSlot is bigger than total size of array of ${slots.size}" }
|
||||
|
||||
val slots = ArrayList<Slot>(finalSlot - initialSlot + 1)
|
||||
|
||||
for (i in (if (inverse) finalSlot downTo initialSlot else initialSlot .. finalSlot)) {
|
||||
slots.add(slots[i])
|
||||
}
|
||||
|
||||
return moveItemStackToSlots(item, slots, simulate)
|
||||
}
|
||||
|
||||
public override fun addDataSlots(p_38885_: ContainerData) {
|
||||
super.addDataSlots(p_38885_)
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ abstract class MatteryPoweredMenu protected constructor(
|
||||
inventory: Inventory,
|
||||
tile: MatteryPoweredBlockEntity? = null
|
||||
) : MatteryMenu(menuType, containerID, inventory, tile) {
|
||||
@JvmField val powerWidget: LevelGaugeWidget
|
||||
@JvmField val batterySlot: BatterySlot
|
||||
val powerWidget: LevelGaugeWidget
|
||||
val batterySlot: BatterySlot
|
||||
|
||||
init {
|
||||
if (tile == null) {
|
||||
|
@ -2,6 +2,8 @@ package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.ImmutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.PatternStorageBlockEntity
|
||||
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
|
||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||
@ -14,10 +16,11 @@ class PatternStorageMenu @JvmOverloads constructor(
|
||||
) : MatteryMenu(
|
||||
MMenus.PATTERN_STORAGE, p_38852_, inventory, tile
|
||||
) {
|
||||
val patternSlots: Array<PatternSlot>
|
||||
val storedThis: LevelGaugeWidget
|
||||
val storedGrid: LevelGaugeWidget
|
||||
|
||||
override val storageSlots: List<PatternSlot>
|
||||
|
||||
init {
|
||||
if (tile == null) {
|
||||
storedThis = LevelGaugeWidget(this)
|
||||
@ -33,25 +36,12 @@ class PatternStorageMenu @JvmOverloads constructor(
|
||||
|
||||
val patterns = tile?.patterns ?: SimpleContainer(2 * 4)
|
||||
|
||||
val patternSlots = arrayOfNulls<PatternSlot>(2 * 4)
|
||||
|
||||
for (row in 0..1) {
|
||||
for (column in 0..3) {
|
||||
patternSlots[row * 4 + column] = PatternSlot(patterns, row * 4 + column, 48 + column * 20, 27 + row * 24)
|
||||
addSlot(patternSlots[row * 4 + column]!!)
|
||||
}
|
||||
storageSlots = ImmutableList(2 * 4) {
|
||||
PatternSlot(patterns, it)
|
||||
}
|
||||
|
||||
this.patternSlots = patternSlots as Array<PatternSlot>
|
||||
storageSlots.forEach(this::addSlot)
|
||||
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getWorkingSlotEnd(): Int {
|
||||
return 2 * 4
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import com.google.common.collect.ImmutableList
|
||||
import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.block.entity.PlatePressBlockEntity
|
||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
@ -16,6 +18,8 @@ class PlatePressMenu @JvmOverloads constructor(
|
||||
val inputSlot = MatterySlot(container, PlatePressBlockEntity.SLOT_INPUT)
|
||||
val outputSlot = MachineOutputSlot(container, PlatePressBlockEntity.SLOT_OUTPUT)
|
||||
|
||||
override val storageSlots: List<MatterySlot> = ImmutableList.of(inputSlot, outputSlot)
|
||||
|
||||
val progressGauge = if (tile != null) ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) else ProgressGaugeWidget(this)
|
||||
|
||||
init {
|
||||
@ -23,7 +27,4 @@ class PlatePressMenu @JvmOverloads constructor(
|
||||
addSlot(outputSlot)
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart() = 0
|
||||
override fun getWorkingSlotEnd() = 2
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.StorageBusBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot
|
||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
||||
@ -28,6 +29,5 @@ class StorageBusMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart() = 0
|
||||
override fun getWorkingSlotEnd() = 1
|
||||
override val storageSlots: Collection<Slot> = listOf(batterySlot)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.StorageExporterBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot
|
||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
||||
@ -28,6 +29,5 @@ class StorageExporterMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart() = 0
|
||||
override fun getWorkingSlotEnd() = 1
|
||||
override val storageSlots: List<Slot> = listOf(batterySlot)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.StorageImporterBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot
|
||||
import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget
|
||||
@ -28,6 +29,5 @@ class StorageImporterMenu @JvmOverloads constructor(
|
||||
addInventorySlots()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart() = 0
|
||||
override fun getWorkingSlotEnd() = 1
|
||||
override val storageSlots: List<Slot> = listOf(batterySlot)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.inventory.Slot
|
||||
import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity
|
||||
import ru.dbotthepony.mc.otm.menu.data.ImpreciseFractionDataContainer
|
||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||
@ -28,6 +29,5 @@ class StoragePowerSupplierMenu @JvmOverloads constructor(
|
||||
super.broadcastChanges()
|
||||
}
|
||||
|
||||
override fun getWorkingSlotStart() = 0
|
||||
override fun getWorkingSlotEnd() = 1
|
||||
override val storageSlots: List<Slot> = listOf(batterySlot)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user