Advertisement
hassansyyid

Untitled

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