hassansyyid

Untitled

Jul 6th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.31 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.        
  101.         List<PoweredTileEntity> list = new ArrayList<PoweredTileEntity>();
  102.         list.add(this.getTop());
  103.         list.add(this.getBack());
  104.         list.add(this.getBottom());
  105.         list.add(this.getLeft());
  106.         list.add(this.getRight());
  107.         list.add(this.getFront());
  108.         for (PoweredTileEntity te : list) {
  109.             if(te != null){
  110.             //If it's a powersource, then add it.
  111.             if(te.isOutputter() && !te.isReciever())
  112.             {
  113.                 this.parents.add(te);
  114.                 te.children.add(this);
  115.                 if(!this.state)
  116.                 {
  117.                     System.out.println("peoeo");
  118.                     this.state = te.canOutputPower();
  119.                 }
  120.             }
  121.             else if(te.isOutputter() && te.isReciever())
  122.             {
  123.                 //Is the neighbor powered?
  124.                 if(te.state)
  125.                 {
  126.                     try
  127.                     {
  128.                         this.parents.add(te);
  129.                         te.children.add(this);
  130.                         this.state = true;
  131.                         te.updateChildren();
  132.                     }
  133.                     catch(ConcurrentModificationException e)
  134.                     {
  135.                         System.out.println("Hello world.");
  136.                     }
  137.                 }
  138.                 else if(this.state && !te.state)
  139.                 {
  140.                     try{
  141.                         this.children.add(te);
  142.                         te.parents.add(this);
  143.                         te.state = true;
  144.                         te.updateChildren();
  145.                     }
  146.                     catch(ConcurrentModificationException e)
  147.                     {
  148.                         System.out.println("Hello world.");
  149.                     }
  150.                 }
  151.             }
  152.             else if(te.isReciever() && !te.isOutputter())
  153.             {
  154.                 this.children.add(te);
  155.                 te.parents.add(this);
  156.                 te.state = this.state;
  157.                 te.updateChildren();
  158.             }
  159.         }
  160.         }
  161.     }
  162.    
  163.     @Override
  164.     public Block getBlockType()
  165.     {
  166.         return Blocks.beacon;
  167.     }
  168.  
  169.     @Override
  170.     public void onOverloadTick()
  171.     {
  172.         ;
  173.     }
  174.  
  175.     @Override
  176.     public void onUnderloadTick()
  177.     {
  178.         ;
  179.     }
  180.  
  181.     @Override
  182.     public boolean isOriginalPowerSourceAttached() {
  183.         try{
  184.             PoweredTileEntity t = this.getPowerSource();
  185.             int x = t.xCoord;
  186.             int y = t.yCoord;
  187.             int z = t.zCoord;
  188.             World world = t.getWorldObj();
  189.             if(world.getTileEntity(x, y, z) instanceof TileEntityRepulsionGenerator)
  190.             {
  191.                 return true;
  192.             }
  193.             else if(world.getTileEntity(x, y, z) instanceof TileEntitySolarPanel)
  194.             {
  195.                 return true;
  196.             }
  197.             else if(world.getTileEntity(x, y, z) instanceof TileEntityR2PConvertor)
  198.             {
  199.                 TileEntityR2PConvertor tre = (TileEntityR2PConvertor) world.getTileEntity(x, y, z);
  200.                 if(tre.isActiveRedstoneWireAttached)
  201.                 {
  202.                     return true;
  203.                 }
  204.                 else
  205.                 {
  206.                     return false;
  207.                 }
  208.             }
  209.             else{
  210.                 return false;
  211.             }
  212.         }
  213.         catch(java.lang.NullPointerException e){
  214.             return false;
  215.         }
  216.     }
  217.  
  218.     @Override
  219.     public void getOriginalPowerSource() {
  220. //      List<PoweredTileEntity> list = new ArrayList<PoweredTileEntity>();
  221. //      list.add(this.getTop());
  222. //      list.add(this.getBack());
  223. //      list.add(this.getBottom());
  224. //      list.add(this.getLeft());
  225. //      list.add(this.getRight());
  226. //      list.add(this.getFront());
  227. //          for(PoweredTileEntity p : list){
  228. //              if(p instanceof TileEntityRepulsionGenerator || p instanceof TileEntityPowerline || p instanceof TileEntitySolarPanel || p instanceof TileEntityTransformer || p instanceof TileEntityNegativeTransformer || p instanceof TileEntityR2PConvertor){
  229. //                  if(p instanceof TileEntityRepulsionGenerator){
  230. //                      setOriginalPowerSource(p);
  231. //                      break;
  232. //                  }
  233. //                  if(p instanceof TileEntitySolarPanel){
  234. //                      setOriginalPowerSource(p);
  235. //                      break;
  236. //                  }
  237. //                  if(p instanceof TileEntityR2PConvertor){
  238. //                      setOriginalPowerSource(p);
  239. //                      break;
  240. //                  }
  241. //                  else if(p instanceof TileEntityPowerline && p.getPowerSource() != null){
  242. //                      if(p.getPowerSource() instanceof TileEntityR2PConvertor && this.getPowerSource() == null && this.neighborRemoved)
  243. //                      {
  244. //                          p.setOriginalPowerSource(null);
  245. //                      }
  246. //                      else
  247. //                      {
  248. //                          setOriginalPowerSource(p.getPowerSource());
  249. //                      }
  250. //                      break;
  251. //                  }
  252. //                  else if(p instanceof TileEntityTransformer && p.getPowerSource() != null){
  253. //                      setOriginalPowerSource(p.getPowerSource());
  254. //                      break;
  255. //                  }
  256. //                  else if(p instanceof TileEntityNegativeTransformer && p.getPowerSource() != null){
  257. //                      setOriginalPowerSource(p.getPowerSource());
  258. //                      break;
  259. //                  }
  260. //              }
  261. //             
  262. //          }
  263.     }
  264.    
  265.     @Override
  266.     public void setOriginalPowerSource(PoweredTileEntity e) {
  267.         originalpowersource = e;
  268.     }
  269.     @Override
  270.     public PoweredTileEntity getPowerSource(){
  271.         if(originalpowersource != null){
  272.                 return originalpowersource;
  273.         }
  274.         return null;
  275.     }
  276.  
  277.     @Override
  278.     public boolean isReciever() {
  279.         return true;
  280.     }
  281.  
  282.     @Override
  283.     public boolean isOutputter() {
  284.         return true;
  285.     }
  286. }
Advertisement
Add Comment
Please, Sign In to add comment