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