Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void update()
- {
- boolean needInfusingUpdate = false;
- // Client - Only Actions
- if (this.worldObj.isRemote)
- {
- // If Infusing spawn Runes
- if (this.isInfusing)
- {
- if (worldObj.rand.nextInt(20) == 0)
- MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
- pos.getZ() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
- if (worldObj.rand.nextInt(20) == 0)
- MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
- pos.getZ() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
- if (worldObj.rand.nextInt(20) == 0)
- MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
- pos.getZ() + 0.5 + worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
- if (worldObj.rand.nextInt(20) == 0)
- MageTechHelper.spawnEntityFX(new EntityRuneFX(worldObj, pos.getX() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), pos.getY(),
- pos.getZ() - 0.5 - worldObj.rand.nextFloat() * worldObj.rand.nextInt(3), 0, 0.01, 0));
- }
- }
- // Server - Only Actions
- else
- {
- // Check if ActiveInfuser and Place, else disableInfuser
- if (this.isActiveInfuser && !hasFlat7x7())
- {
- this.isActiveInfuser = false;
- this.isInfusing = false;
- needInfusingUpdate = true;
- }
- // Check if ActiveInfuser and EmptyCrystal else stop process
- if (this.isActiveInfuser && (!hasCrystal() || getCrystal() != MageTechItems.crystal_Empty))
- {
- this.isInfusing = false;
- needInfusingUpdate = true;
- }
- // Check if ActiveInfuser and has EmptyCrystal
- if (this.isActiveInfuser() && this.hasCrystal() && this.getCrystal() == MageTechItems.crystal_Empty)
- {
- // Get all ItemEntities in Range of the Infuser
- List nearItems = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.fromBounds
- (this.pos.getX() - 3, this.pos.getY(), this.pos.getZ() - 3, this.pos.getX() + 3, this.pos.getY() + 1, this.pos.getZ() + 3));
- // Check for available InfusionRecipes and set craftingResults
- if (nearItems.size() > 0 && RecipesCrystalInfuser.infusing().hasCraftingResult(nearItems))
- this.craftingResults = RecipesCrystalInfuser.infusing().getCraftingResults(nearItems);
- else
- this.craftingResults = null;
- // Check for craftingResults
- if (this.craftingResults != null)
- {
- // Has EssenceProvider
- if (this.essenceProvider != null)
- {
- // EssenceProvider empty ... find new one if possible
- if (((IEssenceProvider) this.essenceProvider).getRemainingEssence(getNeededEssenceForInfusion(this.currentResult).getEssence()) == 0)
- this.essenceProvider = EssenceSystem.getClosestEssenceProvider(this, getNeededEssenceForInfusion(this.currentResult).getEssence());
- // Checks if status of isInfusing will change ... update?
- boolean hasProvider = this.essenceProvider != null;
- if (this.isInfusing != hasProvider)
- needInfusingUpdate = true;
- // Set isInfusing true if has EssenceProvider
- this.isInfusing = this.essenceProvider != null;
- }
- // Has no EssenceProvider
- else
- {
- // No Infusion "In Progress"
- if (this.drainedEssence == 0)
- {
- // CurrentResult is last Result in list ...
- if (this.currentResult == this.craftingResults.get(this.craftingResults.size() - 1))
- {
- // Wait a short delay and then reset CurrentResult
- this.providerSearchDelay ++;
- if (this.providerSearchDelay == 10)
- {
- this.providerSearchDelay = 0;
- this.currentResult = null;
- }
- }
- // CurrentResult is not last Result, try to find a EssenceProvider for one of the other available Infusions
- while (RecipesCrystalInfuser.infusing().getNextCraftingResult(this.craftingResults, this.currentResult) != null)
- {
- this.currentResult = RecipesCrystalInfuser.infusing().getNextCraftingResult(this.craftingResults, this.currentResult);
- this.essenceProvider = EssenceSystem.getClosestEssenceProvider(this, getNeededEssenceForInfusion(this.currentResult).getEssence());
- if (this.essenceProvider != null)
- break;
- }
- }
- // Still Infusion "In Progress"
- else
- {
- // Wait a short delay and then search for new EssenceProvider
- this.providerSearchDelay ++;
- if (this.providerSearchDelay == 10)
- {
- this.providerSearchDelay = 0;
- this.essenceProvider = EssenceSystem.getClosestEssenceProvider(this, getNeededEssenceForInfusion(this.currentResult).getEssence());
- }
- }
- // Checks if status of isInfusing will change ... update?
- boolean hasProvider = this.essenceProvider != null;
- if (this.isInfusing != hasProvider)
- needInfusingUpdate = true;
- // Set isInfusing true if has EssenceProvider
- this.isInfusing = this.essenceProvider != null;
- }
- }
- // Update the state of IsInfusing on the Client (For Rendering)
- if (needInfusingUpdate)
- ServerClientSyncHelper.synchSocketCrystalIsInfusing(this, this.isInfusing);
- }
- // If ActiveInfuser, isInfusing and has EssenceProvider
- if (this.isActiveInfuser && this.isInfusing && this.essenceProvider != null)
- {
- // Drain Essence from EssenceProvider / increase drainedEssence
- ((IEssenceProvider) this.essenceProvider).drainEssence(getNeededEssenceForInfusion(this.currentResult).getEssence(), 1);
- this.drainedEssence ++;
- // Check if drainedEssence equals needed Essence for Infusion
- if (this.drainedEssence == getNeededEssenceForInfusion(this.currentResult).getAmount())
- {
- // Stop Infusion, infuseItem and mark for Update
- this.drainedEssence = 0;
- this.isInfusing = false;
- infuseCrystal();
- markDirty();
- }
- }
- // Infuser not running or no EssenceProvider but drainedEssence ... decrease drained Essence
- else if (this.drainedEssence > 0)
- this.drainedEssence --;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement