Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add throughput monitor #674

Merged
merged 12 commits into from
Feb 13, 2025
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/definitions/IParts.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ default IItemDefinition p2PTunnelSound() {

IItemDefinition storageMonitor();

IItemDefinition throughputMonitor();

IItemDefinition conversionMonitor();

IItemDefinition patternTerminalEx();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/definitions/Parts.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ public class Parts {

public AEItemDefinition partStorageMonitor;

public AEItemDefinition partThroughputMonitor;

public AEItemDefinition partConversionMonitor;
}
5 changes: 5 additions & 0 deletions src/main/java/appeng/client/texture/CableBusTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public enum CableBusTextures {
PartConversionMonitor_Dark("PartConversionMonitor_Dark"),
PartConversionMonitor_Dark_Locked("PartConversionMonitor_Dark_Locked"),

PartThroughputMonitor_Bright("PartThroughputMonitor_Bright"),
PartThroughputMonitor_Colored("PartThroughputMonitor_Colored"),
PartThroughputMonitor_Dark("PartThroughputMonitor_Dark"),
PartThroughputMonitor_Dark_Locked("PartThroughputMonitor_Dark_Locked"),

PartInterfaceTerm_Bright("PartInterfaceTerm_Bright"),
PartInterfaceTerm_Colored("PartInterfaceTerm_Colored"),
PartInterfaceTerm_Dark("PartInterfaceTerm_Dark"),
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/appeng/container/AEBaseContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import appeng.helpers.InventoryAction;
import appeng.items.materials.ItemMultiMaterial;
import appeng.parts.automation.StackUpgradeInventory;
import appeng.parts.automation.UpgradeInventory;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
Expand Down Expand Up @@ -525,11 +526,14 @@ public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
}

// For shift click upgrade card logic
if (ItemMultiMaterial.instance.getType(tis) != null && this instanceof ContainerUpgradeable) {
// Check source or target
if (!((d.inventory instanceof StackUpgradeInventory)
|| (clickSlot.inventory instanceof StackUpgradeInventory))) {
continue;
if (ItemMultiMaterial.instance.getType(tis) != null) {
// Check now container is upgradeable or it's subclass
if (ContainerUpgradeable.class.isAssignableFrom(this.getClass())) {
// Check source or target
if (!((d.inventory instanceof UpgradeInventory)
|| (clickSlot.inventory instanceof StackUpgradeInventory))) {
continue;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/appeng/core/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ private void assignParts(final Parts target, final IParts source) {
target.partCraftingTerminal = this.converter.of(source.craftingTerminal());
target.partTerminal = this.converter.of(source.terminal());
target.partStorageMonitor = this.converter.of(source.storageMonitor());
target.partThroughputMonitor = this.converter.of(source.throughputMonitor());
target.partConversionMonitor = this.converter.of(source.conversionMonitor());
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/appeng/core/api/definitions/ApiParts.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public final class ApiParts implements IParts {
private final IItemDefinition terminal;
private final IItemDefinition storageMonitor;
private final IItemDefinition conversionMonitor;
private final IItemDefinition throughputMonitor;

public ApiParts(final DefinitionConstructor constructor, final IPartHelper partHelper) {
final ItemMultiPart itemMultiPart = new ItemMultiPart(partHelper);
Expand Down Expand Up @@ -119,6 +120,7 @@ public ApiParts(final DefinitionConstructor constructor, final IPartHelper partH
this.terminal = new DamagedItemDefinition(itemMultiPart.createPart(PartType.Terminal));
this.storageMonitor = new DamagedItemDefinition(itemMultiPart.createPart(PartType.StorageMonitor));
this.conversionMonitor = new DamagedItemDefinition(itemMultiPart.createPart(PartType.ConversionMonitor));
this.throughputMonitor = new DamagedItemDefinition(itemMultiPart.createPart(PartType.ThroughputMonitor));
}

@Override
Expand Down Expand Up @@ -344,4 +346,9 @@ public IItemDefinition storageMonitor() {
public IItemDefinition conversionMonitor() {
return this.conversionMonitor;
}

@Override
public IItemDefinition throughputMonitor() {
return this.throughputMonitor;
}
}
1 change: 1 addition & 0 deletions src/main/java/appeng/core/features/AEFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public boolean isVisible() {
ExportBus(Constants.CATEGORY_NETWORK_BUSES),
StorageBus(Constants.CATEGORY_NETWORK_BUSES),
PartConversionMonitor(Constants.CATEGORY_NETWORK_BUSES),
PartThroughputMonitor(Constants.CATEGORY_NETWORK_BUSES),

PortableCell(Constants.CATEGORY_PORTABLE_CELL),

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/appeng/items/parts/PartType.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import appeng.parts.reporting.PartSemiDarkPanel;
import appeng.parts.reporting.PartStorageMonitor;
import appeng.parts.reporting.PartTerminal;
import appeng.parts.reporting.PartThroughputMonitor;

public enum PartType {

Expand Down Expand Up @@ -149,6 +150,9 @@ public boolean isCable() {
StorageMonitor(400, EnumSet.of(AEFeature.StorageMonitor), EnumSet.noneOf(IntegrationType.class),
PartStorageMonitor.class),

ThroughputMonitor(410, EnumSet.of(AEFeature.PartThroughputMonitor), EnumSet.noneOf(IntegrationType.class),
PartThroughputMonitor.class),

ConversionMonitor(420, EnumSet.of(AEFeature.PartConversionMonitor), EnumSet.noneOf(IntegrationType.class),
PartConversionMonitor.class),

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/appeng/parts/reporting/AbstractPartMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ private void tesrRenderScreen(final Tessellator tess, final IAEItemStack ais) {
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}

this.tesrRenderItemNumber(ais);

// GL11.glPopAttrib();
}

public void tesrRenderItemNumber(final IAEItemStack ais) {
GL11.glTranslatef(0.0f, 0.14f, -0.24f);
GL11.glScalef(1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f);

Expand All @@ -326,8 +332,6 @@ private void tesrRenderScreen(final Tessellator tess, final IAEItemStack ais) {
final int width = fr.getStringWidth(renderedStackSize);
GL11.glTranslatef(-0.5f * width, 0.0f, -1.0f);
fr.drawString(renderedStackSize, 0, 0, 0);

// GL11.glPopAttrib();
}

@Override
Expand Down
152 changes: 152 additions & 0 deletions src/main/java/appeng/parts/reporting/PartThroughputMonitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package appeng.parts.reporting;

import java.io.IOException;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;

import org.lwjgl.opengl.GL11;

import appeng.api.storage.data.IAEItemStack;
import appeng.client.texture.CableBusTextures;
import appeng.helpers.Reflected;
import appeng.util.IWideReadableNumberConverter;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
import io.netty.buffer.ByteBuf;

/**
* @author MCTBL
* @version rv3-beta-538-GTNH
* @since rv3-beta-538-GTNH
*/
public class PartThroughputMonitor extends AbstractPartMonitor {

private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;

private static final CableBusTextures FRONT_BRIGHT_ICON = CableBusTextures.PartThroughputMonitor_Bright;
private static final CableBusTextures FRONT_DARK_ICON = CableBusTextures.PartThroughputMonitor_Dark;
private static final CableBusTextures FRONT_COLORED_ICON = CableBusTextures.PartThroughputMonitor_Colored;
private static final CableBusTextures FRONT_COLORED_ICON_LOCKED = CableBusTextures.PartThroughputMonitor_Dark_Locked;

private long lastitemNums;
private long itemNumsChange;
private int timeMode;

@Reflected
public PartThroughputMonitor(final ItemStack is) {
super(is);
this.lastitemNums = 0;
this.itemNumsChange = 0;
this.timeMode = 0;
}

@Override
public CableBusTextures getFrontBright() {
return FRONT_BRIGHT_ICON;
}

@Override
public CableBusTextures getFrontColored() {
return this.isLocked() ? FRONT_COLORED_ICON_LOCKED : FRONT_COLORED_ICON;
}

@Override
public CableBusTextures getFrontDark() {
return FRONT_DARK_ICON;
}

@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.timeMode = data.getInteger("timeMode");
}

@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("timeMode", this.timeMode);
}

@Override
public void writeToStream(final ByteBuf data) throws IOException {
super.writeToStream(data);
data.writeInt(this.timeMode);
}

@Override
public boolean readFromStream(final ByteBuf data) throws IOException {
boolean needRedraw = super.readFromStream(data);
this.timeMode = data.readInt();
return needRedraw;
}

@Override
public boolean onPartShiftActivate(final EntityPlayer player, final Vec3 pos) {
if (Platform.isClient()) {
return true;
}

if (!this.getProxy().isActive()) {
return false;
}

if (!Platform.hasPermissions(this.getLocation(), player)) {
return false;
}

this.timeMode = this.timeMode == 0 ? 1 : 0;

return true;
}

public void updateThroughput() {
if (this.getDisplayed() != null) {
long nowNums = ((IAEItemStack) this.getDisplayed()).getStackSize();
this.itemNumsChange = (nowNums - lastitemNums);
// If is tick mode
if (this.timeMode == 1) {
this.itemNumsChange *= 20;
}
this.lastitemNums = nowNums;
} else {
this.itemNumsChange = 0;
this.lastitemNums = 0;
}
this.getHost().markForUpdate();
}

@Override
public void tesrRenderItemNumber(final IAEItemStack ais) {
GL11.glTranslatef(0.0f, 0.14f, -0.24f);
GL11.glScalef(1.0f / 120.0f, 1.0f / 120.0f, 1.0f / 120.0f);

final long stackSize = ais.getStackSize();
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm(stackSize);

final String renderedStackSizeChange = (this.itemNumsChange > 0 ? "+" : "")
+ Platform.formatNumberLong(this.itemNumsChange)
+ (this.timeMode == 0 ? "/s" : "/t");

final FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int width = fr.getStringWidth(renderedStackSize);
GL11.glTranslatef(-0.5f * width, 0.0f, -1.0f);
fr.drawString(renderedStackSize, 0, 0, 0);
GL11.glTranslatef(+0.5f * width, fr.FONT_HEIGHT + 3, -1.0f);

width = fr.getStringWidth(renderedStackSizeChange);
GL11.glTranslatef(-0.5f * width, 0.0f, -1.0f);
int color = 0;
if (this.itemNumsChange < 0) {
color = 0xFF0000;
} else if (this.itemNumsChange > 0) {
color = 0x17B66C;
}
fr.drawString(renderedStackSizeChange, 0, 0, color);
}

}
15 changes: 15 additions & 0 deletions src/main/java/appeng/tile/networking/TileCableBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IImmibisMicroblocks;
import appeng.parts.CableBusContainer;
import appeng.parts.reporting.PartThroughputMonitor;
import appeng.tile.AEBaseTile;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
Expand All @@ -49,6 +50,8 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl

private CableBusContainer cb = new CableBusContainer(this);

private int tickCounter = 1;

/**
* Immibis MB Support
*/
Expand Down Expand Up @@ -321,4 +324,16 @@ public CableBusContainer getCableBus() {
private void setCableBus(final CableBusContainer cb) {
this.cb = cb;
}

@TileEvent(TileEventType.TICK)
public void update() {
if (++tickCounter >= 20) {
for (ForgeDirection side : ForgeDirection.values()) {
if (this.cb.getPart(side) instanceof PartThroughputMonitor ptm) {
ptm.updateThroughput();
}
}
tickCounter = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ item.appliedenergistics2.ItemPart.CableDense.name=ME Dense Smart Cable
item.appliedenergistics2.ItemPart.CableDenseCovered.name=ME Dense Covered Cable
item.appliedenergistics2.ItemPart.StorageMonitor.name=ME Storage Monitor
item.appliedenergistics2.ItemPart.ConversionMonitor.name=ME Conversion Monitor
item.appliedenergistics2.ItemPart.ThroughputMonitor.name=ME Throughput Monitor
item.appliedenergistics2.ItemPart.SemiDarkMonitor.name=Illuminated Panel
item.appliedenergistics2.ItemPart.Monitor.name=Bright Illuminated Panel
item.appliedenergistics2.ItemPart.DarkMonitor.name=Dark Illuminated Panel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ item.appliedenergistics2.ItemPart.CableDense.name=ME致密智能线缆
item.appliedenergistics2.ItemPart.CableDenseCovered.name=ME致密包层线缆
item.appliedenergistics2.ItemPart.StorageMonitor.name=ME存储监控器
item.appliedenergistics2.ItemPart.ConversionMonitor.name=ME交换监控器
item.appliedenergistics2.ItemPart.ThroughputMonitor.name=ME吞吐量监控器
item.appliedenergistics2.ItemPart.SemiDarkMonitor.name=照明面板
item.appliedenergistics2.ItemPart.Monitor.name=亮色照明面板
item.appliedenergistics2.ItemPart.DarkMonitor.name=暗色照明面板
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.