Pattern fillage gauge
This commit is contained in:
parent
eaa8c11b58
commit
95a96c35ca
@ -182,16 +182,24 @@ public class BlockEntityPatternStorage extends BlockEntityMattery implements IMa
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
AtomicInteger stored = new AtomicInteger();
|
||||
patterns.consumeCapability(MatteryCapability.PATTERN, capability -> stored.getAndAdd(capability.getCapacity()));
|
||||
return stored.get();
|
||||
long stored = 0;
|
||||
|
||||
for (var pattern : patterns.capabilityIterator(MatteryCapability.PATTERN)) {
|
||||
stored += pattern.getCapacity();
|
||||
}
|
||||
|
||||
return stored > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) stored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
AtomicInteger stored = new AtomicInteger();
|
||||
patterns.consumeCapability(MatteryCapability.PATTERN, capability -> stored.getAndAdd(capability.getStored()));
|
||||
return stored.get();
|
||||
long stored = 0;
|
||||
|
||||
for (var pattern : patterns.capabilityIterator(MatteryCapability.PATTERN)) {
|
||||
stored += pattern.getStored();
|
||||
}
|
||||
|
||||
return stored > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) stored;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -260,6 +260,38 @@ public class MatterGrid implements IMatterGridListener {
|
||||
return ImmutableList.copyOf(list);
|
||||
}
|
||||
|
||||
public long getStoredPatternCount() {
|
||||
validate();
|
||||
|
||||
long value = 0;
|
||||
|
||||
for (IMatterGridCell cell : cells) {
|
||||
IPatternStorage storage = cell.getPatternStorage();
|
||||
|
||||
if (storage != null) {
|
||||
value += storage.getStored();
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public long getPatternCapacity() {
|
||||
validate();
|
||||
|
||||
long value = 0;
|
||||
|
||||
for (IMatterGridCell cell : cells) {
|
||||
IPatternStorage storage = cell.getPatternStorage();
|
||||
|
||||
if (storage != null) {
|
||||
value += storage.getCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public Collection<PatternState> findPatterns(Item item) {
|
||||
return findPatterns((patternState -> item == patternState.item()));
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Inventory;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityPatternStorage;
|
||||
import ru.dbotthepony.mc.otm.menu.slot.PatternSlot;
|
||||
import ru.dbotthepony.mc.otm.menu.widget.PatternStorageWidget;
|
||||
|
||||
public class PatternStorageMenu extends MatteryMenu {
|
||||
public PatternStorageMenu(int p_38852_, Inventory inventory) {
|
||||
@ -14,9 +15,32 @@ public class PatternStorageMenu extends MatteryMenu {
|
||||
|
||||
public PatternSlot[] pattern_slots = new PatternSlot[2 * 4];
|
||||
|
||||
public PatternStorageWidget stored_this;
|
||||
public PatternStorageWidget stored_grid;
|
||||
|
||||
public PatternStorageMenu(int p_38852_, Inventory inventory, BlockEntityPatternStorage tile) {
|
||||
super(Registry.Menus.PATTERN_STORAGE, p_38852_, inventory, tile);
|
||||
|
||||
if (tile == null) {
|
||||
stored_this = new PatternStorageWidget(this);
|
||||
stored_grid = new PatternStorageWidget(this);
|
||||
} else {
|
||||
stored_this = new PatternStorageWidget(this, tile.getPatternStorage());
|
||||
stored_grid = new PatternStorageWidget(this, () -> {
|
||||
if (tile.getMatterGrid() != null) {
|
||||
return tile.getMatterGrid().getStoredPatternCount();
|
||||
}
|
||||
|
||||
return 0L;
|
||||
}, () -> {
|
||||
if (tile.getMatterGrid() != null) {
|
||||
return tile.getMatterGrid().getPatternCapacity();
|
||||
}
|
||||
|
||||
return 0L;
|
||||
});
|
||||
}
|
||||
|
||||
Container patterns = tile != null ? tile.patterns : new SimpleContainer(2 * 4);
|
||||
|
||||
for (int row = 0; row < 2; row++) {
|
||||
|
@ -0,0 +1,65 @@
|
||||
package ru.dbotthepony.mc.otm.menu.data;
|
||||
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class LongDataContainer implements ContainerData {
|
||||
public static final int NETWORK_PAYLOAD_SIZE = 4;
|
||||
|
||||
private Long value;
|
||||
private final int[] buffer = new int[NETWORK_PAYLOAD_SIZE];
|
||||
|
||||
public Long getValue() {
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
long a = buffer[0];
|
||||
long b = buffer[1];
|
||||
long c = buffer[2];
|
||||
long d = buffer[3];
|
||||
|
||||
return value = a | b << 16 | c << 32 | d << 48;
|
||||
}
|
||||
|
||||
public void setValue(long value) {
|
||||
if (this.value != null && value == this.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.value = value;
|
||||
buffer[0] = (int) ((value) & 0xFFFF);
|
||||
buffer[1] = (int) ((value >>> 16) & 0xFFFF);
|
||||
buffer[2] = (int) ((value >>> 32) & 0xFFFF);
|
||||
buffer[3] = (int) ((value >>> 48) & 0xFFFF);
|
||||
}
|
||||
|
||||
// override
|
||||
protected void updateValue() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(int index) {
|
||||
updateValue();
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int index, int _value) {
|
||||
if (buffer[index] == _value)
|
||||
return;
|
||||
|
||||
value = null;
|
||||
buffer[index] = _value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NETWORK_PAYLOAD_SIZE;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package ru.dbotthepony.mc.otm.menu.widget;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
||||
import ru.dbotthepony.mc.otm.capability.IPatternStorage;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.menu.FormattingHelper;
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu;
|
||||
import ru.dbotthepony.mc.otm.menu.data.BigDecimalDataContainer;
|
||||
import ru.dbotthepony.mc.otm.menu.data.LongDataContainer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PatternStorageWidget extends GaugeWidget {
|
||||
public Supplier<Long> value_supplier;
|
||||
public Supplier<Long> max_value_supplier;
|
||||
|
||||
protected final LongDataContainer value_container = new LongDataContainer();
|
||||
protected final LongDataContainer max_value_container = new LongDataContainer();
|
||||
|
||||
public PatternStorageWidget(MatteryMenu menu, int x, int y, IPatternStorage capability) {
|
||||
this(menu, x, y, () -> (long) capability.getStored(), () -> (long) capability.getCapacity());
|
||||
}
|
||||
|
||||
public PatternStorageWidget(MatteryMenu menu, IPatternStorage capability) {
|
||||
this(menu, 0, 0, () -> (long) capability.getStored(), () -> (long) capability.getCapacity());
|
||||
}
|
||||
|
||||
public PatternStorageWidget(MatteryMenu menu) {
|
||||
this(menu, 0, 0, null, null);
|
||||
}
|
||||
|
||||
public PatternStorageWidget(MatteryMenu menu, int x, int y, Supplier<Long> value_supplier, Supplier<Long> max_value_supplier) {
|
||||
super(menu, x, y);
|
||||
this.value_supplier = value_supplier;
|
||||
this.max_value_supplier = max_value_supplier;
|
||||
|
||||
addDataSlots(value_container);
|
||||
addDataSlots(max_value_container);
|
||||
}
|
||||
|
||||
public PatternStorageWidget(MatteryMenu menu, Supplier<Long> value_supplier, Supplier<Long> max_value_supplier) {
|
||||
this(menu, 0, 0, value_supplier, max_value_supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateServer() {
|
||||
if (value_supplier == null || max_value_supplier == null)
|
||||
return;
|
||||
|
||||
value_container.setValue(value_supplier.get());
|
||||
max_value_container.setValue(max_value_supplier.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageWidth() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageHeight() {
|
||||
return 48;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageY() {
|
||||
return 148;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Component> getTooltip() {
|
||||
return List.of(
|
||||
new TranslatableComponent("otm.gui.pattern.percentage_level", String.format("%.2f", getLevel() * 100d)),
|
||||
new TranslatableComponent("otm.gui.pattern.format", value_container.getValue(), max_value_container.getValue())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLevel() {
|
||||
return max_value_container.getValue() == 0 ? 0 : (float) ((double) value_container.getValue() / (double) max_value_container.getValue());
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ public class BatteryBankScreen extends MatteryScreen<BatteryBankMenu> implements
|
||||
@Override
|
||||
public void createGridPanels(FlexGridPanel grid) {
|
||||
for (var slot : menu.battery_slots) {
|
||||
new SlotPanel(this, grid, 0, 0, slot);
|
||||
new SlotPanel<>(this, grid, 0, 0, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class MatterCapacitorBankScreen extends MatteryScreen<MatterCapacitorBank
|
||||
@Override
|
||||
public void createGridPanels(FlexGridPanel grid) {
|
||||
for (var slot : menu.container_slots) {
|
||||
new SlotPanel(this, grid, 0, 0, slot);
|
||||
new SlotPanel<>(this, grid, 0, 0, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ public class MatterDecomposerScreen extends MatteryScreen<MatterDecomposerMenu>
|
||||
|
||||
@Override
|
||||
public void createGridPanels(FlexGridPanel grid) {
|
||||
new SlotPanel(this, grid, 0, 0, menu.input).setDockMargin(2, 0, 2, 0);
|
||||
new SlotPanel<>(this, grid, 0, 0, menu.input).setDockMargin(2, 0, 2, 0);
|
||||
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
|
||||
new SlotPanel(this, grid, 0, 0, menu.output).setDockMargin(2, 0, 2, 0);
|
||||
new SlotPanel<>(this, grid, 0, 0, menu.output).setDockMargin(2, 0, 2, 0);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class MatterReplicatorScreen extends MatteryScreen<MatterReplicatorMenu>
|
||||
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
|
||||
|
||||
for (var slot : menu.output_slots) {
|
||||
new SlotPanel(this, grid, 0, 0, slot);
|
||||
new SlotPanel<>(this, grid, 0, 0, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class MatterScannerScreen extends MatteryScreen<MatterScannerMenu> implem
|
||||
|
||||
@Override
|
||||
public void createGridPanels(FlexGridPanel grid) {
|
||||
new SlotPanel(this, grid, 0, 0, menu.input).setDockMargin(2, 0, 2, 0);
|
||||
new SlotPanel<>(this, grid, 0, 0, menu.input).setDockMargin(2, 0, 2, 0);
|
||||
new MatteryWidgetPanel(this, grid, menu.progress).setDockMargin(2, 0, 2, 0);
|
||||
}
|
||||
}
|
||||
|
@ -3,30 +3,26 @@ package ru.dbotthepony.mc.otm.screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import ru.dbotthepony.mc.otm.menu.PatternStorageMenu;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.Dock;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.FlexGridPanel;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.FramePanel;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.SlotPanel;
|
||||
import ru.dbotthepony.mc.otm.menu.widget.GaugeWidget;
|
||||
import ru.dbotthepony.mc.otm.screen.panels.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PatternStorageScreen extends MatteryScreen<PatternStorageMenu> {
|
||||
public class PatternStorageScreen extends MatteryScreen<PatternStorageMenu> implements MatteryScreen.IMatteryScreenGaugeGetter, MatteryScreen.IMatteryScreenGridBased {
|
||||
public PatternStorageScreen(PatternStorageMenu p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected FramePanel makeMainFrame() {
|
||||
var frame = super.makeMainFrame();
|
||||
|
||||
var grid = new FlexGridPanel(this, frame, 0, 0, 0, 0);
|
||||
grid.setDock(Dock.FILL);
|
||||
public List<GaugeWidget> getGauges() {
|
||||
return List.of(menu.stored_this, menu.stored_grid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createGridPanels(FlexGridPanel grid) {
|
||||
for (var slot : menu.pattern_slots) {
|
||||
new SlotPanel(this, grid, 0, 0, slot).setDockMargin(1, 1, 1, 1);
|
||||
new SlotPanel<>(this, grid, 0, 0, slot).setDockMargin(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,9 @@
|
||||
"otm.gui.matter.format": "Matter: %s",
|
||||
"otm.gui.matter.name": "MtU",
|
||||
|
||||
"otm.gui.pattern.percentage_level": "Fill level: %s%%",
|
||||
"otm.gui.pattern.format": "Stored patterns: %s / %s",
|
||||
|
||||
"otm.death_reason": "Decommissioned!",
|
||||
|
||||
"otm.item.power.infinite.storage": "Stored energy: Infinity / Infinity",
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/assets/overdrive_that_matters/textures/gui/widgets.xcf
(Stored with Git LFS)
BIN
src/main/resources/assets/overdrive_that_matters/textures/gui/widgets.xcf
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue
Block a user