Advertisement
TechMage66

SocketCrystal_Update

Aug 20th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.22 KB | None | 0 0
  1. @Override
  2.     public void update()
  3.     {
  4.         boolean needInfusingUpdate = false;
  5.  
  6.         // Client - Only Actions
  7.         if (this.worldObj.isRemote)
  8.         {
  9.             // If Infusing spawn Runes
  10.             if (this.isInfusing)
  11.             {
  12.                 if (worldObj.rand.nextInt(20) == 0)
  13.                     MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
  14.                             pos.getZ() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
  15.  
  16.                 if (worldObj.rand.nextInt(20) == 0)
  17.                     MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
  18.                             pos.getZ() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
  19.  
  20.                 if (worldObj.rand.nextInt(20) == 0)
  21.                     MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
  22.                             pos.getZ() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
  23.  
  24.                 if (worldObj.rand.nextInt(20) == 0)
  25.                     MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
  26.                             pos.getZ() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
  27.             }
  28.         }
  29.  
  30.         // Server - Only Actions
  31.         else
  32.         {
  33.             // Check if ActiveInfuser and Place, else disableInfuser
  34.             if (this.isActiveInfuser && !hasFlat7x7())
  35.             {
  36.                 this.isActiveInfuser = false;
  37.                 this.isInfusing = false;
  38.  
  39.                 needInfusingUpdate = true;
  40.             }
  41.  
  42.             // Check if ActiveInfuser and EmptyCrystal else stop process
  43.             if (this.isActiveInfuser && (!hasCrystal() || getCrystal() != MageTechItems.crystal_Empty))
  44.             {
  45.                 this.isInfusing = false;
  46.  
  47.                 needInfusingUpdate = true;
  48.             }
  49.  
  50.             // Check if ActiveInfuser and has EmptyCrystal
  51.             if (this.isActiveInfuser() && this.hasCrystal() && this.getCrystal() == MageTechItems.crystal_Empty)
  52.             {
  53.                 // Get all ItemEntities in Range of the Infuser
  54.                 List nearItems = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.fromBounds
  55.                         (this.pos.getX() - 3, this.pos.getY(), this.pos.getZ() - 3, this.pos.getX() + 3, this.pos.getY() + 1, this.pos.getZ() + 3));
  56.  
  57.                 // Check for available InfusionRecipes and set craftingResults
  58.                 if (nearItems.size() > 0 && RecipesCrystalInfuser.infusing().hasCraftingResult(nearItems))
  59.                     this.craftingResults = RecipesCrystalInfuser.infusing().getCraftingResults(nearItems);
  60.  
  61.                 else
  62.                     this.craftingResults = null;
  63.  
  64.                 // Check for craftingResults
  65.                 if (this.craftingResults != null)
  66.                 {
  67.                     // Has EssenceProvider
  68.                     if (this.essenceProvider != null)
  69.                     {
  70.                         // EssenceProvider empty ... find new one if possible
  71.                         if (((IEssenceProvider) this.essenceProvider).getRemainingEssence(getNeededEssenceForInfusion(this.currentResult).getEssence()) == 0)
  72.                             this.essenceProvider = EssenceSystem.getClosestEssenceProvider(this, getNeededEssenceForInfusion(this.currentResult).getEssence());
  73.  
  74.                         // Checks if status of isInfusing will change ... update?
  75.                         boolean hasProvider = this.essenceProvider != null;
  76.  
  77.                         if (this.isInfusing != hasProvider)
  78.                             needInfusingUpdate = true;
  79.  
  80.                         // Set isInfusing true if has EssenceProvider
  81.                         this.isInfusing = this.essenceProvider != null;
  82.                     }
  83.  
  84.                     // Has no EssenceProvider
  85.                     else
  86.                     {
  87.                         // No Infusion "In Progress"
  88.                         if (this.drainedEssence == 0)
  89.                         {
  90.                             // CurrentResult is last Result in list ...
  91.                             if (this.currentResult == this.craftingResults.get(this.craftingResults.size() - 1))
  92.                             {
  93.                                 // Wait a short delay and then reset CurrentResult
  94.                                 this.providerSearchDelay ++;
  95.  
  96.                                 if (this.providerSearchDelay == 10)
  97.                                 {
  98.                                     this.providerSearchDelay = 0;
  99.                                     this.currentResult = null;
  100.                                 }
  101.                             }
  102.  
  103.                             // CurrentResult is not last Result, try to find a EssenceProvider for one of the other available Infusions
  104.                             while (RecipesCrystalInfuser.infusing().getNextCraftingResult(this.craftingResults, this.currentResult) != null)
  105.                             {
  106.                                 this.currentResult = RecipesCrystalInfuser.infusing().getNextCraftingResult(this.craftingResults, this.currentResult);
  107.                                 this.essenceProvider = EssenceSystem.getClosestEssenceProvider(this, getNeededEssenceForInfusion(this.currentResult).getEssence());
  108.  
  109.                                 if (this.essenceProvider != null)
  110.                                     break;
  111.                             }
  112.                         }
  113.  
  114.                         // Still Infusion "In Progress"
  115.                         else
  116.                         {
  117.                             // Wait a short delay and then search for new EssenceProvider
  118.                             this.providerSearchDelay ++;
  119.  
  120.                             if (this.providerSearchDelay == 10)
  121.                             {
  122.                                 this.providerSearchDelay = 0;
  123.                                 this.essenceProvider = EssenceSystem.getClosestEssenceProvider(this, getNeededEssenceForInfusion(this.currentResult).getEssence());
  124.                             }
  125.                         }
  126.  
  127.                         // Checks if status of isInfusing will change ... update?
  128.                         boolean hasProvider = this.essenceProvider != null;
  129.  
  130.                         if (this.isInfusing != hasProvider)
  131.                             needInfusingUpdate = true;
  132.  
  133.                         // Set isInfusing true if has EssenceProvider
  134.                         this.isInfusing = this.essenceProvider != null;
  135.                     }
  136.                 }
  137.  
  138.                 // Update the state of IsInfusing on the Client (For Rendering)
  139.                 if (needInfusingUpdate)
  140.                     ServerClientSyncHelper.synchSocketCrystalIsInfusing(this, this.isInfusing);
  141.             }
  142.  
  143.             // If ActiveInfuser, isInfusing and has EssenceProvider
  144.             if (this.isActiveInfuser && this.isInfusing && this.essenceProvider != null)
  145.             {
  146.                 // Drain Essence from EssenceProvider / increase drainedEssence
  147.                 ((IEssenceProvider) this.essenceProvider).drainEssence(getNeededEssenceForInfusion(this.currentResult).getEssence(), 1);
  148.                 this.drainedEssence ++;
  149.  
  150.                 // Check if drainedEssence equals needed Essence for Infusion
  151.                 if (this.drainedEssence == getNeededEssenceForInfusion(this.currentResult).getAmount())
  152.                 {
  153.                     // Stop Infusion, infuseItem and mark for Update
  154.                     this.drainedEssence = 0;
  155.                     this.isInfusing = false;
  156.                     infuseCrystal();
  157.  
  158.                     markDirty();
  159.                 }
  160.             }
  161.  
  162.             // Infuser not running or no EssenceProvider but drainedEssence ... decrease drained Essence
  163.             else if (this.drainedEssence > 0)
  164.                 this.drainedEssence --;
  165.         }
  166.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement