Advertisement
hassansyyid

TileEntityPowerline

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