FluidHelper.FillStatus fillStatus; IErrorLogic errorLogic = getErrorLogic(); errorLogic.clearErrors(); errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_FLUID, EnumErrorCode.NO_RESOURCE_LIQUID); errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_SPACE, EnumErrorCode.NO_SPACE_INVENTORY); errorLogic.setCondition(emptyStatus == FluidHelper.FillStatus.NO_SPACE_FLUID, EnumErrorCode.NO_SPACE_TANK); if (emptyStatus == FillStatus.INVALID_INPUT || fillStatus == FillStatus.INVALID_INPUT || errorLogic.hasErrors()) { currentRecipe = null; return false;
/** * Return true if the tile given in parameter activates the trigger, given the parameters. */ @Override public boolean isTriggerActive(TileEntity tile, EnumFacing side, IStatementContainer source, IStatementParameter[] parameters) { if (!(tile instanceof IErrorLogicSource)) { return false; } IErrorLogicSource apiary = (IErrorLogicSource) tile; return apiary.getErrorLogic().contains(EnumErrorCode.NO_QUEEN); } }
@Override public void onPacketData(PacketBufferForestry data, EntityPlayer player) { Entity entity = data.readEntityById(player.world); if (entity instanceof IErrorLogicSource) { IErrorLogicSource errorSourceTile = (IErrorLogicSource) entity; IErrorLogic errorLogic = errorSourceTile.getErrorLogic(); errorLogic.readData(data); } } }
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; }
@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(); } } }
@BasicObjectMethod.Inject( value = IErrorLogicSource.class, modId = Constants.MOD_ID, doc = "function():table -- Get any errors preventing operation" ) public static Object[] getErrors(IContext<IErrorLogicSource> context, Object[] arg) { return new Object[]{ context.getTarget().getErrorLogic().getErrorStates().stream() .map(IErrorState::getUniqueName) .collect(LuaList.toLuaList()).asMap() }; } }
@Override protected boolean hasErrors() { return delegate.getErrorLogic().hasErrors(); }
@Override protected void writeData(PacketBufferForestry data) { data.writeEntityById(entity); errorLogic.writeData(data); }
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 void detectAndSendChanges() { super.detectAndSendChanges(); if (entity instanceof IErrorLogicSource) { IErrorLogicSource errorLogicSource = (IErrorLogicSource) entity; ImmutableSet<IErrorState> errorStates = errorLogicSource.getErrorLogic().getErrorStates(); if (previousErrorStates == null || !errorStates.equals(previousErrorStates)) { PacketErrorUpdateEntity packet = new PacketErrorUpdateEntity(entity, errorLogicSource); sendPacketToListeners(packet); } previousErrorStates = errorStates; } } }
private boolean isThrottled(IEffectData storedData, IBeeHousing housing) { if (requiresWorkingQueen && housing.getErrorLogic().hasErrors()) { return true; } int time = storedData.getInteger(0); time++; storedData.setInteger(0, time); if (time < throttle) { return true; } // Reset since we are done throttling. storedData.setInteger(0, 0); return false; }
@Override protected void writeData(PacketBufferForestry data) { data.writeBlockPos(pos); errorLogic.writeData(data); }
errorLogic.clearErrors(); errorLogic.setCondition(!hasSpace, EnumErrorCode.NO_SPACE_INVENTORY); errorLogic.setCondition(!hasDrone, EnumErrorCode.NO_DRONE); return !errorLogic.hasErrors(); if (errorLogic.setCondition(queen == null, EnumErrorCode.NO_QUEEN)) { setActive(false); beeProgress = 0; errorLogic.setCondition(true, errorState); errorLogic.setCondition(!hasFlowers, EnumErrorCode.NO_FLOWER); boolean canWork = !errorLogic.hasErrors(); if (active != canWork) { setActive(canWork);
@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; }
ImmutableSet<IErrorState> errorStates = errorLogicSource.getErrorLogic().getErrorStates();
@Override public void onUpdate() { if (new Random().nextInt(2400) == 0) { TileEntity tile = this.getMachine().getTileEntity(); if (tile instanceof TileExtraBeeAlveary) { final IBeeHousing house = ((TileExtraBeeAlveary) tile).getMultiblockLogic().getController(); if (house != null && !house.getErrorLogic().hasErrors()) { final ItemStack queenStack = house.getBeeInventory().getQueen(); final IBee queen = (queenStack.isEmpty()) ? null : Utils.getBeeRoot().getMember(queenStack); if (queen != null) { final ItemStack larvae = Utils.getBeeRoot().getMemberStack(Utils.getBeeRoot().getBee(queen.getGenome()), EnumBeeType.LARVAE); new TransferRequest(larvae, this.getInventory()).transfer(null, true); } } } } } }
/** * Return true if the tile given in parameter activates the trigger, given the parameters. */ @Override public boolean isTriggerActive(TileEntity tile, EnumFacing side, IStatementContainer source, IStatementParameter[] parameters) { if (!(tile instanceof IErrorLogicSource)) { return false; } IErrorLogicSource apiary = (IErrorLogicSource) tile; return apiary.getErrorLogic().contains(EnumErrorCode.NO_DRONE); }
@Override public void onPacketData(PacketBufferForestry data, EntityPlayer player) { BlockPos pos = data.readBlockPos(); TileUtil.actOnTile(player.world, pos, IErrorLogicSource.class, errorSourceTile -> { IErrorLogic errorLogic = errorSourceTile.getErrorLogic(); errorLogic.readData(data); }); } }
@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; }