Advertisement
hassansyyid

Untitled

Jul 7th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.53 KB | None | 0 0
  1. package com.arisux.avp.entities.tile;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.ConcurrentModificationException;
  5. import java.util.EnumMap;
  6. import java.util.List;
  7.  
  8. import cofh.api.energy.EnergyStorage;
  9. import cofh.api.energy.IEnergyProvider;
  10. import cofh.api.energy.IEnergyReceiver;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.network.NetworkManager;
  15. import net.minecraft.network.Packet;
  16. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.common.util.ForgeDirection;
  20.  
  21. public class TileEntityPowerline extends TileEntity implements IEnergyProvider, IEnergyReceiver
  22. {
  23.     public EnergyStorage storage = new EnergyStorage(10000);
  24.     public EnumMap<ForgeDirection, Boolean> directionMap = new EnumMap<ForgeDirection, Boolean>(ForgeDirection.class);
  25.  
  26.     public TileEntityPowerline()
  27.     {
  28.         for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
  29.         {
  30.             directionMap.put(direction, false);
  31.         }
  32.     }
  33.     @Override
  34.     public void updateEntity()
  35.     {
  36.         if (!worldObj.isRemote)
  37.         {
  38.             //          if(!this.isAdjacentToPowerSource())
  39.             //          {
  40.             //              this.storage.setEnergyStored(0);
  41.             //          }
  42.             pushEnergy();
  43.         }
  44.     }
  45.  
  46.     public void pushEnergy()
  47.     {
  48.         for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
  49.         {
  50.             TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
  51.             if(tile != null)
  52.             {
  53.                 if (tile instanceof IEnergyReceiver)
  54.                 {
  55. //                  if(!directionMap.get(dir))
  56. //                  {
  57.                         if(!worldObj.isRemote)
  58.                         {
  59.                             IEnergyReceiver ier = (IEnergyReceiver) tile;
  60.                             ier.receiveEnergy(dir, 120, false);
  61.                             //storage.extractEnergy(ier.receiveEnergy(dir, storage.extractEnergy(10, true), false), false);
  62.                         }
  63. //                  }
  64.                 }
  65.             }
  66.         }
  67.     }
  68.  
  69.     public boolean isAdjacentToPowerSource() {
  70.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  71.         {
  72.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
  73.             if(te.storage.getEnergyStored() > 0)
  74.             {
  75.                 return true;
  76.             }
  77.             return false;
  78.         }
  79.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  80.         {
  81.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord);
  82.             if(te.storage.getEnergyStored() > 0)
  83.             {
  84.                 return true;
  85.             }
  86.             return false;
  87.         }
  88.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityPowerline)
  89.         {
  90.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
  91.             if(te.storage.getEnergyStored() > 0)
  92.             {
  93.                 return true;
  94.             }
  95.             return false;
  96.         }
  97.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityPowerline)
  98.         {
  99.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
  100.             if(te.storage.getEnergyStored() > 0)
  101.             {
  102.                 return true;
  103.             }
  104.             return false;
  105.         }
  106.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityPowerline)
  107.         {
  108.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
  109.             if(te.storage.getEnergyStored() > 0)
  110.             {
  111.                 return true;
  112.             }
  113.             return false;
  114.         }
  115.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityPowerline)
  116.         {
  117.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1);
  118.             if(te.storage.getEnergyStored() > 0)
  119.             {
  120.                 return true;
  121.             }
  122.             return false;
  123.         }
  124.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  125.         {
  126.             return true;
  127.         }
  128.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  129.         {
  130.             return true;
  131.         }
  132.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  133.         {
  134.             return true;
  135.         }
  136.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  137.         {
  138.             return true;
  139.         }
  140.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityRepulsionGenerator)
  141.         {
  142.             return true;
  143.         }
  144.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityRepulsionGenerator)
  145.         {
  146.             return true;
  147.         }
  148.         return false;
  149.     }
  150.  
  151.     @Override
  152.     public boolean canConnectEnergy(ForgeDirection from)
  153.     {
  154.         return true;
  155.     }
  156.  
  157.     @Override
  158.     public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
  159.     {
  160.         this.directionMap.put(from.getOpposite(), true);
  161.  
  162.         return storage.receiveEnergy(maxReceive, simulate);
  163.     }
  164.  
  165.     @Override
  166.     public int extractEnergy(ForgeDirection from, int maxExtract,
  167.             boolean simulate) {
  168.         return storage.extractEnergy(maxExtract, simulate);
  169.     }
  170.  
  171.     @Override
  172.     public int getEnergyStored(ForgeDirection from) {
  173.         return storage.getEnergyStored();
  174.     }
  175.  
  176.     @Override
  177.     public int getMaxEnergyStored(ForgeDirection from) {
  178.         return storage.getMaxEnergyStored();
  179.     }
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement