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

View File

@ -9,7 +9,6 @@ import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
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.screens.inventory.AbstractContainerScreen;
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.minecraftforge.client.event.ContainerScreenEvent;
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 javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
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.world.inventory.AbstractContainerMenu;
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.render.RenderHelper;

View File

@ -3,19 +3,11 @@ package ru.dbotthepony.mc.otm.menu;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
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.block.entity.BlockEntityBatteryBank;
import ru.dbotthepony.mc.otm.capability.IMatteryEnergyStorage;
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 javax.annotation.Nullable;
public class BatteryBankMenu extends MatteryMenu {
protected BlockEntityBatteryBank tile;

View File

@ -5,7 +5,6 @@ import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityCargoCrate;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
public class CargoCrateMenu extends MatteryMenu {
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.entity.player.Inventory;
import net.minecraft.world.inventory.MenuType;
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.block.entity.BlockEntityDriveRack;
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 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.menu.data.INetworkedItemViewSupplier;
import ru.dbotthepony.mc.otm.menu.data.NetworkedItemView;
import ru.dbotthepony.mc.otm.menu.slot.MatterySlot;
import ru.dbotthepony.mc.otm.storage.ItemStackWrapper;
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.block.entity.BlockEntityMatterDecomposer;
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.ProgressGaugeWidget;
@ -40,7 +38,7 @@ public class MatterDecomposerMenu extends PoweredMatteryMenu {
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);
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 ru.dbotthepony.mc.otm.Registry;
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.ProgressGaugeWidget;
@ -24,7 +23,7 @@ public class MatterReplicatorMenu extends PoweredMatteryMenu {
Container container = tile != null ? tile.regularSlots : new SimpleContainer(3);
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]);
}

View File

@ -6,7 +6,6 @@ import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.MenuType;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPowered;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot;
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget;
import javax.annotation.Nullable;
@ -43,7 +42,7 @@ abstract public class PoweredMatteryMenu extends MatteryMenu {
protected void addBatterySlot(int x, int y) {
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);
}
}

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 ru.dbotthepony.mc.otm.menu.MatterCapacitorBankMenu
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.SlotPanel
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) :
MatteryScreen<MatterCapacitorBankMenu>(p_97741_, p_97742_, p_97743_) {
override fun makeMainFrame(): FramePanel {
val frame = super.makeMainFrame()!!
val m = MatterGaugePanel(this, frame, menu.matter_widget, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
MatterGaugePanel(this, frame, menu.matter_widget, LEFT_MARGIN + m.width, GAUGE_TOP_WITHOUT_SLOT)
val m = MatterGaugePanel(this, frame, menu.matterGauge, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
MatterGaugePanel(this, frame, menu.matterGauge, LEFT_MARGIN + m.width, GAUGE_TOP_WITHOUT_SLOT)
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)
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
}

View File

@ -3,13 +3,11 @@ package ru.dbotthepony.mc.otm.client.screen
import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.menu.MatterDecomposerMenu
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.SlotPanel
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.ProgressGaugePanel
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot
class MatterDecomposerScreen(p_97741_: MatterDecomposerMenu, p_97742_: Inventory, p_97743_: Component) :
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.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import ru.dbotthepony.mc.otm.Registry;
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation;
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.menu.slot.BatterySlot;
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation
import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability
import javax.annotation.Nullable;
private class AndroidStationContainer(val player: Player) : SimpleContainer(1) {
var android: IAndroidCapability? = null
public class AndroidStationMenu extends PoweredMatteryMenu {
public static class AndroidStationContainer extends SimpleContainer {
public final Player player;
private final IAndroidCapability android;
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());
});
init {
player.getCapability(MatteryCapability.ANDROID).ifPresent {
android = it
setItem(0, it.batteryItemStack)
}
}
}
public static class AndroidBatterySlot extends BatterySlot {
private final IAndroidCapability android;
private class AndroidBatterySlot(container: AndroidStationContainer, index: Int) : BatterySlot(container, index) {
val android: IAndroidCapability? = container.android
public AndroidBatterySlot(AndroidStationContainer container, int index, int x, int y) {
super(container, index, x, y, false);
android = container.android;
}
@Override
public void set(ItemStack stack) {
super.set(stack);
android.setBatteryItemStack(stack);
override fun set(stack: ItemStack) {
super.set(stack)
android?.batteryItemStack = stack
}
}
// Clientside
public AndroidStationMenu(int containerID, Inventory inventory) {
this(containerID, inventory,null);
class AndroidStationMenu @JvmOverloads constructor(
containerID: Int,
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;
// 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 fun getWorkingSlotStart(): Int {
return androidBattery.index
}
@Override
protected int getWorkingSlotStart() {
return battery_slot_index;
}
@Override
protected int getWorkingSlotEnd() {
return battery_slot_index + 1;
override fun getWorkingSlotEnd(): Int {
return androidBattery.index + 1
}
}

View File

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

View File

@ -3,15 +3,12 @@ package ru.dbotthepony.mc.otm.menu
import kotlin.jvm.JvmOverloads
import net.minecraft.world.entity.player.Inventory
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.LevelGaugeWidget
import net.minecraft.world.SimpleContainer
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.Registry
import ru.dbotthepony.mc.otm.core.Fraction
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
import ru.dbotthepony.mc.otm.matter.MatterRegistry
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.item.ItemStack
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 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.core.Fraction
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
import ru.dbotthepony.mc.otm.menu.slot.PatternSlot
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
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.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.format": "Stored patterns: %s / %s",