Advertisement
hassansyyid

TileEntityPowerline

Jul 6th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.88 KB | None | 0 0
  1. package com.arisux.avp.entities.tile;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.init.Blocks;
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.network.NetworkManager;
  10. import net.minecraft.network.Packet;
  11. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.world.World;
  14.  
  15. public class TileEntityPowerline extends PoweredTileEntity
  16. {
  17.     public PoweredTileEntity originalpowersource = null;
  18.     public boolean state;
  19.  
  20.    
  21.     @Override
  22.     public void updateEntity()
  23.     {
  24.         super.updateEntity();
  25.         getOriginalPowerSource();
  26.         updateState();
  27.     }
  28.    
  29.     @Override
  30.     public void onVoltageTick()
  31.     {
  32.         ;
  33.     }
  34.    
  35.     @Override
  36.     public Packet getDescriptionPacket()
  37.     {
  38.         NBTTagCompound nbtTag = new NBTTagCompound();
  39.         this.writeToNBT(nbtTag);
  40.         return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
  41.     }
  42.  
  43.     @Override
  44.     public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
  45.     {
  46.         this.readFromNBT(packet.func_148857_g());
  47.     }
  48.    
  49.     @Override
  50.     public void writeToNBT(NBTTagCompound nbt)
  51.     {
  52.         super.writeToNBT(nbt);
  53.     }
  54.    
  55.     @Override
  56.     public void readFromNBT(NBTTagCompound nbt)
  57.     {
  58.         super.readFromNBT(nbt);
  59.     }
  60.    
  61.     @Override
  62.     public double getMinOperatingVoltage()
  63.     {
  64.         return 0;
  65.     }
  66.    
  67.     @Override
  68.     public double getMaxOperatingVoltage()
  69.     {
  70.         return 10000;
  71.     }
  72.    
  73.     @Override
  74.     public double getMinOperatingAmps()
  75.     {
  76.         return 0;
  77.     }
  78.    
  79.     @Override
  80.     public double getMaxOperatingAmps()
  81.     {
  82.         return 1000;
  83.     }
  84.    
  85.     @Override
  86.     public double getResistance()
  87.     {
  88.         return 0.002;
  89.     }
  90.    
  91.     @Override
  92.     public boolean canOutputPower()
  93.     {
  94.         return true;
  95.     }
  96.    
  97.     public void updateState(){
  98.         try{
  99.             List<PoweredTileEntity> list = new ArrayList<PoweredTileEntity>();
  100.             list.add(this.getTop());
  101.             list.add(this.getBack());
  102.             list.add(this.getBottom());
  103.             list.add(this.getLeft());
  104.             list.add(this.getRight());
  105.             list.add(this.getFront());
  106.             for (int i = 0; i < list.size(); i++) {
  107.                 PoweredTileEntity p = list.get(i);
  108.                 if(p instanceof TileEntityRepulsionGenerator || p instanceof TileEntitySolarPanel || p instanceof TileEntityNegativeTransformer  || p instanceof TileEntityR2PConvertor || p instanceof TileEntityTransformer){
  109.                     state = true;
  110.                     if(p instanceof TileEntityR2PConvertor)
  111.                     {
  112.                         TileEntityR2PConvertor te = (TileEntityR2PConvertor) p;
  113.                         state = te.isActiveRedstoneWireAttached;
  114.                     }
  115.                 }
  116.                 else if(p instanceof TileEntityPowerline)
  117.                 {
  118.                     TileEntityPowerline te = (TileEntityPowerline) p;
  119.                     boolean itsState = te.state;
  120.                     if(itsState == true && this.state == false)
  121.                     {
  122.                         this.state = itsState;
  123.                     }
  124.                     if(itsState == false && this.state == true)
  125.                     {
  126.                         if(this.getPowerSource() instanceof TileEntityR2PConvertor && this.isOriginalPowerSourceAttached())
  127.                         {
  128.                             TileEntityR2PConvertor tre = (TileEntityR2PConvertor) this.getPowerSource();
  129.                             if(tre.isActiveRedstoneWireAttached);
  130.                             else
  131.                             {
  132.                                 this.state = itsState;
  133.                             }
  134.                         }
  135.                         else
  136.                         {
  137.                             this.state = itsState;
  138.                         }
  139.                     }
  140.                 }
  141.             }
  142.         }
  143.         catch(NullPointerException e)
  144.         {
  145.         }
  146.     }
  147.    
  148.     @Override
  149.     public Block getBlockType()
  150.     {
  151.         return Blocks.beacon;
  152.     }
  153.  
  154.     @Override
  155.     public void onOverloadTick()
  156.     {
  157.         ;
  158.     }
  159.  
  160.     @Override
  161.     public void onUnderloadTick()
  162.     {
  163.         ;
  164.     }
  165.  
  166.     @Override
  167.     public boolean isOriginalPowerSourceAttached() {
  168.         try{
  169.             PoweredTileEntity t = this.getPowerSource();
  170.             int x = t.xCoord;
  171.             int y = t.yCoord;
  172.             int z = t.zCoord;
  173.             World world = t.getWorldObj();
  174.             if(world.getTileEntity(x, y, z) instanceof TileEntityRepulsionGenerator)
  175.             {
  176.                 return true;
  177.             }
  178.             else if(world.getTileEntity(x, y, z) instanceof TileEntitySolarPanel)
  179.             {
  180.                 return true;
  181.             }
  182.             else if(world.getTileEntity(x, y, z) instanceof TileEntityR2PConvertor)
  183.             {
  184.                 TileEntityR2PConvertor tre = (TileEntityR2PConvertor) world.getTileEntity(x, y, z);
  185.                 if(tre.isActiveRedstoneWireAttached)
  186.                 {
  187.                     return true;
  188.                 }
  189.                 else
  190.                 {
  191.                     return false;
  192.                 }
  193.             }
  194.             else{
  195.                 return false;
  196.             }
  197.         }
  198.         catch(java.lang.NullPointerException e){
  199.             return false;
  200.         }
  201.     }
  202.  
  203.     @Override
  204.     public void getOriginalPowerSource() {
  205.         List<PoweredTileEntity> list = new ArrayList<PoweredTileEntity>();
  206.         list.add(this.getTop());
  207.         list.add(this.getBack());
  208.         list.add(this.getBottom());
  209.         list.add(this.getLeft());
  210.         list.add(this.getRight());
  211.         list.add(this.getFront());
  212.             for(PoweredTileEntity p : list){
  213.                 if(p instanceof TileEntityRepulsionGenerator || p instanceof TileEntityPowerline || p instanceof TileEntitySolarPanel || p instanceof TileEntityTransformer || p instanceof TileEntityNegativeTransformer || p instanceof TileEntityR2PConvertor){
  214.                     if(p instanceof TileEntityRepulsionGenerator){
  215.                         setOriginalPowerSource(p);
  216.                         break;
  217.                     }
  218.                     if(p instanceof TileEntitySolarPanel){
  219.                         setOriginalPowerSource(p);
  220.                         break;
  221.                     }
  222.                     if(p instanceof TileEntityR2PConvertor){
  223.                         setOriginalPowerSource(p);
  224.                         break;
  225.                     }
  226.                     else if(p instanceof TileEntityPowerline && p.getPowerSource() != null){
  227.                         setOriginalPowerSource(p.getPowerSource());
  228.                         break;
  229.                     }
  230.                     else if(p instanceof TileEntityTransformer && p.getPowerSource() != null){
  231.                         setOriginalPowerSource(p.getPowerSource());
  232.                         break;
  233.                     }
  234.                     else if(p instanceof TileEntityNegativeTransformer && p.getPowerSource() != null){
  235.                         setOriginalPowerSource(p.getPowerSource());
  236.                         break;
  237.                     }
  238.                 }
  239.                
  240.             }
  241.     }
  242.    
  243.     @Override
  244.     public void setOriginalPowerSource(PoweredTileEntity e) {
  245.         originalpowersource = e;   
  246.     }
  247.     @Override
  248.     public PoweredTileEntity getPowerSource(){
  249.         if(originalpowersource != null){
  250.                 return originalpowersource;
  251.         }
  252.         return null;
  253.     }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement