add The One Probe provider for gas tanks

This commit is contained in:
Xander Victory committed 2017-11-10 15:24:20 +08:00
1 parent a86539f1a0
commit 7fa325bc03
4 files changed
+66

No files matched your search

@@ -799,6 +799,9 @@ public class Mekanism
//Integrate with Waila
FMLInterModComms.sendMessage(MekanismHooks.WAILA_MOD_ID, "register", "mekanism.common.integration.WailaDataProvider.register");
//Register TOP handler
FMLInterModComms.sendFunctionMessage("theoneprobe", "getTheOneProbe", "mekanism.common.integration.TOPProvider");
//Integrate with OpenComputers
if(Loader.isModLoaded(MekanismHooks.OPENCOMPUTERS_MOD_ID))
{
@@ -0,0 +1,61 @@
package mekanism.common.integration;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.IProbeInfoProvider;
import mcjty.theoneprobe.api.IProgressStyle;
import mcjty.theoneprobe.api.ITheOneProbe;
import mcjty.theoneprobe.api.ProbeMode;
import mcjty.theoneprobe.api.TextStyleClass;
import mekanism.api.gas.GasTankInfo;
import mekanism.api.gas.IGasHandler;
import mekanism.common.capabilities.Capabilities;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.util.function.Function;
@SuppressWarnings("unused")//IMC bound
public class TOPProvider implements Function<ITheOneProbe, Void>, IProbeInfoProvider
{
@Override
public Void apply(ITheOneProbe iTheOneProbe)
{
iTheOneProbe.registerProvider(this);
return null;
}
@Override
public String getID()
{
return "mekanism";
}
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data)
{
if (mode != ProbeMode.EXTENDED){
return;
}
final TileEntity tile = world.getTileEntity( data.getPos() );
if (tile != null){
if (tile.hasCapability(Capabilities.GAS_HANDLER_CAPABILITY, null)){
IGasHandler handler = tile.getCapability(Capabilities.GAS_HANDLER_CAPABILITY, null);
if (handler != null){
GasTankInfo[] tanks = handler.getTankInfo();
for (GasTankInfo tank : tanks){
if (tank.getGas() != null){
probeInfo.text(TextStyleClass.NAME + "Gas: " + tank.getGas().getGas().getLocalizedName());
}
IProgressStyle style = probeInfo.defaultProgressStyle().suffix("mB");
probeInfo.progress(tank.getStored(), tank.getMaxGas(), style);
}
}
}
}
}
}