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

Port Central Monitor #196

Merged
merged 28 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2cd504c
Start moving monitors over
bruberu Oct 16, 2021
7935034
Get the base monitor behavior online
bruberu Oct 16, 2021
5e5a594
Do a lot of stuff, including yeeting the weird duplicate RenderUtil.java
bruberu Oct 17, 2021
3db46c9
Finish class porting
bruberu Oct 17, 2021
ed87afe
Fix more clipboard issues... finally
bruberu Oct 18, 2021
7cf0b88
Get plugins working (not their textures)
bruberu Oct 20, 2021
dd288d2
Complete formatting work
bruberu Oct 21, 2021
bc2c8b2
Replace new update code
bruberu Oct 21, 2021
da4075a
Merge branch 'master' into monitorCEu
Yefancy Nov 3, 2021
191d180
add new APIs of the IEnergyContainer
Yefancy Nov 6, 2021
ee0d689
remove duplicate code
Yefancy Nov 10, 2021
045e6ae
fix the center pos of jei multis pages
Yefancy Nov 10, 2021
01dfc65
working
Yefancy Nov 10, 2021
067023f
Merge branch 'master' into monitorCEu
Yefancy Nov 10, 2021
149126a
lang file
Yefancy Nov 10, 2021
afc1680
fix firebox casing textures
Yefancy Nov 11, 2021
e4d84a7
move to GregtechDataCodes
Yefancy Nov 13, 2021
1b5a0a2
move shaders to version 120
Yefancy Nov 13, 2021
376cf53
Wireless Cover Digital Interface
Yefancy Nov 14, 2021
708a43a
finish
Yefancy Nov 15, 2021
d7ad223
Merge branch 'master' into monitorCEu
Yefancy Nov 19, 2021
7f048ce
register id conflict
Yefancy Nov 19, 2021
2a43b64
fix energy enough status and flickering indicator
Yefancy Nov 19, 2021
a0436ad
Merge branch 'master' into monitorCEu
Yefancy Nov 20, 2021
9ea3dd3
format
Yefancy Nov 20, 2021
d2c08b4
Merge branch 'master' into monitorCEu
Yefancy Nov 20, 2021
4efb92d
format
Yefancy Nov 20, 2021
1bf548c
fix another formatting error
TechLord22 Nov 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/main/java/gregtech/api/capability/GregtechDataCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class GregtechDataCodes {
public static final int UPDATE_UI = 0;
public static final int CREATE_FAKE_UI = 1;
public static final int MOUSE_POSITION = 2;
public static final int DETECT_UPDATE_RECEIVED = 3;

// Pump
public static final int PUMP_HEAD_LEVEL = 200;
Expand Down Expand Up @@ -69,4 +70,30 @@ public class GregtechDataCodes {
public static final int DEFORM_TANK = 2;
public static final int SYNC_FLUID_CHANGE = 3;
public static final int SYNC_TANK_SHAPE = 4;

// Central Monitor
public static final int UPDATE_ALL = 1;
public static final int UPDATE_COVERS = 2;
public static final int UPDATE_HEIGHT = 3;
public static final int UPDATE_ACTIVE = 4;
public static final int UPDATE_PLUGIN_ITEM = 3;

// Central Monitor Plugin
public static final int UPDATE_PLUGIN_DATA = 2;
public static final int UPDATE_PLUGIN_CONFIG = 0;
public static final int ACTION_PLUGIN_CONFIG = 0;
public static final int UPDATE_PLUGIN_CLICK = -2;
public static final int UPDATE_ADVANCED_VALID_POS = 1;
public static final int UPDATE_FAKE_GUI = 1;
public static final int ACTION_FAKE_GUI = 1;
public static final int UPDATE_FAKE_GUI_DETECT = -1;

// Digital Interface
public static final int UPDATE_MODE = 1;
public static final int UPDATE_FLUID = 2;
public static final int UPDATE_ITEM = 3;
public static final int UPDATE_ENERGY = 4;
public static final int UPDATE_ENERGY_PER = 5;
public static final int UPDATE_MACHINE = 6;

}
46 changes: 46 additions & 0 deletions src/main/java/gregtech/api/capability/IEnergyContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ default long getOutputVoltage() {
*/
long getInputVoltage();

/**
* @return input eu/s
*/
default long getInputPerSec() {return 0L;}

/**
* @return output eu/s
*/
default long getOutputPerSec() {return 0L;}

/**
* @return true if information like energy capacity should be hidden from TOP.
* Useful for cables
Expand All @@ -106,4 +116,40 @@ default boolean isOneProbeHidden() {
return false;
}

IEnergyContainer DEFAULT = new IEnergyContainer() {
@Override
public long acceptEnergyFromNetwork(EnumFacing enumFacing, long l, long l1) {
return 0;
}

@Override
public boolean inputsEnergy(EnumFacing enumFacing) {
return false;
}

@Override
public long changeEnergy(long l) {
return 0;
}

@Override
public long getEnergyStored() {
return 0;
}

@Override
public long getEnergyCapacity() {
return 0;
}

@Override
public long getInputAmperage() {
return 0;
}

@Override
public long getInputVoltage() {
return 0;
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class EnergyContainerBatteryBuffer extends MTETrait implements IEnergyCon
private final BitSet batterySlotsUsedThisTick = new BitSet();
private final int tier;
private long amps = 0;
private long lastEnergyInputPerSec = 0;
private long lastEnergyOutputPerSec = 0;
private long energyInputPerSec = 0;
private long energyOutputPerSec = 0;

public EnergyContainerBatteryBuffer(MetaTileEntity metaTileEntity, int tier) {
super(metaTileEntity);
Expand Down Expand Up @@ -59,9 +63,20 @@ public long acceptEnergyFromNetwork(EnumFacing side, long voltage, long amperage
notifyEnergyListener(false);
}
amps += usedAmps;
energyInputPerSec += voltage * usedAmps;
return usedAmps;
}

@Override
public long getInputPerSec() {
return lastEnergyInputPerSec;
}

@Override
public long getOutputPerSec() {
return lastEnergyOutputPerSec;
}

private static boolean chargeItemWithVoltage(IElectricItem electricItem, long voltage, int tier, boolean simulate) {
long charged = electricItem.charge(voltage, tier, false, simulate);
return charged > 0;
Expand All @@ -79,6 +94,12 @@ private static long chargeItem(IElectricItem electricItem, long amount, int tier
public void update() {
amps = 0;
if (!metaTileEntity.getWorld().isRemote) {
if (metaTileEntity.getOffsetTimer() % 20 == 0) {
lastEnergyInputPerSec = energyInputPerSec;
lastEnergyOutputPerSec = energyOutputPerSec;
energyInputPerSec = 0;
energyOutputPerSec = 0;
}
this.batterySlotsUsedThisTick.clear();
EnumFacing outFacing = metaTileEntity.getFrontFacing();
TileEntity tileEntity = metaTileEntity.getWorld().getTileEntity(metaTileEntity.getPos().offset(outFacing));
Expand Down Expand Up @@ -106,6 +127,7 @@ public void update() {
if (maxAmperage == 0) return;
long amperageUsed = energyContainer.acceptEnergyFromNetwork(outFacing.getOpposite(), voltage, maxAmperage);
if (amperageUsed == 0) return;
energyOutputPerSec += amperageUsed * voltage;
for (int i : slotsList.toArray()) {
ItemStack batteryStack = inventory.getStackInSlot(i);
IElectricItem electricItem = getBatteryContainer(batteryStack);
Expand Down Expand Up @@ -183,6 +205,7 @@ public long changeEnergy(long energyToAdd) {
if (energyAdded > 0L) {
notifyEnergyListener(false);
}
energyInputPerSec += energyAdded;
return energyAdded;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class EnergyContainerHandler extends MTETrait implements IEnergyContainer
private final long maxOutputVoltage;
private final long maxOutputAmperage;

private long lastEnergyInputPerSec = 0;
private long lastEnergyOutputPerSec = 0;
private long energyInputPerSec = 0;
private long energyOutputPerSec = 0;

private Predicate<EnumFacing> sideInputCondition;
private Predicate<EnumFacing> sideOutputCondition;

Expand Down Expand Up @@ -56,6 +61,16 @@ public static EnergyContainerHandler receiverContainer(MetaTileEntity tileEntity
return new EnergyContainerHandler(tileEntity, maxCapacity, maxInputVoltage, maxInputAmperage, 0L, 0L);
}

@Override
public long getInputPerSec() {
return lastEnergyInputPerSec;
}

@Override
public long getOutputPerSec() {
return lastEnergyOutputPerSec;
}

@Override
public String getName() {
return "EnergyContainer";
Expand Down Expand Up @@ -93,6 +108,11 @@ public long getEnergyStored() {
}

public void setEnergyStored(long energyStored) {
if (energyStored > this.energyStored) {
energyInputPerSec += energyStored - this.energyStored;
} else {
energyOutputPerSec += this.energyStored - energyStored;
}
this.energyStored = energyStored;
if (!metaTileEntity.getWorld().isRemote) {
metaTileEntity.markDirty();
Expand Down Expand Up @@ -138,6 +158,12 @@ public void update() {
amps = 0;
if (getMetaTileEntity().getWorld().isRemote)
return;
if (metaTileEntity.getOffsetTimer() % 20 == 0) {
lastEnergyOutputPerSec = energyOutputPerSec;
lastEnergyInputPerSec = energyInputPerSec;
energyOutputPerSec = 0;
energyInputPerSec = 0;
}
if (getEnergyStored() >= getOutputVoltage() && getOutputVoltage() > 0 && getOutputAmperage() > 0) {
long outputVoltage = getOutputVoltage();
long outputAmperes = Math.min(getEnergyStored() / outputVoltage, getOutputAmperage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ public EnergyContainerList(List<IEnergyContainer> energyContainerList) {
this.energyContainerList = energyContainerList;
}

@Override
public long getInputPerSec() {
long sum = 0;
for (IEnergyContainer energyContainer : energyContainerList) {
sum += energyContainer.getInputPerSec();
}
return sum;
}

@Override
public long getOutputPerSec() {
long sum = 0;
for (IEnergyContainer energyContainer : energyContainerList) {
sum += energyContainer.getOutputPerSec();
}
return sum;
}

@Override
public long acceptEnergyFromNetwork(EnumFacing side, long voltage, long amperage) {
long amperesUsed = 0L;
Expand Down
Loading