Recreate android station menu

This commit is contained in:
DBotThePony 2021-12-31 15:33:14 +07:00
parent c14e955564
commit 39096c0f14
Signed by: DBot
GPG Key ID: DCC23B5715498507
28 changed files with 288 additions and 464 deletions

View File

@ -1,252 +1,247 @@
package ru.dbotthepony.mc.otm.client.screen; package ru.dbotthepony.mc.otm.client.screen
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component
import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.chat.TranslatableComponent
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.android.AndroidResearch; import ru.dbotthepony.mc.otm.android.AndroidResearch
import ru.dbotthepony.mc.otm.android.AndroidResearchType; import ru.dbotthepony.mc.otm.android.AndroidResearchType
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.android.AndroidCapabilityPlayer; import ru.dbotthepony.mc.otm.capability.android.AndroidCapabilityPlayer
import ru.dbotthepony.mc.otm.client.render.RGBAColor; import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability
import ru.dbotthepony.mc.otm.client.render.RenderHelper; import ru.dbotthepony.mc.otm.client.render.RGBAColor
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel; import ru.dbotthepony.mc.otm.client.render.RenderHelper
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu; import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot; import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.panels.*; import ru.dbotthepony.mc.otm.menu.AndroidStationMenu
import java.util.*
import javax.annotation.Nullable;
import java.util.*;
public class AndroidStationScreen extends MatteryScreen<AndroidStationMenu> {
class AndroidResearchButton extends EditablePanel {
public static final int BUTTON_SIZE = 18;
private final AndroidResearch node;
public static final RGBAColor RESEARCHED = new RGBAColor(150, 150, 200); class AndroidStationScreen(p_97741_: AndroidStationMenu, p_97742_: Inventory, p_97743_: Component) :
public static final RGBAColor CAN_BE_RESEARCHED = new RGBAColor(150, 200, 150); MatteryScreen<AndroidStationMenu>(p_97741_, p_97742_, p_97743_) {
public static final RGBAColor CAN_NOT_BE_RESEARCHED = new RGBAColor(200, 150, 150);
public AndroidResearchButton(@Nullable EditablePanel parent, AndroidResearch node) { internal inner class AndroidResearchButton(parent: EditablePanel?, private val node: AndroidResearch) :
super(AndroidStationScreen.this, parent, 0, 0, BUTTON_SIZE, BUTTON_SIZE); EditablePanel(
this.node = node; this@AndroidStationScreen,
setDockMargin(2, 2, 2, 2); parent,
0f,
0f,
BUTTON_SIZE.toFloat(),
BUTTON_SIZE.toFloat()
) {
init {
setDockMargin(2f, 2f, 2f, 2f)
} }
@Override override fun innerRender(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float) {
protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) { Minecraft.getInstance().player!!.getCapability(MatteryCapability.ANDROID)
Minecraft.getInstance().player.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> { .ifPresent { _cap: IAndroidCapability? ->
if (_cap instanceof AndroidCapabilityPlayer cap) { if (_cap is AndroidCapabilityPlayer) {
if (node.isResearched()) { if (node.isResearched) {
RESEARCHED.setSystemColor(); RESEARCHED.setSystemColor()
} else if (node.canResearch()) { } else if (node.canResearch()) {
CAN_BE_RESEARCHED.setSystemColor(); CAN_BE_RESEARCHED.setSystemColor()
} else { } else {
CAN_NOT_BE_RESEARCHED.setSystemColor(); CAN_NOT_BE_RESEARCHED.setSystemColor()
} }
var icon = node.getIcon(); val icon = node.icon
if (icon != null) { if (icon != null) {
icon.render(stack, 0, 0, getWidth(), getHeight()); icon.render(stack, 0f, 0f, width, height)
} else { } else {
RenderHelper.drawRect(stack, 0, 0, getWidth(), getHeight()); RenderHelper.drawRect(stack, 0f, 0f, width, height)
} }
var text = node.getIconText(); val text = node.iconText
if (text != null) { if (text != null) {
font.drawShadow(stack, text, getWidth() - font.width(text), getHeight() - font.lineHeight, 0xFFFFFFFF); font.drawShadow(stack, text, width - font.width(text), height - font.lineHeight, -0x1)
}
} }
} }
});
} }
@Override override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int flag) { node.researchClient()
node.researchClient(); return true
return true;
} }
@Override override fun innerRenderTooltips(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float): Boolean {
protected boolean innerRenderTooltips(PoseStack stack, float mouse_x, float mouse_y, float flag) { if (isHovered) {
if (isHovered()) { val list = ArrayList(
var list = new ArrayList<>(node.getTooltip()); node.tooltip
)
if (node.isResearched()) { if (node.isResearched) {
list.add(new TranslatableComponent("otm.android_station.research.researched").withStyle(ChatFormatting.DARK_AQUA)); list.add(TranslatableComponent("otm.android_station.research.researched").withStyle(ChatFormatting.DARK_AQUA))
} else if (node.canResearch()) { } else if (node.canResearch()) {
list.add(new TranslatableComponent("otm.android_station.research.can_be_researched").withStyle(ChatFormatting.DARK_GREEN)); list.add(TranslatableComponent("otm.android_station.research.can_be_researched").withStyle(ChatFormatting.DARK_GREEN))
} else { } else {
list.add(new TranslatableComponent("otm.android_station.research.can_not_be_researched").withStyle(ChatFormatting.DARK_RED)); list.add(TranslatableComponent("otm.android_station.research.can_not_be_researched").withStyle(ChatFormatting.DARK_RED))
} }
renderComponentTooltip(stack, list, (int) mouse_x, (int) mouse_y); renderComponentTooltip(stack, list, mouse_x.toInt(), mouse_y.toInt())
} }
return isHovered(); return isHovered
} }
} }
public static final int FRAME_WIDTH = 210; private val rows = arrayOfNulls<EditablePanel>(100)
public static final int GRID_WIDTH = 5; private val seen: MutableSet<AndroidResearchType<*>> = HashSet()
public static final int FRAME_HEIGHT = 120; private var nextX = 0f
private val rowsWidth = FloatArray(100)
private val createdButtons = Array(100) { arrayOfNulls<AndroidResearchButton>(1000) }
private val createdButtonsIdx = IntArray(100)
public AndroidStationScreen(AndroidStationMenu p_97741_, Inventory p_97742_, Component p_97743_) { private fun dive(cap: AndroidCapabilityPlayer, research: AndroidResearchType<*>, level: Int) {
super(p_97741_, p_97742_, p_97743_); if (seen.contains(research)) return
} seen.add(research)
private final EditablePanel[] rows = new EditablePanel[100];
private final Set<AndroidResearchType<?>> seen = new HashSet<>();
private float next_x = 0;
private final float[] rows_width = new float[100];
private final AndroidResearchButton[][] created_buttons = new AndroidResearchButton[100][1000];
private final int[] created_buttons_idx = new int[100];
private void dive(AndroidCapabilityPlayer cap, AndroidResearchType<?> research, int level) {
if (seen.contains(research))
return;
seen.add(research);
if (rows[level] == null) { if (rows[level] == null) {
rows[level] = new EditablePanel(this, canvas, 0, level * 22, 10000, 22) { rows[level] = object : EditablePanel(this@AndroidStationScreen, canvas, 0f, (level * 22).toFloat(), 10000f, 22f) {
@Override override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, flag: Int) = false
protected boolean mouseClickedInner(double mouse_x, double mouse_y, int flag) { override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int) = false
return false; override fun mouseDraggedInner(mouse_x: Double, mouse_y: Double, flag: Int, drag_x: Double, drag_y: Double) = false
}
} }
@Override val row = rows[level]
protected boolean mouseReleasedInner(double mouse_x, double mouse_y, int flag) { val button = AndroidResearchButton(row, cap.getResearch(research))
return false;
}
@Override button.setPos(nextX + rowsWidth[level], 2f)
protected boolean mouseDraggedInner(double mouse_x, double mouse_y, int flag, double drag_x, double drag_y) {
return false;
}
};
}
var row = rows[level]; createdButtons[level][createdButtonsIdx[level]] = button
var button = new AndroidResearchButton(row, cap.getResearch(research)); createdButtonsIdx[level]++
button.setPos(next_x + rows_width[level], 2); rowsWidth[level] += 22f
created_buttons[level][created_buttons_idx[level]] = button;
created_buttons_idx[level]++;
rows_width[level] += 22; for (_research in research.unlocks) {
dive(cap, _research, level + 1)
for (var _research : research.getUnlocks()) {
dive(cap, _research, level + 1);
} }
if (level > 0) { if (level > 0) {
for (var _research : research.getPrerequisites()) { for (_research in research.prerequisites) {
dive(cap, _research, level - 1); dive(cap, _research, level - 1)
} }
} }
} }
private DraggableCanvasPanel canvas; private var canvas: DraggableCanvasPanel? = null
private FramePanel research; private var research: FramePanel? = null
private void openResearchTree() { private fun openResearchTree() {
var window = this.minecraft.getWindow(); val window = minecraft!!.window
research = new FramePanel(this, null, 0, 0, window.getGuiScaledWidth() * 0.8f, window.getGuiScaledHeight() * 0.8f, new TranslatableComponent("otm.gui.android_research"));
canvas = new DraggableCanvasPanel(this, research, 0, 0, GRID_WIDTH * 22, 0) { research = FramePanel(this, null, 0f, 0f, window.guiScaledWidth * 0.8f, window.guiScaledHeight * 0.8f, TranslatableComponent("otm.gui.android_research"))
@Override
protected void innerRender(PoseStack stack, float mouse_x, float mouse_y, float flag) { canvas = object : DraggableCanvasPanel(this@AndroidStationScreen, research, width = (GRID_WIDTH * 22).toFloat(), height = 0f) {
RenderHelper.setDrawColor(RGBAColor.BLACK); override fun innerRender(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float) {
RenderHelper.drawRect(stack, 0, 0, width, height); RenderHelper.setDrawColor(RGBAColor.BLACK)
RenderHelper.drawRect(stack, 0f, 0f, width, height)
}
} }
};
minecraft.player.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> { minecraft?.player?.getCapability(MatteryCapability.ANDROID)?.ifPresent {
if (_cap instanceof AndroidCapabilityPlayer cap) { if (it !is AndroidCapabilityPlayer)
Arrays.fill(rows, null); return@ifPresent
next_x = 0;
for (var research : Registry.ANDROID_RESEARCH.getValues()) { Arrays.fill(rows, null)
if (research.getPrerequisites().size() == 0) { nextX = 0f
dive(cap, research, 0);
float max = 0;
for (float v : rows_width) for (research in Registry.ANDROID_RESEARCH.values) {
max = Math.max(max, v); if (research.prerequisites.size == 0) {
dive(it, research, 0)
for (var button_list : created_buttons) { var max = 0f
int count = 0;
for (int i = 0; i < button_list.length; i++) { for (v in rowsWidth)
max = Math.max(max, v)
for (button_list in createdButtons) {
var count = 0
for (i in button_list.indices) {
if (button_list[i] == null) { if (button_list[i] == null) {
count = i; count = i
break; break
} }
} }
if (count > 0) { if (count > 0) {
float this_x = next_x + max / 2f - (count * 22f) / 2f; var thisX = nextX + max / 2f - count * 22f / 2f
for (int i = 0; i < count; i++) { for (i in 0 until count) {
button_list[i].setPos(this_x, 2); button_list[i]!!.setPos(thisX, 2f)
this_x += 22; thisX += 22f
} }
} }
} }
for (var v : created_buttons) for (v in createdButtons)
Arrays.fill(v, null); Arrays.fill(v, null)
next_x += max; nextX += max
Arrays.fill(rows_width, 0); Arrays.fill(rowsWidth, 0f)
Arrays.fill(created_buttons_idx, 0); Arrays.fill(createdButtonsIdx, 0)
} }
} }
seen.clear(); seen.clear()
}
});
canvas.setDock(Dock.FILL);
var bottom = new EditablePanel(this, research, 0, 0, 0, 20);
var close = new ButtonPanel(this, bottom, 0, 0, 90, 20, new TranslatableComponent("otm.container.matter_panel.close"));
bottom.setDock(Dock.BOTTOM);
close.setDock(Dock.RIGHT);
close.bindOnPress(research::remove);
bottom.setDockMargin(0, 0, 4, 4);
canvas.setDockMargin(4, 4, 4, 4);
research.toScreenCenter();
addPanel(research);
} }
@Override canvas!!.dock = Dock.FILL
public void resize(Minecraft minecraft, int p_96576_, int p_96577_) {
super.resize(minecraft, p_96576_, p_96577_); val bottom = EditablePanel(this, research, 0f, 0f, 0f, 20f)
val close = ButtonPanel(this, bottom, 0f, 0f, 90f, 20f, TranslatableComponent("otm.container.matter_panel.close"))
bottom.dock = Dock.BOTTOM
close.dock = Dock.LEFT
close.bindOnPress { research!!.remove() }
bottom.setDockMargin(0f, 0f, 4f, 4f)
canvas!!.setDockMargin(4f, 4f, 4f, 4f)
research!!.toScreenCenter()
addPanel(research!!)
}
override fun resize(minecraft: Minecraft, p_96576_: Int, p_96577_: Int) {
super.resize(minecraft, p_96576_, p_96577_)
val research = research
if (research != null) { if (research != null) {
var window = minecraft.getWindow(); val window = minecraft.window
research.setSize(window.getGuiScaledWidth() * 0.8f, window.getGuiScaledHeight() * 0.8f); research.setSize(window.guiScaledWidth * 0.8f, window.guiScaledHeight * 0.8f)
research.toScreenCenter(); research.toScreenCenter()
} }
} }
@Nullable override fun makeMainFrame(): FramePanel {
@Override val frame = super.makeMainFrame()!!
protected FramePanel makeMainFrame() {
var frame = new FramePanel(this, null, 0, 0, FRAME_WIDTH, FRAME_HEIGHT, getTitle());
var button = new ButtonPanel(this, frame, 0, 0, 90, 20, new TranslatableComponent("otm.gui.android_research")); PowerGaugePanel(this, frame, menu.battery_widget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
button.setDock(Dock.BOTTOM); SlotPanel(this, frame, menu.battery_slot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE)
button.bindOnPress(this::openResearchTree); SlotPanel(this, frame, menu.androidBattery, 38f, 17f)
button.setDockMargin(10, 0, 10, 0);
return frame; val button = ButtonPanel(this, frame, 38f, 69f, 124f, 20f, TranslatableComponent("otm.gui.android_research"))
button.bindOnPress(this::openResearchTree)
return frame
}
companion object {
const val GRID_WIDTH = 5
const val BUTTON_SIZE = 18
val RESEARCHED = RGBAColor(150, 150, 200)
val CAN_BE_RESEARCHED = RGBAColor(150, 200, 150)
val CAN_NOT_BE_RESEARCHED = RGBAColor(200, 150, 150)
} }
} }

