content: package com.mekeng.github.common.part;
  
  import appeng.api.config.Settings;
  import appeng.api.config.SortDir;
  import appeng.api.config.SortOrder;
  import appeng.api.config.ViewItems;
  import appeng.api.implementations.tiles.IViewCellStorage;
  import appeng.api.parts.IPartModel;
  import appeng.api.storage.IMEMonitor;
  import appeng.api.storage.IStorageChannel;
  import appeng.api.storage.ITerminalHost;
  import appeng.api.storage.data.IAEStack;
  import appeng.api.util.IConfigManager;
  import appeng.me.GridAccessException;
  import appeng.parts.PartModel;
  import appeng.parts.reporting.AbstractPartDisplay;
  import appeng.tile.inventory.AppEngInternalInventory;
  import appeng.util.ConfigManager;
  import appeng.util.IConfigManagerHost;
  import appeng.util.Platform;
  import appeng.util.inv.IAEAppEngInventory;
  import appeng.util.inv.InvOperation;
  import com.mekeng.github.MekEng;
  import com.mekeng.github.common.container.handler.GuiHandler;
  import com.mekeng.github.common.container.handler.MkEGuis;
  import net.minecraft.entity.player.EntityPlayer;
  import net.minecraft.item.ItemStack;
  import net.minecraft.nbt.NBTTagCompound;
  import net.minecraft.util.EnumHand;
  import net.minecraft.util.ResourceLocation;
  import net.minecraft.util.math.Vec3d;
  import net.minecraftforge.items.IItemHandler;
  
  import javax.annotation.Nonnull;
  import java.util.List;
  
  public class PartGasTerminal extends AbstractPartDisplay implements ITerminalHost, IConfigManagerHost, IViewCellStorage, IAEAppEngInventory {
  
      private final IConfigManager cm = new ConfigManager(this);
      private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5);
      public static final ResourceLocation MODEL_OFF = new ResourceLocation(MekEng.MODID, "part/gas_terminal_off");
      public static final ResourceLocation MODEL_ON = new ResourceLocation(MekEng.MODID, "part/gas_terminal_on");
      public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
      public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
      public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
  
      public PartGasTerminal(final ItemStack is) {
          super(is);
          this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME);
          this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
          this.cm.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
      }
  
      @Override
      public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
          super.getDrops(drops, wrenched);
          for (final ItemStack is : this.viewCell) {
              if (!is.isEmpty()) {
                  drops.add(is);
              }
          }
      }
  
      @Override
      public IConfigManager getConfigManager() {
          return this.cm;
      }
  
      @Override
      public void readFromNBT(final NBTTagCompound data) {
          super.readFromNBT(data);
          this.cm.readFromNBT(data);
          this.viewCell.readFromNBT(data, "viewCell");
      }
  
      @Override
      public void writeToNBT(final NBTTagCompound data) {
          super.writeToNBT(data);
          this.cm.writeToNBT(data);
          this.viewCell.writeToNBT(data, "viewCell");
      }
  
      @Nonnull
      @Override
      public IPartModel getStaticModels() {
          return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
      }
  
      @Override
      public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
          if (!super.onPartActivate(player, hand, pos)) {
              if (Platform.isServer() && this.getActionableNode() != null) {
                  GuiHandler.openPartGui(player, this.getTile().getWorld(), this.getTile().getPos(), this.getSide().getFacing(), MkEGuis.GAS_TERMINAL);
              }
          }
          return true;
      }
  
      @Override
      public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
          try {
              return this.getProxy().getStorage().getInventory(channel);
          } catch (final GridAccessException e) {
              // err nope?
          }
          return null;
      }
  
      @Override
      public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
  
      }
  
      @Override
      public IItemHandler getViewCellStorage() {
          return this.viewCell;
      }
  
      @Override
      public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
          this.getHost().markForSave();
      }
  
  }
  