Skip to content

Commit

Permalink
Allow PSS to display on CM (GregTechCEu#2405)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss authored Mar 7, 2024
1 parent 4e47ef8 commit fd65290
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 25 deletions.
71 changes: 54 additions & 17 deletions src/main/java/gregtech/common/covers/CoverDigitalInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import gregtech.api.util.TextFormattingUtil;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.utils.RenderUtil;
import gregtech.common.metatileentities.multi.electric.MetaTileEntityPowerSubstation;
import gregtech.common.terminal.app.prospector.widget.WidgetOreList;

import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -228,7 +229,7 @@ public void onAttachment(@NotNull CoverableView coverableView, @NotNull EnumFaci
} else if (getItemCapability() != null) {
items = new ItemStack[getItemCapability().getSlots()];
this.mode = MODE.ITEM;
} else if (getEnergyCapability() != null) {
} else if (getEnergyCapability() != null || getCoverableView() instanceof MetaTileEntityPowerSubstation) {
this.mode = MODE.ENERGY;
} else if (getMachineCapability() != null) {
this.mode = MODE.MACHINE;
Expand Down Expand Up @@ -579,22 +580,19 @@ private void syncAllInfo() {
}
}
if (this.mode == MODE.ENERGY || (mode == MODE.PROXY && proxyMode[2] > 0)) {
IEnergyContainer energyContainer = this.getEnergyCapability();
if (energyContainer != null) {
// TODO, figure out what to do when values exceed Long.MAX_VALUE, ie with multiple Ultimate batteries
if (energyStored != energyContainer.getEnergyStored() ||
energyCapability != energyContainer.getEnergyCapacity()) {
energyStored = energyContainer.getEnergyStored();
energyCapability = energyContainer.getEnergyCapacity();
if (getCoverableView() instanceof MetaTileEntityPowerSubstation pss) {
if (energyStored != pss.getStoredLong() || energyCapability != pss.getCapacityLong()) {
energyStored = pss.getStoredLong();
energyCapability = pss.getCapacityLong();
writeCustomData(GregtechDataCodes.UPDATE_ENERGY, packetBuffer -> {
packetBuffer.writeLong(energyStored);
packetBuffer.writeLong(energyCapability);
});
}
if (this.getOffsetTimer() % 20 == 0) { // per second
if (this.getOffsetTimer() % 20 == 0) {
writeCustomData(GregtechDataCodes.UPDATE_ENERGY_PER, packetBuffer -> {
packetBuffer.writeLong(energyContainer.getInputPerSec());
packetBuffer.writeLong(energyContainer.getOutputPerSec());
packetBuffer.writeLong(pss.getAverageInLastSec() * 20L);
packetBuffer.writeLong(pss.getAverageOutLastSec() * 20L);
inputEnergyList.add(energyInputPerDur);
outputEnergyList.add(energyOutputPerDur);
if (inputEnergyList.size() > 13) {
Expand All @@ -603,6 +601,33 @@ private void syncAllInfo() {
}
});
}
} else {
IEnergyContainer energyContainer = this.getEnergyCapability();
if (energyContainer != null) {
// TODO, figure out what to do when values exceed Long.MAX_VALUE, ie with multiple Ultimate
// batteries
if (energyStored != energyContainer.getEnergyStored() ||
energyCapability != energyContainer.getEnergyCapacity()) {
energyStored = energyContainer.getEnergyStored();
energyCapability = energyContainer.getEnergyCapacity();
writeCustomData(GregtechDataCodes.UPDATE_ENERGY, packetBuffer -> {
packetBuffer.writeLong(energyStored);
packetBuffer.writeLong(energyCapability);
});
}
if (this.getOffsetTimer() % 20 == 0) { // per second
writeCustomData(GregtechDataCodes.UPDATE_ENERGY_PER, packetBuffer -> {
packetBuffer.writeLong(energyContainer.getInputPerSec());
packetBuffer.writeLong(energyContainer.getOutputPerSec());
inputEnergyList.add(energyInputPerDur);
outputEnergyList.add(energyOutputPerDur);
if (inputEnergyList.size() > 13) {
inputEnergyList.remove(0);
outputEnergyList.remove(0);
}
});
}
}
}
}
if (this.mode == MODE.MACHINE || (mode == MODE.PROXY && proxyMode[3] > 0)) {
Expand All @@ -626,17 +651,28 @@ private void syncAllInfo() {
});
}
if (this.getOffsetTimer() % 20 == 0) {
IEnergyContainer energyContainer = this.getEnergyCapability();
if (energyContainer != null) {
if (energyStored != energyContainer.getEnergyStored() ||
energyCapability != energyContainer.getEnergyCapacity()) {
energyStored = energyContainer.getEnergyStored();
energyCapability = energyContainer.getEnergyCapacity();
if (getCoverableView() instanceof MetaTileEntityPowerSubstation pss) {
if (energyStored != pss.getStoredLong() || energyCapability != pss.getCapacityLong()) {
energyStored = pss.getStoredLong();
energyCapability = pss.getCapacityLong();
writeCustomData(GregtechDataCodes.UPDATE_ENERGY, packetBuffer -> {
packetBuffer.writeLong(energyStored);
packetBuffer.writeLong(energyCapability);
});
}
} else {
IEnergyContainer energyContainer = this.getEnergyCapability();
if (energyContainer != null) {
if (energyStored != energyContainer.getEnergyStored() ||
energyCapability != energyContainer.getEnergyCapacity()) {
energyStored = energyContainer.getEnergyStored();
energyCapability = energyContainer.getEnergyCapacity();
writeCustomData(GregtechDataCodes.UPDATE_ENERGY, packetBuffer -> {
packetBuffer.writeLong(energyStored);
packetBuffer.writeLong(energyCapability);
});
}
}
}
}
}
Expand Down Expand Up @@ -861,6 +897,7 @@ public boolean canCapabilityAttach() {
return getFluidCapability() != null ||
getItemCapability() != null ||
getEnergyCapability() != null ||
getCoverableView() instanceof MetaTileEntityPowerSubstation ||
getMachineCapability() != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,69 @@ private void updateProxyPlugin() {
}

public int getX() {
if (this.getController() != null) {
if (this.getController().getPos().getX() - this.getPos().getX() != 0) {
return Math.abs(this.getController().getPos().getX() - this.getPos().getX()) - 1;
} else {
return Math.abs(this.getController().getPos().getZ() - this.getPos().getZ()) - 1;
MultiblockControllerBase controller = this.getController();
if (controller != null) {
EnumFacing spin = controller.getUpwardsFacing();
switch (controller.getFrontFacing().getAxis()) {
case Y -> {
if (spin.getAxis() == EnumFacing.Axis.X)
return Math.abs(this.getController().getPos().getZ() - this.getPos().getZ()) - 1;
else
return Math.abs(this.getController().getPos().getX() - this.getPos().getX()) - 1;
}
case X -> {
if (spin.getAxis() == EnumFacing.Axis.Z)
return Math.abs(this.getController().getPos().getZ() - this.getPos().getZ()) - 1;
else
return Math.abs(this.getController().getPos().getY() - this.getPos().getY()) - 1;
}
default -> {
if (spin.getAxis() == EnumFacing.Axis.Z)
return Math.abs(this.getController().getPos().getX() - this.getPos().getX()) - 1;
else
return Math.abs(this.getController().getPos().getY() - this.getPos().getY()) - 1;
}
}
}
return -1;
}

public int getY() {
if (this.getController() != null) {
return ((MetaTileEntityCentralMonitor) this.getController()).height -
(this.getPos().getY() + 1 - this.getController().getPos().getY()) - 1;
MultiblockControllerBase controller = this.getController();
if (controller != null) {
EnumFacing spin = controller.getUpwardsFacing();
EnumFacing facing = controller.getFrontFacing();
int height = ((MetaTileEntityCentralMonitor) this.getController()).height;
switch (facing.getAxis()) {
case Y -> {
if (spin.getAxis() == EnumFacing.Axis.X)
return height -
(Math.abs(controller.getPos().getX() - spin.getXOffset() - this.getPos().getX())) - 1;
else
return height -
(Math.abs(controller.getPos().getZ() - spin.getZOffset() - this.getPos().getZ())) - 1;
}
case X -> {
if (spin.getAxis() == EnumFacing.Axis.Z)
return height -
(Math.abs(controller.getPos().getY() + spin.getZOffset() - this.getPos().getY())) - 1;
else
return height - (Math.abs(
controller.getPos().getZ() + spin.getXOffset() * facing.rotateY().getZOffset() -
this.getPos().getZ())) -
1;
}
default -> {
if (spin.getAxis() == EnumFacing.Axis.Z)
return height -
(Math.abs(controller.getPos().getY() + spin.getZOffset() - this.getPos().getY())) - 1;
else
return height - (Math.abs(
controller.getPos().getX() + spin.getXOffset() * facing.rotateY().getXOffset() -
this.getPos().getX())) -
1;
}
}
}
return -1;
}
Expand Down

0 comments on commit fd65290

Please sign in to comment.