hassansyyid

Powerline

Jul 6th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.43 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 net.minecraft.block.Block;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.network.NetworkManager;
  11. import net.minecraft.network.Packet;
  12. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  13. import net.minecraft.tileentity.TileEntity;
  14. import net.minecraft.world.World;
  15.  
  16. public class TileEntityPowerline extends PoweredTileEntity
  17. {
  18.     public PoweredTileEntity originalpowersource = null;
  19.    
  20.     @Override
  21.     public void updateEntity()
  22.     {
  23.         this.updateState();
  24.     }
  25.    
  26.     @Override
  27.     public void onVoltageTick()
  28.     {
  29.         ;
  30.     }
  31.    
  32.     @Override
  33.     public Packet getDescriptionPacket()
  34.     {
  35.         NBTTagCompound nbtTag = new NBTTagCompound();
  36.         this.writeToNBT(nbtTag);
  37.         return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
  38.     }
  39.  
  40.     @Override
  41.     public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
  42.     {
  43.         this.readFromNBT(packet.func_148857_g());
  44.     }
  45.    
  46.     @Override
  47.     public void writeToNBT(NBTTagCompound nbt)
  48.     {
  49.         super.writeToNBT(nbt);
  50.     }
  51.    
  52.     @Override
  53.     public void readFromNBT(NBTTagCompound nbt)
  54.     {
  55.         super.readFromNBT(nbt);
  56.     }
  57.    
  58.     @Override
  59.     public double getMinOperatingVoltage()
  60.     {
  61.         return 0;
  62.     }
  63.    
  64.     @Override
  65.     public double getMaxOperatingVoltage()
  66.     {
  67.         return 10000;
  68.     }
  69.    
  70.     @Override
  71.     public double getMinOperatingAmps()
  72.     {
  73.         return 0;
  74.     }
  75.    
  76.     @Override
  77.     public double getMaxOperatingAmps()
  78.     {
  79.         return 1000;
  80.     }
  81.    
  82.     @Override
  83.     public double getResistance()
  84.     {
  85.         return 0.002;
  86.     }
  87.    
  88.     @Override
  89.     public boolean canOutputPower()
  90.     {
  91.         return true;
  92.     }
  93.    
  94.     @Override
  95.     public void updateState()
  96.     {
  97.         //Must keep lists empty so we don't have 1 block as a parent AND a child.
  98.         parents.clear();
  99.         children.clear();
  100.         List<PoweredTileEntity> list = new ArrayList<PoweredTileEntity>();
  101.         list.add(this.getTop());
  102.         list.add(this.getBack());
  103.         list.add(this.getBottom());
  104.         list.add(this.getLeft());
  105.         list.add(this.getRight());
  106.         list.add(this.getFront());
  107.         for (PoweredTileEntity te : list) {
  108.             if(te != null){
  109.             //If it's a powersource, then add it.
  110.             if(te.isOutputter() && !te.isReciever())
  111.             {
  112.                 this.parents.add(te);
  113.                 te.children.add(this);
  114.                 if(!this.state)
  115.                 {
  116.                     System.out.println("peoeo");
  117.                     this.state = te.canOutputPower();
  118.                 }
  119.             }
  120.             else if(te.isOutputter() && te.isReciever())
  121.             {
  122.                 //Is the neighbor powered?
  123.                 if(te.state)
  124.                 {
  125.                     try
  126.                     {
  127.                         this.parents.add(te);
  128.                         te.children.add(this);
  129.                         this.state = true;
  130.                     }
  131.                     catch(ConcurrentModificationException e)
  132.                     {
  133.                         //e.printStackTrace();
  134.                     }
  135.                 }
  136.                 else if(this.state && !te.state)
  137.                 {
  138.                     try{
  139.                         this.children.add(te);
  140.                         te.parents.add(this);
  141.                         te.state = true;
  142.                         te.updateChildren();
  143.                     }
  144.                     catch(ConcurrentModificationException e)
  145.                     {
  146.                         //e.printStackTrace();
  147.                     }
  148.                 }
  149.             }
  150.             else if(te.isReciever() && !te.isOutputter())
  151.             {
  152.                 this.children.add(te);
  153.                 te.parents.add(this);
  154.                 te.state = this.state;
  155.             }
  156.         }
  157.         }
  158.     }
  159.    
  160.     @Override
  161.     public Block getBlockType()
  162.     {
  163.         return Blocks.beacon;
  164.     }
  165.  
  166.     @Override
  167.     public void onOverloadTick()
  168.     {
  169.         ;
  170.     }
  171.  
  172.     @Override
  173.     public void onUnderloadTick()
  174.     {
  175.         ;
  176.     }
  177.  
  178.     @Override
  179.     public boolean isOriginalPowerSourceAttached() {
  180.         try{
  181.             PoweredTileEntity t = this.getPowerSource();
  182.             int x = t.xCoord;
  183.             int y = t.yCoord;
  184.             int z = t.zCoord;
  185.             World world = t.getWorldObj();
  186.             if(world.getTileEntity(x, y, z) instanceof TileEntityRepulsionGenerator)
  187.             {
  188.                 return true;
  189.             }
  190.             else if(world.getTileEntity(x, y, z) instanceof TileEntitySolarPanel)
  191.             {
  192.                 return true;
  193.             }
  194.             else if(world.getTileEntity(x, y, z) instanceof TileEntityR2PConvertor)
  195.             {
  196.                 TileEntityR2PConvertor tre = (TileEntityR2PConvertor) world.getTileEntity(x, y, z);
  197.                 if(tre.isActiveRedstoneWireAttached)
  198.                 {
  199.                     return true;
  200.                 }
  201.                 else
  202.                 {
  203.                     return false;
  204.                 }
  205.             }
  206.             else{
  207.                 return false;
  208.             }
  209.         }
  210.         catch(java.lang.NullPointerException e){
  211.             return false;
  212.         }
  213.     }
  214.  
  215.     @Override
  216.     public void getOriginalPowerSource() {
  217. //      List<PoweredTileEntity> list = new ArrayList<PoweredTileEntity>();
  218. //      list.add(this.getTop());
  219. //      list.add(this.getBack());
  220. //      list.add(this.getBottom());
  221. //      list.add(this.getLeft());
  222. //      list.add(this.getRight());
  223. //      list.add(this.getFront());
  224. //          for(PoweredTileEntity p : list){
  225. //              if(p instanceof TileEntityRepulsionGenerator || p instanceof TileEntityPowerline || p instanceof TileEntitySolarPanel || p instanceof TileEntityTransformer || p instanceof TileEntityNegativeTransformer || p instanceof TileEntityR2PConvertor){
  226. //                  if(p instanceof TileEntityRepulsionGenerator){
  227. //                      setOriginalPowerSource(p);
  228. //                      break;
  229. //                  }
  230. //                  if(p instanceof TileEntitySolarPanel){
  231. //                      setOriginalPowerSource(p);
  232. //                      break;
  233. //                  }
  234. //                  if(p instanceof TileEntityR2PConvertor){
  235. //                      setOriginalPowerSource(p);
  236. //                      break;
  237. //                  }
  238. //                  else if(p instanceof TileEntityPowerline && p.getPowerSource() != null){
  239. //                      if(p.getPowerSource() instanceof TileEntityR2PConvertor && this.getPowerSource() == null && this.neighborRemoved)
  240. //                      {
  241. //                          p.setOriginalPowerSource(null);
  242. //                      }
  243. //                      else
  244. //                      {
  245. //                          setOriginalPowerSource(p.getPowerSource());
  246. //                      }
  247. //                      break;
  248. //                  }
  249. //                  else if(p instanceof TileEntityTransformer && p.getPowerSource() != null){
  250. //                      setOriginalPowerSource(p.getPowerSource());
  251. //                      break;
  252. //                  }
  253. //                  else if(p instanceof TileEntityNegativeTransformer && p.getPowerSource() != null){
  254. //                      setOriginalPowerSource(p.getPowerSource());
  255. //                      break;
  256. //                  }
  257. //              }
  258. //             
  259. //          }
  260.     }
  261.    
  262.     @Override
  263.     public void setOriginalPowerSource(PoweredTileEntity e) {
  264.         originalpowersource = e;
  265.     }
  266.     @Override
  267.     public PoweredTileEntity getPowerSource(){
  268.         if(originalpowersource != null){
  269.                 return originalpowersource;
  270.         }
  271.         return null;
  272.     }
  273.  
  274.     @Override
  275.     public boolean isReciever() {
  276.         return true;
  277.     }
  278.  
  279.     @Override
  280.     public boolean isOutputter() {
  281.         return true;
  282.     }
  283.  
  284.     @Override
  285.     public void updateChildren() {
  286.         if(this.children.size() > 0)
  287.         {
  288.             for(PoweredTileEntity te : this.children)
  289.             {
  290.                 te.state = this.state;
  291.                 te.updateChildren();
  292.             }
  293.         }
  294.     }
  295. }
Advertisement
Add Comment
Please, Sign In to add comment