View File

@ -5,16 +5,13 @@ import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.client.screen.panels.*; import ru.dbotthepony.mc.otm.client.screen.panels.*;
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel;
import ru.dbotthepony.mc.otm.item.ItemPortableCondensationDrive; import ru.dbotthepony.mc.otm.item.ItemPortableCondensationDrive;
import ru.dbotthepony.mc.otm.menu.DriveViewerMenu; import ru.dbotthepony.mc.otm.menu.DriveViewerMenu;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
import ru.dbotthepony.mc.otm.network.MatteryNetworking; import ru.dbotthepony.mc.otm.network.MatteryNetworking;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> { public class DriveViewerScreen extends MatteryScreen<DriveViewerMenu> {
public static final int FRAME_WIDTH = 210; public static final int FRAME_WIDTH = 210;

View File

@ -4,13 +4,10 @@ import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.client.screen.panels.*; import ru.dbotthepony.mc.otm.client.screen.panels.*;
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel;
import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu; import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
public class ItemMonitorScreen extends MatteryScreen<ItemMonitorMenu> { public class ItemMonitorScreen extends MatteryScreen<ItemMonitorMenu> {
public static final int FRAME_WIDTH = 210; public static final int FRAME_WIDTH = 210;

View File

@ -9,7 +9,6 @@ import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font; import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Widget; import net.minecraft.client.gui.components.Widget;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.renderer.entity.ItemRenderer;
@ -22,14 +21,13 @@ import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.event.ContainerScreenEvent; import net.minecraftforge.client.event.ContainerScreenEvent;
import ru.dbotthepony.mc.otm.menu.MatteryMenu; import ru.dbotthepony.mc.otm.menu.MatteryMenu;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot; import ru.dbotthepony.mc.otm.menu.MatterySlot;
import ru.dbotthepony.mc.otm.client.screen.panels.*; import ru.dbotthepony.mc.otm.client.screen.panels.*;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import static org.lwjgl.opengl.GL11.GL_ALWAYS; import static org.lwjgl.opengl.GL11.GL_ALWAYS;

View File

@ -6,7 +6,7 @@ import net.minecraft.ChatFormatting;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot; import ru.dbotthepony.mc.otm.menu.MatterySlot;
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen; import ru.dbotthepony.mc.otm.client.screen.MatteryScreen;
import ru.dbotthepony.mc.otm.client.render.RenderHelper; import ru.dbotthepony.mc.otm.client.render.RenderHelper;

View File

@ -3,19 +3,11 @@ package ru.dbotthepony.mc.otm.menu;
import net.minecraft.world.Container; import net.minecraft.world.Container;
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.MenuType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional;
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityBatteryBank; import ru.dbotthepony.mc.otm.block.entity.BlockEntityBatteryBank;
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage;
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.data.BigDecimalDataContainer;
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot;
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget; import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget;
import javax.annotation.Nullable;
public class BatteryBankMenu extends MatteryMenu { public class BatteryBankMenu extends MatteryMenu {
protected BlockEntityBatteryBank tile; protected BlockEntityBatteryBank tile;

View File

@ -5,7 +5,6 @@ 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.Registry; import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate; import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
public class CargoCrateMenu extends MatteryMenu { public class CargoCrateMenu extends MatteryMenu {
public CargoCrateMenu(int p_38852_, Inventory inventory) { public CargoCrateMenu(int p_38852_, Inventory inventory) {

View File

@ -2,15 +2,10 @@ 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.MenuType;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveRack; import ru.dbotthepony.mc.otm.block.entity.BlockEntityDriveRack;
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
import javax.annotation.Nullable;
public class DriveRackMenu extends PoweredMatteryMenu { public class DriveRackMenu extends PoweredMatteryMenu {
public DriveRackMenu(int p_38852_, Inventory inventory) { public DriveRackMenu(int p_38852_, Inventory inventory) {

View File

@ -14,7 +14,6 @@ import ru.dbotthepony.mc.otm.capability.drive.IMatteryDrive;
import ru.dbotthepony.mc.otm.item.ItemPortableCondensationDrive; import ru.dbotthepony.mc.otm.item.ItemPortableCondensationDrive;
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.menu.slot.MatterySlot;
import ru.dbotthepony.mc.otm.storage.ItemStackWrapper; import ru.dbotthepony.mc.otm.storage.ItemStackWrapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View File

@ -8,8 +8,6 @@ import ru.dbotthepony.mc.otm.matter.MatterRegistry;
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer; import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer;
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
import ru.dbotthepony.mc.otm.menu.slot.MachineOutputSlot;
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;
@ -40,7 +38,7 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
addSlot(input); addSlot(input);
// Выход // Выход
output = new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36, true); output = new MachineOutputSlot(container, 1, 61 + 18 + 10 + 3 + 22, 36);
addSlot(output); addSlot(output);
if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) { if (tile == null || tile.getCapability(MatteryCapability.MATTER).resolve().isEmpty()) {

View File

@ -5,7 +5,6 @@ import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterReplicator; import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterReplicator;
import ru.dbotthepony.mc.otm.menu.slot.MachineOutputSlot;
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;
@ -24,7 +23,7 @@ public class MatterReplicatorMenu extends PoweredMatteryMenu {
Container container = tile != null ? tile.regularSlots : new SimpleContainer(3); Container container = tile != null ? tile.regularSlots : new SimpleContainer(3);
for (int i = 0; i < container.getContainerSize(); i++) { for (int i = 0; i < container.getContainerSize(); i++) {
output_slots[i] = new MachineOutputSlot(container, i, 64 + 18 * i, 38, true); output_slots[i] = new MachineOutputSlot(container, i, 64 + 18 * i, 38);
addSlot(output_slots[i]); addSlot(output_slots[i]);
} }

View File

@ -6,7 +6,6 @@ import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.MenuType;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered; import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered;
import ru.dbotthepony.mc.otm.capability.MatteryCapability; import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot;
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget; import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -43,7 +42,7 @@ abstract public class PoweredMatteryMenu extends MatteryMenu {
protected void addBatterySlot(int x, int y) { protected void addBatterySlot(int x, int y) {
Container battery_container = tile != null ? tile.battery_container : new SimpleContainer(1); Container battery_container = tile != null ? tile.battery_container : new SimpleContainer(1);
battery_slot = new BatterySlot(battery_container, 0, x, y, true); battery_slot = new BatterySlot(battery_container, 0, x, y);
addSlot(battery_slot); addSlot(battery_slot);
} }
} }

View File

@ -1,31 +0,0 @@
package ru.dbotthepony.mc.otm.menu.slot;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import java.util.Optional;
public class BatterySlot extends MatterySlot {
public boolean auto_bg;
public BatterySlot(Container container, int index, int x, int y, boolean auto_bg) {
super(container, index, x, y);
this.auto_bg = auto_bg;
}
public BatterySlot(Container container, int index, int x, int y) {
this(container, index, x, y, true);
}
@Override
public boolean mayPlace(ItemStack stack) {
LazyOptional<IEnergyStorage> capability = stack.getCapability(CapabilityEnergy.ENERGY);
return capability.resolve().isPresent() && capability.resolve().get().canExtract();
}
}

View File

@ -1,23 +0,0 @@
package ru.dbotthepony.mc.otm.menu.slot;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
public class MachineOutputSlot extends MatterySlot {
public boolean auto_bg;
public MachineOutputSlot(Container p_40223_, int index, int x, int y, boolean auto_bg) {
super(p_40223_, index, x, y);
this.auto_bg = auto_bg;
}
public MachineOutputSlot(Container p_40223_, int index, int x, int y) {
this(p_40223_, index, x, y, true);
}
@Override
public boolean mayPlace(ItemStack p_40231_) {
return false;
}
}

View File

@ -1,31 +0,0 @@
package ru.dbotthepony.mc.otm.menu.slot;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import java.util.Optional;
public class MatterContainerInputSlot extends MatterySlot {
public boolean auto_bg;
public IMatterHandler.MatterDirection desired_direction;
public MatterContainerInputSlot(Container p_40223_, int p_40224_, int p_40225_, int p_40226_, boolean auto_bg, IMatterHandler.MatterDirection desired_direction) {
super(p_40223_, p_40224_, p_40225_, p_40226_);
this.auto_bg = auto_bg;
this.desired_direction = desired_direction;
}
@Override
public boolean mayPlace(ItemStack p_40231_) {
Optional<IMatterHandler> handler = p_40231_.getCapability(MatteryCapability.MATTER).resolve();
if (handler.isEmpty())
return false;
IMatterHandler.MatterDirection direction = handler.get().getDirection();
return direction == IMatterHandler.MatterDirection.BIDIRECTIONAL || desired_direction == direction;
}
}

View File

@ -1,33 +0,0 @@
package ru.dbotthepony.mc.otm.menu.slot;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.container.MatteryContainer;
// Just a sign that this slot needs auto draw
// or belongs to MatteryContainer
// or needs a fkin x y changed
public class MatterySlot extends Slot {
public boolean auto_bg;
public int x;
public int y;
public MatterySlot(Container p_40223_, int index, int x, int y, boolean auto_bg) {
super(p_40223_, index, x, y);
this.x = x;
this.y = y;
this.auto_bg = auto_bg;
}
public MatterySlot(Container p_40223_, int index, int x, int y) {
this(p_40223_, index, x, y, true);
}
public MatterySlot(Container p_40223_, int index) {
this(p_40223_, index, 0, 0, true);
}
}

View File

@ -1,20 +0,0 @@
package ru.dbotthepony.mc.otm.menu.slot;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
public class PatternSlot extends MatterySlot {
public PatternSlot(Container p_40223_, int index, int x, int y, boolean auto_bg) {
super(p_40223_, index, x, y, auto_bg);
}
public PatternSlot(Container p_40223_, int index, int x, int y) {
super(p_40223_, index, x, y);
}
@Override
public boolean mayPlace(ItemStack p_40231_) {
return p_40231_.getCapability(MatteryCapability.PATTERN).isPresent();
}
}

View File

@ -3,25 +3,23 @@ package ru.dbotthepony.mc.otm.client.screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.menu.MatterCapacitorBankMenu import ru.dbotthepony.mc.otm.menu.MatterCapacitorBankMenu
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
class MatterCapacitorBankScreen(p_97741_: MatterCapacitorBankMenu, p_97742_: Inventory, p_97743_: Component) : class MatterCapacitorBankScreen(p_97741_: MatterCapacitorBankMenu, p_97742_: Inventory, p_97743_: Component) :
MatteryScreen<MatterCapacitorBankMenu>(p_97741_, p_97742_, p_97743_) { MatteryScreen<MatterCapacitorBankMenu>(p_97741_, p_97742_, p_97743_) {
override fun makeMainFrame(): FramePanel { override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!! val frame = super.makeMainFrame()!!
val m = MatterGaugePanel(this, frame, menu.matter_widget, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT) val m = MatterGaugePanel(this, frame, menu.matterGauge, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
MatterGaugePanel(this, frame, menu.matter_widget, 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.container_slots[i], 44f + 18 * i, 32f) SlotPanel(this, frame, menu.workSlots[i], 44f + 18 * i, 32f)
for (i in 6 .. 11) for (i in 6 .. 11)
SlotPanel(this, frame, menu.container_slots[i], 44f + 18 * (i - 6), 32f + 18f) SlotPanel(this, frame, menu.workSlots[i], 44f + 18 * (i - 6), 32f + 18f)
return frame return frame
} }

View File

@ -3,13 +3,11 @@ package ru.dbotthepony.mc.otm.client.screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot
class MatterDecomposerScreen(p_97741_: MatterDecomposerMenu, p_97742_: Inventory, p_97743_: Component) : class MatterDecomposerScreen(p_97741_: MatterDecomposerMenu, p_97742_: Inventory, p_97743_: Component) :
MatteryScreen<MatterDecomposerMenu>(p_97741_, p_97742_, p_97743_) { MatteryScreen<MatterDecomposerMenu>(p_97741_, p_97742_, p_97743_) {

View File

@ -1,83 +1,52 @@
package ru.dbotthepony.mc.otm.menu; 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.item.ItemStack; import net.minecraft.world.item.ItemStack
import net.minecraftforge.common.util.LazyOptional; import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.Registry; import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation; import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability; import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot;
import javax.annotation.Nullable; private class AndroidStationContainer(val player: Player) : SimpleContainer(1) {
var android: IAndroidCapability? = null
public class AndroidStationMenu extends PoweredMatteryMenu { init {
public static class AndroidStationContainer extends SimpleContainer { player.getCapability(MatteryCapability.ANDROID).ifPresent {
public final Player player; android = it
private final IAndroidCapability android; setItem(0, it.batteryItemStack)
}
public AndroidStationContainer(Player ply) {
super(1);
player = ply;
LazyOptional<IAndroidCapability> capability = ply.getCapability(MatteryCapability.ANDROID);
android = capability.isPresent() ? capability.resolve().get() : null;
capability.ifPresent(cap -> {
setItem(0, cap.getBatteryItemStack());
});
} }
} }
public static class AndroidBatterySlot extends BatterySlot { private class AndroidBatterySlot(container: AndroidStationContainer, index: Int) : BatterySlot(container, index) {
private final IAndroidCapability android; val android: IAndroidCapability? = container.android
public AndroidBatterySlot(AndroidStationContainer container, int index, int x, int y) { override fun set(stack: ItemStack) {
super(container, index, x, y, false); super.set(stack)
android = container.android; android?.batteryItemStack = stack
}
@Override
public void set(ItemStack stack) {
super.set(stack);
android.setBatteryItemStack(stack);
} }
} }
// Clientside class AndroidStationMenu @JvmOverloads constructor(
public AndroidStationMenu(int containerID, Inventory inventory) { containerID: Int,
this(containerID, inventory,null); inventory: Inventory,
tile: BlockEntityAndroidStation? = null
) : PoweredMatteryMenu(Registry.Menus.ANDROID_STATION, containerID, inventory, tile) {
val androidBattery: MatterySlot = AndroidBatterySlot(AndroidStationContainer(inventory.player), 0)
init {
addSlot(androidBattery)
addBatterySlot()
addInventorySlots()
} }
private final int battery_slot_index; override fun getWorkingSlotStart(): Int {
return androidBattery.index
// Serverside
public AndroidStationMenu(
int containerID,
Inventory inventory,
@Nullable BlockEntityAndroidStation tile
) {
super(
Registry.Menus.ANDROID_STATION,
containerID,
inventory,
tile);
battery_slot_index = addMainSlot(new AndroidBatterySlot(new AndroidStationContainer(inventory.player), 0, 39, 15)).index;
addBatterySlot();
addInventorySlots();
} }
@Override override fun getWorkingSlotEnd(): Int {
protected int getWorkingSlotStart() { return androidBattery.index + 1
return battery_slot_index;
}
@Override
protected int getWorkingSlotEnd() {
return battery_slot_index + 1;
} }
} }

View File

@ -8,7 +8,6 @@ import net.minecraftforge.energy.CapabilityEnergy
import ru.dbotthepony.mc.otm.Registry import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityChemicalGenerator import ru.dbotthepony.mc.otm.block.entity.BlockEntityChemicalGenerator
import ru.dbotthepony.mc.otm.menu.data.IntDataContainer import ru.dbotthepony.mc.otm.menu.data.IntDataContainer
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot
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

View File

@ -8,7 +8,6 @@ import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterBottler
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
import ru.dbotthepony.mc.otm.menu.data.BooleanDataContainer import ru.dbotthepony.mc.otm.menu.data.BooleanDataContainer
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot
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 ru.dbotthepony.mc.otm.network.MatterBottlerSwitchPacket import ru.dbotthepony.mc.otm.network.MatterBottlerSwitchPacket

View File

@ -4,30 +4,28 @@ import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.Registry import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCapacitorBank import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCapacitorBank
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
import ru.dbotthepony.mc.otm.core.Fraction import ru.dbotthepony.mc.otm.core.Fraction
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
import ru.dbotthepony.mc.otm.menu.slot.MatterContainerInputSlot
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
class MatterCapacitorBankMenu @JvmOverloads constructor( class MatterCapacitorBankMenu @JvmOverloads constructor(
p_38852_: Int, p_38852_: Int,
inventory: Inventory?, inventory: Inventory,
tile: BlockEntityMatterCapacitorBank? = null tile: BlockEntityMatterCapacitorBank? = null
) : MatteryMenu( ) : MatteryMenu(
Registry.Menus.MATTER_CAPACITOR_BANK, p_38852_, inventory!!, tile Registry.Menus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile
) { ) {
val matter_widget: LevelGaugeWidget val matterGauge: LevelGaugeWidget
val total_matter_widget: LevelGaugeWidget val totalMatterGauge: LevelGaugeWidget
val container_slots = arrayOfNulls<MatterContainerInputSlot>(2 * 6) val workSlots = arrayOfNulls<MatterContainerInputSlot>(2 * 6)
init { init {
if (tile == null) { if (tile == null) {
matter_widget = LevelGaugeWidget(this) matterGauge = LevelGaugeWidget(this)
total_matter_widget = LevelGaugeWidget(this) totalMatterGauge = LevelGaugeWidget(this)
} else { } else {
matter_widget = LevelGaugeWidget(this, tile) matterGauge = LevelGaugeWidget(this, tile)
total_matter_widget = LevelGaugeWidget(this, { totalMatterGauge = LevelGaugeWidget(this, {
(tile.getAsMatterNode().graph as MatterNetworkGraph?)?.getMatterStorageLevel() ?: Fraction.ZERO (tile.getAsMatterNode().graph as MatterNetworkGraph?)?.getMatterStorageLevel() ?: Fraction.ZERO
}, { }, {
(tile.getAsMatterNode().graph as MatterNetworkGraph?)?.getMatterStorageMaxLevel() ?: Fraction.ZERO (tile.getAsMatterNode().graph as MatterNetworkGraph?)?.getMatterStorageMaxLevel() ?: Fraction.ZERO
@ -38,18 +36,12 @@ class MatterCapacitorBankMenu @JvmOverloads constructor(
for (row in 0..1) { for (row in 0..1) {
for (column in 0..5) { for (column in 0..5) {
container_slots[row * 6 + column] = MatterContainerInputSlot( val slot = MatterContainerInputSlot(container, row * 6 + column)
container, workSlots[row * 6 + column] = slot
row * 6 + column, addSlot(slot)
44 + column * 18, }
20 + row * 18, }
true,
IMatterHandler.MatterDirection.BIDIRECTIONAL
)
addSlot(container_slots[row * 6 + column]!!)
}
}
addInventorySlots() addInventorySlots()
} }

View File

@ -3,15 +3,12 @@ package ru.dbotthepony.mc.otm.menu
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.BlockEntityMatterScanner import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterScanner
import ru.dbotthepony.mc.otm.menu.PoweredMatteryMenu
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot
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.item.ItemStack import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.Registry import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.core.Fraction import ru.dbotthepony.mc.otm.core.Fraction
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
import ru.dbotthepony.mc.otm.matter.MatterRegistry import ru.dbotthepony.mc.otm.matter.MatterRegistry
import java.math.BigInteger import java.math.BigInteger

View File

@ -5,7 +5,6 @@ import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.* import net.minecraft.world.inventory.*
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.entity.BlockEntity
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot
import ru.dbotthepony.mc.otm.menu.widget.AbstractWidget import ru.dbotthepony.mc.otm.menu.widget.AbstractWidget
import java.util.function.Consumer import java.util.function.Consumer

View File

@ -6,7 +6,6 @@ import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityPatternStorage import ru.dbotthepony.mc.otm.block.entity.BlockEntityPatternStorage
import ru.dbotthepony.mc.otm.core.Fraction import ru.dbotthepony.mc.otm.core.Fraction
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
import ru.dbotthepony.mc.otm.menu.slot.PatternSlot
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
class PatternStorageMenu @JvmOverloads constructor( class PatternStorageMenu @JvmOverloads constructor(

View File

@ -0,0 +1,44 @@
package ru.dbotthepony.mc.otm.menu
import net.minecraft.world.Container
import net.minecraft.world.inventory.Slot
import net.minecraft.world.item.ItemStack
import net.minecraftforge.energy.CapabilityEnergy
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.matter.IMatterHandler
open class MatterySlot @JvmOverloads constructor(p_40223_: Container, index: Int, x: Int = 0, y: Int = 0) : Slot(p_40223_, index, x, y)
open class MachineOutputSlot @JvmOverloads constructor(p_40223_: Container, index: Int, x: Int = 0, y: Int = 0) : MatterySlot(p_40223_, index, x, y) {
override fun mayPlace(p_40231_: ItemStack): Boolean {
return false
}
}
open class BatterySlot @JvmOverloads constructor(container: Container, index: Int, x: Int = 0, y: Int = 0) : MatterySlot(container, index, x, y) {
override fun mayPlace(stack: ItemStack): Boolean {
val capability = stack.getCapability(CapabilityEnergy.ENERGY)
return capability.resolve().isPresent && capability.resolve().get().canExtract()
}
}
open class MatterContainerInputSlot @JvmOverloads constructor(
p_40223_: Container,
index: Int,
x: Int = 0,
y: Int = 0,
val direction: IMatterHandler.MatterDirection = IMatterHandler.MatterDirection.BIDIRECTIONAL
) : MatterySlot(p_40223_, index, x, y) {
override fun mayPlace(p_40231_: ItemStack): Boolean {
val handler = p_40231_.getCapability(MatteryCapability.MATTER).resolve()
if (handler.isEmpty) return false
val direction = handler.get().direction
return direction == IMatterHandler.MatterDirection.BIDIRECTIONAL || this.direction == direction
}
}
open class PatternSlot(p_40223_: Container, index: Int, x: Int = 0, y: Int = 0) : MatterySlot(p_40223_, index, x, y) {
override fun mayPlace(p_40231_: ItemStack): Boolean {
return p_40231_.getCapability(MatteryCapability.PATTERN).isPresent
}
}

View File

@ -20,7 +20,7 @@
"otm.gui.matter.format": "Matter: %s", "otm.gui.matter.format": "Matter: %s",
"otm.gui.matter.name": "MtU", "otm.gui.matter.name": "MtU",
"otm.gui.android_research": "Android research tree", "otm.gui.android_research": "Research Tree",
"otm.gui.pattern.percentage_level": "Fill level: %s%%", "otm.gui.pattern.percentage_level": "Fill level: %s%%",
"otm.gui.pattern.format": "Stored patterns: %s / %s", "otm.gui.pattern.format": "Stored patterns: %s / %s",