content: package mods.eln.sixnode.electricalsource;
  
  import mods.eln.Eln;
  import mods.eln.i18n.I18N;
  import mods.eln.item.IConfigurable;
  import mods.eln.misc.Direction;
  import mods.eln.misc.LRDU;
  import mods.eln.misc.Utils;
  import mods.eln.node.NodeBase;
  import mods.eln.node.six.SixNode;
  import mods.eln.node.six.SixNodeDescriptor;
  import mods.eln.node.six.SixNodeElement;
  import mods.eln.sim.ElectricalLoad;
  import mods.eln.sim.ThermalLoad;
  import mods.eln.sim.mna.component.VoltageSource;
  import mods.eln.sim.nbt.NbtElectricalLoad;
  import net.minecraft.entity.player.EntityPlayer;
  import net.minecraft.nbt.NBTTagCompound;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
  
  import java.io.DataInputStream;
  import java.io.DataOutputStream;
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  
  public class ElectricalSourceElement extends SixNodeElement implements IConfigurable {
  
      NbtElectricalLoad electricalLoad = new NbtElectricalLoad("electricalLoad");
      VoltageSource voltageSource = new VoltageSource("voltSrc", electricalLoad, null);
  
      public static final int setVoltageId = 1;
  
      public ElectricalSourceElement(SixNode sixNode, Direction side, SixNodeDescriptor descriptor) {
          super(sixNode, side, descriptor);
          electricalLoadList.add(electricalLoad);
          electricalComponentList.add(voltageSource);
      }
  
      @Override
      public void readFromNBT(@NotNull NBTTagCompound nbt) {
          super.readFromNBT(nbt);
          voltageSource.setVoltage(nbt.getDouble("voltage"));
      }
  
      public static boolean canBePlacedOnSide(Direction side, int type) {
          return true;
      }
  
      @Override
      public void writeToNBT(NBTTagCompound nbt) {
          super.writeToNBT(nbt);
          nbt.setDouble("voltage", voltageSource.getVoltage());
      }
  
      @Override
      public ElectricalLoad getElectricalLoad(LRDU lrdu, int mask) {
          return electricalLoad;
      }
  
      @Nullable
      @Override
      public ThermalLoad getThermalLoad(@NotNull LRDU lrdu, int mask) {
          return null;
      }
  
      @Override
      public int getConnectionMask(LRDU lrdu) {
          if (((ElectricalSourceDescriptor) sixNodeElementDescriptor).isSignalSource()) {
              return NodeBase.maskElectricalGate;
          } else {
              return NodeBase.maskElectricalPower;
          }
      }
  
      @Override
      public String multiMeterString() {
          return Utils.plotUIP(electricalLoad.getVoltage(), voltageSource.getCurrent());
      }
  
      @NotNull
      @Override
      public Map<String, String> getWaila() {
          Map<String, String> info = new HashMap<String, String>();
          info.put(I18N.tr("Voltage"), Utils.plotVolt("", electricalLoad.getVoltage()));
          info.put(I18N.tr("Current"), Utils.plotAmpere("", electricalLoad.getCurrent()));
          if (Eln.wailaEasyMode) {
              info.put(I18N.tr("Power"), Utils.plotPower("", electricalLoad.getVoltage() * electricalLoad.getCurrent()));
          }
          return info;
      }
  
      @NotNull
      @Override
      public String thermoMeterString() {
          return "";
      }
  
      @Override
      public void networkSerialize(DataOutputStream stream) {
          super.networkSerialize(stream);
          try {
              stream.writeFloat((float) voltageSource.getVoltage());
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @Override
      public void initialize() {
          Eln.applySmallRs(electricalLoad);
      }
  
      @Override
      public boolean onBlockActivated(EntityPlayer entityPlayer, Direction side, float vx, float vy, float vz) {
          return onBlockActivatedRotate(entityPlayer);
      }
  
      @Override
      public void networkUnserialize(DataInputStream stream) {
          super.networkUnserialize(stream);
          try {
              switch (stream.readByte()) {
                  case setVoltageId:
                      voltageSource.setVoltage(stream.readFloat());
                      needPublish();
                      break;
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @Override
      public boolean hasGui() {
          return true;
      }
  
      @Override
      public void readConfigTool(NBTTagCompound compound, EntityPlayer invoker) {
          if(compound.hasKey("voltage")) {
              voltageSource.setVoltage(compound.getDouble("voltage"));
              needPublish();
          }
      }
  
      @Override
      public void writeConfigTool(NBTTagCompound compound, EntityPlayer invoker) {
          compound.setDouble("voltage", voltageSource.getVoltage());
      }
  }
  