Advertisement
hassansyyid

Untitled

Jul 7th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.03 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.             this.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.                 ier.receiveEnergy(dir, 120, false);
  46.             }
  47.         }
  48.     }
  49.    
  50.     public boolean isAdjacentToPowerSource() {
  51.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  52.         {
  53.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord);
  54.             if(te.storage.getEnergyStored() > 0)
  55.             {
  56.                 return true;
  57.             }
  58.             return false;
  59.         }
  60.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityPowerline)
  61.         {
  62.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord);
  63.             if(te.storage.getEnergyStored() > 0)
  64.             {
  65.                 return true;
  66.             }
  67.             return false;
  68.         }
  69.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityPowerline)
  70.         {
  71.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
  72.             if(te.storage.getEnergyStored() > 0)
  73.             {
  74.                 return true;
  75.             }
  76.             return false;
  77.         }
  78.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityPowerline)
  79.         {
  80.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
  81.             if(te.storage.getEnergyStored() > 0)
  82.             {
  83.                 return true;
  84.             }
  85.             return false;
  86.         }
  87.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityPowerline)
  88.         {
  89.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1);
  90.             if(te.storage.getEnergyStored() > 0)
  91.             {
  92.                 return true;
  93.             }
  94.             return false;
  95.         }
  96.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityPowerline)
  97.         {
  98.             TileEntityPowerline te = (TileEntityPowerline) this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1);
  99.             if(te.storage.getEnergyStored() > 0)
  100.             {
  101.                 return true;
  102.             }
  103.             return false;
  104.         }
  105.         if(this.getWorldObj().getTileEntity(this.xCoord + 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  106.         {
  107.             return true;
  108.         }
  109.         if(this.getWorldObj().getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord) instanceof TileEntityRepulsionGenerator)
  110.         {
  111.             return true;
  112.         }
  113.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  114.         {
  115.             return true;
  116.         }
  117.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord) instanceof TileEntityRepulsionGenerator)
  118.         {
  119.             return true;
  120.         }
  121.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord + 1) instanceof TileEntityRepulsionGenerator)
  122.         {
  123.             return true;
  124.         }
  125.         if(this.getWorldObj().getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1) instanceof TileEntityRepulsionGenerator)
  126.         {
  127.             return true;
  128.         }
  129.         return false;
  130.     }
  131.    
  132.     @Override
  133.     public boolean canConnectEnergy(ForgeDirection from) {
  134.         return true;
  135.     }
  136.  
  137.     @Override
  138.     public int receiveEnergy(ForgeDirection from, int maxReceive,
  139.             boolean simulate) {
  140.         return storage.receiveEnergy(maxReceive, simulate);
  141.     }
  142.  
  143.     @Override
  144.     public int extractEnergy(ForgeDirection from, int maxExtract,
  145.             boolean simulate) {
  146.         return storage.extractEnergy(maxExtract, simulate);
  147.     }
  148.  
  149.     @Override
  150.     public int getEnergyStored(ForgeDirection from) {
  151.         return storage.getEnergyStored();
  152.     }
  153.  
  154.     @Override
  155.     public int getMaxEnergyStored(ForgeDirection from) {
  156.         return storage.getMaxEnergyStored();
  157.     }
  158.    
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement