Skip to content

Commit

Permalink
Add getInfoMap method to IGregTechDeviceInformation (GTNewHorizon…
Browse files Browse the repository at this point in the history
…s#3897)

Co-authored-by: Julia Dijkstra <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Maya <[email protected]>
  • Loading branch information
4 people authored Feb 7, 2025
1 parent 9bdaeb0 commit 67b5824
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import gregtech.api.enums.Dyes;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.modularui.IGetGUITextureSet;
import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.IGregtechWailaProvider;
import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable;
Expand All @@ -43,7 +44,7 @@
* Don't implement this yourself and expect it to work. Extend @MetaTileEntity itself.
*/
public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHandler, IMachineBlockUpdateable,
IGregtechWailaProvider, IGetGUITextureSet, ICraftingIconProvider {
IGregtechWailaProvider, IGetGUITextureSet, ICraftingIconProvider, IGregTechDeviceInformation {

/**
* This determines the BaseMetaTileEntity belonging to this MetaTileEntity by using the Meta ID of the Block itself.
Expand Down Expand Up @@ -380,10 +381,6 @@ ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection sid

float getExplosionResistance(ForgeDirection side);

String[] getInfoData();

boolean isGivingInformation();

ItemStack[] getRealInventory();

boolean connectsToItemPipe(ForgeDirection side);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package gregtech.api.interfaces.tileentity;

import java.util.Collections;
import java.util.Map;

/**
* You are allowed to include this File in your Download, as i will not change it.
*/
Expand All @@ -10,13 +13,26 @@ public interface IGregTechDeviceInformation {
* MetaTileEntities, you MUST check this!!! Do not assume that it's a Information returning Device, when it just
* implements this Interface.
*/
boolean isGivingInformation();
default boolean isGivingInformation() {
return false;
}

/**
* Up to 8 Strings can be returned. Note: If you insert "\\\\" in the String it tries to translate seperate Parts of
* Up to 8 Strings can be returned. Note: If you insert "\\\\" in the String it tries to translate separate Parts of
* the String instead of the String as a whole.
*
* @return an Array of Information Strings. Don't return null!
* @return an Array of Information Strings.
*/
default String[] getInfoData() {
return new String[] {};
}

/**
* Returns a map of key-value pairs containing device information.
*
* @return a Map where keys are information categories and values are corresponding details.
*/
String[] getInfoData();
default Map<String, String> getInfoMap() {
return Collections.emptyMap();
}
}
20 changes: 12 additions & 8 deletions src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -482,8 +483,17 @@ public ArrayList<String> getDebugInfo(EntityPlayer aPlayer, int aLogLevel) {

@Override
public boolean isGivingInformation() {
if (canAccessData()) return mMetaTileEntity.isGivingInformation();
return false;
return canAccessData() && mMetaTileEntity.isGivingInformation();
}

@Override
public String[] getInfoData() {
return canAccessData() ? getMetaTileEntity().getInfoData() : new String[] {};
}

@Override
public Map<String, String> getInfoMap() {
return canAccessData() ? getMetaTileEntity().getInfoMap() : Collections.emptyMap();
}

@Override
Expand Down Expand Up @@ -1324,12 +1334,6 @@ public boolean isUniversalEnergyStored(long aEnergyAmount) {
return getUniversalEnergyStored() >= aEnergyAmount;
}

@Override
public String[] getInfoData() {
if (canAccessData()) return getMetaTileEntity().getInfoData();
return new String[] {};
}

@Override
public byte getConnections() {
return mConnections;
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -874,8 +875,17 @@ public ArrayList<String> getDebugInfo(EntityPlayer aPlayer, int aLogLevel) {

@Override
public boolean isGivingInformation() {
if (canAccessData()) return mMetaTileEntity.isGivingInformation();
return false;
return canAccessData() && mMetaTileEntity.isGivingInformation();
}

@Override
public String[] getInfoData() {
return canAccessData() ? getMetaTileEntity().getInfoData() : new String[] {};
}

@Override
public Map<String, String> getInfoMap() {
return canAccessData() ? getMetaTileEntity().getInfoMap() : Collections.emptyMap();
}

@Override
Expand Down Expand Up @@ -2225,14 +2235,6 @@ public boolean isUniversalEnergyStored(long aEnergyAmount) {
return false;
}

@Override
public String[] getInfoData() {
{
if (canAccessData()) return getMetaTileEntity().getInfoData();
return new String[] {};
}
}

@Override
public int getLightOpacity() {
return mMetaTileEntity == null ? getLightValue() > 0 ? 0 : 255 : mMetaTileEntity.getLightOpacity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,6 @@ public String getSpecialVoltageToolTip() {
return null;
}

@Override
public boolean isGivingInformation() {
return false;
}

@Override
public String[] getInfoData() {
return new String[] {};
}

public boolean isDigitalChest() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,11 @@ protected boolean filtersFluid() {
return true;
}

@Override
public boolean isGivingInformation() {
return true;
}

@Override
public String[] getInfoData() {
long storedEnergy = 0;
Expand Down Expand Up @@ -1976,8 +1981,32 @@ public String[] getInfoData() {
}

@Override
public boolean isGivingInformation() {
return true;
public Map<String, String> getInfoMap() {
long energy = 0, maxEnergy = 0, maxEnergyUsage = 0, minEnergyTier = Long.MAX_VALUE;

for (MTEHatchEnergy tHatch : validMTEList(mEnergyHatches)) {
IGregTechTileEntity energyHatch = tHatch.getBaseMetaTileEntity();
energy += energyHatch.getStoredEU();
maxEnergy += energyHatch.getEUCapacity();
maxEnergyUsage += energyHatch.getInputAmperage() * energyHatch.getInputVoltage();
minEnergyTier = Math.min(minEnergyTier, energyHatch.getInputVoltage());
}

minEnergyTier = minEnergyTier == Long.MAX_VALUE ? 0 : minEnergyTier;

Map<String, String> infoMap = new HashMap<>();
infoMap.put("progressTime", Integer.toString(mProgresstime));
infoMap.put("maxProgressTime", Integer.toString(mMaxProgresstime));
infoMap.put("energy", Long.toString(energy));
infoMap.put("maxEnergy", Long.toString(maxEnergy));
infoMap.put("energyUsage", Long.toString(getActualEnergyUsage()));
infoMap.put("maxEnergyUsage", Long.toString(maxEnergyUsage));
infoMap.put("minEnergyTier", Long.toString(minEnergyTier));
infoMap.put("maintenanceIssues", Integer.toString(getIdealStatus() - getRepairStatus()));
infoMap.put("energyEfficiency", Double.toString(mEfficiency / 10_000F));
infoMap.put("pollution", Double.toString(getAveragePollutionPercentage() / 100F));

return infoMap;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,6 @@ public boolean isGivingInformation() {
return true;
}

@Override
public String[] getInfoData() {
return null;
}

public long getEUVar() {
return this.mStoredEnergy;
}
Expand Down

0 comments on commit 67b5824

Please sign in to comment.