content: package com.mekeng.github.common.part;
  
  import appeng.api.config.Upgrades;
  import appeng.api.networking.IGridNode;
  import appeng.api.networking.events.MENetworkChannelsChanged;
  import appeng.api.networking.events.MENetworkEventSubscribe;
  import appeng.api.networking.events.MENetworkPowerStatusChange;
  import appeng.api.networking.ticking.IGridTickable;
  import appeng.api.networking.ticking.TickRateModulation;
  import appeng.api.networking.ticking.TickingRequest;
  import appeng.api.parts.IPartCollisionHelper;
  import appeng.api.parts.IPartHost;
  import appeng.api.parts.IPartModel;
  import appeng.api.storage.IMEMonitor;
  import appeng.api.storage.IStorageChannel;
  import appeng.api.storage.IStorageMonitorable;
  import appeng.api.storage.data.IAEStack;
  import appeng.api.util.AECableType;
  import appeng.api.util.AEPartLocation;
  import appeng.api.util.IConfigManager;
  import appeng.core.sync.GuiBridge;
  import appeng.core.sync.GuiWrapper;
  import appeng.helpers.IPriorityHost;
  import appeng.helpers.Reflected;
  import appeng.items.parts.PartModels;
  import appeng.parts.PartBasicState;
  import appeng.parts.PartModel;
  import appeng.util.Platform;
  import com.mekeng.github.MekEng;
  import com.mekeng.github.common.ItemAndBlocks;
  import com.mekeng.github.common.container.handler.AEGuiBridge;
  import com.mekeng.github.common.container.handler.GuiHandler;
  import com.mekeng.github.common.container.handler.MkEGuis;
  import com.mekeng.github.common.me.duality.IGasInterfaceHost;
  import com.mekeng.github.common.me.duality.impl.DualityGasInterface;
  import com.mekeng.github.common.me.inventory.IConfigurableGasInventory;
  import com.mekeng.github.common.me.inventory.IGasInventory;
  import net.minecraft.entity.player.EntityPlayer;
  import net.minecraft.item.ItemStack;
  import net.minecraft.nbt.NBTTagCompound;
  import net.minecraft.tileentity.TileEntity;
  import net.minecraft.util.EnumFacing;
  import net.minecraft.util.EnumHand;
  import net.minecraft.util.ResourceLocation;
  import net.minecraft.util.math.Vec3d;
  import net.minecraftforge.common.capabilities.Capability;
  import net.minecraftforge.items.IItemHandler;
  
  import javax.annotation.Nonnull;
  import java.util.EnumSet;
  import java.util.List;
  
  public class PartGasInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IGasInterfaceHost, IPriorityHost, IConfigurableGasInventory {
      public static final ResourceLocation MODEL_BASE = new ResourceLocation(MekEng.MODID, "part/gas_interface_base");
  
      @PartModels
      public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(MekEng.MODID, "part/gas_interface_off"));
  
      @PartModels
      public static final PartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(MekEng.MODID, "part/gas_interface_on"));
  
      @PartModels
      public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(MekEng.MODID, "part/gas_interface_has_channel"));
  
      private final DualityGasInterface duality = new DualityGasInterface(this.getProxy(), this);
  
      @Reflected
      public PartGasInterface(final ItemStack is) {
          super(is);
      }
  
      @Override
      public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
          super.setPartHostInfo(side, host, tile);
          this.duality.getTankHandler().setSide(this.getTargets());
      }
  
      @Override
      public DualityGasInterface getDualityGasInterface() {
          return this.duality;
      }
  
      @Override
      @MENetworkEventSubscribe
      public void chanRender(final MENetworkChannelsChanged c) {
          this.duality.notifyNeighbors();
      }
  
      @Override
      @MENetworkEventSubscribe
      public void powerRender(final MENetworkPowerStatusChange c) {
          this.duality.notifyNeighbors();
      }
  
      @Override
      public void getBoxes(final IPartCollisionHelper bch) {
          bch.addBox(2, 2, 14, 14, 14, 16);
          bch.addBox(5, 5, 12, 11, 11, 14);
      }
  
      @Override
      public void gridChanged() {
          this.duality.gridChanged();
      }
  
      @Override
      public void readFromNBT(final NBTTagCompound data) {
          super.readFromNBT(data);
          this.duality.readFromNBT(data);
      }
  
      @Override
      public void writeToNBT(final NBTTagCompound data) {
          super.writeToNBT(data);
          this.duality.writeToNBT(data);
      }
  
      @Override
      public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
          this.duality.addDrops(drops);
      }
  
      @Override
      public float getCableConnectionLength(AECableType cable) {
          return 4;
      }
  
      @Override
      public boolean onPartActivate(final EntityPlayer p, final EnumHand hand, final Vec3d pos) {
          if (Platform.isServer() && this.getActionableNode() != null) {
              GuiHandler.openPartGui(p, this.getTile().getWorld(), this.getTile().getPos(), this.getSide().getFacing(), MkEGuis.GAS_INTERFACE);
          }
          return true;
      }
  
      @Override
      public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
          return this.duality.getInventory(channel);
      }
  
      @Nonnull
      @Override
      public TickingRequest getTickingRequest(@Nonnull final IGridNode node) {
          return this.duality.getTickingRequest(node);
      }
  
      @Nonnull
      @Override
      public TickRateModulation tickingRequest(@Nonnull final IGridNode node, final int ticksSinceLastCall) {
          return this.duality.tickingRequest(node, ticksSinceLastCall);
      }
  
      @Override
      public EnumSet<EnumFacing> getTargets() {
          return EnumSet.of(this.getSide().getFacing());
      }
  
      @Override
      public TileEntity getTileEntity() {
          return super.getHost().getTile();
      }
  
      @Nonnull
      @Override
      public IPartModel getStaticModels() {
          if (this.isActive() && this.isPowered()) {
              return MODELS_HAS_CHANNEL;
          } else if (this.isPowered()) {
              return MODELS_ON;
          } else {
              return MODELS_OFF;
          }
      }
  
      @Override
      public int getPriority() {
          return this.duality.getPriority();
      }
  
      @Override
      public void setPriority(final int newValue) {
          this.duality.setPriority(newValue);
      }
  
      @Override
      public boolean hasCapability(Capability<?> capabilityClass) {
          return this.duality.hasCapability(capabilityClass, this.getSide().getFacing());
      }
  
      @Override
      public <T> T getCapability(Capability<T> capabilityClass) {
          return this.duality.getCapability(capabilityClass, this.getSide().getFacing());
      }
  
      @Override
      public int getInstalledUpgrades(Upgrades u) {
          return this.duality.getInstalledUpgrades(u);
      }
  
      @Override
      public IConfigManager getConfigManager() {
          return this.duality.getConfigManager();
      }
  
      @Override
      public IItemHandler getInventoryByName(String name) {
          return this.duality.getInventoryByName(name);
      }
  
      @Override
      public IGasInventory getGasInventoryByName(final String name) {
          return this.duality.getGasInventoryByName(name);
      }
  
      @Override
      public ItemStack getItemStackRepresentation() {
          return new ItemStack(ItemAndBlocks.GAS_INTERFACE_PART);
      }
  
      @Override
      public GuiBridge getGuiBridge() {
          return GuiWrapper.INSTANCE.wrap(AEGuiBridge.GAS_INTERFACE);
      }
  }
  