private boolean tryAddPending() { if (pendingProducts.isEmpty()) { return false; } ItemStack next = pendingProducts.peek(); boolean added = InventoryUtil.tryAddStack(this, next, InventoryCentrifuge.SLOT_PRODUCT_1, InventoryCentrifuge.SLOT_PRODUCT_COUNT, true); if (added) { pendingProducts.pop(); if (pendingProducts.isEmpty()) { craftPreviewInventory.setInventorySlotContents(0, ItemStack.EMPTY); } } getErrorLogic().setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY); return added; }
private boolean tryAddPending() { if (pendingProduct == null) { return false; } boolean added = InventoryUtil.tryAddStack(this, pendingProduct, InventoryMoistener.SLOT_PRODUCT, 1, true); getErrorLogic().setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY); if (added) { pendingProduct = null; } return added; }
@Override public boolean hasWork() { checkRecipe(); checkFuel(); int fermented = Math.min(fermentationTime, fuelCurrentFerment); boolean hasRecipe = currentRecipe != null; boolean hasFuel = fuelBurnTime > 0; boolean hasResource = fermentationTime > 0 || !getStackInSlot(InventoryFermenter.SLOT_RESOURCE).isEmpty(); FluidStack drained = resourceTank.drain(fermented, false); boolean hasFluidResource = drained != null && drained.amount == fermented; boolean hasFluidSpace = true; if (hasRecipe) { int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier); Fluid output = currentRecipe.getOutput(); FluidStack fluidStack = new FluidStack(output, productAmount); hasFluidSpace = productTank.fillInternal(fluidStack, false) == fluidStack.amount; } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL); errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE); errorLogic.setCondition(!hasFluidResource, EnumErrorCode.NO_RESOURCE_LIQUID); errorLogic.setCondition(!hasFluidSpace, EnumErrorCode.NO_SPACE_TANK); return hasRecipe && hasFuel && hasResource && hasFluidResource && hasFluidSpace; }
@Override public boolean hasWork() { if (updateOnInterval(20)) { checkRecipe(); } boolean hasRecipe = currentRecipe != null; boolean hasLiquidResources = true; boolean hasItemResources = true; boolean canAdd = true; if (hasRecipe) { hasLiquidResources = removeLiquidResources(false); hasItemResources = removeItemResources(false); ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getOutput(); canAdd = InventoryUtil.tryAddStack(this, pendingProduct, InventoryCarpenter.SLOT_PRODUCT, InventoryCarpenter.SLOT_PRODUCT_COUNT, true, false); } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID); errorLogic.setCondition(!hasItemResources, EnumErrorCode.NO_RESOURCE_INVENTORY); errorLogic.setCondition(!canAdd, EnumErrorCode.NO_SPACE_INVENTORY); return hasRecipe && hasItemResources && hasLiquidResources && canAdd; }
@Override public boolean hasWork() { if (!pendingProducts.isEmpty()) { return true; } checkRecipe(); boolean hasResource = !getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE).isEmpty(); IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE); return hasResource; }
/** * The trade station should show errors for missing stamps and paper first. * Once it is able to send letters, it should display other error states. */ @Override public void updateServerSide() { if (!isLinked() || !updateOnInterval(10)) { return; } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasPostageMin(3), EnumErrorCode.NO_STAMPS); errorLogic.setCondition(!hasPaperMin(2), EnumErrorCode.NO_PAPER); IInventory inventory = getInternalInventory(); ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD); errorLogic.setCondition(tradeGood.isEmpty(), EnumErrorCode.NO_TRADE); boolean hasRequest = hasItemCount(TradeStation.SLOT_EXCHANGE_1, TradeStation.SLOT_EXCHANGE_COUNT, ItemStack.EMPTY, 1); errorLogic.setCondition(!hasRequest, EnumErrorCode.NO_TRADE); if (!tradeGood.isEmpty()) { boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.getCount()); errorLogic.setCondition(!hasSupplies, EnumErrorCode.NO_SUPPLIES); } if (inventory instanceof TradeStation && updateOnInterval(200)) { boolean canReceivePayment = ((TradeStation) inventory).canReceivePayment(); errorLogic.setCondition(!canReceivePayment, EnumErrorCode.NO_SPACE_INVENTORY); } }
@Override public boolean hasWork() { checkRecipe(); boolean hasResources = inventory.hasResources(); boolean hasRecipe = true; boolean canFill = true; boolean canAdd = true; if (hasResources) { hasRecipe = currentRecipe != null; if (hasRecipe) { FluidStack resultFluid = currentRecipe.getFluidOutput(); canFill = productTank.fillInternal(resultFluid, false) == resultFluid.amount; if (!currentRecipe.getRemnants().isEmpty()) { canAdd = inventory.addRemnant(currentRecipe.getRemnants(), false); } } } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!canFill, EnumErrorCode.NO_SPACE_TANK); errorLogic.setCondition(!canAdd, EnumErrorCode.NO_SPACE_INVENTORY); return hasResources && hasRecipe && canFill && canAdd; }
private void setAddress(IMailAddress address) { Preconditions.checkNotNull(address, "address must not be null"); if (this.address.isValid() && this.address.equals(address)) { return; } if (!world.isRemote) { IErrorLogic errorLogic = getErrorLogic(); boolean hasValidTradeAddress = PostManager.postRegistry.isValidTradeAddress(world, address); errorLogic.setCondition(!hasValidTradeAddress, EnumErrorCode.NOT_ALPHANUMERIC); boolean hasUniqueTradeAddress = PostManager.postRegistry.isAvailableTradeAddress(world, address); errorLogic.setCondition(!hasUniqueTradeAddress, EnumErrorCode.NOT_UNIQUE); if (hasValidTradeAddress & hasUniqueTradeAddress) { this.address = address; PostManager.postRegistry.getOrCreateTradeStation(world, getOwnerHandler().getOwner(), address); } } else { this.address = address; } }
@Override public boolean hasWork() { moveSpecimenToAnalyzeSlot(); ItemStack specimen = getStackInSlot(InventoryAnalyzer.SLOT_ANALYZE); boolean hasSpecimen = !specimen.isEmpty(); boolean hasResource = true; boolean hasSpace = true; if (hasSpecimen) { hasSpace = InventoryUtil.tryAddStack(invOutput, specimen, true, false); if (specimenToAnalyze != null && !specimenToAnalyze.isAnalyzed()) { FluidStack drained = resourceTank.drain(HONEY_REQUIRED, false); hasResource = drained != null && drained.amount == HONEY_REQUIRED; } } getErrorLogic().setCondition(!hasSpecimen, EnumErrorCode.NO_SPECIMEN); getErrorLogic().setCondition(!hasResource, EnumErrorCode.NO_RESOURCE_LIQUID); getErrorLogic().setCondition(!hasSpace, EnumErrorCode.NO_SPACE_INVENTORY); return hasSpecimen && hasResource && hasSpace; }
@Override public void updateServerSide() { super.updateServerSide(); if (!updateOnInterval(20)) { return; } // Check if we have suitable items waiting in the item slot FluidHelper.drainContainers(tankManager, this, InventoryEngineBiogas.SLOT_CAN); IErrorLogic errorLogic = getErrorLogic(); boolean hasHeat = getHeatLevel() > 0.2 || heatingTank.getFluidAmount() > 0; errorLogic.setCondition(!hasHeat, EnumErrorCode.NO_HEAT); boolean hasFuel = burnTank.getFluidAmount() > 0 || fuelTank.getFluidAmount() > 0; errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL); }
@Override public boolean hasWork() { checkRecipe(); boolean hasRecipe = currentRecipe != null; boolean hasTankSpace = true; boolean hasLiquidResource = true; if (hasRecipe) { FluidStack fluidStack = currentRecipe.getOutput(); hasTankSpace = productTank.fillInternal(fluidStack, false) == fluidStack.amount; if (bufferedLiquid == null) { int cycles = currentRecipe.getCyclesPerUnit(); FluidStack input = currentRecipe.getInput(); int drainAmount = cycles * input.amount; FluidStack drained = resourceTank.drain(drainAmount, false); hasLiquidResource = drained != null && drained.amount == drainAmount; if (hasLiquidResource) { bufferedLiquid = new FluidStack(input, drainAmount); resourceTank.drain(drainAmount, true); } } } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!hasTankSpace, EnumErrorCode.NO_SPACE_TANK); errorLogic.setCondition(!hasLiquidResource, EnumErrorCode.NO_RESOURCE_LIQUID); return hasRecipe && hasLiquidResource && hasTankSpace; }
@Override public boolean hasWork() { boolean hasRecipe = true; boolean hasLiquidResources = true; boolean hasResources = true; ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN); RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory); if (!recipePair.isEmpty()) { IFabricatorRecipe recipe = recipePair.getRecipe(); NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT); hasResources = removeFromInventory(crafting, recipePair, false); FluidStack toDrain = recipe.getLiquid(); FluidStack drained = moltenTank.drainInternal(toDrain, false); hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain); } else { hasRecipe = false; } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID); errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE_INVENTORY); return hasRecipe; }
@Override public void updateServerSide() { IErrorLogic errorLogic = getErrorLogic(); //No work to be done if IC2 is unavailable. if (errorLogic.setCondition(ic2EnergySink == null, EnumErrorCode.NO_ENERGY_NET)) { return; } ic2EnergySink.update(); super.updateServerSide(); if (forceCooldown) { return; } if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) { replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY); } //Updating of gui delayed to prevent it from going crazy if (!updateOnInterval(80)) { return; } boolean canUseEnergy = ic2EnergySink.canUseEnergy(euConfig.euForCycle); errorLogic.setCondition(!canUseEnergy, EnumErrorCode.NO_FUEL); }
public void checkRecipe() { IMoistenerRecipe sameRec = MoistenerRecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(InventoryMoistener.SLOT_RESOURCE)); if (currentRecipe != sameRec) { currentRecipe = sameRec; resetRecipe(); } getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NO_RECIPE); }
private boolean cullCrop(ICrop crop) { final int fertilizerConsumption = Math.round(logic.getFertilizerConsumption() * Config.fertilizerModifier * 2); IErrorLogic errorLogic = getErrorLogic(); // Check fertilizer Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption); if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) { return false; } // Check water float hydrationModifier = hydrationManager.getHydrationModifier(); int waterConsumption = logic.getWaterConsumption(hydrationModifier); FluidStack requiredLiquid = new FluidStack(FluidRegistry.WATER, waterConsumption); boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid); if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_LIQUID_FARM)) { return false; } NonNullList<ItemStack> harvested = crop.harvest(); if (harvested != null) { // Remove fertilizer and water fertilizerManager.removeFertilizer(inventory, fertilizerConsumption); removeLiquid(requiredLiquid); inventory.stowHarvest(harvested, pendingProduce); } return true; }
@Override public void updateServerSide() { if (updateOnInterval(20)) { IErrorLogic errorLogic = getErrorLogic(); BlockPos pos = getPos(); Biome biome = world.getBiome(pos); errorLogic.setCondition(!biome.canRain(), EnumErrorCode.NO_RAIN_BIOME); BlockPos posAbove = pos.up(); boolean hasSky = world.canBlockSeeSky(posAbove); errorLogic.setCondition(!hasSky, EnumErrorCode.NO_SKY_RAIN_TANK); errorLogic.setCondition(!world.isRainingAt(posAbove), EnumErrorCode.NOT_RAINING); if (!errorLogic.hasErrors()) { resourceTank.fillInternal(WATER_PER_UPDATE, true); } containerFiller.updateServerSide(); } if (canDumpBelow == null) { canDumpBelow = FluidHelper.canAcceptFluid(world, getPos().down(), EnumFacing.UP, STACK_WATER); } if (canDumpBelow) { if (dumpingFluid || updateOnInterval(20)) { dumpingFluid = dumpFluidBelow(); } } }
@Override public void updateServerSide() { super.updateServerSide(); if (!updateOnInterval(40)) { return; } dumpStash(); int fuelSlot = getFuelSlot(); boolean hasFuel = fuelSlot >= 0 && determineBurnDuration(getInternalInventory().getStackInSlot(fuelSlot)) > 0; getErrorLogic().setCondition(!hasFuel, EnumErrorCode.NO_FUEL); }
private void updateTemperature(IErrorLogic errorLogic, IClimateState changedState) { IClimateManipulator manipulator = transformer.createManipulator(ClimateType.TEMPERATURE).setAllowBackwards().build(); EnergyManager energyManager = getEnergyManager(); int currentCost = getEnergyCost(changedState); if (energyManager.extractEnergy(currentCost, true) > 0) { IClimateState simulatedState = manipulator.addChange(true); int energyCost = getEnergyCost(simulatedState); if (energyManager.extractEnergy(energyCost, true) > 0) { energyManager.extractEnergy(energyCost, false); manipulator.addChange(false); } else { energyManager.extractEnergy(currentCost, false); } errorLogic.setCondition(false, EnumErrorCode.NO_POWER); } else { manipulator.removeChange(false); errorLogic.setCondition(true, EnumErrorCode.NO_POWER); } manipulator.finish(); }
@Override public void updateServerSide() { if (updateOnInterval(20)) { FluidHelper.drainContainers(tankManager, this, InventoryGenerator.SLOT_CAN); } IErrorLogic errorLogic = getErrorLogic(); // No work to be done if IC2 is unavailable. if (errorLogic.setCondition(ic2EnergySource == null, EnumErrorCode.NO_ENERGY_NET)) { return; } ic2EnergySource.update(); if (resourceTank.getFluidAmount() > 0) { GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid()); if (resourceTank.canDrainFluidType(fuel.getFuelConsumed()) && ic2EnergySource.getFreeCapacity() >= fuel.getEu()) { ic2EnergySource.addEnergy(fuel.getEu()); this.tickCount++; if (tickCount >= fuel.getRate()) { tickCount = 0; resourceTank.drain(fuel.getFuelConsumed().amount, true); } } } boolean hasFuel = resourceTank.getFluidAmount() > 0; errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL); }
private boolean checkRecipe() { ISqueezerRecipe matchingRecipe = null; if (inventory.hasResources()) { NonNullList<ItemStack> resources = inventory.getResources(); if (currentRecipe != null && ItemStackUtil.containsSets(currentRecipe.getResources(), resources, true, false) > 0) { matchingRecipe = currentRecipe; } else { matchingRecipe = SqueezerRecipeManager.findMatchingRecipe(resources); } } if (currentRecipe != matchingRecipe) { currentRecipe = matchingRecipe; if (currentRecipe != null) { int recipeTime = currentRecipe.getProcessingTime(); setTicksPerWorkCycle(recipeTime * TICKS_PER_RECIPE_TIME); setEnergyPerWorkCycle(recipeTime * ENERGY_PER_RECIPE_TIME); } } getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NO_RECIPE); return currentRecipe != null; }