Advertisement
hassansyyid

Untitled

Jul 7th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.07 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 IEnergyReceiver)
  55.                 {
  56.                     IEnergyReceiver ier = (IEnergyReceiver) tile;
  57.                     ier.receiveEnergy(dir, 120, false);
  58.                 }
  59.             }
  60.         }
  61.     }
  62.  
  63.     public boolean isAdjacentToPowerSource() {
  64.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  65.         {
  66.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
  67.             if(te.voltage > 0)
  68.             {
  69.                 return true;
  70.             }
  71.             return false;
  72.         }
  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, this.yCoord + 1, this.zCoord) instanceof TileEntityPowerline)
  83.         {
  84.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, 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, this.zCoord + 1) instanceof TileEntityPowerline)
  101.         {
  102.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
  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 + 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  119.         {
  120.             return true;
  121.         }
  122.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  123.         {
  124.             return true;
  125.         }
  126.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  127.         {
  128.             return true;
  129.         }
  130.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  131.         {
  132.             return true;
  133.         }
  134.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityRepulsionGenerator)
  135.         {
  136.             return true;
  137.         }
  138.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityRepulsionGenerator)
  139.         {
  140.             return true;
  141.         }
  142.  
  143.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntitySolarPanel)
  144.         {
  145.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
  146.             if(te.canOutputPower())
  147.             {
  148.                 return true;
  149.             }
  150.             return false;
  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, this.yCoord + 1, this.zCoord) instanceof TileEntitySolarPanel)
  162.         {
  163.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, 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, this.zCoord + 1) instanceof TileEntitySolarPanel)
  180.         {
  181.             TileEntitySolarPanel te = (TileEntitySolarPanel) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
  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.  
  198.         return false;
  199.     }
  200.  
  201.     @Override
  202.     public boolean canConnectEnergy(ForgeDirection from)
  203.     {
  204.         return true;
  205.     }
  206.  
  207.     @Override
  208.     public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
  209.     {
  210.         d.add(from.getOpposite());
  211.         pushEnergy();
  212.         if(turnOff)
  213.         {
  214.             turnOff = false;
  215.         }
  216.         return this.voltage = maxReceive;
  217.     }
  218.  
  219.     @Override
  220.     public int extractEnergy(ForgeDirection from, int maxExtract,
  221.             boolean simulate) {
  222.         if(maxExtract < this.voltage)
  223.         {
  224.             return maxExtract;
  225.         }
  226.         else
  227.         {
  228.             return this.voltage;
  229.         }
  230.     }
  231.  
  232.     @Override
  233.     public int getEnergyStored(ForgeDirection from) {
  234.         return this.voltage;
  235.     }
  236.  
  237.     @Override
  238.     public int getMaxEnergyStored(ForgeDirection from) {
  239.         return 10000;
  240.     }
  241.  
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement