Advertisement
hassansyyid

Untitled

Jul 7th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.26 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.HashSet;
  7. import java.util.List;
  8. import java.util.Set;
  9.  
  10. import cofh.api.energy.EnergyStorage;
  11. import cofh.api.energy.IEnergyProvider;
  12. import cofh.api.energy.IEnergyReceiver;
  13. import net.minecraft.block.Block;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.nbt.NBTTagCompound;
  16. import net.minecraft.network.NetworkManager;
  17. import net.minecraft.network.Packet;
  18. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  19. import net.minecraft.tileentity.TileEntity;
  20. import net.minecraft.world.World;
  21. import net.minecraftforge.common.util.ForgeDirection;
  22.  
  23. public class TileEntityPowerline extends TileEntity implements IEnergyProvider, IEnergyReceiver
  24. {
  25.     public int voltage;
  26.     public boolean turnOff = true;
  27.     public Set<ForgeDirection> d = new HashSet<ForgeDirection>();
  28.  
  29.     @Override
  30.     public void updateEntity()
  31.     {
  32.         if(!this.isAdjacentToPowerSource())
  33.         {
  34.             this.voltage = 0;
  35.         }
  36.         if(turnOff)
  37.         {
  38.             this.voltage = 0;
  39.         }
  40.         turnOff = true;
  41.     }
  42.  
  43.     public void pushEnergy()
  44.     {
  45.         for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
  46.         {
  47.             if(d.contains(dir))
  48.             {      
  49.                 continue;
  50.             }
  51.             TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
  52.             if(tile != null)
  53.             {
  54.                 if(tile instanceof TileEntityPowerline)
  55.                 {
  56.                     TileEntityPowerline tep = (TileEntityPowerline) tile;
  57.                     if(tep.voltage > 0)
  58.                     {
  59.                         d.add(dir);
  60.                         continue;
  61.                     }
  62.                 }
  63.                 if (tile instanceof IEnergyReceiver)
  64.                 {
  65.                     IEnergyReceiver ier = (IEnergyReceiver) tile;
  66.                     ier.receiveEnergy(dir, 120, false);
  67.                 }
  68.             }
  69.         }
  70.     }
  71.  
  72.     public boolean isAdjacentToPowerSource() {
  73.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  74.         {
  75.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
  76.             if(te.voltage > 0)
  77.             {
  78.                 return true;
  79.             }
  80.             return false;
  81.         }
  82.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  83.         {
  84.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord);
  85.             if(te.voltage > 0)
  86.             {
  87.                 return true;
  88.             }
  89.             return false;
  90.         }
  91.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityPowerline)
  92.         {
  93.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
  94.             if(te.voltage > 0)
  95.             {
  96.                 return true;
  97.             }
  98.             return false;
  99.         }
  100.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityPowerline)
  101.         {
  102.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
  103.             if(te.voltage > 0)
  104.             {
  105.                 return true;
  106.             }
  107.             return false;
  108.         }
  109.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityPowerline)
  110.         {
  111.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
  112.             if(te.voltage > 0)
  113.             {
  114.                 return true;
  115.             }
  116.             return false;
  117.         }
  118.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityPowerline)
  119.         {
  120.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1);
  121.             if(te.voltage > 0)
  122.             {
  123.                 return true;
  124.             }
  125.             return false;
  126.         }
  127.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  128.         {
  129.             return true;
  130.         }
  131.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  132.         {
  133.             return true;
  134.         }
  135.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  136.         {
  137.             return true;
  138.         }
  139.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  140.         {
  141.             return true;
  142.         }
  143.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityRepulsionGenerator)
  144.         {
  145.             return true;
  146.         }
  147.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityRepulsionGenerator)
  148.         {
  149.             return true;
  150.         }
  151.  
  152.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntitySolarPanel)
  153.         {
  154.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
  155.             if(te.canOutputPower())
  156.             {
  157.                 return true;
  158.             }
  159.             return false;
  160.         }
  161.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntitySolarPanel)
  162.         {
  163.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord);
  164.             if(te.canOutputPower())
  165.             {
  166.                 return true;
  167.             }
  168.             return false;
  169.         }
  170.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntitySolarPanel)
  171.         {
  172.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
  173.             if(te.canOutputPower())
  174.             {
  175.                 return true;
  176.             }
  177.             return false;
  178.         }
  179.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntitySolarPanel)
  180.         {
  181.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
  182.             if(te.canOutputPower())
  183.             {
  184.                 return true;
  185.             }
  186.             return false;
  187.         }
  188.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntitySolarPanel)
  189.         {
  190.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
  191.             if(te.canOutputPower())
  192.             {
  193.                 return true;
  194.             }
  195.             return false;
  196.         }
  197.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntitySolarPanel)
  198.         {
  199.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1);
  200.             if(te.canOutputPower())
  201.             {
  202.                 return true;
  203.             }
  204.             return false;
  205.         }
  206.  
  207.         return false;
  208.     }
  209.  
  210.     @Override
  211.     public boolean canConnectEnergy(ForgeDirection from)
  212.     {
  213.         return true;
  214.     }
  215.  
  216.     @Override
  217.     public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
  218.     {
  219.         d.add(from.getOpposite());
  220.         pushEnergy();
  221.         if(turnOff)
  222.         {
  223.             turnOff = false;
  224.         }
  225.         return this.voltage = maxReceive;
  226.     }
  227.  
  228.     @Override
  229.     public int extractEnergy(ForgeDirection from, int maxExtract,
  230.             boolean simulate) {
  231.         if(maxExtract < this.voltage)
  232.         {
  233.             return maxExtract;
  234.         }
  235.         else
  236.         {
  237.             return this.voltage;
  238.         }
  239.     }
  240.  
  241.     @Override
  242.     public int getEnergyStored(ForgeDirection from) {
  243.         return this.voltage;
  244.     }
  245.  
  246.     @Override
  247.     public int getMaxEnergyStored(ForgeDirection from) {
  248.         return 10000;
  249.     }
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement